xfs

filesystemLinux/Unix
The xfs command is one of the most frequently used commands in Linux/Unix-like operating systems. xfs XFS filesystem utilities and commands

Quick Reference

Command Name:

xfs

Category:

filesystem

Platform:

Linux/Unix

Basic Usage:

xfs [options] [arguments]

Common Use Cases

    Syntax

    xfs tools are a suite of commands: xfs_admin, xfs_repair, xfs_db, etc.

    Options

    XFS is managed through a suite of command-line utilities, each with their own set of options:

    mkfs.xfs - Create an XFS filesystem

    Option Description
    -b size=value Specify the block size (in bytes)
    -d name=value Specify data section options
    -i name=value Specify inode options
    -l name=value Specify log section options
    -L label Set the filesystem label
    -f Force overwriting an existing filesystem

    xfs_repair - Repair an XFS filesystem

    Option Description
    -n No-modify mode (check but don't repair)
    -d Repair dangerously (use only as a last resort)
    -v Verbose output
    -L Force log zeroing

    xfs_growfs - Expand an XFS filesystem

    Option Description
    -d Grow data section only
    -D size Grow to specified size
    -i Grow inodes
    -n Don't change anything, just show what would be done

    xfs_admin - Change parameters of an XFS filesystem

    Option Description
    -L label Set the filesystem label
    -U uuid Set the filesystem UUID
    -u Print the UUID
    -l Print the label

    xfs_freeze - Suspend access to an XFS filesystem

    Option Description
    -f Freeze the filesystem
    -u Unfreeze the filesystem

    Examples

    How to Use These Examples

    The examples below show common ways to use the xfs command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    Create an XFS filesystem on a partition
    mkfs.xfs /dev/sdb1
    Mount an XFS filesystem
    mount -t xfs /dev/sdb1 /mnt/xfs_mount
    Check and repair an XFS filesystem (unmounted)
    xfs_repair /dev/sdb1

    Advanced Examples:

    Grow an XFS filesystem to fill the partition
    xfs_growfs /mnt/xfs_mount
    Defragment an XFS filesystem
    xfs_fsr -v /mnt/xfs_mount
    Back up an XFS filesystem metadata
    xfs_metadump /dev/sdb1 metadata_backup.xfsdump
    Freeze an XFS filesystem for backup
    xfs_freeze -f /mnt/xfs_mount
    Unfreeze an XFS filesystem
    xfs_freeze -u /mnt/xfs_mount
    Display XFS filesystem information
    xfs_info /mnt/xfs_mount
    Debug an XFS filesystem
    xfs_db -r /dev/sdb1
    Change XFS filesystem label
    xfs_admin -L "Data_Drive" /dev/sdb1
    Display XFS filesystem UUID
    xfs_admin -u /dev/sdb1
    Set XFS filesystem UUID
    xfs_admin -U generate /dev/sdb1
    Estimate the space used by an XFS filesystem
    xfs_estimate /path/to/directory

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    XFS is a high-performance 64-bit journaling filesystem originally developed by Silicon Graphics, Inc. for their IRIX operating system and later ported to Linux. It is now one of the most robust, mature, and high-performance filesystems available for Linux, particularly well-suited for large filesystems and high-performance requirements. **Core Functionality:** 1. **High Performance**: XFS is designed for high performance and scalability, with excellent throughput for large files and parallel I/O operations. 2. **Large Filesystem Support**: XFS supports extremely large file and filesystem sizes, theoretically up to 8 exbibytes (8×10^18 bytes), although practical limits are often imposed by the kernel or hardware. 3. **Journaling**: XFS uses journaling to ensure filesystem consistency after system crashes or power failures, recording metadata changes before committing them to the main filesystem. 4. **Delayed Allocation**: XFS uses delayed allocation, which improves performance and reduces fragmentation by optimizing how blocks are allocated for file data. 5. **Online Resizing**: XFS filesystems can be grown (but not shrunk) while mounted and in use. 6. **Advanced Features**: XFS includes features like extent-based allocation, variable block sizes, directory indexing, and direct I/O support. **XFS Utilities Suite:** The XFS utilities include several commands for creating, maintaining, and repairing XFS filesystems: 1. **mkfs.xfs**: Creates a new XFS filesystem. 2. **xfs_repair**: Checks and repairs corrupted XFS filesystems (must be unmounted). 3. **xfs_db**: Debug tool for examining and modifying XFS filesystem metadata. 4. **xfs_growfs**: Expands an XFS filesystem (can be done while the filesystem is mounted). 5. **xfs_info**: Displays information about an XFS filesystem. 6. **xfs_admin**: Sets filesystem parameters like labels and UUIDs. 7. **xfs_fsr**: Filesystem reorganizer for defragmenting XFS filesystems. 8. **xfs_freeze**: Temporarily suspends I/O operations on a filesystem, useful for taking snapshots. 9. **xfs_quota**: Manages user and group quotas on XFS filesystems. 10. **xfs_metadump**: Creates a metadata dump for debugging or backup purposes. 11. **xfs_copy**: Makes a copy of an XFS filesystem. 12. **xfs_estimate**: Estimates the space that would be used by an XFS filesystem. **Common Use Cases:** 1. **Enterprise Storage**: XFS is commonly used for enterprise-level storage solutions where reliability and performance are critical. 2. **Large File Handling**: The filesystem excels at handling large files, making it suitable for media servers, database servers, and scientific computing. 3. **High-Performance Computing**: XFS's ability to handle parallel I/O operations efficiently makes it valuable for high-performance computing environments. 4. **Default Filesystem**: Several major Linux distributions, including RHEL and CentOS, use XFS as their default filesystem, especially for server installations. **Technical Details:** 1. **Allocation Groups**: XFS divides storage into allocation groups to enable parallel I/O and improved performance through concurrent access. 2. **B+ Trees**: XFS uses B+ trees for directory indexing, free space management, and inode allocation, providing efficient lookups even with large directories. 3. **Extent-Based Allocation**: Rather than allocating individual blocks, XFS uses extents (contiguous groups of blocks) to reduce fragmentation and metadata overhead. 4. **Delayed Allocation**: XFS defers block allocation until data is written to disk, optimizing space usage and reducing fragmentation. 5. **Direct I/O**: XFS supports direct I/O, bypassing the page cache for applications that manage their own caching. 6. **Write Barriers**: XFS implements write barriers to ensure data integrity, particularly important for journaling operations. **Performance Considerations:** 1. **Mount Options**: Performance can be tuned with various mount options: - `noatime`: Disables access time updates, reducing write operations - `logbsize`: Controls the size of the journal log buffer - `allocsize`: Sets the default allocation size for files 2. **Stripe Alignment**: For RAID arrays, aligning XFS's allocation groups with the RAID stripe size can improve performance: ```bash mkfs.xfs -d su=64k,sw=4 /dev/device ``` 3. **Directory Blocks**: The `dirbsize` parameter can be tuned to optimize directory performance based on expected directory sizes. 4. **Log Size**: The journal log size can be adjusted for specific workloads: ```bash mkfs.xfs -l size=128m /dev/device ``` **Limitations and Considerations:** 1. **No Shrinking**: Unlike some filesystems, XFS cannot be shrunk once created; it can only be grown. 2. **Recovery Time**: For very large filesystems, recovery after a crash can take longer compared to some other filesystems. 3. **Memory Usage**: XFS can use more memory than some other filesystems, particularly for large or complex directory structures. 4. **Small File Performance**: While excellent for large files, XFS may not always offer the best performance for workloads dominated by small files and metadata operations. **Best Practices:** 1. **Regular Backups**: Despite XFS's reliability, regular backups are essential. Use tools like `xfsdump` and `xfsrestore` for XFS-aware backup and recovery. 2. **Appropriate Sizing**: Properly sizing allocation groups and log size during filesystem creation can avoid performance issues later: ```bash mkfs.xfs -d agcount=16 -l size=128m /dev/device ``` 3. **Defragmentation**: For long-running filesystems with changing data, periodic defragmentation with `xfs_fsr` can help maintain performance. 4. **Freeze Before Snapshots**: Use `xfs_freeze` before taking snapshots to ensure filesystem consistency. 5. **External Journals**: For critical systems, consider placing the XFS journal on a separate, possibly higher-performance device: ```bash mkfs.xfs -l logdev=/dev/fast_device /dev/main_device ``` **Historical Context:** XFS was developed by Silicon Graphics, Inc. (SGI) in 1993 for their IRIX operating system. It was later ported to Linux and open-sourced in 2000. Over time, it has gained a reputation for stability, performance, and scalability, leading to its adoption as the default filesystem by several major Linux distributions, particularly for server deployments. The filesystem continues to evolve, with ongoing development focusing on improved performance, scalability, and features like metadata checksumming for enhanced data integrity.

    Related Commands

    These commands are frequently used alongside xfs or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the xfs command works in different scenarios.

    $ xfs
    View All Commands