genfstab - ArchWiki

Jump to content
From ArchWiki

This article or section is a candidate for merging with fstab#Tips and tricks.

Notes: There is not enough content for a separate article. The genfstab(8) man page provides everything besides the warnings and examples. (Discuss in Talk:Genfstab)

Related articles

- fstab
- Persistent block device naming
- File systems

genfstab is a Bash script that is used to automatically detect all mounts under a given mountpoint, its output can then be redirected into a file, usually `/etc/fstab`.

## Installation

It is present by default on Arch installation media and can be installed as part of the arch-install-scripts package on an already installed system.

There is also a stand alone fork of this tool that can be used on other distributions, you can find it here.

## Usage

You can get a list of your current mounts by using:

    $ genfstab /

The script supports finding mounts by kernel descriptor, device/partition label or device/partition UUID. It will output `kernel descriptor` by default (kernel descriptor being `/dev/xxx`), you can use `-L`, `-t PARTLABEL`, `-U` or `-t PARTUUID` for file system label, GPT partition label, file system UUID or GPT partition UUID respectively.

Warning: Kernel name descriptors for block devices are not persistent and can change each boot, they should not be used in configuration files (including `/etc/fstab`).

The more common usage scenario would be getting an fstab for a chroot, for this you would do something like the following:

    # mount /dev/sda3 /mnt
    # mount --mkdir /dev/sda1 /mnt/efi

    $ genfstab -U /mnt

    # /dev/sda3
    UUID=185aebd2-ce76-47dd-baf4-5ad0a80fa963       /               ext4            rw,noatime      0 1

    # /dev/sda1
    UUID=E5C7-6DD7          /efi       vfat             rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro   0 2

In this case `genfstab` shows both mounts below the mountpoint `/mnt` and list them by device `UUID`.

Tip: Notice we mounted the device `sda3` into `/mnt` yet genfstab shows it as being the main root mountpoint `/`, this is because it treats the given mountpoint as the root mount.

Usually you would want to redirect the output to a file, this can be achieved with the following:

    # genfstab -U /mnt >> /mnt/etc/fstab

Warning:

- Make sure you create a backup of your existing fstab before overwriting it.
- Be mindful of where you are saving the fstab file, for example if you want to create it for a chroot then you do not want to overwrite the one on your main installation.

Categories:

- File systems
- Installation process

Hidden category:

- Pages or sections flagged with Template:Merge