Linux How To Create XFS Filesystem
NOTE - Many of these commands will need you to be logged in as root or will need you to use sudo.
On an Ubuntu base system you can install the software necessary to work with XFS like this:
sudo apt-get update
sudo apt-get install xfsprogs
You may want/need to enable/check the driver but you probably won’t need to.
sudo modprobe -v xfs
lsmod | grep xfs
modinfo xfs
Show your disks with fdisk like this:
sudo fdisk -l
Create a partition with fdisk:
fdisk /dev/sdb
n - for new partition
p - for primary ( default )
1 - for partition 1 ( default )
[enter] - first sector ( default )
[enter] - last sector ( default ) ( or specify size )
w - to write the partition table
Create an actual XFS filesystem on the partition:
mkfs.xfs /dev/sdb1
Create a directory to mount it on:
mkdir /data
Mount the filesystem:
mount /dev/sdb1 /data/
View and verify the file system like this:
df -Th
Find the UUID for the partition:
sudo blkid /dev/sdb1
The UUID will look something like this:
afcdc3e6-ba07-411f-8121-8ebc8620e39e
Add an entry to your fstab ( make sure you swap in your own UUID ):
sudo vi /etc/fstabUUID=afcdc3e6-ba07-411f-8121-8ebc8620e39e /data xfs defaults,errors=remount-ro 0 1
Unmount it and verify that you can mount it like this now:
umount /data
mount /data
df -Th
Optionally disable write barriers. This can avoid performance problems. Write barriers help with file integrity during system or power failures.
mount -o nobarrier /dev/device /mount/point
You can repair an XFS filesystem like this:
umount /dev/sdb1
xfs_repair /dev/sdb1
Expand an XFS File System
Do this at your own risk. Backup everything first. Be careful and pay attention to what you are doing.
You can expand a partition like this:
fdisk /dev/sdb
n - for new partition
p - for primary ( default )
1 - for partition 1 ( default )
[enter] - first sector ( default )
[enter] - last sector ( specify a larger size )
w - to write the partition table
If you have expanded your partition you could grow an XFS filesystem with the following command.
xfs_growfs -d /mnt/db