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:
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
recfstab /mnt >> /mnt/etc/fstab recfstab -L /mnt >> /mnt/etc/fstab recfstab -p /mnt >> /mnt/etc/fstab recfstab /mnt Output Format
Each mount produces a commented device path followed by the fstab entry:
# /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
| Type | Flag | Example | Use Case |
|---|---|---|---|
| UUID | (default) | UUID=a1b2c3d4-... | Most reliable for single-disk systems |
| LABEL | -L | LABEL=ROOT_A | Human-readable if you label filesystems |
| PARTUUID | -p | PARTUUID=12345678-01 | GPT partition UUID, survives reformatting |
| PARTLABEL | -t | PARTLABEL=EFI | GPT 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 defaultseclabel- SELinux runtime statesubvolid=<id>- changes when a btrfs subvolume is recreated, whilesubvol=<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,swaponandblkidfrom 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
| Feature | recfstab | genfstab |
|---|---|---|
| Identifier types | UUID, LABEL, PARTUUID, PARTLABEL | Same |
| Output to stdout | Yes | Yes |
| Pseudo-filesystem filtering | Automatic | Automatic |
| Network filesystems | Included | Included |
| btrfs subvolumes | Supported | Supported |
| Swap detection | Automatic | Automatic |
See Also
- recstrap - Extract the base system
- recchroot - Enter chroot environment
- Installation Tools Overview - Workflow overview