46

Both /etc/mtab and /etc/fstab contain data about mounted volumes, for example:

/etc/mtab

/dev/xvda1 / ext4 rw,discard 0 0
proc /proc proc rw,noexec,nosuid,nodev 0 0
...

/etc/fstab

LABEL=cloudimg-rootfs   /    ext4   defaults,discard    0 0
/dev/xvdf /home/ubuntu/logs ext4 rw 0 0

What is the difference between the files?

2 Answers 2

48

/etc/fstab is a list of filesystems to be mounted at boot time. If you want your Windows or file-storage partitions mounted once your computer boots, you'll need to put appropriate entries into /etc/fstab.

/etc/mtab is a list of currently mounted filesystems. If you have a disk connected but not mounted, it won't show up in the /etc/mtab file. Once you mount it, it will show up there.

Note also, that with systemd (to which Ubuntu switched beginning from 15.04 release) it is possible to declare filesystems that need to be mounted at boot via *.mount files. See James Oguya's tutorial on the topic.

For more info, read mount manual.

1
  • Also note that on modern systems /etc/mtab is normally not written to disk anymore. Instead, it is a symbolic link pointing to /proc/self/mounts, which is a virtual file whose contents are generated by the kernel.
    – Bachsau
    Jul 7, 2021 at 10:12
30

TL;DR

  • /etc/fstab is a created by the user. It contains list of volumes to be mounted by mount.
  • /etc/mtab is a created by the system. It contains a list of currently mounted devices.
  • The format of the files is similar. After mounting a new device, copy the relevant line from /etc/mtab to /etc/fstab so that it will be auto-mounted after boot or when calling mount -a.

Quotes from the mount manual

The /etc/fstab, /etc/mtab and /proc/mounts files

The file /etc/fstab, may contain lines describing what devices are usually mounted where, using which options.

The programs mount and umount maintain a list of currently mounted filesystems in the file /etc/mtab.

When the proc filesystem is mounted (say at /proc), the files /etc/mtab and /proc/mounts have very similar contents. The former has somewhat more information, such as the mount options used, but is not necessarily up-to-date.

mount -a

mount -a [-t type] [-O optlist]

(usually given in a bootscript) causes all filesystems mentioned in fstab (of the proper type and/or having or not having the proper options) to be mounted as indicated, except for those whose line contains the noauto keyword. Adding the -F option will make mount fork, so that the filesystems are mounted simultaneously.

3
  • 1
    What if a device shows up as mounted in /etc/fstab but not under /etc/mtab? What is going on then?
    – JohnyTex
    Nov 25, 2020 at 15:02
  • 2
    @JohnyTex it means that the user intended to mount it, but it did not happen for some reason: it might be invalid, or that mount was not executed.
    – Adam Matan
    Nov 25, 2020 at 19:11
  • 1
    In my particular case I can access the partition even though it is not visible in /etc/mtab -any idea how that is possible?
    – JohnyTex
    Nov 26, 2020 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .