LinuxCommandLibrary

genfstab

Generate fstab file for current system

TLDR

Generate the /etc/fstab file using volume UUIDs during an Arch Linux installation (requires root permissions)

$ genfstab -U [/mnt] >> [/mnt/etc/fstab]
copy

Display fstab-compatible output based on volume labels
$ genfstab -L [path/to/mount_point]
copy

Display fstab-compatible output based on volume UUIDs
$ genfstab -U [path/to/mount_point]
copy

Display fstab-compatible output based on the specified identifier
$ genfstab -t [LABEL|UUID|PARTLABEL|PARTUUID]
copy

Append a volume into the /etc/fstab file to mount it automatically
$ genfstab -U [path/to/mount_point] | sudo tee -a /etc/fstab
copy

SYNOPSIS

genfstab [options] [rootdir]

PARAMETERS

-U, --uuid
    Generate entries using filesystem UUIDs. This is generally the recommended and default behavior for stable booting.

-L, --label
    Generate entries using filesystem labels instead of UUIDs or device paths.

-P, --path
    Generate entries using device paths (e.g., /dev/sda1). Less robust than UUIDs/labels.

-R, --root


    Specify the root directory of the target system. This is crucial when running genfstab from a live environment or another system.

-r, --old-root
    Specify the old root directory. Useful when running genfstab from within a chroot where the original root is still accessible.

-F, --fstab
    Specify an alternative fstab file to read from instead of /etc/fstab.

-A, --all
    Include all currently mounted filesystems, including bind mounts, virtual filesystems (proc, sys, devpts), etc.

--no-dump
    Do not include the dump field (the fifth field) in the generated entries.

--no-pass
    Do not include the pass field (the sixth field) in the generated entries. This field determines fsck order.

--no-defaults
    Do not add defaults as a mount option if no specific options are determined.

--preserve-swap
    Preserve existing swap entries from the specified fstab file.

--preserve-all
    Preserve all existing non-root entries from the specified fstab file, merging them with newly generated entries.

--exclude
    Exclude a specific mount point from the generated entries.

--exclude-fs
    Exclude filesystems of a specific type (e.g., tmpfs, proc) from the generated entries.

--help
    Display a help message and exit.

--version
    Output version information and exit.

DESCRIPTION

The genfstab command is a utility designed to automatically generate entries for the /etc/fstab file, based on the currently mounted filesystems or a specified root directory. It scans the detected mount points, determines filesystem types, device paths (or more robustly, UUIDs or labels), and appropriate mount options (like defaults, noatime).

It is most commonly used in system installation or recovery scenarios, particularly within a chroot environment, to create an initial or updated fstab file for a new or existing Linux system. This helps ensure that filesystems are mounted correctly upon boot, especially for partitions that might not be easily identified by traditional device paths (e.g., due to kernel device naming changes). By default, it prioritizes using UUIDs or labels for greater reliability and persistence across reboots or hardware changes.

CAVEATS

genfstab generates entries based on the current system state or a specified root. It might not perfectly replicate a hand-tuned fstab file, especially regarding custom mount options or specific dump/pass values. Always review the generated output before redirecting it to /etc/fstab, as an incorrect fstab can prevent your system from booting. It's primarily a tool for generating an initial fstab or for basic system recovery, not for complex, nuanced configurations.

TYPICAL USAGE

The most common use case involves generating an fstab for a new system mounted at a specific directory (e.g., /mnt) from a live environment. The output is usually redirected to the target system's /etc/fstab.

Example: genfstab -U /mnt > /mnt/etc/fstab

This command scans the filesystems mounted under /mnt (including /mnt/boot, /mnt/home, etc.) and generates fstab entries using UUIDs, writing them to /mnt/etc/fstab.

UUIDS VS. DEVICE PATHS

While genfstab can generate entries using device paths (e.g., /dev/sda1), it strongly recommends and often defaults to using UUIDs (Universally Unique Identifiers) or LABELS. UUIDs are unique identifiers assigned to filesystems and remain constant even if the device path changes (e.g., due to adding or removing other drives), making them far more reliable for system booting.

HISTORY

The genfstab utility is typically part of distribution-specific scripts or utilities (e.g., in Arch Linux's arch-install-scripts package) or integrated into installation environments. Its primary development focus has been on simplifying the creation of a correct /etc/fstab, especially for new installations or when dealing with systems where device names might be inconsistent. Over time, it has evolved to prioritize the use of UUIDs and filesystem labels for increased robustness, moving away from less reliable device paths.

SEE ALSO

fstab(5), mount(8), lsblk(8), blkid(8), chroot(1)

Copied to clipboard