LINUX: How to Create XFS Filesystem on Linux Hosts?
Below are steps to create XFS filesystem on Linux hosts.
1) Attach the Disk to the Linux Host
2) Verify that the attached disk is shown.
ls -lrt /dev/
It should be shown as sdb
Please note that the name for attached disk may vary. If you are attaching the 2nd disk it will show as sbd, lets assume you are attaching one more disk and creating filesystem is will show as sdc, and any further disks attached it will show as sdd, sde .. and so on.
3) Create partition for attached / extended disk as follows:
sudo fdisk /dev/sdb
Enter inputs in fdisk console prompts as follows as highlighted in bold.
# sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n >>>>> enter n here for new partition
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p >>>>> enter p here as primary partition
Partition number (1-4, default 1): 1 >>>> enter partition number as 1
First sector (2048-251658239, default 2048): >>> just enter go with defaults
Last sector, +sectors or +size{K,M,G,T,P} (2048-251658239, default 251658239): >>>> just enter go with defaults
Created a new partition 1 of type 'Linux' and of size 120 GiB.
Command (m for help): p >>>>> enter p here to print partition.
Disk /dev/sdb: 120 GiB, 128849018880 bytes, 251658240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x004734fb
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 251658239 251656192 120G 83 Linux
Command (m for help): w >>>> enter w to write and save the changes.
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
4) Format the created partition as xfs using below command.
sudo mkfs.xfs -f /dev/sdb1
Below is sample command output you see when running above command.
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=7864256 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=31457024, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=15359, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
5) Create a directory on which you want to mount the xfs partition. For e.g. lets assume apps
mkdir /apps
6) Mount the newly created xfs partition using below command.
sudo mount -t xfs /dev/sdb1 /apps
7) Run "df -Th" command and verify that the partition is mounted as xfs filesystem. Below is snippet.
/dev/sdb1 xfs 120G 889M 120G 1% /apps
8) Update /etc/fstab and add below entry to have newly created xfs partition automounted during the reboot.
/dev/sdb1 /apps xfs defaults 0 0
9) Reboot the node. After the reboot you would notice that the XFS filesystem is auto mounted.