top of page
Writer's pictureSiddhesh Kadam

The Ultimate XFS File System Troubleshooting Guide: Everything You Need to Know


XFS

XFS is a high-performance journaling file system designed for Unix-like operating systems. Developed by Silicon Graphics, Inc. (SGI), it was initially deployed on their IRIX operating system and later ported to Linux and other Unix-based systems.

Here are some key features of the XFS file system:

Scalability: XFS is designed to handle large amounts of data and very large file systems. It supports file systems up to 16 exbibytes (approximately 18 million terabytes) in size.

High Performance: XFS is optimized for high-performance I/O operations, making it well-suited for environments with large files and high throughput requirements. It employs techniques such as delayed allocation and extent-based allocation to improve performance.

Journaling: XFS uses journaling to maintain the integrity of the file system in the event of a crash or system failure. This ensures that the file system can recover quickly and reliably after an interruption.

Metadata Handling: XFS efficiently manages file system metadata using B-tree data structures, allowing for fast access and manipulation of directories, inodes, and other file system objects.

Extent-Based Allocation: XFS employs an extent-based allocation scheme, which reduces fragmentation and improves performance by allocating contiguous blocks of disk space for file storage.


In this blog, we're going to understand various concepts of managing and maintaining XFS file system data volumes efficiently.


1.Creating an XFS File System & Internal Log On Same Disk


[root@siddhesh ~]# mkfs.xfs /dev/nvme1n1
meta-data=/dev/nvme1n1           isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@siddhesh ~]#

The output confirms that the XFS file system has been successfully created on the specified device. 2.Creating an XFS File System On An Existing Formatted Disk.

[root@siddhesh ~]# mkfs.xfs /dev/nvme1n1
mkfs.xfs: /dev/nvme1n1 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@siddhesh ~]#
[root@siddhesh ~]# mkfs.xfs -f /dev/nvme1n1
meta-data=/dev/nvme1n1           isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@siddhesh ~]#

The command mkfs.xfs -f /dev/nvme1n1 is used to create an XFS file system on the device /dev/nvme1n1. Here's a breakdown of the command:

mkfs.xfs: This is the command used to create an XFS file system.

-f: This option forces the creation of the file system without prompting for confirmation. It is used to automate the process.

/dev/nvme1n1: This is the device where the XFS file system will be created. In this case, it is likely a NVMe solid-state drive (SSD) represented by the device name /dev/nvme1n1.


3.Display information about an XFS file system.


[root@siddhesh ~]# xfs_info /dev/nvme1n1
meta-data=/dev/nvme1n1           isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@siddhesh ~]#

The xfs_info command is used to display information about an XFS file system. When executed without any arguments, it provides information about the mounted XFS file systems on the system.

This output provides detailed information about various aspects of the XFS file system, including metadata, allocation groups, data configuration, naming configuration, log configuration, and realtime configuration. Each line corresponds to a specific aspect of the file system configuration, providing details such as block size, block count, allocation group count, and more.


4.Creating an XFS File System & Log On Different Disk


[root@siddhesh ~]# mkfs.xfs -f -l logdev=/dev/nvme2n1,size=10000b /dev/nvme1n1
meta-data=/dev/nvme1n1           isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =/dev/nvme2n1           bsize=4096   blocks=10000, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@siddhesh ~]#

This command is used to create a new XFS filesystem on the device /dev/nvme1n1 with a separate log device specified at /dev/nvme2n1. Below is the breakdown of the command and its options:


mkfs.xfs: This is the command used to create an XFS filesystem on a disk partition.

-f: This option is used to force the creation of the filesystem without asking for confirmation. It overrides any existing data on the specified device without prompting for confirmation.

-l logdev=/dev/nvme2n1,size=10000b: This option specifies the log device to use for the filesystem and sets the size of the log in bytes. In this case, the log device is /dev/nvme2n1 and the size is set to 10000 bytes (approximately 10 KB). The log device is where the filesystem journal is stored. Using a separate log device can improve performance and reliability.

/dev/nvme1n1: This is the device on which the XFS filesystem will be created. It's important to note that this command will format and erase all existing data on /dev/nvme1n1, so caution should be exercised before running this command.


5.Mount XFS partition when log is configured on external partition.


[root@siddhesh ~]# mount -t xfs -o logdev=/dev/nvme2n1 /dev/nvme1n1 /mnt/siddhesh/
[root@siddhesh ~]#

This command is used to mount an existing XFS filesystem on the device /dev/nvme1n1 to the directory /mnt/siddhesh/, specifying a separate log device located at /dev/nvme2n1. Below is the breakdown of the command and its options:


mount: This command is used to mount a filesystem onto a directory in the Linux filesystem hierarchy.

-t xfs: This option specifies the filesystem type to be mounted. In this case, it's XFS.

-o logdev=/dev/nvme2n1: This option specifies additional mount options. Here, it specifies the log device to be used for the XFS filesystem. The log device helps in improving filesystem performance and reliability by separating the journal from the main filesystem data. In this case, it's /dev/nvme2n1.

/dev/nvme1n1: This is the device containing the XFS filesystem that you want to mount. It is the source device.

/mnt/siddhesh/: This is the target directory where the filesystem will be mounted. It is a directory within the existing filesystem hierarchy.


After executing this command, the XFS filesystem located on /dev/nvme1n1 will be mounted onto the directory /mnt/siddhesh/, with the log stored on /dev/nvme2n1. Any files and directories within the XFS filesystem will be accessible under /mnt/siddhesh/, and the separate log device will assist in maintaining filesystem integrity and performance.


6.Print the log of an XFS filesystem


[root@siddhesh ~]#  xfs_logprint /dev/nvme1n1 -l /dev/nvme2n1
xfs_logprint:
xfs_logprint: /dev/nvme1n1 contains a mounted and writable filesystem
    data device: 0x10302
    log file: "/dev/nvme2n1" daddr: 6291488 length: 20480
xfs_logprint: skipped 20480 zeroed blocks in range: 0 - 20479
xfs_logprint: totally zeroed log
xfs_logprint: physical end of log
============================================================================
xfs_logprint: logical end of log
============================================================================
[root@siddhesh ~]#

The command xfs_logprint /dev/nvme1n1 -l /dev/nvme2n1 is used to print the contents of the XFS log.

Here's the breakdown of the output:

xfs_logprint: This is the name of the command being executed.

/dev/nvme1n1: This is the device name of the first NVMe device specified in the command. It contains a mounted and writable filesystem.

-l /dev/nvme2n1: This option specifies the log device to be printed. In this case, it's /dev/nvme2n1.

data device: 0x10302: This line indicates the data device ID.

log file: "/dev/nvme2n1" daddr: 6291488 length: 20480: This line indicates the log file being printed, its starting address, and its length.

skipped 20480 zeroed blocks in range: 0 - 20479: This line indicates that 20480 zeroed blocks were skipped in the log.

totally zeroed log: This line indicates that the log is entirely zeroed out.

physical end of log: This line indicates the physical end of the log.

logical end of log: This line indicates the logical end of the log.


7.XFS Quota Management


XFS (Extended File System) is a high-performance file system commonly used in Linux environments. It supports quota management, allowing administrators to control and limit disk usage by users or groups. Here's a basic overview of XFS quota management.


Enabling Quotas: Before using quotas, you need to ensure that quota support is enabled when mounting the XFS file system. This can be done by adding the quota option to the file system entry in the /etc/fstab file.

/dev/nvme1n1 /mnt/siddhesh    xfs    defaults,usrquota,grpquota 0    0

Setting Quotas: Once quotas are initialized, you can set disk space limits for users or groups using the xfs_quota command. For example, to set a disk quota of 1GB for a user named builddevops, you can use:

 [root@siddhesh ~]# xfs_quota -x -c 'limit bsoft=1g bhard=1g builddevops' /dev/nvme1n1

Viewing Quotas: You can view quota information using the xfs_quota command. For example, to display the quota limits for all users, you can use:

[root@siddhesh ~]# xfs_quota -x -c 'report -h'  /dev/nvme1n1
User quota on /mnt/siddhesh (/dev/nvme1n1)
                        Blocks
User ID      Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            0      0      0  00 [------]
builddevops         0     1G     1G  00 [------]
Group quota on /mnt/siddhesh (/dev/nvme1n1)
                        Blocks
Group ID     Used   Soft   Hard Warn/Grace
---------- ---------------------------------
root            0      0      0  00 [------]
[root@siddhesh ~]#

Modifying Quotas: Quotas can be modified or removed as needed using the xfs_quota command. For example, to remove a quota limit for a user, you can use:

[root@siddhesh ~]#  xfs_quota -x -c 'remove builddevops' /mnt/siddhesh

8.Increasing the Size of an XFS File System


An XFS file system may be grown while mounted using the xfs_growfs command:

[root@siddhesh ~]# xfs_growfs /mnt/siddhesh/
meta-data=/dev/nvme1n1           isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =external               bsize=4096   blocks=10000, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
xfs_growfs: log growth not supported yet
data blocks changed from 1310720 to 1572864
[root@siddhesh ~]# 

9.Suspending an XFS File System


To suspend or resume write activity to a file system, use the following command:

[root@siddhesh ~]# xfs_freeze -f /mnt/siddhesh/

The xfs_freeze command is used to suspend or resume access to an XFS file system. When the -f option is used with the command, it suspends all activity on the specified file system.

In the provided command:

xfs_freeze: This is the command itself, used for freezing or suspending activity on an XFS file system.

-f: This option is used to freeze the specified file system. When the file system is frozen, any ongoing disk writes are blocked, allowing for consistent backups or other maintenance tasks to be performed safely.

/mnt/siddhesh/: This is the path to the XFS file system that you want to freeze. In this case, the file system mounted at /mnt/siddhesh/ will be frozen.

When you freeze a file system using xfs_freeze -f, it is typically used before taking a snapshot, backup, or performing other operations that require a consistent file system state. Once the task is completed, you can use xfs_freeze -u to unfreeze the file system and resume normal activity.

[root@siddhesh ~]# xfs_freeze -u /mnt/siddhesh/

10. Backing Up and Restoring XFS File Systems


XFS file system backup and restoration involve these utilities:

xfsdump for creating the backup.

xfsrestore for restoring from backup. Full Backup using xfsdump:

 [root@siddhesh ~]# xfsdump -l 0 -f /root/backup/siddhesh.xfsdump /dev/nvme1n1

Here's an explanation of the provided command:

xfsdump: This is the command itself, used for creating backups of XFS file systems.

-l 0: This option specifies the level of the dump. In this case, -l 0 indicates a level 0 dump, which is a full backup of the file system.

-f /root/backup/siddhesh.xfsdump: This option specifies the filename and location where the backup will be stored. In this case, the backup will be saved as siddhesh.xfsdump in the directory /root/backup/.

/dev/nvme1n1: This is the device name of the XFS file system that you want to back up. In this example, the file system located at /dev/nvme1n1 will be backed up. Incremental Backup using xfsdump:

[root@siddhesh ~]# xfsdump -l 1 -L sidtest -M newlyadded -f /root/backup/siddhesh_L1.xfsdump  /dev/nvme1n1

Let's break down the provided command:

xfsdump: This is the command itself, used for creating backups of XFS file systems.

-l 1: This option specifies the level of the dump. In this case, -l 1 indicates a level 1 dump, which is an incremental backup. Incremental backups only include the changes made since the last full or incremental backup.

-L sidtest: This option specifies the label for the dump session. It identifies the backup session with the provided label.

-M newlyadded: This option specifies the media label for the dump session. It identifies the media, such as tape or disk, used for storing the backup data.

-f /root/backup/siddhesh_L1.xfsdump: This option specifies the filename and location where the backup will be stored. In this case, the backup will be saved as siddhesh_L1.xfsdump in the directory /root/backup/.

/dev/nvme1n1: This is the device name of the XFS file system that you want to back up. In this example, the file system located at /dev/nvme1n1 will be backed up.


Restore Full Backup using xfsrestore

[root@siddhesh ~]# xfsrestore -r -f /root/backup/siddhesh.xfsdump /mnt/siddhesh/restore/

Let's break down the provided command: xfsrestore: This is the command itself, used for restoring backups onto XFS file systems.

-r: This option specifies that the restore process should be performed in a read-only mode. This means that no changes will be made to the original backup files.

-f /root/backup/siddhesh.xfsdump: This option specifies the filename and location of the backup file to be restored. In this case, the backup file is located at /root/backup/siddhesh.xfsdump.

/mnt/siddhesh/restore/: This is the path where the backup will be restored. In this example, the backup will be restored to the directory /mnt/siddhesh/restore/.

So, putting it all together, the command is restoring the backup file siddhesh.xfsdump located at /root/backup/ onto the XFS file system located at /mnt/siddhesh/restore/. The restore process will be performed in read-only mode, meaning that no changes will be made to the original backup files.


Restore Incremental Backup using xfsrestore

[root@siddhesh ~]# xfsrestore -r -f  /root/backup/siddhesh_L1.xfsdump /mnt/siddhesh/restore/

Let's break down the provided command:

xfsrestore: This is the command itself, used for restoring backups onto XFS file systems.

-r: This option specifies that the restore process should be performed in a read-only mode. This means that no changes will be made to the original backup files.

-f /root/backup/siddhesh_L1.xfsdump: This option specifies the filename and location of the backup file to be restored. In this case, the backup file is located at /root/backup/siddhesh_L1.xfsdump.

/mnt/siddhesh/restore/: This is the path where the backup will be restored. In this example, the backup will be restored to the directory /mnt/siddhesh/restore/.

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page