Home / Alt manpages / fstab(5)

  • fstab(5)
  • File format
  • linux

Edit /etc/fstab Safely and Prove the Mount Works

One bad line in /etc/fstab can leave a server stuck at boot, so check the entry before the reboot does it for you. You will add or review one filesystem entry, validate its six fields and test the table before trusting boot or mount -a. Allow about fifteen minutes, longer if you still need to identify the right partition.

  • Checked against: the local fstab(5) page from the Ubuntu mount package, version 2.39.3-9ubuntu6.6, which describes the util-linux 2.39.3 format. The system binaries used below also report util-linux 2.39.3.
  • Placeholders: the UUID and mount point are made up. Replace them with details from your own machine.

1. Inspect the current table

Reading needs no special privilege. Look at both the file and what the kernel has mounted right now:

sed -n '1,160p' /etc/fstab
findmnt

Each non-comment line has six fields, separated by spaces or tabs:

  1. Source, normally a device identifier such as UUID=....
  2. Target directory, such as /srv/archive.
  3. Filesystem type, such as ext4.
  4. Options, a comma-separated list.
  5. Dump frequency, normally 0.
  6. Check order for fsck, normally 0 or 2.

Checkpoint

Do not edit yet. Write down the exact source, target and filesystem type you intend to use. A tidy-looking line with the wrong UUID can mount the wrong data, or fail during boot.

2. Find a stable source identifier

Names like /dev/sdb1 can change when hardware detection order changes, which is why the man page recommends labels or UUIDs. Ask blkid:

$ sudo blkid
/dev/sdX1: UUID="YOUR-UUID" TYPE="ext4"

It may need sudo to read all block-device metadata. Copy the UUID for the filesystem you actually want, not the example.

Tip

Preserve the UUID exactly as reported. Matching is case-sensitive in practice for some formats, and the local documentation calls out upper-case volume IDs for FAT and NTFS.

If the filesystem is already mounted, compare its source:

findmnt --target /srv/archive --output SOURCE,TARGET,FSTYPE,OPTIONS

If the target does not exist yet, this reports no matching mount. That only means nothing is mounted there; it does not mean the UUID is wrong.

3. Create the mount point

A normal mount needs the target directory to exist. Creating it changes system state, so pick the path deliberately:

sudo install -d -m 0755 /srv/archive

Check it:

$ stat -c '%A %U:%G %n' /srv/archive
drwxr-xr-x root:root /srv/archive

That mode and ownership are just a starting point: once mounted, the filesystem's own permissions and mount options control access.

Warning

Do not hand out a broad writable mode just to make an application work. Fix ownership or ACLs for the actual service account.

4. Back up, then add one complete entry

Back up first. The copy holds the system's mount configuration, so keep it protected:

sudo cp -a /etc/fstab /etc/fstab.before-archive

Open the file in the editor you trust and add one line:

UUID=YOUR-UUID /srv/archive ext4 defaults,nofail 0 2
  • defaults is not a fixed bundle. It asks for the filesystem and kernel defaults; the local man page says the kernel usually supplies read-write, device, executable and automatic-mount behaviour, among others.
  • nofail cuts both ways. It stops an error being reported when the device does not exist. Fine for optional storage, but it can also hide a disconnected disk you expected to be there.
  • Field five is the old dump setting. Zero means do not dump.
  • Field six is fsck order. Root is normally 1, other checked filesystems 2, and 0 means do not check. For an ordinary non-root ext4 data filesystem, 0 2 is the representative choice. Follow your distribution's policy and do not casually change the root line.

Example

Fields cannot contain literal spaces or tabs, so a path with a space uses the octal escape \040 (a tab is \011): /srv/Media Files becomes /srv/Media\040Files.

5. Verify before mounting

Run the parser check. It does not mount anything:

$ sudo findmnt --verify --fstab
0 parse errors, 0 errors

Read any warnings anyway. They can flag a missing device, an unreadable filesystem type or an odd check order even when the syntax is fine.

Then have libmount show the entries with UUIDs and labels resolved:

sudo findmnt --fstab --evaluate --output SOURCE,TARGET,FSTYPE,OPTIONS,FREQ,PASSNO

Checkpoint

The resolved source, target and type match the disk you meant. If not, stop and fix the line before going anywhere near mount -a.

6. Mount and confirm

Mounting can expose data and affect services, so do it when you understand the impact.

Warning

sudo mount -a needs elevated privilege and attempts every eligible entry in /etc/fstab, not just your new one.

sudo mount -a

To limit the blast radius, mount just the target:

sudo mount /srv/archive

A quiet command is not proof. Check what actually happened:

findmnt --target /srv/archive --output SOURCE,TARGET,FSTYPE,OPTIONS
df -hT /srv/archive

Unexpected options? They may come from the filesystem, the kernel or an existing mount, not only the word defaults in the file. Compare the entry with the findmnt output.

Common traps

  • Parse error. Check field boundaries first: six columns, no unescaped whitespace inside a field, commas only between mount options.
  • Missing device. Rerun sudo blkid and compare the complete UUID.
  • Missing target. Create the directory with sudo install -d.
  • Machine will not boot. Use the system's recovery or emergency route, restore the backup, and verify the file before attempting a normal boot.

To undo the change, unmount the target before removing its entry:

sudo umount /srv/archive
sudo cp -a /etc/fstab.before-archive /etc/fstab

Warning

Do not unmount a filesystem while a service or shell is using it; find those users with your normal process-inspection tools first. Restoring the backup also throws away every edit made since it was taken, so compare it with the current file if other administrators may have changed the table.

Done means

  • Correct entry: the right UUID or label, target, filesystem type and six fields.
  • Deliberate mount point: it exists with ownership and permissions you chose.
  • Clean check: findmnt --verify --fstab reports no parse errors or errors.
  • Right disk: the evaluated source matches the disk you intended.
  • Mount confirmed: it shows in findmnt, or the failure is diagnosed before rebooting.
  • Backup in place: a dated copy exists if you need to undo the edit.