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
It is present by default on Arch installation media and can be installed as part of the 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.
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
-t PARTUUID for file system label, GPT partition label, file system UUID or GPT partition UUID respectively.
# 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
/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
- 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.