Tag Archives: CentOS7 XFS

Expanding the file system based on XFS in LVM

did not contact CentsOS 7 before, do not understand its changed characteristics, accidentally in centos 7 contact LVM, the method to create LVM and 6 is no different, but the LVM is a little different, the use of the previous method for capacity expansion has not been effective, it took a long time to figure out its capacity expansion method. Xfs is the default file system type for CentOS7, and different file system types have different create, check, and adjust commands.

Xfs is the default file system type for CentOS7, and different file system types have different create, check, and adjust commands.

In the XFS file system, you can only increase the partition, not decrease it.

[root@localhost ~]# ls /lib//modules/3.10.0-229.20.1.el7.x86_64/kernel/fs   #View all file system types supported by the kernel
binfmt_misc.ko  ceph    dlm    fat      gfs2   lockd       nfs_common  overlayfs  udf
btrfs           cifs    exofs  fscache  isofs  mbcache.ko  nfsd        pstore     xfs
cachefiles      cramfs  ext4   fuse     jbd2   nfs         nls         squashfs

I’ve created new partitions and added them to the VG, and I’ve extended the physical boundaries.
When extending logical boundaries, errors are reported as follows:

[root@localhost ~]# resize2fs -p /dev/mapper/centos-root     
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block When trying to open the /dev/mapper/centos-root 时
Can't find a valid file system superblock.

First, I thought of using FSCK for repair, but it didn’t work. When I saw the error message, I knew that XFS file should be repaired with XfS_REPAIR

[root@localhost ~]# fsck /dev/mapper/centos-root      
fsck,from util-linux 2.23.2
If you wish to check the consistency of an XFS filesystem or
repair a damaged filesystem, see xfs_repair(8).

Then try to fix it, but it doesn’t work, you need to unmount it to fix it, and the filesystem is mounted to /, so don’t even think about it.

[root@localhost ~]# xfs_repair /dev/mapper/centos-root 
xfs_repair: /dev/mapper/centos-root contains a mounted filesystem
xfs_repair: /dev/mapper/centos-root contains a mounted and writable filesystem
 
fatal error -- couldn't initialize XFS library

Finally, a web search reveals that there is one more step to go after the logical extension of the XFS filesystem:

[root@localhost ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 95.00g                                                    
  swap centos -wi-ao----  3.88g             
[root@localhost ~]# df  -lh
File   System Capacity Used Available Used % Used Mount Points
/dev/mapper/centos-root   46G   42G  4.5G   91%/  ------------>46G
devtmpfs                 1.9G     0  1.9G    0% /dev
tmpfs                    1.9G  164K  1.9G    1% /dev/shm
tmpfs                    1.9G  8.7M  1.9G    1% /run
tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1                497M  208M  290M   42% /boot                                       
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root      #This step is required to perform the adjustment, after the expansion.
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=2987776 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=11951104, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=5835, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 11951104 to 24903680
 
[root@localhost ~]# df -lh
File System Capacity Used Available Used % Used Mount Points
/dev/mapper/centos-root   95G   42G   54G   44%/     ------------>Expansion has been completed
devtmpfs                 1.9G     0  1.9G    0% /dev
tmpfs                    1.9G  164K  1.9G    1% /dev/shm
tmpfs                    1.9G  8.7M  1.9G    1% /run
tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1                497M  208M  290M   42% /boot

XFS related common commands

xfs_admin: Adjusting various parameters of the xfs file system  
xfs_copy: copies the contents of the xfs file system to one or more targets (in parallel).  
xfs_db: debugging or inspecting the xfs file system (looking at file system fragments, etc.)  
xfs_check: checks the integrity of the xfs file system.  
xfs_bmap: View a block map of a file.  
xfs_repair: Attempts to repair damaged xfs filesystems  
xfs_fsr: Defragmentation  
xfs_quota: manages disk quotas for xfs filesystems  
xfs_metadump: copies the metadata of the xfs file system to a file  
xfs_mdrestore: restores metadata from a file to the xfs file system  
xfs_growfs: Resize an xfs file system (only expandable)  
xfs_freeze Suspend (-f) and Restore (-u) xfs filesystems
xfs_logprint: prints the xfs filesystem log.  
xfs_mkfile: Creates the xfs file system.  
xfs_info: Queries file system details  
xfs_ncheck: generate pathnames from i-numbers for XFS  
xfs_rtcp: XFS real-time copy command   
xfs_io: debugging xfs I/O paths

Note:
becomes ext2 after using the mke2fs command on the Xfs filesystem. You need to change the filesystem type in /etc/fstab!

This paper address: http://www.linuxprobe.com/lvm+xfs++.html