Skip to main content

Linux and servers · Intermediate · 14 min

Mount a disk at boot with fstab and UUIDs

By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · util-linux 2.41.3 · systemd 259

You will add a data volume to /etc/fstab by its filesystem UUID, with options that let the server finish booting if the volume is missing, and prove the line is correct with findmnt before you reboot.

On this page

A disk you mount by hand is gone after the next reboot. To mount it every time the server starts, you add one line to /etc/fstab. That line is also the easiest way to stop a server from booting: a typo in it, or a volume detached in the cloud console, can leave the machine waiting at an emergency shell with no SSH. If nobody can reach a console, for example on an office server after a power cut, that means someone has to go to the machine.

This tutorial writes the line carefully. You will name the disk by its filesystem UUID, not by /dev/sdb. You will go through the six fields one by one and add options so that a missing volume delays the boot by seconds instead of stopping it. You will set ownership on the right side of the mount point. Then you will check everything with findmnt --verify before mount -a and a reboot. The last step shows the same mount written as a systemd .mount unit, so you can recognise one.

The examples mount an ext4 filesystem labelled data at /srv/data. If you have not formatted the volume yet, follow /tutorials/partition-and-format-a-new-disk-with-parted first. If you manage the server over mobile data, run the steps inside tmux or screen, so a dropped connection does not leave /etc/fstab half-edited.

Step 1 · Find the filesystem UUID

Linux names disks sda, sdb or nvme1n1 in the order it finds them at boot. Add a second volume, change the instance type or let the cloud provider attach disks in a different order, and the disk that was /dev/sdb yesterday can be /dev/sdc today. An fstab line that says /dev/sdb1 then mounts the wrong filesystem, or nothing. The UUID is written inside the filesystem itself when you run mkfs, so it moves with the disk.

List the block devices with their filesystems:

Bash
lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL,UUID,MOUNTPOINTS

You see something like this, with your own names and values:

Text
NAME         SIZE TYPE FSTYPE LABEL           UUID                                 MOUNTPOINTS
nvme0n1       40G disk
├─nvme0n1p1   39G part ext4   cloudimg-rootfs 0b6c1a52-8d0e-4c41-9f2e-6a3b7d1c5e08 /
├─nvme0n1p15 106M part vfat   UEFI            7C1A-3F2D                            /boot/efi
└─nvme0n1p16 913M part ext4   BOOT            e4d2f6a1-3b5c-4e7d-8a9f-1c2b3d4e5f60 /boot
nvme1n1      100G disk
└─nvme1n1p1  100G part ext4   data            5f3c9a6e-2b71-4d0e-9a54-8e1c2f7b3d90

Your data volume is the partition with your label, the size you chose and no mount point. Put its device path in a variable. Replace the example with your own partition:

Bash
PART=/dev/nvme1n1p1

Read the UUID straight from the filesystem and keep it in a second variable:

Bash
sudo blkid "$PART"
DATA_UUID=$(sudo blkid -s UUID -o value "$PART")
echo "$DATA_UUID"

Both variables last for this shell session only. If you log out, set them again before you carry on.

LABEL=data would also survive a reboot, and it is easier to read. The catch is that labels are not unique: two volumes formatted from the same notes both get data. UUIDs are random, with one exception. A volume restored from a snapshot of another volume carries the same UUID. If you ever attach a copy next to the original, give the copy a new one while it is unmounted, with sudo tune2fs -U random on its partition.

Check it worked

echo prints one UUID in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. Confirm udev knows it too:

Bash
ls -l /dev/disk/by-uuid/ | grep "$DATA_UUID"

One line comes back, a link pointing at ../../nvme1n1p1 or whatever your partition is called. This link is how the system finds the disk at boot.

Step 2 · Create the mount point and protect it

The mount point is an ordinary empty directory. Make it now:

Bash
sudo mkdir -p /srv/data

Later you add nofail, so the server boots even if the volume is missing. The side effect is that /srv/data is then a plain directory on the root disk, and an application that writes there fills the root disk without anyone noticing. Mark the empty directory immutable so nothing can write into it while the volume is not mounted:

Bash
sudo chattr +i /srv/data

The flag belongs to the directory on the root disk. Once the volume is mounted on top, you see the volume's own top directory instead, which does not have the flag, so normal writes work.

Check it worked

Bash
lsattr -d /srv/data
sudo touch /srv/data/should-fail

lsattr prints a line with an i in the flags, such as ----i---------e------- /srv/data. touch fails with Operation not permitted. That is the result you want while nothing is mounted.

Step 3 · Write the fstab line one field at a time

An fstab line has six fields separated by spaces or tabs. This is the one for the data volume:

Text
UUID=5f3c9a6e-2b71-4d0e-9a54-8e1c2f7b3d90  /srv/data  ext4  defaults,noatime,nofail,x-systemd.device-timeout=10s  0  2

Field by field:

  1. What to mount: UUID= and the filesystem UUID. LABEL=data works the same way.
  2. Where to mount it: /srv/data, an absolute path to a directory that exists.
  3. Filesystem type: ext4, or xfs if you formatted with XFS. It must match what blkid reported as TYPE.
  4. Options, comma-separated with no spaces:
  • defaults is the standard set: read-write, mounted at boot, with normal permissions.
  • noatime stops the kernel from writing a new access time each time a file is read. Ubuntu's default, relatime, already limits those writes; noatime removes them, which helps on busy data volumes and on cloud disks billed or throttled per operation.
  • nofail tells systemd the server can finish booting without this mount. Without it, a missing volume fails local-fs.target, and Ubuntu drops to emergency mode.
  • x-systemd.device-timeout=10s sets how long the boot waits for the disk to appear. The default is 90 seconds. Only systemd reads x-systemd. options; the kernel never sees them.
  1. dump: 0. The old dump backup tool reads this field; almost nothing else does.
  2. fsck order: 2 checks this filesystem at boot after the root filesystem, which is 1. Use 0 for XFS, because XFS repairs itself from its journal and its boot-time check does nothing.

Do not edit /etc/fstab directly yet. Work on a copy, so a mistake never reaches the real file:

Bash
mkdir -p ~/fstab-demo
cp /etc/fstab ~/fstab-demo/fstab.new
printf '\n# Data volume, added %s\nUUID=%s  /srv/data  ext4  defaults,noatime,nofail,x-systemd.device-timeout=10s  0  2\n' "$(date +%F)" "$DATA_UUID" >> ~/fstab-demo/fstab.new
tail -n 3 ~/fstab-demo/fstab.new

The blank line at the start of printf keeps the new entry on a line of its own even if the existing file does not end with a newline. If you formatted with XFS, change ext4 to xfs and the last 2 to 0 in the file before going on.

Check it worked

tail prints a blank line, your comment and the new entry with your own UUID in the first field. If the first field is UUID= with nothing after it, DATA_UUID was empty: set it again from the first step and rebuild the copy.

Step 4 · Check the new file with findmnt before installing it

findmnt --verify reads an fstab file the way the boot does and reports problems without mounting anything. For each line it checks that the mount point exists, that a UUID= or LABEL= resolves to a real device, and that the type in field 3 matches the filesystem on the disk. --tab-file points it at your copy instead of /etc/fstab:

Bash
sudo findmnt --verify --verbose --tab-file ~/fstab-demo/fstab.new

The section for the new line looks something like this:

Text
/srv/data
   [ ] target exists
   [ ] VFS options: noatime
   [ ] userspace options: nofail,x-systemd.device-timeout=10s
   [ ] UUID=5f3c9a6e-2b71-4d0e-9a54-8e1c2f7b3d90 translated to /dev/nvme1n1p1
   [ ] source /dev/nvme1n1p1 exists
   [ ] FS type is ext4

The other lines from your original fstab, such as / and /boot/efi, get their own sections. [ ] is a pass, [W] a warning and [E] an error. The command ends with Success, no errors or warnings detected, or a count such as 0 parse errors, 1 error, 0 warnings. Its exit code is the number of errors, so it also works in a script.

Now see what a mistake looks like. Make a second copy with a wrong UUID and check it:

Bash
printf 'UUID=00000000-0000-0000-0000-000000000000  /srv/data  ext4  defaults,nofail  0  2\n' > ~/fstab-demo/fstab.typo
sudo findmnt --verify --tab-file ~/fstab-demo/fstab.typo || echo "findmnt reported $? error(s)"

It prints [E] unreachable on boot required source: UUID=00000000-... and findmnt reported 1 error(s). nofail does not hide this from findmnt; only noauto, which skips the mount at boot, turns it into a warning.

Check it worked

The run against fstab.new shows no [E] lines, and the /srv/data section shows your UUID translated to your partition with FS type is ext4 (or xfs). A [W] xfs does not match with on-disk ext4 line means field 3 is wrong. Fix it in ~/fstab-demo/fstab.new and run the check again until it is clean.

Step 5 · Install the line and mount it

Keep a dated copy of the current file first. If the new one causes trouble, this backup is what you restore from a rescue shell:

Bash
sudo cp /etc/fstab "/etc/fstab.bak-$(date +%F)"

The next command replaces /etc/fstab with your checked copy. Do it only after the previous step showed no errors:

Bash
sudo install -m 644 -o root -g root ~/fstab-demo/fstab.new /etc/fstab
sudo findmnt --verify

Run without --tab-file, findmnt --verify checks the installed file. On a running server it also warns your fstab has been modified, but systemd still uses the old version. systemd builds its mount units from /etc/fstab, so reload it, then mount everything in the file that is not mounted yet:

Bash
sudo systemctl daemon-reload
sudo mount -a

mount -a prints nothing when it works. It is the closest thing to a boot you can test without rebooting: an error here would have been an error at boot.

Check it worked

Bash
findmnt /srv/data

You see one row with TARGET /srv/data, SOURCE your partition, FSTYPE ext4 and OPTIONS starting rw,noatime. nofail and the timeout are not in the list, because the kernel never receives them. sudo findmnt --verify now ends with Success, no errors or warnings detected.

Step 6 · Set ownership on the mounted filesystem

Ownership and permissions belong to whatever is mounted at the path. Before mounting, chown /srv/data changes the directory on the root disk. After mounting, it changes the top directory of the volume, which is what applications see. Run it now, with the volume mounted. This gives your own user the directory; for an application, use its service account instead, as in /tutorials/give-a-service-its-own-system-user-and-directories:

Bash
sudo chown "$USER":"$USER" /srv/data
sudo chmod 755 /srv/data

The setting is stored in the filesystem, so it survives reboots and comes with the disk if you move it to another server. Numeric user IDs are what is stored, so on a different server the same files may show a different owner name.

Check it worked

Bash
stat -c '%U:%G %a %n' /srv/data
touch /srv/data/hello.txt
ls -l /srv/data

stat prints your user and group with 755, and touch works without sudo. ls shows hello.txt next to lost+found, which ext4 creates for recovered files. Leave lost+found where it is.

Step 7 · Reboot and see what systemd made of the line

At boot, systemd's fstab generator turns each line into a mount unit named after the mount point. A nofail line is linked so that local-fs.target wants it; a line without nofail is linked so that it requires it. You can see this before you reboot:

Bash
ls /run/systemd/generator/local-fs.target.wants/ /run/systemd/generator/local-fs.target.requires/
systemctl cat srv-data.mount

srv-data.mount is in the local-fs.target.wants list, and the root filesystem's unit, -.mount, is under local-fs.target.requires. systemctl cat shows a file that starts with # Automatically generated by /usr/lib/systemd/system-generators/systemd-fstab-generator, with your UUID in What= and /srv/data in Where=.

Now reboot. Your SSH session closes; give the server a minute before you log back in:

Bash
sudo reboot

If you want to prove nofail works, you can test it on purpose: stop the server, detach the volume in your provider's console, start the server again and log in. Only do this with a volume no running service depends on, and reattach it afterwards.

Check it worked

After the reboot, findmnt /srv/data shows the volume and cat /srv/data/hello.txt works. In the optional test without the volume, the server still comes up, a few seconds later than usual. findmnt /srv/data prints nothing, systemctl status srv-data.mount reports the mount as inactive after its device timed out, and touch /srv/data/x fails with Operation not permitted because of the immutable flag. Reattach the volume and run sudo mount /srv/data to bring it back without another reboot.

Step 8 · Recognise the same mount as a systemd unit

You can also skip fstab and write the mount unit yourself. Some configuration tools do this, and you will meet such files under /etc/systemd/system/. The file name must be the mount point path with / turned into -. systemd-escape works it out for you:

Bash
systemd-escape --path --suffix=mount /srv/data

Write the equivalent unit into your practice folder to read and check. Do not install it: one mount should be defined in one place, and a unit in /etc/systemd/system/ takes precedence over the fstab line:

Bash
cat > ~/fstab-demo/srv-data.mount <<EOF
[Unit]
Description=Data volume

[Mount]
What=/dev/disk/by-uuid/$DATA_UUID
Where=/srv/data
Type=ext4
Options=defaults,noatime

[Install]
WantedBy=local-fs.target
EOF
systemd-analyze verify ~/fstab-demo/srv-data.mount

WantedBy=local-fs.target gives the same "wanted, not required" behaviour as nofail, once the unit is enabled. What the unit cannot hold is x-systemd.device-timeout, which only works in fstab. For one data volume, the fstab line is shorter and is what other people expect to find. Mount units are worth it when a mount needs ordering against other services, such as After= or Requires= lines.

Check it worked

systemd-escape prints srv-data.mount, and systemd-analyze verify prints nothing. Rename the file to data.mount and run the check again: it fails with an error about Where= not matching the unit name, which is the mistake people most often make with hand-written mount units.

Remove the practice folder when you are done. The fstab backup stays in /etc:

Bash
rm -rf ~/fstab-demo

Next steps

  • Add swap the same way, with a line in fstab: /tutorials/add-swap-space-with-a-swap-file.
  • If a bad fstab line ever stops a server booting, get it back from the emergency shell: /tutorials/recover-a-server-that-will-not-boot.
  • Pool several disks and grow mounted filesystems: /tutorials/add-disks-and-grow-filesystems-with-lvm.
  • Grow the volume in place when it fills up: /tutorials/grow-a-cloud-server-disk-without-downtime.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.