Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

mkfs.xfs

Create an XFS file system — the default file system of RHEL.

Level
RHCSA exam
Group
Disks and file systems
Needs root
Yes
Package
xfsprogs

What it does

XFS is fast with large files and many parallel writers. It can grow while mounted (xfs_growfs) but can not be shrunk. The defaults are good for nearly all cases; the label (-L, max 12 characters) is the option you use most.

How to write it

mkfs.xfs [OPTION]... DEVICE

Options 16

Most used

-L LABEL
Set a label (max 12 characters).
-f
Overwrite an existing file system.
-b size=N
Block size (default 4096).
-d OPTIONS
Data section, like su=,sw= for RAID stripes, agcount=N.
-i OPTIONS
Inode options (size, maxpct).
-l OPTIONS
Log (journal) options, like an external log logdev=.
-m OPTIONS
Metadata options: crc, reflink, bigtime, finobt, uuid=.
-n OPTIONS
Directory naming options.
-r OPTIONS
Realtime section.
-s size=N
Sector size.
-p FILE
Prototype file to fill the file system.
-c options=FILE
Read options from a config file.
-N
Show the settings but do not create anything.
-K
Do not discard (TRIM) blocks at creation.
-q
Quiet.
-V
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Create XFS

    mkfs.xfs /dev/vdb1

    Prints the geometry it chose.

  2. 2With a label

    mkfs.xfs -L data /dev/vdb1

    Mount with LABEL=data.

  3. 3Overwrite an old file system

    mkfs.xfs -f /dev/vdb1

    Without -f it refuses when it finds a file system.

  4. 4On a logical volume

    mkfs.xfs /dev/vgdata/lvdata

    Grow later with lvextend -r.

  5. 5Show settings without creating

    mkfs.xfs -N /dev/vdb1

    Dry run.

  6. 6Fast creation on a thin or SSD device

    mkfs.xfs -K /dev/vdb1

    Skips the discard step (faster on big devices).

  7. 7For a RAID with stripe settings

    mkfs.xfs -d su=64k,sw=4 /dev/md0

    Aligns with the RAID layout.

  8. 8Check the result

    xfs_info /dev/vdb1

    After mounting, use the mount point.

  9. 9Set the label later

    xfs_admin -L newname /dev/vdb1

    Only when not mounted.

  10. 10Remember: no shrinking

    xfs_growfs /data

    XFS grows only. Plan sizes; use ext4 when you may need to shrink.

Exit codes

0Done.
1Error.