Learn xfs file system commands to create, grow, repair xfs file system along with command examples.
Learn xfs commands with examples In our another article we walked you through what is xfs, features of xfs etc. In this article we will see some frequently used xfs administrative commands. We will see how to create xfs filesystem, how to grow xfs filesystem, how to repair xfs file system and check xfs filesystem along with command examples.
Create XFS filesystem
mkfs.xfs command is used to create xfs filesystem. Without any special switches command output looks like one below –
Note : Once XFS filesystem is created it can not be reduced. It can only be extended to bigger size.
Resize XFS file system
In XFS, you can only extend file system and can not reduce it. To grow XFS file system use xfs_growfs. You need to specify new size of mount point along with -D switch. -D takes argument number as file system blocks. If you dont supply -D switch, xfs_growfs will grow filesystem to maximum available limit on that device.
In above output, observe last line. Since I supplied new size smaller than the existing size, xfs_growfsdidnt change filesystem. This show you can not reduce XFS file system. You can only extend it.
Now, I supplied new size 1GB extra and it successfully grew the file system. 1GB blocks calculation : Current filesystem has bsize=4096 i.e. block size of 4MB. We need 1 GB i.e. 256 blocks. So add 256 in current number of blocks i.e. 2883584 which gives you 2883840. So I used 2883840 as argument to -D switch.
Repair XFS file system
File system consistency check and repair of XFS can be performed using xfs_repair command. You can run command with -n switch so that it will not modify anything on filesystem. It will only scans and reports which modification to be done. If you are running it without -n switch, it will modify file system wherever necessary to make it clean. Please note that you need to un-mount XFS filesystem before you can run checks on it. Otherwise you will see below error.
Once successfully un-mounting file system you can run command on it.
Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
root@kerneltalks# xfs_repair -n /dev/xvdf
Phase1-findandverify superblock...
Phase2-using internal log
-zero log...
-scan filesystem freespace andinode maps...
-found root inode chunk
Phase3-foreachAG...
-scan(but don'tclear)agi unlinked lists...
-process known inodes andperform inode discovery...
-agno=0
-agno=1
-agno=2
-agno=3
-agno=4
-process newly discovered inodes...
Phase4-check forduplicate blocks...
-setting up duplicate extent list...
-check forinodes claiming duplicate blocks...
-agno=0
-agno=1
-agno=2
-agno=3
-agno=4
No modify flag set,skipping phase5
Phase6-check inode connectivity...
-traversing filesystem...
-traversal finished...
-moving disconnected inodes tolost+found...
Phase7-verify linkcounts...
No modify flag set,skipping filesystem flush andexiting.
In above output you can observe, in each phase command shows possible modification which can be done to make file system healthy. If you want command to do those modification during scan then run command without any switch.
xfs_repair output
In above output you can observer xfs_repair command is executing possible filesystem modification as well to make it healthy.
Check XFS version and details
Checking xfs file system version is easy. Run xfs_info command with -V switch on mount point.
Shell
1
2
3
4
root@kerneltalks# xfs_info -V /shrikant
xfs_info version4.5.0
To view details of XFS file system like block size and number of blocks which helps you in calculating new block number for growing XFS file system, use xfs_info without any switch.
It displays all details as it shows while creating XFS file system There are another XFS file system management commands which alters and manages its metadata. We will cover them in another article.