XFS File System
XFS File System
XFS(Extent File system) is a default root filesystem in Redhat Linux ES 7 onwards (Linux
Kernel with version 2.4). This might indicates Redhat shifting their “ext” FS paradigm to
XFS going forward.
1. Handles large files much better and more efficiently than ext3.
2. Minimizes both storage access time (read/write) and processing power (very low CPU
usage).
3. Allows users to defrag files to further minimize read/write times.
4. Has been around for a long time, stable (ext4 is comparatively new)
Let’s take a deep dive into some of the practice examples –
# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- 9.51g 0
test 2 0 0 wz--n- 3.99g 3.99g
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- 9.51g 0
/dev/sdb test lvm2 a-- 2.00g 2.00g
/dev/sdc test lvm2 a-- 2.00g 2.00g
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy
%Sync Convert
root rhel -wi-ao---- 8.51g
swap rhel -wi-ao---- 1.00g
lvol0 test -wi-a----- 100.00m
Now that we have logical volume "lvol0" in place. Let us create a XFS filesystem using
mkfs.xfs command.
# mkfs.xfs /dev/test/lvol0
meta-data=/dev/test/lvol0 isize=256 agcount=32,
agsize=8473312 blks
= sectsz=512 attr=2,
projid32bit=0
data = bsize=4096
blocks=271145984, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=32768,
version=2
= sectsz=512 sunit=0 blks,
lazy-count=1
realtime =none extsz=4096 blocks=0,
rtextents=0
To create an XFS file system with a stripe-unit size of 32 KB and 6 units per stripe, you
would specify the su and sw arguments to the -d option, for example:
Page 2 of 5
# mkfs.xfs -d su=32k,sw=6 /dev/test/lvol1
# mkdir -p /first_xfs
# df -h /first_xfs
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/test-lvol0 84M 5.2M 79M 7% /first_xfs
BTW, XFS can increase on the fly. You need to use xfs_grow command to do that. Let’s
try it –
# df -h /new_xfs/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/test-lvol0 84M 5.2M 79M 7% /first_xfs
# xfs_growfs /first_xfs
meta-data=/dev/mapper/test-lvol0 isize=256 agcount=4,
agsize=6400 blks
= sectsz=512 attr=2,
projid32bit=1
= crc=0
data = bsize=4096 blocks=25600,
imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=4265,
version=2
= sectsz=512 sunit=0 blks, lazy-
count=1
realtime =none extsz=4096 blocks=0,
rtextents=0
# df -h /new_xfs/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/test-lvol0 184M 5.3M 179M 3% /first_xfs
One important note – you can’t shrink the XFS filesystem, The only way is to
destroy and recreate it then restore the data from backup.
How do I check the filesystem integrity? Is it same as fsck for XFS as well ?
No. There is no fsck for XFS but you have to use xfs_repair to do that. Before running
xfs_repair make sure you un-mount the filesystem.
Page 3 of 5
Warning: Do NOT run xfs_repair on a mounted filesystem! Serious data corruption can
occur if you dare try it!
Unless you are experiencing strange filesystem-related errors or crashes, you may never
need to run xfs_repair.
# umount /dev/sda3
# xfs_repair /dev/sda3
Phase 1 - find and verify superblock...
Phase 2 - using internal log
- zero log...
- scan filesystem freespace and inode maps...
- found root inode chunk
Phase 3 - for each AG...
- scan and clear agi unlinked lists...
- process known inodes and perform inode discovery...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
- process newly discovered inodes...
Phase 4 - check for duplicate blocks...
- setting up duplicate extent list...
- check for inodes claiming duplicate blocks...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
Phase 5 - rebuild AG headers and trees...
- reset superblock...
Phase 6 - check inode connectivity...
- resetting contents of realtime bitmap and summary
inodes
- traversing filesystem ...
- traversal finished ...
- moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done
# mount /dev/sda3
# xfs_freeze -f /first_xfs
# df -h /first_xfs/
Filesystem Size Used Avail Use% Mounted on
Page 4 of 5
/dev/mapper/uavg-lvol0 184M 288K 184M 1% /first_xfs
# cd /first_xfs
# touch foo
^C^C^C^C^C^C^C^X^C^C^C^C^C^C^C^C^C
# xfs_freeze -u /first_xfs
#
This is a baby step towards understanding XFS filesystem & I’m sure our sysadmin
curious minds will explore this topic !!!
Page 5 of 5