231

I modified /etc/fstab.

I verified the new devices and I can mount them with the mount command.

How may I validate the modifications made to /etc/fstab ?

8 Answers 8

237

You can simple run: mount -a

-a Mount all filesystems (of the given types) mentioned in fstab.

This command will mount all (not-yet-mounted) filesystems mentioned in fstab and is used in system script startup during booting.

5
  • 5
    ...and compare it to /etc/mtab once you've done a "sudo mount -a", just to make sure all your options have been honoured.
    – adebaumann
    Commented Aug 25, 2010 at 10:25
  • 1
    mount -a by rereading /etc/fstab would also reload /etc/mtab so he should be fine with that only.
    – Prix
    Commented Aug 26, 2010 at 2:41
  • 4
    isn't that the point which adebaumann is trying to raise here? mount -a might return success, but doesn't necessarily mean that all the specific mount options have been honoured. since this will also reload /etc/mtab, you should check to see if all option are working?
    – RapidWebs
    Commented Jun 28, 2014 at 7:21
  • 1
    You may need to run a "systemctl daemon-reload" before this. Mount uses systemd's view of the world and if that is not updated you will just be loading what was present at last boot
    – m12lrpv
    Commented Dec 22, 2021 at 7:37
  • 2
    From current mount man page: Note that it is a bad practice to use mount -a for fstab checking. The recommended solution is findmnt --verify. (see answer by rockwotj)
    – simon
    Commented Sep 1 at 12:30
135
+150

sudo findmnt --verify --verbose is the best way I've found

4
  • 11
    Amazing answer. I'd never heart of findmnt before, but it's really fully-featured and part of util-linux! Commented May 5, 2020 at 3:18
  • findmnt told me that fuse.sshfs seems unsupported by the current kernel, which is not true because I was able to mount the sshfs share with mount -a
    – user84207
    Commented Mar 8, 2021 at 3:10
  • this could not detect typos XD errors=remout-ro for example, i have to boot using another live cd to investigate
    – Kokizzu
    Commented Jun 25, 2022 at 6:09
  • I can't thank you enough! It saved me a lot of effort while troubleshooting fuse3-based mounting of azure-blob-container. Commented May 29 at 13:44
112

The mount command take an --fake or -f for short. The following command should do what you need:

mount -fav

The following is in the documentation for -f option:

Causes everything to be done except for the actual system call; if it's not obvious, this ``fakes'' mounting the filesystem. This option is useful in conjunction with the -v flag to determine what the mount command is trying to do.

(Note this is Linux - check before using elsewhere: FreeBSD uses -f for 'force' - exactly the opposite meaning.)

6
  • 10
    mount -fav doesn't check that device with specified UUID is actually in the system. Also one would like to combine -f with -n not to pollute /etc/mtab Commented Feb 6, 2015 at 17:55
  • I like mount --fake -a but it seems to return exit code($?)=0 always. Umm..
    – kujiy
    Commented Oct 3, 2018 at 11:54
  • 3
    Also the fake option does not check whether the directory exists. It says successfully mounted even when the mount point dosent exist Commented Nov 23, 2018 at 8:33
  • 1
    This seems to be a good first thing to try, but you should also do a "mount -a" afterwards to verify. In my case, I set the options to "default" instead of "defaults" (which was preventing my Pi from booting), but mount -fav validated it as correct. As soon as I did a mount -a it found an error. Commented Aug 11, 2019 at 20:42
  • work with me "Debian GNU/Linux 11 (bullseye)" Commented Jul 28, 2022 at 15:24
10

Note that if you add a swap file to your fstab, mount -a won't turn it on: you'll want to run swapon -a.

4

I found this /problem/ but the solution didn't meet my requirements.

When rebooting with any invalid entries in the /etc/fstab, such as missing file systems that fsck cannot check; the system will fail to boot. That can be much more difficult to deal with if you have a headless box.

This is my solution to checking /etc/fstab to avoid this boot problem:

    # cat /usr/local/bin/check-fstab-uuid-entries.sh
    #!/usr/bin/env bash

    for x in $(grep ^UUID /etc/fstab|cut -d \  -f 1|cut -d = -f 2)
    do
            if [ ! -h /dev/disk/by-uuid/$x ];then
                    echo $(grep $x /etc/fstab)  ..... not found
            fi
    done
2
  • 1
    Nice script, but can you please explain what it does? Commented Jan 28, 2022 at 21:10
  • @PeterWippermann Well, it just checks fstab entries using UUID to make sure the volume is available; if it wasn't available then boot would stop and require intervention to continue. I think other options might be better, like mount -fav ... Commented Jan 30, 2022 at 5:18
3

TBH even fake mounting doesn't safely validate the fstab for bad fs type entries.

you can have entries that have correct uuid's, directories etc but if you specify a noexistant FS type this will halt your boot next time.

[root@grumpy ~]# grep backup /etc/fstab
UUID=5ed48e5e-7251-4d49-a273-195cf0432a89       /mnt/backup     noatime,nodiratime,xfs defaults,nodev,nosuid    0 0
[root@grump ~]#

[root@grumpy ~]# mount -fav | grep backup
/mnt/backup              : successfully mounted
[root@grumpy ~]#
2

mount -a is safe method to check /etc/fstab otherwise wrong entry could break the system

It is also advised to keep a backup copy of original /etc/fstab file. it could be copied to home directory of root

2

I open another term or tab and run: tail -f /var/log/kern.log

Sometimes errors show there that don't show when mounting.

You must log in to answer this question.

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