Docs: recfstab

Documentation

recfstab

Generate fstab entries from mounted filesystems. Like genfstab for Arch Linux.

Overview

recfstab reads mounted filesystems under a root directory and outputs properly formatted fstab entries to stdout. This is the equivalent of Arch Linux's genfstab command.

The output is suitable for appending to /etc/fstab. Only storage the target owns is listed: filesystems under the root backed by a block device or a network share, and the target's swap. Mount points are written relative to the root.

Usage

Options as printed by recfstab --help:

Text
Reads mounted filesystems under a root directory and outputs fstab entries naming each partition by PARTUUID (or filesystem UUID/LABEL, or PARTLABEL). PARTUUID is what the boot entries name the root by, and it survives `recab copy` creating the other root's filesystem anew. Designed for system installation workflows where you need to generate /etc/fstab for a newly installed system.

Usage: recfstab [OPTIONS] <ROOT>

Arguments:
  <ROOT>
          Root directory to scan for mounted filesystems (e.g., /mnt)

Options:
  -L, --label
          Use filesystem LABEL instead of PARTUUID for device identification

  -U, --uuid
          Use the filesystem UUID instead of PARTUUID

  -p, --partuuid
          Use partition UUID (PARTUUID), the default

  -t, --partlabel
          Use partition LABEL (PARTLABEL) instead of PARTUUID

  -w, --write
          Append the entries to <ROOT>/etc/fstab; refused (E036) when it already has entries for the same mount points

      --replace
          With --write: replace the fstab's entries for those mount points

      --json
          Print the entries, the fstab's current entries and warnings as JSON (errors go to stderr as JSON)

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

Examples:
  recfstab /mnt                   Preview entries; leave fstab unchanged
  recfstab /mnt --write           Append entries to /mnt/etc/fstab
  recfstab /mnt --write --replace  Replace entries for these mount points

Mount the target's root, boot and other filesystems before generating entries.
Plain stdout is valid fstab text, so 'recfstab /mnt > fstab.preview' also works.

Examples

Generate fstab with UUIDs (default)
recfstab /mnt >> /mnt/etc/fstab
Generate fstab with filesystem LABELs
recfstab -L /mnt >> /mnt/etc/fstab
Generate fstab with partition UUIDs
recfstab -p /mnt >> /mnt/etc/fstab
Preview output without writing
recfstab /mnt

Output Format

Each mount produces a commented device path followed by the fstab entry:

Shell
# /dev/nvme0n1p2
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890	/	ext4	relatime	0	1

# /dev/nvme0n1p1
UUID=ABCD-1234	/boot	vfat	relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro	0	0

# /dev/nvme0n1p4
UUID=0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f0	/var	ext4	relatime	0	2

Fields: device identifier, mount point, filesystem type, options, dump, pass. Pass is 1 for /, 2 for other ext2/3/4, XFS and F2FS filesystems, and 0 for the rest (vfat and btrfs are not checked at boot).

Identifier Types

TypeFlagExampleUse Case
UUID(default)UUID=a1b2c3d4-...Most reliable for single-disk systems
LABEL-LLABEL=ROOT_AHuman-readable if you label filesystems
PARTUUID-pPARTUUID=12345678-01GPT partition UUID, survives reformatting
PARTLABEL-tPARTLABEL=EFIGPT partition label if set during partitioning

Filtered Options

Options the kernel adds at mount time are removed, since they should not be pinned in fstab. Everything else is kept as mounted:

  • rw - the default
  • seclabel - SELinux runtime state
  • subvolid=<id> - changes when a btrfs subvolume is recreated, while subvol=<path> is preserved

An entry left with no options gets defaults.

What Is Left Out

Pseudo filesystems (proc, sysfs, devpts, cgroup, efivarfs and the like), tmpfs, overlays and FUSE daemons are not the target's storage, so they are never listed. When a path is mounted twice, only the visible (last) mount is used.

Swap Handling

Active swap (from swapon --show) is included when it belongs to the target:

  • Swap files under the root, with the path written relative to the root
  • Swap partitions on one of the disks that hold the target's filesystems
  • The live system's own swap, on any other disk (including zram), is left out

Error Codes

Every failure prints a code such as E004; the number is also the exit status. The codes and their meaning are the Code enum in tools/recstrap/src/error.rs.

Requirements

  • findmnt, swapon and blkid from util-linux
  • A device without the chosen identifier (for example no filesystem label with -L) is an error, not a fallback to the raw device path
  • Root privileges, for reliable block metadata access

Comparison with genfstab

Featurerecfstabgenfstab
Identifier typesUUID, LABEL, PARTUUID, PARTLABELSame
Output to stdoutYesYes
Pseudo-filesystem filteringAutomaticAutomatic
Network filesystemsIncludedIncluded
btrfs subvolumesSupportedSupported
Swap detectionAutomaticAutomatic

See Also