Basic Operations

Creating XFS

# Format with default parameters
$ mkfs.xfs /dev/sda1

# Format with specific block size
$ mkfs.xfs -b size=4096 /dev/sda1

# Format with directory block size
$ mkfs.xfs -n size=8192 /dev/sda1

# Create with specific sector size
$ mkfs.xfs -s size=512 /dev/sda1

Mounting Operations

# Basic mount
$ mount -t xfs /dev/sda1 /mnt/data

# Mount with specific options
$ mount -o noatime,nodiratime /dev/sda1 /mnt/data

# Mount with quota support
$ mount -o uquota,gquota /dev/sda1 /mnt/data

# Add to fstab
/dev/sda1  /mnt/data  xfs  defaults  0  2

Maintenance

Filesystem Check

# Check XFS filesystem
$ xfs_repair /dev/sda1

# Force check (unmounted only)
$ xfs_repair -L /dev/sda1

# Check with verbose output
$ xfs_repair -v /dev/sda1

# Dry run check
$ xfs_repair -n /dev/sda1

Backup Operations

# Create filesystem backup
$ xfsdump -f /backup/xfs.dump /mnt/data

# Incremental backup (level 1)
$ xfsdump -l 1 -f /backup/xfs.dump.1 /mnt/data

# Restore from backup
$ xfsrestore -f /backup/xfs.dump /mnt/data

# List contents of backup
$ xfsrestore -i -f /backup/xfs.dump

Advanced Operations

Quota Management

# Enable user quotas
$ xfs_quota -x -c 'limit bsoft=100m bhard=120m user1' /mnt/data

# Display quota information
$ xfs_quota -x -c 'report' /mnt/data

# Set project quota
$ xfs_quota -x -c 'project -s projectname' /mnt/data

# Check quota status
$ xfs_quota -x -c 'state' /mnt/data

Performance Tuning

# Disable atime updates
$ mount -o noatime /dev/sda1 /mnt/data

# Enable direct I/O
$ mount -o dio /dev/sda1 /mnt/data

# Set allocation groups
$ mkfs.xfs -d agcount=32 /dev/sda1

# Enable realtime subvolume
$ mkfs.xfs -r rtdev=/dev/sdb1 /dev/sda1

Monitoring

System Information

# Display filesystem info
$ xfs_info /mnt/data

# Show filesystem stats
$ xfs_db -r -c "sb 0" -c "p" /dev/sda1

# Display free space
$ xfs_spaceman -c "freesp" /mnt/data

# Show fragmentation
$ xfs_db -r -c "frag" /dev/sda1

Debugging Tools

# Metadata debugger
$ xfs_db /dev/sda1

# Check metadata consistency
$ xfs_metadump /dev/sda1 /tmp/metadata

# Examine inode
$ xfs_db -r -c "inode 128" /dev/sda1

# Trace filesystem operations
$ xfs_io -c "tracefile /tmp/trace.log" /mnt/data

Field Types

Mount Options

Option Description
noatime Disable access time updates
nodiratime Disable directory access time updates
logbufs=8 Number of log buffers
logbsize=256k Size of each log buffer

Repair Options

Option Description
-L Force log zeroing
-n No modify mode
-P Disables prefetch operations
-r Read-only mode

References

  • Based on XFS filesystem version 5.x
  • Consult the XFS documentation for complete details: man xfs, man xfsdump, man xfs_repair
0 Comments for this cheatsheet. Write yours!