RHEL 7 or CentOS 7: How to work with XFS filesystem: Backup/Restore/Create/Extend Operations ?

XFS stand for Extents File System.

XFS was first created by Silicon Graphics INC in 1993. In 2001, its support in included in Linux kernel.

Till RHEL 6, we have ext3/ext4 filesystem i.e. extended file system available.

However from RHEL 7 onwards, we have XFS filesystem available as default root filesystem.

Let us have a look the benefits of XFS filesystem and how to work with this in RHEL 7 or Centos 7.


Features of XFS filesystem
1. High performance Journalling filesystem
2. Supports filesystem size upto 500TB, and individual filesize limit upto 16TB.
3. Consistent File System:- Ability to recover or redo the transaction in case of a crash.
4. Separate disk for journalling:- The metadata journal of XFS filesystem can be saved on the same or different disk to recover the data in case of any issue with disk.
5. Allocation Groups :- Allocation Groups provides an ability to perform multiple application I/O threads simultaneously.
6. Native Backup/Restore:– Filesystem can be backed up while in use and can be restored as well.
xfsdump and xfsrestore utilities are provided for this task by XFS filesystem.
7. Snapshots:– XFS filesystem provides an ability to create an image of current state of filesystem also known as snapshots.
8. Delayed Allocation:– Helps to improve filesystem performance by writing files of unknown size while they are in use.
9. Spare file usage:- XFS provides an excellent feature of sparse files where a large file which contains zeros are eliminated and the data is represented by its metadata saving huge amount of filesystem space.
10. Online Resizing:- XFS filesystem can be resized and its space can be increased. However it can’t be reduced.

11. Atomic disk quotas:– Are available to limit disk space usage for multiple users.
12. DMAPI(Data Managament API) :– Helps to move rarely used data to another drive to save space on current XFS filesystem.


Working with XFS Filesystem
1. Creation of XFS filesystem

[root@ngelinux ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@ngelinux ~]# 

 


2. Mounting XFS filesystem

[root@ngelinux ~]# mkdir /Test
[root@ngelinux ~]# mount /dev/sdb1 /Test/
[root@ngelinux ~]# df -h /Test/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1      1014M   33M  982M   4% /Test
[root@ngelinux ~]# 

 


3. XFS Quota

To enable quota, we need to specify any of the below 
option with mount option of the partition.
uquota/uqnoenforce: User quotas
gquota/gqnoenforce: Group quotas
pquota/pqnoenforce: Project quota 

User Quota Setup example
a. Enable user quota

[root@ngelinux ~]# umount /Test/
[root@ngelinux ~]# mount -o quota /dev/sdb1 /Test/
[root@ngelinux ~]#

 

b. Check quota for a user, say saket.

[root@ngelinux ~]# quota saket
Disk quotas for user saket (uid 1000): none
[root@ngelinux ~]# 

 

c. Set quota limit for users on a XFS filesystem

# Inodes Limit
[root@ngelinux ~]# xfs_quota -x -c 'limit isoft=100 ihard=200 saket' /Test/

# Blocks Limit
[root@ngelinux ~]# xfs_quota -x -c 'limit bsoft=1000m bhard=1200m saket' /Test/

# Check quota report partition wise
[root@ngelinux ~]# xfs_quota -x -c 'report -h' /Test/
User quota on /Test (/dev/sdb1)
                        Blocks              
User ID      Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
root            0      0      0  00 [------]
saket           0  1000M   1.2G  00 [------]
[root@ngelinux ~]# 

 

d. Get XFS quota details.

[root@ngelinux ~]# xfs_quota -x -c state
User quota state on /Test (/dev/sdb1)
  Accounting: ON
  Enforcement: ON
  Inode: #67 (2 blocks, 2 extents)
Group quota state on /Test (/dev/sdb1)
  Accounting: OFF
  Enforcement: OFF
  Inode: #0 (0 blocks, 0 extents)
Project quota state on /Test (/dev/sdb1)
  Accounting: OFF
  Enforcement: OFF
  Inode: #0 (0 blocks, 0 extents)
Blocks grace time: [7 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]

 


4. Extending XFS Filesystem

We need to first increase the size of underlying partition and then grow the XFS filesystem.
[root@ngelinux ~]# xfs_growfs /Test/ -D 362144
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data size 362144 too large, maximum is 262144
[root@ngelinux ~]#

 


5. Repair XFS Filesystem

[root@ngelinux ~]# umount /dev/sdb1
[root@ngelinux ~]# xfs_repair /dev/sdb1
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...
Note - quota info will be regenerated on next quota mount.
done
[root@ngelinux ~]# 

 


6. Freeze/Unfreeze a XFS Mount Point

# Freeze with option -f
[root@ngelinux ~]# xfs_freeze -f /Test/
[root@ngelinux ~]# 

# Unfreeze with option -u
[root@ngelinux ~]# xfs_freeze -u /Test
[root@ngelinux ~]# 

 


7. Taking Backup of XFS Filesystem

## Backup the /boot partition to a file.
[root@ngelinux ~]# xfsdump -l 0 -f /Test/boot.xfsdump /boot
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control

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

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

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

xfsdump: WARNING: no session label specified
xfsdump: level 0 dump of ngelinux:/boot
xfsdump: dump date: Mon Mar 25 04:21:58 2019
xfsdump: session id: 7d81218c-2bfa-48da-b51c-16680407641b
xfsdump: session label: ""
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: 153714368 bytes
xfsdump: /var/lib/xfsdump/inventory created

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

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

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

xfsdump: WARNING: no media label specified
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 153318400 bytes
xfsdump: dump size (non-dir files) : 153047648 bytes
xfsdump: dump complete: 27 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /Test/boot.xfsdump OK (success)
xfsdump: Dump Status: SUCCESS
[root@ngelinux ~]# 

## Verifying the Backup.
[root@ngelinux ~]# df -h /Test/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1      1014M  179M  836M  18% /Test

[root@ngelinux ~]# df -h /boot/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1      1014M  179M  836M  18% /boot

[root@ngelinux ~]# du -sh /Test/boot.xfsdump 
147M	/Test/boot.xfsdump
[root@ngelinux ~]# 

 


8. Restoring XFS filesystem

[root@ngelinux ~]# xfsrestore -f /Test/boot.xfsdump /boot/
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.7 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description: 
xfsrestore: hostname: ngelinux
xfsrestore: mount point: /boot
xfsrestore: volume: /dev/sda1
xfsrestore: session time: Mon Mar 25 04:21:58 2019
xfsrestore: level: 0
xfsrestore: session label: ""
xfsrestore: media label: ""
xfsrestore: file system id: d4d03e1e-2b47-4756-9027-007716fef8dc
xfsrestore: session id: 7d81218c-2bfa-48da-b51c-16680407641b
xfsrestore: media id: ea790ef7-1b82-43e8-9cd4-a71a6fb1c083
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 12 directories and 382 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 8 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /Test/boot.xfsdump OK (success)
xfsrestore: Restore Status: SUCCESS
[root@ngelinux ~]# 

 

 

References:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/
https://www.linux.com/news/use-xfsfsr-keep-your-xfs-filesystem-optimal
http://www2.cs.uregina.ca/~hamilton/courses/330/notes/memory/paging.html
https://www.rootusers.com/how-to-defragment-an-xfs-file-system/

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments