How to Create XFS File System in Linux (Step by Step)

XFS is a 64-bit journaling file system and used where high performance is required. XFS file system is available in most of the linux distribution like Ubuntu, Debian and RHEL. In RHEL based distributions XFS is the default file system.

In guide, we will learn how to create XFS file system from the scratch step by step and then also learn how to mount and use it. For managing file system in Linux, we need a user with sudo privileges. For the demonstration purpose, I have attached 10 GB (/dev/sdb) disk to my linux system. I would be creating XFS file system on it.

Let’s deep dive into the steps,

Create XFS file system and internal log on same disk

Use mkfs.xfs command to create xfs file system and internal log on the same disk, example is shown below:

$ sudo mkfs.xfs /dev/sdb



Create XFS file system and Internal Log on separate disk

If you want to place journal on another disk while creating xfs file system, then it is also possible. Let’s assume I have /dev/sdc disk where I want to store journal of xfs file system. Run beneath command,

$ sudo mkfs.xfs -l logdev=/dev/sdc,size=10000b /dev/sdb

To overwrite the existing xfs file system, use ‘-f’ option on mkfs.xfs command

$ sudo mkfs.xfs -f -l logdev=/dev/sdc,size=10000b /dev/sdb



In above command, value after size parameter shows that number of blocks (10000)

Create XFS File system on LVM

To create LVM based file system, refer the following steps,

1 ) Create Physical Volume (PV)

Create pv on disk /dev/sdb, run

$ sudo pvcreate /dev/sdb

2) Create Volume Group (VG)

Run beneath vgcreate command to volume group on pv /dev/sdb,

$ sudo vgcreate vg01_xfs /dev/sdb

3) Create LV (Logical Volume) from VG

Use below lvcreate command to create logical volume of size 10 GB,

$ sudo lvcreate -L 9.9G -n lv01_xfs vg01_xfs

4) Format LV (logical volume) with XFS file system

Run below mkfs.xfs command to format lv (/dev/vg01_xfs/lv01_xfs) with xfs file system,

$ sudo mkfs.xfs /dev/vg01_xfs/lv01_xfs

Output of above commands would look like below:


Mount XFS File system

To mount a file system in linux, first we must have mount point, let’s create the mount point as ‘/var/data’, run

$ sudo mkdir /var/data

Now run following mount command to mount xfs file system,

$ sudo mount /dev/vg01_xfs/lv01_xfs /var/data/
$ df -Th /var/data/
Filesystem                                        Type  Size   Used   Avail  Use%   Mounted on
/dev/mapper/vg01_xfs-lv01_xfs xfs    9.9G  103M   9.8G   2%     /var/data

This is a temporary mount, so to mount the xfs file system permanently add following entries in /etc/fstab file.

/dev/vg01_xfs/lv01_xfs  /var/data  xfs  defaults 0 0

To access the file system, go to the mount point and try to create a file,

$ cd /var/data/
$ sudo touch testfile
$ ls -l
total 0
-rw-r--r-- 1 root root 0 Jan 10 10:31 testfile

Great, above confirms that we have successfully able to write on xfs file system. That’s all from this guide, please do share your feedback and queries in below comments section.

Also ReadHow to Set or Change Hostname in Linux System

Leave a Comment

19 + three =