How to install xfs and create xfs file system on Debian/Ubuntu Linux

Posted on in Categories , , last updated September 23, 2017

I recently switched to a Ubuntu/Debian Linux server from a CentOS/RHEL 7.x. How do I install mkfs.xfs command on a Debian/Ubuntu Linux server? How do I create and manage file XFS file system on a Ubuntu or Debian Linux LTS server?

XFS was created at Silicon Graphics, Inc. XFS is not the default file system for Debian or Ubuntu Linux based system. XFS feature includes scalable and high-performance design. This guide shows you how to install XFS and create an XFS file system on Debian/Ubuntu Linux based system.

Install xfs

Use the apt command/apt-get command:
$ sudo apt-get install xfsprogs
Sample outputs

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libreadline5
Suggested packages:
  xfsdump acl attr quota
The following NEW packages will be installed:
  libreadline5 xfsprogs
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 931 kB of archives.
After this operation, 4,789 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian stretch/main amd64 libreadline5 amd64 5.2+dfsg-3+b1 [119 kB]
Get:2 http://deb.debian.org/debian stretch/main amd64 xfsprogs amd64 4.9.0+nmu1 [811 kB]
Fetched 931 kB in 0s (5,356 kB/s)
Selecting previously unselected package libreadline5:amd64.
(Reading database ... 33907 files and directories currently installed.)
Preparing to unpack .../libreadline5_5.2+dfsg-3+b1_amd64.deb ...
Unpacking libreadline5:amd64 (5.2+dfsg-3+b1) ...
Selecting previously unselected package xfsprogs.
Preparing to unpack .../xfsprogs_4.9.0+nmu1_amd64.deb ...
Unpacking xfsprogs (4.9.0+nmu1) ...
Processing triggers for libc-bin (2.24-11+deb9u1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libreadline5:amd64 (5.2+dfsg-3+b1) ...
Setting up xfsprogs (4.9.0+nmu1) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for libc-bin (2.24-11+deb9u1) ...
Processing triggers for initramfs-tools (0.130) ...
update-initramfs: Generating /boot/initrd.img-4.9.0-3-amd64

How to create an xfs file system

The syntax is:
mkfs.xfs /dev/device
mkfs.xfs [options] /dev/device

First create partition using the fdisk command/cfdisk command/partx command/sfdisk command:
# fdisk /dev/sdb
OR
# cfdisk /dev/sdb
I created a partition named /dev/sdb1. To create an XFS file system, use the mkfs.xfs /dev/sdb1 command:
# mkfs.xfs /dev/sdb1
Sample outputs:

Fig.01: mkfs.xfs in action
Fig.01: mkfs.xfs in action

How to mount an xfs file system

Type the following command:
# mkdir /data
# mount /dev/sdb1 /data/
# df -T

Sample outputs:


Filesystem     Type     1K-blocks    Used Available Use% Mounted on
udev           devtmpfs   1885404       0   1885404   0% /dev
tmpfs          tmpfs       379308    6728    372580   2% /run
/dev/sda1      ext4      10188088 1086400   8561120  12% /
tmpfs          tmpfs      1896536       0   1896536   0% /dev/shm
tmpfs          tmpfs         5120       0      5120   0% /run/lock
tmpfs          tmpfs      1896536       0   1896536   0% /sys/fs/cgroup
/dev/sdb1      xfs      209611760  241952 209369808   1% /data

Update /etc/fstab file

To see /dev/sdb1 block device’s UUID (Universally Unique Identifier) run:
# blkid /dev/device
# blkid /dev/sdb1

Sample outputs:

/dev/sdb1: UUID="ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6" TYPE="xfs" PARTUUID="43eccd3d-9d50-4c29-a815-9fcf2986b235"

Edit/updated /etc/fstab file using the following synta:
UUID={YOUR-UID} /data xfs defaults,errors=remount-ro 0 1
For example, the following will update /etc/fstab so that /dev/sda1 get mounted at boot time:

## type the following command as 
## root user 
echo 'UUID=ea8b08a4-3e9f-4482-83e9-c5f03b9f05d6 /data xfs defaults 1 1' >> /etc/fstab

Test it:
# mount -a
# df -T

How to check and epair an XFS file system

To repair an XFS file system, use xfs_repair and syntax is (do not run xfs_repair on a mounted filesystem):
# xfs_repair /dev/device
# umount /dev/sdb1
# xfs_repair /dev/sdb1

Sample outputs:

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...
done

For more info about above commands, read their respective man pages:
$ man mkfs.xfs
$ man apt-get
$ man xfs_repair
$ man blkid
$ man fdisk

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 0 comments/add one below):

Leave a Comment