How to Create, Mount and Extend xfs Filesystem

XFS is a high-performance 64-bit journaling file system created by SGI in 1993. It was introduced in the Linux kernel in 2001, XFS is supported by most Linux distributions, some of which use it as the default file system (RHEL/CentOS 7.0).

XFS excels in the execution of parallel input/output (I/O) operations due to its design, which is based on allocation groups, because of this, XFS enables extreme scalability of I/O threads, file system bandwidth, and size of files and of the file system itself when spanning multiple physical storage devices. A disadvantage of the XFS file system is that it cannot be shrunk, also metadata operations in have historically been slower than with other file systems, resulting in, for example, poor performance with operations such as deletions of large numbers of files. FAQ of is a good place to read before you start implementing this filesystem.

Creating a new XFS partition

To create a new XFS file system you will first need a partition to format. You can use fdisk to create a new partition, like in the example below, you first need to invoke fdisk with the name of the harddisk you wish to create the partition on and then use "n" command inside fdisk for a new parttion, after you have set the size like in the example below you will need to use the "w" command to write the new table to disk.

xfs fdisk new partition

You can find more info about fdisk here.

If the partition you want to format as xfs already exists on the system you must make sure it's not mounted by using the command umount command like this:

# umount /dev/sdb1

/dev/sdb1 should of course be replaced by the name of the partition you want to use.

Now that your partition is ready you can create a xfs filesystem by using the mkfs.xfs command, with the name of the partition you created like this:

# mkfs.xfs /dev/sdb1

Mounting the xfs filesystem

To mount the newly created partition you will have to first create a directory to be a mount point with the mkdir command, in our example we will use /mnt/db. Next you can mount the xfs parttion using the mount command as you would with any partition. Afterwards you can use the mount command to check if the partition was correctly mounted.

# mkdir /mnt/db
# mount /dev/sdb1 /mnt/db
# mount | grep /dev/sdb1
xfs mount

If you have environment with filesystem above 2 TB , you could try benchmark with mounting with inode64 option.

# mount -o inode64 /dev/device /mount/point

XFS enable write barriers to ensure file system integrity which preserves it across power failure, interface resets, system crashes by default.  If your hardware have a healthy write cache feature then its recommended to disable write barriers otherwise performance would be negatively affected. You can disable write barrier using mount option below.

# mount -o nobarrier /dev/device /mount/point

Extending a xfs filesystem

You can see the size of the current mounted partitions using the following command:

# df -h

xfs df--h

To extend a xfs filesystem you will first have to modify the partition table to the new size, you can do this similar to the way you created the partition using fdisk, first use "d" command to remove the partition (be careful to select the correct partition if you have more then one on the device) then use the "n" to create a partition of a bigger size, in our case 20GB.

xfs extend fdisk

Next all you have to do is run the xfs_growfs command with the -d switch (to grow the data part of the file system) and the filesystem will be grown to the new size of the partition.

# xfs_growfs -d /mnt/db

Note : Filesystem must be mounted for you to be able to use xfs_growfs and also that you can never shrink a xfs filesystem.

Leave a Comment