genfstab
Generate fstab file for current system
TLDR
Display an fstab compatible output based on a volume label
Display an fstab compatible output based on a volume UUID
A usual way to generate an fstab file, requires root permissions
Append a volume into an fstab file to mount it automatically
SYNOPSIS
genfstab [options] [path]
PARAMETERS
-U
Use UUIDs for identifying devices. This is the default.
-L
Use labels for identifying devices.
-t fstypes
Specify filesystem types to include in the fstab
file.
Comma-separated list (e.g., ext4,xfs
). Defaults to all filesystem types if not specified.
-p
Print output to standard output. Otherwise, it will write to /etc/fstab
.
-o options
Append additional options to each fstab
entry. Example: -o noatime,discard
-s
Do not use swap device in output
path
Optional path to the root filesystem. If specified, genfstab
will use this path to determine filesystem information instead of relying on the currently mounted filesystems.
DESCRIPTION
The genfstab
command is a utility primarily used in Linux environments, especially during system installation or recovery. Its core function is to automatically generate an /etc/fstab
file based on the currently mounted filesystems. The fstab
file is crucial for defining how and where filesystems should be mounted during system boot. Instead of manually editing this file (which can be prone to errors), genfstab
automatically detects existing partitions, their UUIDs or labels, and their mount points. It then constructs a suitable fstab
entry for each. This significantly simplifies the process of configuring persistent filesystem mounting. It can be used with or without root permissions (using the -U or -L flags without root). It relies on querying the kernel and parsing mount information to accurately represent the current filesystem layout in the generated fstab
file. It supports multiple output formats to standard output or file as well as filtering mounted file system types.
CAVEATS
genfstab
relies on the current mount state. If filesystems are not properly mounted, the generated fstab
file may be incomplete or incorrect. It's essential to ensure that all intended partitions are mounted before running genfstab
. Incorrect entries in /etc/fstab
can cause boot failures.
EXAMPLES
Basic usage: genfstab -p /mnt > fstab
Generates an fstab
file based on the mounted filesystems under /mnt
and prints the output to fstab
file.
Using labels: genfstab -L -p
Generates an fstab
file using labels instead of UUIDs and prints the output to standard output.
Specifying filesystem types: genfstab -t ext4,btrfs -p
Only includes ext4 and btrfs filesystem types in the generated fstab
file.
HISTORY
genfstab
emerged as a convenient tool in Linux distributions, particularly within Arch Linux, to simplify the often-tedious task of creating the /etc/fstab
file. Its primary motivation was to automate the process of detecting and representing existing filesystems, UUIDs/labels, and mount points in the correct fstab
format. Early versions provided basic functionality. Development has focused on improving accuracy, supporting different filesystem types, and offering options for customization (e.g., UUIDs vs. labels, specific filesystem types). Its adoption has grown alongside the increasing complexity of modern Linux systems and the need for streamlined installation and recovery procedures.