Home / Redhat-LINUX / What is XFS ? The Default Redhat Linux Filesystem

What is XFS ? The Default Redhat Linux Filesystem

XFS(Extend File system) is a default root filesystem in Redhat Linux ES 7 onwards. This shows redhat has plan to shift from ext filesystems. XFS filesystem is originally developed by  Silicon Graphics. XFS is a highly scalable, high-performance file system compare to ext4 and it supports up to 16 exabytes filesystem and 8 exabytes files.  XFS supports metadata journaling, which facilitates quicker crash recovery on the power failures and system crash.It can also be defragmented and extended while mounted and active.It also supports quota. 

Its a default filesystem in IRIX too.

Here we will see various operations of XFS.

1.Let me create a logical volume to format as XFS filesystem.

[root@RHEL7UA ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
[root@RHEL7UA ~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
[root@RHEL7UA ~]#
[root@RHEL7UA ~]# vgcreate uavg /dev/sdb /dev/sdc
Volume group "uavg" successfully created
[root@RHEL7UA ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- 9.51g 0
uavg 2 0 0 wz--n- 3.99g 3.99g
[root@RHEL7UA ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- 9.51g 0
/dev/sdb uavg lvm2 a-- 2.00g 2.00g
/dev/sdc uavg lvm2 a-- 2.00g 2.00g
[root@RHEL7UA ~]#
[root@RHEL7UA ~]# lvcreate -L 100 uavg
Logical volume "lvol0" created
[root@RHEL7UA ~]# 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 uavg -wi-a----- 100.00m
[root@RHEL7UA ~]#


2.We have the logical volume “lvol0” in place. Let us create a XFS filesystem using mkfs.xfs command.

[root@RHEL7UA ~]# mkfs.xfs /dev/uavg/lvol0
meta-data=/dev/uavg/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 log bsize=4096 blocks=4265, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@RHEL7UA ~]#


3.Let us mount it using mount command.

[root@RHEL7UA ~]# mkdir /new_xfs
[root@RHEL7UA ~]# mount -t xfs /dev/uavg/lvol0 /new_xfs
[root@RHEL7UA ~]# df -h /new_xfs
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/uavg-lvol0 84M 5.2M 79M 7% /new_xfs
[root@RHEL7UA ~]#


4.Can XFS filesystem to be grow it on fly ? Let us test it. You need to use xfs_grow command to do that. 

[root@RHEL7UA ~]# lvresize -L +100M /dev/uavg/lvol0
Extending logical volume lvol0 to 200.00 MiBs
Logical volume lvol0 successfully resized
[root@RHEL7UA ~]#
[root@RHEL7UA ~]# df -h /new_xfs/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/uavg-lvol0 84M 5.2M 79M 7% /new_xfs
[root@RHEL7UA ~]#
[root@RHEL7UA ~]# xfs_growfs /new_xfs
meta-data=/dev/mapper/uavg-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
data blocks changed from 25600 to 51200
[root@RHEL7UA ~]#

That;s too fast. 

5.Check the new size is reflected on mount point or not.

[root@RHEL7UA ~]# df -h /new_xfs/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/uavg-lvol0 184M 5.3M 179M 3% /new_xfs
[root@RHEL7UA ~]#


6.How can we check the filesystem integrity ? Is it same as fsck for XFS as well ? 
No. You have to use xfs_repair to do that .You have to un-mount it before doing the repair.That makes sense ?

[root@RHEL7UA ~]# xfs_repair /dev/mapper/uavg-lvol0
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
- agno = 4
- agno = 5
- agno = 6
- agno = 7
- 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
- agno = 4
- agno = 5
- agno = 6
- agno = 7
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
[root@RHEL7UA ~]#


7.Is it possible to shrink/reduce the XFS filesystem ? No.You can;t shrink or reduce the FS.
Only way is destroy and recreate it .Restore the data from backup.

8.XFS has lot of inbuilt features. You can freeze the filesystem is an one example. 
Freezing the FS can stop all the I/O to the filesystem.

[root@RHEL7UA ~]# xfs_freeze -f /new_xfs
[root@RHEL7UA ~]# df -h /new_xfs/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/uavg-lvol0 184M 288K 184M 1% /new_xfs
[root@RHEL7UA ~]#

Here is the test .

[root@RHEL7UA ~]# cd /new_xfs
[root@RHEL7UA new_xfs]# touch unixarena
^C^C^C^C^C^C^C^X^C^C^C^C^C^C^C^C^C

Finally i got the prompt after unfreeze it .

[root@RHEL7UA ~]# xfs_freeze -u /new_xfs
[root@RHEL7UA ~]#


9.Since you can’t shrink the filesystem , how easily to backup and restore the data after recreating the new filesystem on XFS ?

[root@RHEL7UA new_xfs]# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/uavg-lvol0 184M 12M 172M 7% /new_xfs
[root@RHEL7UA new_xfs]#

Take the backup (0 – refers full backup / similar to ufsdump :))

[root@RHEL7UA ~]# cd /new_xfs/
[root@RHEL7UA new_xfs]# ls -lrt |wc -l
54
[root@RHEL7UA new_xfs]#

[root@RHEL7UA ~]# xfsdump -l 0 -f /root/new_xfs_dump /new_xfs
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.3 (dump format 3.0) - type ^C for status and control

============================= dump label dialog ==============================

please enter label for this dump session (timeout in 300 sec)
-> new_fs
session label entered: "new_fs"

--------------------------------- end dialog ---------------------------------

xfsdump: level 0 dump of RHEL7UA:/new_xfs
xfsdump: dump date: Tue Dec 17 01:45:48 2013
xfsdump: session id: 71634d90-2a45-4bb9-b213-058b4d1b82b0
xfsdump: session label: "new_fs"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 311872 bytes
xfsdump: /var/lib/xfsdump/inventory created

============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)
-> 12172013
media label entered: "12172013"

--------------------------------- end dialog ---------------------------------

xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 197976 bytes
xfsdump: dump size (non-dir files) : 143272 bytes
xfsdump: dump complete: 20 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /root/new_xfs_dump OK (success)
xfsdump: Dump Status: SUCCESS
[root@RHEL7UA ~]#
[root@RHEL7UA ~]#

Re-create the filesystem with less size (The amount of space you want to shrink)

[root@RHEL7UA ~]# umount /new_xfs
[root@RHEL7UA ~]# lvremove /dev/uavg/lvol0
Do you really want to remove active logical volume lvol0? [y/n]: y
Logical volume "lvol0" successfully removed
[root@RHEL7UA ~]# lvcreate -L 100M uavg
Logical volume "lvol0" created
[root@RHEL7UA ~]# mkfs.xfs /dev/uavg/lvol0
meta-data=/dev/uavg/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 log bsize=4096 blocks=4265, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@RHEL7UA ~]# mount -t xfs /dev/uavg/lvol0 /new_xfs/
[root@RHEL7UA ~]#

Check the possibilities  of restore,

[root@RHEL7UA ~]# xfsrestore -I
file system 0:
fs id: 29bc1912-bfdd-4a3c-a671-b82486866a62
session 0:
mount point: RHEL7UA:/new_xfs
device: RHEL7UA:/dev/mapper/uavg-lvol0
time: Tue Dec 17 01:45:48 2013
session label: "new_fs"
session id: 71634d90-2a45-4bb9-b213-058b4d1b82b0
level: 0
resumed: NO
subtree: NO
streams: 1
stream 0:
pathname: /root/new_xfs_dump
start: ino 131 offset 0
end: ino 183 offset 0
interrupted: NO
media files: 1
media file 0:
mfile index: 0
mfile type: data
mfile size: 197976
mfile start: ino 131 offset 0
mfile end: ino 183 offset 0
media label: "12172013"
media id: 4fd4408f-1cea-4ae5-8f59-2b56bea7ae52
xfsrestore: Restore Status: SUCCESS
[root@RHEL7UA ~]#

As per the above output, the restore can be successful. Let me restore it. 

[root@RHEL7UA new_xfs]# ls -lrt
total 0
[root@RHEL7UA new_xfs]#
[root@RHEL7UA ~]# xfsrestore -f /root/new_xfs_dump -S 71634d90-2a45-4bb9-b213-058b4d1b82b0 -r /new_xfs/
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.3 (dump format 3.0) - type ^C for status and control
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: examining media file 0
xfsrestore: reading directories
xfsrestore: 1 directories and 52 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /root/new_xfs_dump OK (success)
xfsrestore: Restore Status: SUCCESS
[root@RHEL7UA ~]#

Verify the restore,

[root@RHEL7UA ~]# cd /new_xfs/
[root@RHEL7UA new_xfs]# ls -lrt |wc -l
54
[root@RHEL7UA new_xfs]#


That’s it. Hope you have enjoyed the XFS ride. 

Please leave a comment if you have any doubt .I will get back to you.

Thank you for visiting UnixArena.

VMTURBO-CLOUD-CAPACITY

One comment

  1. Thank you very much for portraying the uses of the various xfs utilities in real-world scenarios.

Leave a Reply

Your email address will not be published. Required fields are marked *