Did you encounter an error “mkfs.xfs: No such file or directory” while trying to format a partition or logical volume in your Linux system?. XFS is a highly scalable, high-performance file system originally designed at Silicon Graphics, Inc. XFS is not the default file system on all Linux systems, but operating systems such Red Hat Enterprise Linux 7 and later use it as default.

To create an XFS file system, you’ll run the following command:

sudo mkfs.xfs block_device

If your system doesn’t have XFS utilities installed you’ll get an error saying “mkfs.xfs: No such file or directory“.

The solution to the error “mkfs.xfs: No such file or directory” is installation of required tools that enables XFS file system management in your machine.

Install XFS Utilities on Ubuntu / Debian

On an Ubuntu / Debian based system, install utilities for managing the XFS filesystem using the commands below:

sudo apt update
sudo apt install xfsprogs

You can validate installation using dpkg command:

$ dpkg --status xfsprogs
Package: xfsprogs
Status: install ok installed
Priority: optional
Section: admin
Installed-Size: 2676
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Version: 5.3.0-1ubuntu2
Replaces: xfsdump (<< 3.0.0)
Provides: fsck-backend
Depends: libblkid1 (>= 2.17.2), libc6 (>= 2.28), libdevmapper1.02.1 (>= 2:1.02.20), libicu66 (>= 66.1~rc-1~), libreadline5 (>= 5.2), libuuid1 (>= 2.16), python3:any, util-linux
Suggests: xfsdump, acl, attr, quota
Breaks: xfsdump (<< 3.0.0)

This installation provides a set of commands to use the XFS filesystem, including mkfs.xfs.

$ which mkfs.xfs

Ensure required kernel module is loaded:

$ sudo modprobe -v xfs
insmod /lib/modules/5.4.0-72-generic/kernel/fs/xfs/xfs.ko

Install XFS Utilities on CentOS / RHEL based systems

For Red Hat based Linux systems, install the Utilities for managing the XFS filesystem with the command below:

sudo yum install xfsprogs

Accept installation of XFS Utilities by pressing the y key in your keyboard:

Dependencies Resolved

 Package                              Arch                               Version                                    Repository                               Size
 xfsprogs                             x86_64                             4.5.0-15.el7                               xcp-ng-base                             895 k

Transaction Summary
Install  1 Package

Total download size: 895 k
Installed size: 3.9 M
Is this ok [y/d/N]: y

Kernel module should be loaded automatically:

$ sudo modprobe -v xfs
insmod /lib/modules/4.19.0+1/kernel/fs/xfs/xfs.ko

After installation of XFS utilities package you can proceed to format the filesystem:

$ sudo mkfs.xfs block_device

Where block_device is replaced with the path to a block device, example:

  • /dev/sdb1
  • /dev/disk/by-uuid/06e99ec8-def1-7a5e-8a3d-5945639ceb1a
  • /dev/my-volgroup/my-lv

Here is an example on mkfs.xfs usage:

$ sudo mkfs.xfs /dev/VG_XenStorage-ba6c41c7-f32c-d49a-6d5b-d60cdd50b79a/data
meta-data=/dev/VG_XenStorage-ba6c41c7-f32c-d49a-6d5b-d60cdd50b79a/data isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Get the UUID of the device:

$ sudo blkid /dev/VG_XenStorage-ba6c41c7-f32c-d49a-6d5b-d60cdd50b79a/data
/dev/VG_XenStorage-ba6c41c7-f32c-d49a-6d5b-d60cdd50b79a/data: UUID="4a65b2fd-6b95-4309-ada2-3cefd658aeff" TYPE="xfs"

We can then configure mounting on /etc/fstab file

$ sudo vim /etc/fstab
UUID="4a65b2fd-6b95-4309-ada2-3cefd658aeff" /data xfs defaults 0 0

Create mount point

sudo mkdir /data

Mount the partition:

$ sudo mount /data

Confirm it is actually mounted and partition type is XFS:

$ df -hT /data
Filesystem                                                               Type  Size  Used Avail Use% Mounted on
/dev/mapper/VG_XenStorage--ba6c41c7--f32c--d49a--6d5b--d60cdd50b79a-data xfs    50G   33M   50G   1% /data

That’s all on how to fix “mkfs.xfs: No such file or directory” error message on both Debian and Red Hat based systems.