Creating and Mounting an XFS File System

Use the mkfs.xfs command to create an XFS file system on a block device, such as a partition, an LVM volume, a disk, or a similar hardware device.

You create XFS file systems by using the mkfs.xfs command. The default options for the command are appropriate for most common use cases. For more information, see the mkfs.xfs(8) manual page.

  1. Identify the target device, partition, or file that you want to format with XFS.

    Typically, you might use the lsblk command to list block devices and partitions that are available to the system.

    Note that formatting a file system is a destructive operation and erases any data on the target device. Ensure that the following steps use the correct target device or file paths.

  2. To create an XFS file system on a device, run:
    sudo mkfs.xfs [options] <device>

    For example, to format a file system on the device /dev/sdb1 with the default options, run:

    sudo mkfs.xfs /dev/sdb1

    Use the appropriate flags to set any custom options on the file system if you need to do so. See Notable XFS Feature Options.

  3. Mount the file system.

    For example, you can run:

    sudo mount /dev/sdb /mnt
  4. Validate and view information about the file system using the xfs_info command.
    For example, you can run:
    xfs_info /mnt

    The command returns information including the device path and the file system geometry. See the xfs_info(8) manual page for more information.

Notable XFS Feature Options

You can set some notable options when creating an XFS file system. Options are also described in more detail in the mkfs.xfs(8) manual page.

Table 3-1 Notable XFS Feature Options

Option Description
logdev

Using an external log device for the XFS journal can reduce disk contention and improve the file system's I/O throughput. A suitable host device for the journal is a solid-state drive (SSD) device or a RAID device with a battery-backed, write-back cache. The default location for an XFS journal is on the same block device as the data.

To reserve an external journal with a specified size when you create an XFS file system, specify the -l logdev=device,size=size option to the mkfs.xfs command. If you omit the size parameter, mkfs.xfs selects a journal size based on the size of the file system. To mount the XFS file system so that it uses the external journal, specify the -o logdev=device option to the mount command.

bigtime

The bigtime option extends the maximum recorded inode timestamps from 2038 to 2486. This feature requires a kernel later than 5.10 and after it's enabled the file system can no longer be mounted on systems running an earlier kernel.

Older XFS file systems might be formatted without this option enabled. To enable the option on an existing file system, use the xfs_admin -O bigtime=1 command. See Changing XFS File System Feature Options for more information.

inobtcount

The inobtcount option reduces mount time on large file systems by speeding up metadata space reservation calculations. This feature requires a kernel later than 5.10 and after it's enabled the file system can no longer be mounted on systems running an earlier kernel.

Older XFS file systems might be formatted without this option enabled. To enable the option on an existing file system, use the xfs_admin -O inobtcount=1 command. See Changing XFS File System Feature Options for more information.

reflink

The reflink feature takes advantage of the copy-on-write functionality within XFS to create lightweight copies of a file or directory within an XFS file system. This feature is enabled by default, unless CRC checks are disabled or the XFS file system is used with a DAX mount option.

See Copying Files By Using Shared Data Blocks for more information.

su, sw The su option, for stripe unit, and the sw option, for stripe width, can be specified when formatting an XFS file system for a RAID device or a striped logical volume. Specify the -d su=<size>,sw=<width> option to the mkfs.xfs command when you need to specify particular device geometry. The stripe unit is specified as a multiple of the file system block size. The stripe width is expressed as a multiplier of the stripe unit value and is usually the same as the number of members in the striped logical volume configuration or number of disks in the RAID device.