Introduction to XFS

XFS Filesystem and Linux

What is XFS?


XFS is a highly scalable, high-performance file journalling file system which was originally designed at Silicon Graphics, Inc in 1993. Originally XFS was used on Silicon Graphics Inc's own operating system Irix, however, it was later ported to the Linux kernel in 2001. Today XFS is supported by most Linux distributions and has now become the default filesystem on RHEL (Red Hat Enterprise Linux), Oracle Linux 7, CentOS 7 and many other distributions. Originally XFS was created to support extremely large filesystems with sizes of up to 16 exabytes and file sizes of up to 8 exabytes.

XFS supports metadata journalling allowing for quicker recovery after a system crash. The XFS file system can also be de-fragmented and enlarged while mounted and active. The XFS file system can not be reduced in size !



XFS features the following allocation schemes:


Extent based allocation
Stripe-aware allocation policies
Delayed allocation
Space pre-allocation
Delayed allocation and other performance optimizations affect XFS the same way that they do ext4. Namely, a program's writes to a an XFS file system are not guaranteed to be on-disk unless the program issues an fsync() call afterwards.

The XFS file system also supports the following:

Extended attributes (xattr), which allows the system to associate several additional name/value pairs per file.
Quota journalling, which avoids the need for lengthy quota consistency checks after a crash.
Project/directory quotas, allowing quota restrictions over a directory tree.
Subsecond timestamps


The Basic Layout of a XFS File System


An XFS filesystem can reside on a regular disk partition or on a logical volume. An XFS filesystem has up to three parts: a data section, a log section, and a real-time section. Using the default mkfs.xfs options, the real-time section is absent, and the log area is contained within the data section. The log section can be either separate from the data section or contained within it. The filesystem sections are divided into a certain number of blocks, whose size is specified with the -b option of the mkfs.xfs command.

The data section contains all the filesystem metadata (inodes, directories, indirect blocks) as well as the user file data for ordinary (non-real-time) files and the log area if the log is internal to the data section. The data section is divided into a number of allocation groups. The number and size of the allocation groups are chosen by mkfs.xfs so that there is normally a small number of equal sized groups. The number of allocation groups controls the amount of parallelism available in file and block allocation. It should be increased from the default if there is sufficient memory and a lot of allocation activity. The number of allocation groups should not be set very high, since this can cause large amounts of CPU time to be used by the filesystem, especially when the filesystem is nearly full.

More allocation groups are added (of the original size) when xfs_growfs is run. An example of this command in use can be seen in the xfs_growfs example below.

The log section (or area, if it is internal to the data section) is used to store changes to the file system metadata while the file system is running until those changes are made to the data section. Changes are written sequentially during normal operation and read only during a mount. When mounting a file system after a crash, the log is read to complete operations that were in progress at the time of the crash.

The real-time section is used to store the data of real-time files. These files have an attribute bit set through xfsctl after file creation, before any data was written to the file. The real-time section is divided into a number of extents of fixed size (specified at mkfs.xfs time). Each file in the real-time section has an extent size that is a multiple of the real-time section extent size.

Each allocation group contains several data structures. The first sector contains the superblock. For allocation groups after the first, the superblock is just a copy and is not updated after mkfs.xfs. The next three sectors contain information for block and inode allocation within the allocation group. Also contained within each allocation group are data structures to locate free blocks and inodes. These are located through the header structures.

Each XFS file system is labelled with a Universal Unique Identifier (UUID). The UUID is stored in every allocation group header and is used to help distinguish one XFS filesystem from another, therefore you should avoid using the "dd" utility or any other block by block copying programs to copy XFS filesystems. If two XFS filesystems on the same machine have the same UUID, xfsdump may become confused when carrying out an incremental backup or a resumed dump. xfsdump and xfsrestore are recommended for making copies of XFS filesystems. (see also xfs_copy)



Creating a XFS File System


To create a XFS file system, you can use the command mkfs.xfs /dev/device.

When using mkfs.xfs on a block device containing an existing file system, you should use the -f option to force an overwrite of that file system.

Below is an example of the mkfs.xfs command being issued on a CentOS 7 server. Once the command has run successfully, we issued the mount command. In this example, we are using a mount point of "xfs_test". This was created by issuing the command "mkdir /xfs_test". (see output below)



[root@centos07a ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=32704 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=130816, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0

[root@centos07a ~]# mount /dev/sdb1 /xfs_test
[root@centos07a ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/sdb1               xfs       508M   26M  482M   6% /xfs_test

Using LVM (Logical Volume Manager) to add space to an XFS file system


Generally to increase space you would use LVM (Logical Volume Manager. In the following example we will create a partition with a type of "8e" which denotes LVM. We will create a Physical Volume with the pvcreate command, create a VolumeGroup and define a Logical Volume. Next we will generate an XFS filesystem on the Logical Volume. For more information regarding LVM, follow the LVM link: Introduction to LVM

An overview of the basic process involved can be seen below:


Create a Partition using fdisk


In this example, we are going to create a partition using the disk partitioning tool "fdisk". The commands used to create the partition can be seen in the output below:



[root@centos07a ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4194303, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): 
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x340b4c69

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4194303     2096128   8e  Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

From the above output we can see that a Primary partition was created on device "/dev/sdb" with a partition number of "1" (/dev/sdb1). Type "8e" was specified for use with Logical Volume Management. The partition layout was then previewed using the option "p", and then our changes were written using the "w" option.


Create Logical Volume Manager Components: PV, VG and LV


Our next step is to create a Physical Volume comprising of the /dev/sdb1 partition. Next we then create a Volume Group called "vg01" and finally we create a Logical Volume that will use all available space within our Volume Group. The commands issued can be seen in the output below:



[root@centos07a ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

[root@centos07a ~]# vgcreate vg01 /dev/sdb1
  Volume group "vg01" successfully created

[root@centos07a ~]# lvcreate -n lv01 -l 100%VG vg01
  Logical volume "lv01" created

You can use the command "pvs" and "vgs" commands to display PV (Physical Volume) and VG (Volume Group) information:



[root@centos07a ~]# pvs
  PV         VG     Fmt  Attr PSize PFree
  /dev/sda2  centos lvm2 a--  7.51g    0 
  /dev/sdb1  vg01   lvm2 a--  2.00g    0 

[root@centos07a ~]# vgs
  VG     #PV #LV #SN Attr   VSize VFree
  centos   1   2   0 wz--n- 7.51g    0 
  vg01     1   1   0 wz--n- 2.00g    0 


From the above output we can see that the "pvs" command displays our device "/dev/sdb1" and its associated VG "vg01". The output from the "vgs" command indicates that our PV is only associated with one Volume Group and has a size of 2GB.


Create a XFS file system on a Logical Volume


Before you can use the storage that has been created, you will need to create a file system on the Logical Volume (LV). This is achieved using the "mkfs.xfs" command.



[root@centos07a ~]# mkfs.xfs /dev/vg01/lv01
meta-data=/dev/vg01/lv01         isize=256    agcount=4, agsize=130816 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=523264, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0


The "mkfs.xfs" command was issued against the path to the Logical Volume "/dev/vg01/lv01".


Create a Mount Point


Before you can start to use the file system, it first has to be mounted on a mount point. In the example below, we are using the mount point of "xfs_test". This mount point is created with the standard "mkdir" command.



[root@centos07a /]# mkdir xfs_test

Mount File system



[root@centos07a /]# mount /dev/vg01/lv01 xfs_test/

Once the file system has been successfully mounted, it is available for use.


Display information about a mounted File System with the df command


To display information about our mounted file system we can use the "df" command. In the example below, we used the "-h" parameter to display sizes in MB, GB... and the "-T" option displays the file system type. (In this example xfs)



[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/mapper/vg01-lv01   xfs       2.0G   33M  2.0G   2% /xfs_test

From the above output we can see that our xfs file system is 2GB in size and has the mount point of "/xfs_test".


Add a File System to the mount table /etc/fstab


Generally when you create a file system, you will want your file system to be automatically mounted after a system reboot. To auto mount your file system, you will need to add a line similar to the one below into your mount table "/etc/fstab":

Add an entry to "/etc/fstab"



/dev/sdb1               /xfs_test               xfs     defaults        0 0

In the above example, we have specified our device, its mount point, a type of "xfs". We are using the default settings and have specified no checking or dumping options. For more information regarding the mount table see our link: Mount Table


Extend xfs File System using LVM


In next part of this example we are going to add an additional disk to our system. Once this disk has been added, we will then add this space to the existing Volume Group "vg01" and then extend the Logical Volume "lv01". The commands used for this can be seen in the output below:


Create a New Partition on a newly added disk


Once again, we are going to use the partition tool "fdisk" to create our new partition for the new disk added. The commands used can be seen in the output below:



[root@centos07a ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1048575, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575, default 1048575): 
Using default value 1048575
Partition 1 of type Linux and of size 511 MiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdc: 536 MB, 536870912 bytes, 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x934cae77

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     1048575      523264   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Create a new Physical Volume


Next we create a new PV (Physical Volume using the device "/dev/sdc1".



[root@centos07a ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created

Add the new Physical Volume to an existing Volume Group


Here we are adding our new space to the existing Volume Group "vg01". This extra space will be then available to our Logical Volume. The command to add the new partition to our Volume Group is "vgextend".



[root@centos07a ~]# vgextend vg01 /dev/sdc1
  Volume group "vg01" successfully extended

Check PV and VG


If we now issue the "pvs" and vgs" commands again, we will now see the new additions:



[root@centos07a ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree  
  /dev/sda2  centos lvm2 a--    7.51g      0 
  /dev/sdb1  vg01   lvm2 a--    2.00g      0 
  /dev/sdc1  vg01   lvm2 a--  508.00m 508.00m

[root@centos07a ~]# vgs
  VG     #PV #LV #SN Attr   VSize VFree  
  centos   1   2   0 wz--n- 7.51g      0 
  vg01     2   1   0 wz--n- 2.49g 508.00m

From the above "pvs" command we can see that the new PV has been added with 508MB of space. The "vgs" command is now indicating that there are now two Physical Volumes associated with the Volume Group "vg01".


Extend a Logical Volume


To extend the Logical Volume, we are going to use the "lvextend command. In the example below we are extending the Logical Volume by 500MB. The file system will be automatically resized because we are using the "-r" option.



[root@centos07a /]# lvextend /dev/vg01/lv01 -L +500M -r
  Extending logical volume lv01 to 2.48 GiB
  Logical volume lv01 successfully resized
meta-data=/dev/mapper/vg01-lv01  isize=256    agcount=4, agsize=130816 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=523264, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 523264 to 651264

Use df to check File System


We can verify that the file system has now increased by issuing the "df" command. The output from this can be seen below.



[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/mapper/vg01-lv01   xfs       2.5G   33M  2.5G   2% /xfs_test

We can now see from the above output that we have 2.5GB of space now available to our xfs file system.

Important: You can not reduce a XFS filesystem, if you try you will get the following message:



[root@centos07a /]# lvreduce /dev/vg01/lv01 -L -500M -r
fsadm: Xfs filesystem shrinking is unsupported
  fsadm failed: 1
  Filesystem resize failed.

Method 2 for extending a XFS File System using the utility xfs_growfs


The following method allows you to extend the file system by using the "xfs_growfs" command. The xfs_growfs command is used to increase the size of a mounted XFS file system only if there is space on the underlying devices to accommodate the change. The xfs_growfs command does not require LVM to extend the file system as per the previous example.

The mount point argument that is passed is the pathname to the directory where the filesystem is mounted. The xfs filesystem must be mounted first before it can be grown. The contents of the file system are undisturbed, and the added space is then made available for additional file storage.

In the following example I am using a CentOS 7 server running in VirtualBox. Initially the disk used "/dev/sdb" is set to a size of 500MB. Our next step is to then create a XFS file system by issuing the "mkfs.xfs" command. The resulting file system can be seen after issuing the "df -hT" command. (The -h option displays a human readable format in MB, GB etc.. and the -T option displays the type of file system (XFS in this example).

After the file system was initially created, I then increased the size of the underlying disk by using the following VirtualBox command:



VBoxManage modifyhd "/home/john/VirtualBox VMs/CentOS_7/CentOS7_XFS_Test1.vdi" --resize 2048

An outline of the steps involved for this example are below:


Create xfs file system on a 500MB Disk


Create the xfs file system using the "mkfs.xfs" command:



[root@centos07a /]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0

Mount File System


Next we need to mount the file system using the mount command (syntax: mount /dev/device /mount_point)



[root@centos07a /]# mount /dev/sdb1 xfs_test/

Display XFS File System information


We can use the "df" command again to look at the size of our mounted xfs file system:



[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/sdb1               xfs       497M   26M  472M   6% /xfs_test

We can now see that our file system is mounted at mount point /xfs_test. You may wish to add your disk/filesystem into "/etc/fstab" so that it will be automatically mounted at system reboot. To do this, simply add a line similar to the one below into the file "/etc/fstab".


Example /etc/fstab entry



/dev/sdb1               /xfs_test               xfs     defaults        0 0

Shutdown Partition and Increase underlying Disk size


As we are using Oracle's VirtualBox software, we need to shutdown the partition first to increase the under lying disk. The shutdown command "shutdown -h now" can be used to cleanly shutdown your partition. Unfortunately, VirtualBox only allows the disk to be increased when it is not in use. The following command will be issued from the host computer. The "host" computer is the computer that is running the VirtualBox software.


VirtualBox - Increase Disk Size


The following command is issued to the host computer.



$ VBoxManage modifyhd "/home/john/VirtualBox VMs/CentOS_7/CentOS7_XFS_Test1.vdi" --resize 2048
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

The above command has now resized the virtual disk "CentOS7_XFS_Test1.vdi" to a size of 2GB. Notice the double quotes around the path name. Double quotes are needed as there are spaces within the path name name. If you are unsure of the name of the Virtualdisk that you created originally for your partition, you can "right click" on the name of your VM in the VirtualBox manager and select the option to "Show in file manager". Here you will see a list of all the virtual disks that have been allocated to your server.


Restart Server and Delete Original Partition


Once we have increased the under lying disk space, we will need to restart our server. Next we are going to use fdisk to delete our original partition and then recreate it again with more space. The disk in the example is known as "/dev/sdb".

Below are the steps taken using fdisk to accomplish the above task.



[root@centos07a /]# umount /xfs_test

[root@centos07a /]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x340b4c69

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     1026047      512000   83  Linux

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-4194303, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): 
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Remount xfs File System


Before we can increase a xfs file system, it needs to be mounted first.



[root@centos07a /]# mount /dev/sdb1 /xfs_test

We can issue the "df" command again to display our file system information.


[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/sdb1               xfs       497M   26M  472M   6% /xfs_test

From the above we can see that the file system on "xfs_test" is still indicating its original size.


Issue xfs_growfs against mount point


Next we are going to issue the "xfs_growfs" command:



[root@centos07a /]# xfs_growfs xfs_test/
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 128000 to 524032

The important information to look for when you issue this command can be found within the last line of the output. You are looking for an increase in size relating to data blocks. We can now issue the "df" command again to verify that the xfs_growfs command was successful:



[root@centos07a /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       6.7G  1.1G  5.7G  16% /
devtmpfs                devtmpfs  492M     0  492M   0% /dev
tmpfs                   tmpfs     498M     0  498M   0% /dev/shm
tmpfs                   tmpfs     498M  6.6M  491M   2% /run
tmpfs                   tmpfs     498M     0  498M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  100M  398M  20% /boot
/dev/sdb1               xfs       2.0G   26M  2.0G   2% /xfs_test

This time we can see that the file system is now 2GB in size.


Overview of Options that can be passed to the xfs_growfs utility



SYNOPSIS
       xfs_growfs  [  -dilnrx  ] [ -D size ] [ -e rtextsize ] [ -L size ] [ -m
       maxpct ] [ -t mtab ] [ -R size ] mount-point
       xfs_growfs -V

       xfs_info [ -t mtab ] mount-point
       xfs_info -V

Options that can be passed to the xfs_growfs utility


d | -D size

The "-d or -D" option is used to specify that the data section of the filesystem should be grown. If the "-D" size option is passed, then the data section is grown to the specified size. The "-d" option specifies that the data section is grown to the largest possible size. The size is specified in file system blocks.

-e

Allows the real-time extent size to be specified. This can also be specified with the mkfs.xfs command with the specified option of "-r extsize=nnnn".

-l | -L size

Specifies that the log section of the filesystem should be grown, shrunk, or moved. If the -L size option is given, the log section is changed to be that size, if possible. The size is expressed in file system blocks. The size of an internal log must be smaller than the size of an allocation group (this value is printed at mkfs time). If neither -i nor -x is given with -l, the log continues to be internal or external as it was before. [NOTE: These options are not implemented]

-m

Specify a new value for the maximum percentage of space in the file system that can be allocated as inodes. In mkfs.xfs(8) this is specified with -i maxpct=nn.

-n

Specifies that no change to the filesystem is to be made. The file system geometry is printed, and argument checking is performed, but no growth occurs.

-r | -R size

Specifies that the real time section of the file system should be grown. If the -R size option is given, the real time section is grown to that size, otherwise the real time section is grown to the largest size possible with the -r option. The size is expressed in filesystem blocks. The filesystem does not need to have contained a real time section before the xfs_growfs operation.

-t

Specifies an alternate mount table file.

-V

Prints the version number and exits. The mount point argument is not required with -V.


Summary of resizing a XFS file system


Although both of the methods used allowed you to increase the size of the XFS file system. Neither of the methods allowed us to reduce the size. The most common method of resizing a file system is to use the LVM (Logical Volume Manager) approach. LVM gives you the advantage of being able to add additional disk easily to an existing Volume Group and then use the lvextend command to increase the size of your filesystem.



An Overview of other xfs Utilities




Repairing a XFS File System with xfs_repair


Basic Syntax:

xfs_repair /dev/device

The xfs_repair utility is designed to repair file systems whether small or large very quickly. Unlike other file system repair tools, xfs_repair does not run at system boot time. xfs_repair replays its logs at mount time to ensure a consistent file system. If xfs_repair encounters a dirty log, then it will not be able to repair the file system. To rectify the file system, you will need to first clear the relevant log, mount and then unmount the xfs file system. You may use the option "-L" to force log zeroing if the log file is corrupt and can not be replayed successfully. The command to issue for zeroing the log is as follows:

xfs_repair -L /dev/device

For full details regarding the xfs_repair utility, please consult the relevant man pages: man xfs_repair


XFS Quota Management - xfs_quota


xfs_quota gives the administrator the ability to manage limits on disk space. XFS quotas can control or report usage on users, groups or directory project level. XFS quotas are enabled at mount time. You may specify the "noenforce" option which allows reporting of usage, however, it does not enforce any limits. For full details of XFS quotas see the relevant man page: man xfs_quota


Suspending a XFS File System with xfs_freeze


The command to suspend access or resume write activity to a xfs file system is "xfs_freeze". Generally this option is used for suspending write activity thus allowing hardware based device snapshots to be used to capture the file system in a consistent state.

The xfs_freeze utility is provided by the package "xfsprogs", note, this is only available to x86_64 architecture.

To freeze a XFS file system the basic syntax is:

xfs_freeze -f /mount/point

The -f flag requests that the specified XFS filesystem should be set to a state of frozen, immediately stopping any modifications from being made. When this option is selected, all ongoing transactions in the file system are allowed to complete. Any new write system calls are halted.

To unfreeze a XFS file system the basic syntax is:

xfs_freeze -u /mount/point

The -u flag is used to unfreeze the file system and allow operations to continue again. Any file system modifications that were blocked by the freeze option are unblocked and allowed to complete.

If you are taking a LVM snapshot, then it is not necessary to run the "xfs_freeze" utility as the LVM utility will automatically suspend the relevant xfs file system.

You can also use the "xfs_freeze" utility to freeze or unfreeze an ext3, ext4 and btrfs, file system.


xfs_copy


Copy the contents of a XFS file system. xfs_copy should only be used to copy unmounted file systems, read-only mounted file systems, or file systems that have been frozen with the xfs_freeze utility. The basic syntax of the utility is as follows:



xfs_copy [ -bd ] [ -L log ] source target1 [ target2 ... ]

OPTIONS
       -d     Create a duplicate (true clone) filesystem. This should be done
              only if the new filesystem will be used as a replacement for the
              original filesystem (such as in the case of disk replacement).

       -b     The buffered option can be  used  to ensure direct IO is not
              attempted to any of the target files. This is  useful  when  the
              filesystem holding the target file does not support direct IO.

       -L log Specifies  the  location  of  the log if the default location of
              /var/tmp/xfs_copy.log.XXXXXX is not desired.

       -V     Prints the version number and exits.

xfs_fsr - File System re-organizer for XFS


The "xfs_fsr" utility is used to defragment mounted XFS file systems. The reorganization algorithm operates on one file at a time, compacting or otherwise improving the layout of the file extents (contiguous blocks of file data). When invoked with out any arguments, xfs_fsr will defragment all regular files in all mounted xfs file systems. xfs_fsr uses the file "/etc/mtab" as its source of mounted file systems. The xfs_fsr utility also allows a user to suspend a defragmentation process at a specified time and then resume from where it last left off. The current position of the defragmentation process is stored in the file:

/var/tmp/.fsrlast_xfs

xfs_fsr can also be invoked to work with a single file:

xfs_fsr /path/to/file

When xfs_fsr is invoked, it will require sufficient free space to be available as each file is copied to a temporary location whilst it is processed. A warning message will be displayed if sufficient space is not available.


xfs_bmap


Prints the map of disk blocks used by files in an XFS filesystem. The map lists each extent used by the file, as well as regions in the file with no corresponding blocks.

Each line of the listing takes the following form: extent: [startoffset..endoffset]: startblock..endblock



[root@centos07a xfs_test]# xfs_bmap test.file 
test.file:
	0: [0..7]: 96..103

[root@centos07a xfs_test]# xfs_bmap -v test.file 
test.file:
 EXT: FILE-OFFSET      BLOCK-RANGE      AG AG-OFFSET        TOTAL
   0: [0..7]:          96..103           0 (96..103)            8

For further information regarding this utility, please consult the relevant man page: man xfs_bmap


xfs_info


To view your XFS file system information, the command "xfs_info" can be issued:



[root@centos07a /]# xfs_info /dev/sdc1
meta-data=/dev/sdc1              isize=256    agcount=17, agsize=32704 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=524032, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
real-time =none                   extsz=4096   blocks=0, rtextents=0

xfs_admin


The xfs_admin command allows an administrator to changes parameters of a XFS file system. The xfs_admin utility can only modify parameters of unmounted devices/file systems. (Mounted devices can not be modified).

For a full list of parameters that can be changed, please consult the relevant man page: man xfs_admin


xfs_metadump


xfs_metadump is a debugging tool that copies XFS file system metadata to a file. The xfs_metadump utility should only be used to copy unmounted, read-only, or frozen/suspended file systems; otherwise, generated dumps could be corrupted or inconsistent. For a full list of available option please consult the relevant man page: man xfs_metadump


xfs_mdrestore


xfs_mdrestore is used to restore a XFS metadump image to a filesystem image. The source argument specifies the location of the metadump image and the target argument specifies the destination for the filesystem image. The target can be either a file or a device.

xfs_mdrestore [ -g ] source target

The "-g" parameter shows the restore progress on stdout.


xfs_db


A utility that can be used to debug a XFS file system. For further information, please consult the relevant man page: man xfs_db.


xfs_estimate


The xfs_estimate utility is used to estimate the amount of space that a xfs file system will take.



[root@centos07a xfs_test]# xfs_estimate /var/tmp
/var/tmp will take about 4.4 megabytes

[root@centos07a xfs_test]# xfs_estimate -v /var/tmp
directory                               bsize   blocks    megabytes    logsize
/var/tmp                                 4096     1138        4.4MB    4096000

xfs_estimate parameters:



[root@centos07a xfs_test]# xfs_estimate -h
Usage: xfs_estimate [opts] directory [directory ...]
	-b blocksize (fundamental filesystem blocksize)
	-i logsize (internal log size)
	-e logsize (external log size)
	-v prints more verbose messages
	-V prints version and exits
	-h prints this usage message

Note:	blocksize may have 'k' appended to indicate x1024
	logsize may also have 'm' appended to indicate (1024 x 1024)

xfs_mkfile


xfs_mkfile is used to create a xfs file. The file is padded with zeroes by default. The default size is in bytes, but it can be flagged as kilobytes, blocks, megabytes, or gigabytes with the k, b, m, or g suffixes respectively.

Syntax: xfs_mkfile [ -v ] [ -n ] [ -p ] size[k|b|m|g] filename

Options that can be passed:



       -v     Verbose. Report the names and sizes of the created files.

       -n     No bytes. Create a holey file - that is, do not write out any
              data, just seek to the end of the file and write a block.

       -p     Preallocate.  The file is preallocated, then overwritten with
              zeroes, it is then truncated to the desired size.

       -V     Prints the version number and exits.

xfs_io


xfs_io is a debugging tool similar to the utility xfs_db, but is aimed at examining the regular file I/O paths rather than the raw XFS volume itself. For a full list of all the parameters/options that can be passed, please consult the relevant man page: man xfs_io


xfs_logprint


xfs_logprint prints the log of a XFS file system. The device argument is the pathname of the partition or logical volume containing the filesystem. The device can be a regular file if the "-f" option is used. The contents of the file system remain undisturbed.

There are two major modes of operation in xfs_logprint:

One mode is better for filesystem operation debugging. It is called the transactional view and is enabled through the "-t" option. The transactional view prints only the portion of the log that pertains to recovery. In other words, it prints out complete transactions between the tail and the head. This view tries to display each transaction without regard to how they are split across log records.

The second mode starts printing out information from the beginning of the log. Some error blocks might print out in the beginning because the last log record usually overlaps the oldest log record. A message is printed when the physical end of the log is reached and when the logical end of the log is reached. A log record view is displayed one record at a time. Transactions that span log records may not be decoded fully.

Syntax: xfs_logprint [ options ] device

Options that can be passed:



       -b     Extract and print buffer information. Only used in transactional
              view.

       -c     Attempt to continue when an error is detected.

       -C filename
              Copy  the log from the filesystem to the file filename.  The log
              itself is not printed.

       -d     Dump the log from front to end, printing where each  log  record
              is located on disk.

       -D     Do not decode anything; just print data.

       -e     Exit  when  an error is found in the log. Normally, xfs_logprint
              tries to continue and unwind from bad logs.  However,  sometimes
              it  just  dies  in  bad  ways.   Using this option prevents core
              dumps.
       
       -f     Specifies that the filesystem image to be processed is stored in
              a  regular  file at device (see the mkfs.xfs(8) -d file option).
              This might happen if an image copy of a filesystem has been made
              into an ordinary file with xfs_copy(8).

       -l logdev
              External  log  device.  Only  for those filesystems which use an
              external log.

       -i     Extract and print inode information. Only used in  transactional
              view.

       -q     Extract  and print quota information. Only used in transactional
              view.

       -n     Do not try and interpret log data;  just  interpret  log  header
              information.

       -o     Also  print  buffer  data in hex.  Normally, buffer data is just
              decoded, so better information can be printed.
       -s start-block
              Override any notion of where to start printing.

       -t     Print out the transactional view.

       -v     Print "overwrite" data.

       -V     Prints the version number and exits.

xfs_rtcp


xfs_rtcp copies a file to the real-time partition on a XFS file system. If there is more than one source and target, the final argument (the target) must be a directory which already exists.

Syntax: xfs_rtcp [ -e extsize ] [ -p ] source ... target

Options that can be used:



OPTIONS
       -e extsize
              Sets the extent size of the destination real-time file.

       -p     Use  if  the  size of the source file is not an even multiple of
              the block size of the destination filesystem. When -p is  speci‐
              fied  xfs_rtcp  will pad the destination file to a size which is
              an even multiple of the filesystem block size.  This  is  neces‐
              sary since the real-time file is created using direct I/O and the
              minimum I/O is the filesystem block size.

       -V     Prints the version number and exits.

xfs_ncheck


The utility xfs_ncheck is used to generate a list of inode numbers along with path names.

Syntax: xfs_ncheck [ -i ino ] ... [ -f ] [ -s ] [ -l logdev ] device

Options:



       -f       Specifies that the filesystem image to be processed is  stored
                in a regular file at device (see the mkfs.xfs -d file option).
                This might happen if an image copy of a  filesystem  has  been
                made into an ordinary file.

       -l logdev
                Specifies  the  device  where  the  filesystem's  external log
                resides.  Only for those filesystems  which  use  an  external
                log.  See  the  mkfs.xfs  -l option, and refer to xfs(5) for a
                detailed description of the XFS log.

       -s       Limits the report to special files and  files  with  setuserid
                mode.   This  option may be used to detect violations of secu‐
                rity policy.

       -i ino   Limits the report to only those files whose inode numbers fol‐
                low.   May  be  given  multiple times to select multiple inode
                numbers.

       -V       Prints the version number and exits.

xfsdump


xfsdump is a file system incremental dump utility that is used in conjunction with xfsrestore. xfsdump backs up files and their attributes in a xfs file system. The files can be dumped to storage media, a regular file, or to standard output. Various dump options allow the administrator to create a full dump or an incremental dump. You may also specify a path to limit the files that are dumped.

To use the xfsdump utility, you first have to install it. This can be easily achieved by issuing the following command:

yum install xfsdump


xfsrestore


xfsrestore restores filesystems from dumps produced by xfsdump. For a full list of all available parameters and options available to xfsdump and xfsrestore, please consult the relevant man pages


Further sources of information for the xfs file system


FAQ - XFS.org XFS FAQs

XFS User Guide XFS User Guide

RHEL - XFS File System - Storage Administration RHEL - XFS - Storage Administration