How do you validate fstab without rebooting?

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 ?


Solution 1:

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.

Solution 2:

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.)

Solution 3:

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

Solution 4:

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.

Solution 5:

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