5 Managing the XFS File System

XFS is a high-performance journaling file system that was initially created by Silicon Graphics, Inc. for the IRIX OS and then later ported to Linux. The parallel I/O performance of XFS provides high scalability for I/O threads, file system bandwidth, file, and file system size, even when the file system spans many storage devices.

A typical use case for XFS is to implement a Tbyte-sized file system across several storage servers, with each server consisting of several FC-connected disk arrays.

XFS can be used with the root (/) or boot file systems on Oracle Linux 8.

XFS has many features that are suitable for deployment in an enterprise-level computing environment that requires the implementation of large file systems:

  • Implements journaling for metadata operations.

    Journaling guarantees the consistency of the file system following loss of power or a system failure. XFS records file system updates asynchronously to a circular buffer (the journal) before it can commit the actual data updates to disk. The journal can be stored either internally in the data section of the file system, or externally on a separate device to reduce contention for disk access. If the system fails or loses power, it reads the journal when the file system is remounted, and replays any pending metadata operations to ensure the consistency of the file system. The speed of this recovery doesn't depend on the size of the file system.

  • Is internally partitioned into allocation groups, which are virtual storage regions of fixed size.

    Any files and directories that you create can span several allocation groups. Each allocation group manages its own set of inodes and free space independently of other allocation groups to provide both scalability and parallelism of I/O operations. If the file system spans many physical devices, allocation groups can optimize throughput by taking advantage of the underlying separation of channels to the storage components.

  • Is an extent-based file system.

    To reduce file fragmentation and file scattering, each file's blocks can have variable length extents, where each extent consists of one or more contiguous blocks. XFS's space allocation scheme is designed to efficiently identify free extents that it can use for file system operations. XFS doesn't allocate storage to the holes in sparse files. If possible, the extent allocation map for a file is stored in its inode. Large allocation maps are stored in a data structure maintained by the allocation group.

  • Includes the reflink and deduplication features, which provides the following benefits:

    • Each copy can have different file metadata (permissions, and so on) because each copy has its own distinct inode. Only the data extents are shared.

    • The file system ensures that any write causes a copy-on-write, without applications requiring to do anything special.

    • Changing one extent continues to permit all the other extents to remain shared. In this way, space is saved on a per-extent basis. Note, however, that a change to a hard-linked file does require a new copy of the entire file.

  • Implements delayed allocation

    To reduce fragmentation and increase performance, XFS reserves file system blocks for data in the buffer cache, and allocates the block when the OS flushes that data to disk.

  • XFS recognizes extended attributes for files.

    The size of each attribute's value can be up to 64 KB, and each attribute can be allocated to either a root or a username space.

  • Direct I/O in XFS implements high throughput, noncached I/O.

    XFS performs DMA directly between an application and a storage device, using the full I/O bandwidth of the device.

  • Includes the snapshot facilities that volume managers, hardware subsystems, and databases provide.

    Use the xfs_freeze command to suspend and resume I/O for an XFS file system. See Freezing and Unfreezing an XFS File System.

  • XFS enables user, group, and project disk quotas on block and inode usage that are initialized when the file system is mounted. Project disk quotas enable you to set limits for individual directory hierarchies within an XFS file system without regard to which user or group has write access to that directory hierarchy.

To maximize throughput for XFS file systems that you create on an underlying striped software or hardware based array, you can use the su and sw arguments to the -d option of the mkfs.xfs command to specify the size of each stripe unit and the number of units per stripe. XFS uses the information to align data, inodes, and journal appropriately for the storage. On lvm and md volumes and some hardware RAID configurations, XFS can automatically select the best stripe parameters for you.

To defragment individual files in an active XFS file system, you can use the xfs_fsr command. See Defragmenting an XFS File System.

To grow an XFS file system, you can use the xfs_growfs command. See Growing an XFS File System.

To back up and restore a live XFS file system, you can use the xfsdump and xfsrestore commands. See Backing Up and Restoring an XFS File System.

For more information about XFS, see https://xfs.wiki.kernel.org/.

For an overview of local file system management, see About File System Management.

Installing XFS Packages

Note:

You can also obtain the XFS packages from the Oracle Linux yum server.

  1. Log in to ULN, and subscribe the system to the ol8_x86_64_baseos_latest channel.

  2. On the system, install the xfsprogs and xfsdump packages:
    sudo dnf install xfsprogs xfsdump
  3. If you require the XFS development and QA packages, subscribe the system to the ol8_x86_64_optional channel and install them:

    sudo dnf install xfsprogs-devel xfsprogs-qa-devel

Creating an XFS File System

You can use the mkfs.xfs command to create an XFS file system, for example:

sudo mkfs.xfs /dev/vg0/lv0

Running the previous command produces the following output:

meta-data=/dev/vg0/lv0           isize=256    agcount=32, agsize=8473312 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=271145984, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=32768, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0 

The following examples shows how you would create an XFS file system with a stripe-unit size of 32 KB and 6 units per stripe. To do so, you would specify the su and sw arguments to the -d option:

sudo mkfs.xfs -d su=32k,sw=6 /dev/vg0/lv1

For more information, see the mkfs.xfs(8) manual page.

Modifying an XFS File System

Note:

You can't modify a mounted XFS file system.

You can use the xfs_admin command to modify an unmounted XFS file system, such as the following actions:

  • Enable or disable lazy counters

  • Change the file system UUID

  • Change the file system label

To display the existing label for an unmounted XFS file system and then apply a new label, use the following command:

sudo xfs_admin -l /dev/sdb
label = ""
sudo xfs_admin -L "VideoRecords" /dev/sdb
writing all SBs
new label = "VideoRecords"

Note:

The label can be a maximum of 12 characters in length.

To display the existing UUID and then generate a new UUID, use the following command:

sudo xfs_admin -u /dev/sdb
sudo xfs_admin -U generate /dev/sdb

To clear the UUID altogether, use the following command:

sudo xfs_admin -U nil /dev/sdb
Clearing log and setting UUID
writing all SBs
new UUID = 00000000-0000-0000-0000-000000000000

To disable and then reenable lazy counters, use the following commands:

sudo xfs_admin -c 0 /dev/sdb
sudo xfs_admin -c 1 /dev/sdb

For more information, see the mkfs_admin(8) manual page.

Growing an XFS File System

Note:

You can't grow an unmounted XFS file system. Also, no command exists to shrink an XFS file system.

You can use the xfs_growfs command to increase the size of a mounted XFS file system if space is available on the underlying devices to accommodate the change. The command doesn't have any effect on the layout or size of the underlying devices. If needed, use the underlying volume manager to increase the physical storage that's available. For example, you can use the vgextend command to increase the storage that's available to an LVM volume group and lvextend to increase the size of the logical volume that contains the file system.

You can't use the parted command to resize a partition that contains an XFS file system. You must instead re-create the partition with a larger size and restore its contents from a backup if you deleted the original partition or from the contents of the original partition if you didn't delete it to free up disk space.

For example, you would increase the size of /myxfs1 to 4 TB, assuming a block size of 4 KB, as follows:

sudo xfs_growfs -D 1073741824 /myxfs1

To increase the size of the file system to the maximum size that the underlying device supports, specify the -d option:

sudo xfs_growfs -d /myxfs1

For more information, see the xfs_growfs(8) manual page.

In Oracle Linux 8, you can create XFS file systems by using the Reflink feature. This feature reduces disk space consumption and copies files faster. For example, if you use a reflink-aware tool to copy a directory tree, the files in the copy share disk space with the original. It takes much less time make a reflink copy of the directory tree than to create a regular copy of a file system. In addition, no added storage is used.

Note that the reflink feature is enabled by default in Oracle Linux 8 when formatting by using the mkfs.xfs command.

To begin working with XFS's reflink support, do the following steps:

  1. Format a file system:

    sudo mkfs.xfs /dev/sda1
    meta-data=/dev/sda1              isize=512    agcount=4, agsize=6553600 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=1, sparse=1, rmapbt=0
             =                       reflink=1
    data     =                       bsize=4096   blocks=26214400, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
    log      =internal log           bsize=4096   blocks=12800, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
  2. Mount the file system:

    sudo mount /dev/sda1 /storage

    The files system is now ready to absorb new files.

For a detailed demonstration on using the reflink feature, see https://blogs.oracle.com/linux/xfs-data-block-sharing-reflink.

Freezing and Unfreezing an XFS File System

If you need to take a hardware-based snapshot of an XFS file system, you can temporarily stop write operations to it.

Note:

You don't need to explicitly suspend write operations if you use the lvcreate command to take an LVM snapshot.

To freeze an XFS file system, use the -f option with the xfs_freeze command:

sudo xfs_freeze -f /myxfs

To unfreeze an XFS file system, use the -u option with the xfs_freeze command:

sudo xfs_freeze -u /myxfs

Note:

You can also use the xfs_freeze command with btrfs, ext3, and ext4 file systems.

For more information, see the xfs_freeze(8) manual page.

Managing Quotas on an XFS File System

Use the xfs_quota tool to manage quotas on an XFS file system. This tool is catered to quota implementation in XFS. While other quota tools, such as edquota might enable you to edit XFS quotas, xfs_quota is preferred.

For more information, see the xfs_quota(8) manual page.

Displaying Block Usage Information

To display the block usage limits and the current usage in the myxfs file system for all users, use the xfs_quota command, for example:

xfs_quota -x -c 'report -h' /myxfs
User quota on /myxfs (/dev/vg0/lv0)
                        Blocks              
User ID      Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
root            0      0      0  00 [------]
guest           0   200M   250M  00 [------]

The following forms of the command display the free and used counts for blocks and inodes in the manner of the df -h command:

sudo xfs_quota -c 'df -h' /myxfs
Filesystem     Size   Used  Avail Use% Pathname
/dev/vg0/lv0 200.0G  32.2M  20.0G   1% /myxfs
sudo xfs_quota -c 'df -ih' /myxfs
Filesystem   Inodes   Used   Free Use% Pathname
/dev/vg0/lv0  21.0m      4  21.0m   1% /myxfs

Setting Quota Limits

If you specify the -x option to enter expert mode, you can use subcommands such as limit to set soft and hard limits for block and inode usage by an individual user, for example:

sudo xfs_quota -x -c 'limit bsoft=200m bhard=250m isoft=200 ihard=250 guest' /myxfs 

Note that this command requires that you have mounted the file system with user quotas enabled.

To set limits for a group on an XFS file system that you have mounted with group quotas enabled, specify the -g option to limit:

sudo xfs_quota -x -c 'limit -g bsoft=5g bhard=6g devgrp' /myxfs

Setting Project Quota Limits

The instructions that follow here assume that you have already mounted the file system using the pquota option and have created a project ID in /etc/projects. See Setting Project Quotas.

  1. Use the project subcommand of xfs_quota to define a managed tree in the XFS file system for the project.

    sudo xfs_quota -x -c ’project -s project_namemountpoint

    For example, you would define a managed tree in the /myxfs file system for the project testproj, which corresponds to the directory hierarchy /myxfs/testdir, as follows:

    sudo xfs_quota -x -c ’project -s testproj’ /myxfs
  2. Use the limit subcommand to set limits on the disk usage of the project.

    sudo xfs_quota -x -c ’limit -p arguments project_namemountpoint

    For example, to set a hard limit of 10 GB of disk space for the project testproj, you would use the following command:

    sudo xfs_quota -x -c ’limit -p bhard=10g testproj’ /myxfs

For more information, see the projects(5), projid(5), and xfs_quota(8) manual pages.

Backing Up and Restoring an XFS File System

The xfsdump package contains the xfsdump and xfsrestore utilities. The xfsdump command examines the files in an XFS file system, identifies files that need to be backed up, and copies them to the storage medium. Any backups that you create by using the xfsdump command are portable between systems with different endian architectures. The xfsrestore command restores a full or incremental backup of an XFS file system. You can also restore individual files and directory hierarchies from backups.

Note:

Unlike an LVM snapshot, which immediately creates a sparse clone of a volume, xfsdump takes time to make a copy of the file system data.

You can use the xfsdump command to create a backup of an XFS file system on a device such as a tape drive or in a backup file on a different file system. A backup can span several physical media that are written on the same device. Also, you can write several backups to the same medium. Note that you can write only a single backup to a file. The command doesn't overwrite existing XFS backups that are found on physical media. If you need to overwrite any existing backups, you must use the appropriate command to erase a physical medium.

For example, the following command writes a level 0 (base) backup of the XFS file system (/myxfs) to the device, /dev/st0, and assigns a session label to the backup:

sudo xfsdump -l 0 -L "Backup level 0 of /myxfs `date`" -f /dev/st0 /myxfs

You can make incremental dumps that are relative to an existing backup by using the same command, for example:

sudo xfsdump -l level -L "Backup level level of /myxfs `date`" -f /dev/st0 /myxfs

A level 1 backup records only file system changes after the level 0 backup, a level 2 backup records only the changes after the latest level 1 backup, and so on up to level 9.

If you interrupt a backup by typing Ctrl-C and you didn't specify the -J option (suppress the dump inventory) to xfsdump , you can resume the dump later by specifying the -R option, for example:

sudo xfsdump -R -l 1 -L "Backup level 1 of /myxfs `date`" -f /dev/st0 /myxfs

In the previous example, the backup session label from the earlier interrupted session is overridden.

Use the xfsrestore command to find out information about the backups you have made of an XFS file system or to restore data from a backup.

The xfsrestore -I command displays information about the available backups, including the session ID and session label. To restore a specific backup session from a backup medium, you can specify either the session ID or the session label.

For example, to restore an XFS file system from a level 0 backup by specifying the session ID, you would use the following command:

sudo xfsrestore -f /dev/st0 -S c76b3156-c37c-5b6e-7564-a0963ff8ca8f /myxfs

Specify the -r option to cumulatively recover all the data from a level 0 backup, as well as higher-level backups that are based on that backup:

sudo xfsrestore -r -f /dev/st0 -v silent /myxfs

This command searches for backups in the archive, based on the level 0 backup, and then prompts you to choose whether you want to restore each backup, in turn. After restoring the selected backup, the command exits. Note that you must run this command several times, first selecting to restore the level 0 backup, and then later higher-level backups, including the most recent backup that you require to restore the file system data.

Note:

After completing a cumulative restoration of an XFS file system, delete the housekeeping directory that the xfsrestore command creates in the destination directory.

As shown in the following example, you can recover a selected file or subdirectory contents from the backup medium. Running the command recovers the contents of /myxfs/profile/examples to /tmp/profile/examples, from the backup with the specified session label:

sudo xfsrestore -f /dev/sr0 -L "Backup level 0 of /myxfs Sat Mar 2 14:47:59 GMT 2013" \
  -s profile/examples /usr/tmp

Alternatively, you can interactively browse a backup by specifying the -i option, for example:

sudo xfsrestore -f /dev/sr0 -i

The previous form of the command enables you browse a backup as though it were a file system. You can change directories, list files, add files, delete files, or extract files from a backup.

To copy the entire contents of one XFS file system to another, you can combine the xfsdump and xfsrestore command by using the -J option to suppress the usual dump inventory housekeeping that the commands perform, for example:

sudo xfsdump -J - /myxfs | xfsrestore -J - /myxfsclone

For more information, see the xfsdump(8) and xfsrestore(8) manual pages.

Checking and Repairing an XFS File System

Note:

If you have an Oracle Linux Premier Support account and observe a problem mounting an XFS file system, send a copy of the /var/log/messages file to Oracle Support and wait for advice.

If you can't mount an XFS file system, you can use the xfs_repair -n command to check its consistency. Typically, you would only run this command on the device file of an unmounted file system that you believe has a problem. The xfs_repair -n command displays output to indicates changes that would be made to the file system in the case where it would need to complete a repair operation, but doesn't modify the file system directly.

If you can mount the file system and you don't have a suitable backup, you can use the xfsdump command to back up the existing file system data. However, note that the command might fail if the file system's metadata has become corrupted.

You can use the xfs_repair command to repair an XFS file system that's specified by its device file. The command replays the journal log to fix any inconsistencies that might have resulted from the file system not being cleanly unmounted. Unless the file system has an inconsistency, you typically don't need to use the follwoing command, as the journal is replayed every time that you mount an XFS file system.

sudo xfs_repair device

If the journal log has become corrupted, you can reset the log by specifying the -L option to xfs_repair.

Attention:

Resetting the log can leave the file system in an inconsistent state, resulting in data loss and data corruption. Unless you're experienced with debugging and repairing XFS file systems by using the xfs_db command, we recommend that you instead re-create the file system and restore its contents from a backup.

If you can't mount the file system or you don't have a suitable backup, running the xfs_repair command is the only viable option, unless you're experienced in using the xfs_db command.

xfs_db provides an internal command set for debuggin and repairing an XFS file system manually. The commands enable you to perform scans on the file system, and navigate and display its data structures. If you specify the -x option to enable expert mode, you can modify the data structures.

sudo xfs_db [-x] device

For more information, see the xfs_db(8) and xfs_repair(8) manual pages, and run the help command within xfs_db.

Defragmenting an XFS File System

You can use the xfs_fsr command to defragment whole XFS file systems or individual files within an XFS file system. As XFS is an extent-based file system, defragmenting a whole file system is unnecessary and also discouraged.

To defragment an individual file, use the following command to specify the name of the file as the argument to xfs_fsr:

sudo xfs_fsr pathname

Running the xfs_fsr command without any options defragments all the mounted and writeable XFS file systems that are listed in /etc/mtab. For two hours, the command passes over each file system, in turn, and defragments the top 10 percent of files with the greatest number of extents. After two hours, the command records its progress in the /var/tmp/.fsrlast_xfs file. If you run the command again, the process is resumed from that point.

For more information, see the xfs_fsr(8) manual page.