XFS is the default file system in RHEL7. To create a XFS file system:
# mkfs.xfs -f /dev/sdb
meta-data=/dev/sdb isize=256 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 asciici=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazycount=1
realtime =none extsz=4096 blocks=0, rtextents=0
The mkfs.xfs command has many options (man mkfs.xfs and xfs.org) but most of them need only be used when fine-tuning of the filesystem is required. The command mkfs -t xfs calls mkfs.xfs so using one or the other is a matter of personal preference with no practical difference. Let’s see some examples though:
# mkfs.xfs -b size=2048 /xfstest -> block size of 2K instead of the default 4K
# mkfs.xfs -d account=24 /xfstest -> 24 allocation groups for faster concurrent performance
# mkfs.xfs -l logdev=/dev/sdd1 /xfstest -> log device set to external device to speed up performance
# mkfs.xfs -s size=8192 /xfstest -> set sector size to 8K rather than the default 512 bytes
An interesting feature of XFS is the possibility of enforcing quotas (space, inodes and real-time) for users, groups and projects. That feature is disabled by default so the filesystem will need to be mounted (remounting won’t work!) with the options uquota, gquota and/or pquota as required:
# umount /xfs; mount -o uquota,gquota /xfs → user & group quotas enabled and enforced
# umount /xfs; mount -o uqnoenforce,gqnoenforce /xfs → user & group quotas not enforced
With the following command we set soft & hard limits for inodes & blocks for user marc in the /xfs mount point. The -x and -c flags stand for expert mode and command.
# xfs_quota -x -c ‘limit isoft=1000 ihard=1200 bsoft=100m bhard=120m marc’ /xfs
The next command sets the same limits for group accounting (see “-g” flag after limit) on the same file system:
# xfs_quota -x -c ‘limit -g isoft=1000 ihard=1200 bsoft=100m bhard=120m accounting’ /xfs
Every time we want to check on the utilisation of blocks & inodes we can do so with the command …
# xfs_quota -x -c ‘report -h’ /xfs
To implement quotas at the project level, first we need to make sure the project exists …
# echo “89:/xfs” >> /etc/projects → set /xfs as parent folder for projid 89
# echo “accounting:89” >> /etc/projid → create new projects
# xfs_quota -x -c ‘project -s accounting’ /xfs → initialise quotas
… and only then can we enforce limits:
# xfs_quota -x -c ‘project -p bhard=1g accounting’ /xfs → restrict to 1Gb the space utilisation
Unlike ext4, XFS file systems cannot be shrunk. But they can be grown without having to umount them.
# xfs_growfs /xfs → grows the file system to the size of the underlying device
# xfs_growfs /xfs -D 2097152 → sets the new size in file system blocks
To repair a corrupted XFS file system we can use:
# xfs_repair /dev/sdb → replays the log ending with a consistent file system
# xfs_repair -L /dev/sdb → clears the log because it is corrupted
. and brings the file system up with a possible data loss
To perform backups and restores of XFS file systems we use xfsdump and xfsrestore.
# xfsdump -l 0 -f /dev/st0 /xfs → performs a dump level 0 (non-incremental) of /xfs onto tape
To perform a simple restore we need the session ID of the backup which we can find with the command:
# xfsrestore -I
When we have identified the session ID we want to restore, we can proceed with …
# xfsrestore -f /dev/st0 -S <session ID> /xfs
If the backup was cumulative, we need to add the “-r” flag to the restore command:
# xfsrestore -f /dev/st0 -S <session ID> -r /xfs
If we want to perform an interactive restore (i.e. to restore just a few files), we can do so with:
# xfsrestore -f /dev/st0 -i /xfs
Out of all the XFS utilities we have not yet covered, the one we will use most often is xfs_info:
# xfs_info /xfs
meta-data=/dev/sdb isize=256 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 asciici=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazycount=1
realtime =none extsz=4096 blocks=0, rtextents=0
The other of XFS tools worth mentioning would be:
-
xfs_fsr: used to defragment XFS filesystems
-
xfs_bmap: used to map disk blocks used by files
-
xfs_admin: used to change configuration parameters but only on unmounted filesystems
-
xfs_copy: used to copy entire filesystems to one or more targets
-
xfs_metadump: used to dump XFS metadata onto a file
-
xfs_mdrestore: used to restore XFS metadata dump from files