XFS – creating, modifying, and more
XFS is a highly advanced and established filesystem that boasts an array of benefits and features, making it an ideal option for a wide range of use cases. XFS is designed to handle vast storage capacities, making it suitable for environments with heavy data demands. It can support filesystems and files up to 8 exabytes in size, allowing for the management of vast amounts of data. This scalability makes XFS highly suitable for big data applications, enterprise storage systems, and large-scale storage deployments. XFS has exceptional performance capabilities. It employs advanced techniques such as allocation-group-based block mapping, delayed allocation, and asynchronous I/O, which optimize disk I/O operations and improve overall throughput. XFS is particularly effective at handling large files and performing tasks that involve intensive read and write operations.
XFS incorporates data protection features to safeguard against data corruption. It employs checksumming for both metadata and data, allowing the filesystem to detect and address potential data integrity issues. Additionally, XFS supports copy-on-write (COW) snapshots, enabling efficient point-in-time backups and data recovery options. XFS also uses a journaling mechanism that provides fast recovery in case of system crashes or power failures. The journaling feature records modifications to the filesystem metadata, ensuring the consistency and integrity of data. This results in faster boot times and improved reliability, as well as the reduction of time required for filesystem checks during system startup.
Note
Oracle actively contributes to many Linux technologies. The COW XFS feature was one example of an Oracle contribution to the community, keeping Linux free and open source. For more info, refer to https://blogs.oracle.com/linux/post/xfs-data-block-sharing-reflink.
With XFS, administrators can perform a broad range of filesystem operations while the filesystem is mounted and in use. This includes online resizing, enabling seamless expansion or contraction of filesystems without requiring unmounting or disruption of services. These online administration capabilities make XFS highly suitable for environments that demand continuous availability and minimal downtime. XFS also offers extensive support for extended attributes, access-control lists (ACLs), and timestamps with nanosecond precision. These features provide flexibility in managing file metadata and enable the implementation of complex permission structures and custom metadata schemes.
XFS is natively supported by the Linux kernel, making it a well-integrated and widely adopted choice for Linux distributions. It is the default filesystem in Oracle Linux and continues to benefit from ongoing development and improvement by Oracle and the Linux community. Additionally, XFS comes with a comprehensive set of tools for filesystem management and administration, making it an all-around top-notch option.
Getting ready
The examples in this recipe will use the previously created xfs1 LV. XFS filesystems can be created on any block device.
How to do it…
The most common way to create an XFS filesystem is to use the mkfs.xfs command with a single block device. This will place both the data and the journal on the same device:
mkfs.xfs /dev/mapper/DATA-xfs1
Additionally, you can get more control using additional parameters:
Option | Description | Samples |
-L | This adds a label to the filesystem. | –L Test |
-b | This sets the block size. | –b 8192 |
-f | This is the force option. | -f |
-l | This sets the location and size for the journal. This is commonly used to tune the performance by enabling the journal to be on a fast device while the data is on a slower device. Size=20m /dev/$DEVICE | -l 20m /dev/mapper/journal1 |
Table 4.3 – XFS options
Next, add in the /etc/fstab entry info. Make sure to verify whether the mountpoint exists, and that you’re using the correct /dev/mapper path. The updated files are seen in the following screenshot:
Figure 4.28 – /etc/fstab
We can now mount the filesystem with the following mount command:
mount /xfs1
We can clearly see the filesystem is mounted now, as seen in the output from the df command:
Figure 4.29 – df -h
How it works…
Now that the filesystem is mounted, we can do a few things to it. The first task is to grow the filesystem as 2 GB was a tad small for the application. This is done in a few steps. First, we grow the LV that holds the filesystem, and then we can grow the filesystem. Let’s grow this to 10 GB.
To grow the volume, we will use the lvextend command, passing to it the + option to add an additional 8 GB:
lvextend -L +8G /dev/mapper/DATA-xfs1
The output is seen in the following screenshot:
Figure 4.30 – lvextend
Once the LV is grown, we need to extend the actual filesystem. This is done with the xfs_growfs command, passing the mapper path:
xfs_growfs /dev/mapper/DATA-xfs1
Depending on how much activity is on the filesystem, the growth can take a few minutes. The output from the xfs_growfs command will show the details of the filesystem when it completes:
Figure 4.31 – xfs_growfs
You can also see these details by using the xfs_info command, passing the mountpoint of the filesystem or the mapper path.
If you encounter problems mounting an xfs filesystem, you can use the xfs_repair command-line utility to repair and recover it. However, keep in mind that the command must be run on an unmounted filesystem. The main purpose of xfs_repair is to fix inconsistencies and repair filesystem corruption in XFS partitions caused by power failures, system crashes, or hardware issues. You can also use the -n option to check a filesystem without repairing it. For example, you can check the xfs1 filesystem without repairing it by using the following command:
xfs_repair -n /dev/mapper/DATA-xfs1