Mounting and Automounting Drives on Linux with fstab: Internal Disks and NAS Shares
A field guide I put together while wiring up storage on my own desktop. It covers two jobs people usually look up separately: mounting a secondary internal drive so it comes back after every reboot and mounting network shares from a NAS so they are there when you need them but do not hang your boot when the NAS is off.
If you have ever added a second drive and watched it mount at a different letter next time, or added a NAS line to /etc/fstab and then could not boot because the server was unplugged, this is the post for you. Everything here is done on a systemd-based Ubuntu or Kubuntu system, and the same approach works on most modern distributions.
All IP addresses and share names below are examples. Swap in your own.
What fstab actually is
/etc/fstab (the “file systems table”) is the list your system reads at boot to decide what gets mounted, where and with which options. Each line has six fields:
<what to mount> <where> <type> <options> <dump> <pass>
- what to mount: a device (better: its UUID) for local disks, or
server:/exportfor a network share. - where: the mount point, an empty directory you create.
- type: the filesystem, for example
ext4for a local disk ornfsfor a network share. - options: a comma-separated list that controls how and when it mounts. This is where most of the useful behavior lives.
- dump: almost always
0. - pass: the
fsckorder at boot.1for the root filesystem,2for other local disks,0for network shares.
The golden rule for local disks: mount by UUID, not by /dev/sdX. Device names like /dev/sdb are assigned in the order the kernel finds disks, so adding a drive or changing a cable can rename them and break your mounts. A UUID is baked into the filesystem and never changes.
Part 1: A secondary internal drive
Say you added a second SSD or hard drive and you want it mounted at /mnt/data on every boot.
Step 1: Find the drive
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT
Look for your new drive (for example /dev/sdb) and note whether it already has a filesystem. If the FSTYPE column is blank, the drive is unformatted.
Step 2: Format it, only if it is new
Skip this step if the drive already has data you want to keep. Formatting erases everything on the target.
# DANGER: this wipes /dev/sdb1. Triple-check the device name first.
sudo mkfs.ext4 /dev/sdb1
If the drive has no partition table yet, create one first with sudo fdisk /dev/sdb (make a single primary partition), or use the Disks GUI (gnome-disks) if you prefer clicking to typing.
Step 3: Get the UUID
sudo blkid /dev/sdb1
You will get a line with UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx". Copy that value.
Step 4: Create the mount point
sudo mkdir -p /mnt/data
Step 5: Add the fstab line
sudoedit /etc/fstab
Add:
# Secondary internal data drive
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/data ext4 defaults,nofail 0 2
defaultsis a sensible baseline (read-write, mount at boot and so on).nofailmeans the system still boots if the drive is missing or dies, instead of dropping you into an emergency shell.0 2means no dump andfsckthis disk after the root filesystem.
Step 6: Apply and test without rebooting
sudo systemctl daemon-reload
sudo mount -a
mount -a mounts everything in fstab that is not already mounted. If it returns with no errors, you are good. Confirm:
df -h /mnt/data
If you want the files owned by your user rather than root, either sudo chown -R $USER:$USER /mnt/data after mounting, or for filesystems without Linux permissions (like NTFS or exFAT on an external drive) set ownership in the options, for example uid=1000,gid=1000.
Part 2: NAS shares over NFS
Now the network side. The goal here is different from a local disk. You want the share available on demand, but you never want a missing NAS to hang your boot. The trick is to let systemd mount it the moment something touches the folder, rather than at boot.
For this walkthrough the NAS lives at 192.168.1.50 and exports a few shares we will mount under /mnt/nas/.
Step 1: Install the NFS client
sudo apt install -y nfs-common
Confirm the mount helper is present and check what the NAS is offering:
which mount.nfs
showmount -e 192.168.1.50
showmount lists the exports the server is willing to share. If your share is not in that list, fix it on the NAS side before touching fstab.
Step 2: Map out the shares
| NAS export | Local mount point |
|---|---|
192.168.1.50:/volume1/Media | /mnt/nas/Media |
192.168.1.50:/volume1/Projects | /mnt/nas/Projects |
192.168.1.50:/volume1/My Files | /mnt/nas/My_Files |
192.168.1.50:/volume1/Backups | /mnt/nas/Backups |
Step 3: Create the mount points
sudo mkdir -p /mnt/nas/{Media,Projects,My_Files,Backups}
Step 4: Add the fstab block
# NAS NFS mounts from 192.168.1.50 (on-demand automount)
192.168.1.50:/volume1/Media /mnt/nas/Media nfs noauto,vers=4.1,_netdev,nofail,x-systemd.automount,x-systemd.requires=network-online.target 0 0
192.168.1.50:/volume1/Projects /mnt/nas/Projects nfs noauto,vers=4.1,_netdev,nofail,x-systemd.automount,x-systemd.requires=network-online.target 0 0
192.168.1.50:/volume1/My\040Files /mnt/nas/My_Files nfs noauto,vers=4.1,_netdev,nofail,x-systemd.automount,x-systemd.requires=network-online.target 0 0
192.168.1.50:/volume1/Backups /mnt/nas/Backups nfs noauto,vers=4.1,_netdev,nofail,x-systemd.automount,x-systemd.requires=network-online.target 0 0
Note the third line. The export path My Files contains a space, and a space would break the fstab field parsing, so it is written as My\040Files. The \040 is the octal escape for a space. Any space in a path needs this.
Option reference
| Option | Meaning |
|---|---|
noauto | Do not mount at boot. Paired with x-systemd.automount, the share mounts on first access instead. |
vers=4.1 | Force NFS protocol version 4.1. Change to vers=3 if your NAS does not support 4.x. |
_netdev | Marks this as a network mount so systemd orders it after the network is up. |
nofail | Do not block boot if the mount cannot be made. |
x-systemd.automount | Creates an automount unit so the share mounts when you open the folder (for example in your file manager). |
x-systemd.requires=network-online.target | Holds the mount until the network is actually online. |
0 0 | No dump, no fsck (never fsck a network share). |
Step 5: Apply and verify
sudo systemctl daemon-reload
sudo systemctl restart 'mnt-nas-*.automount'
Systemd turns each mount point into a unit named after its path, so /mnt/nas/Media becomes mnt-nas-Media.automount. Check they are active:
systemctl list-units --type=automount | grep mnt-nas
Then trigger a mount just by listing the folder:
ls /mnt/nas/Media
The first access is slightly slow because that is when the real mount happens. After that it behaves like any other folder.
Manual test if something misbehaves
Before trusting fstab, you can always mount a share by hand to prove the server and path are right:
sudo mount -t nfs -o vers=4.1 192.168.1.50:/volume1/Media /mnt/nas/Media
ls /mnt/nas/Media
sudo umount /mnt/nas/Media
If the manual mount works but the automount does not, the problem is in your fstab options, not the network.
Troubleshooting
See why an automount or mount failed
systemctl status mnt-nas-Media.automount
systemctl status mnt-nas-Media.mount
journalctl -u mnt-nas-Media.mount -n 50
The journal output almost always names the real reason: wrong path, wrong NFS version, permission denied or no route to the host.
mount-start-limit-hit
This means the .mount unit failed several times quickly and systemd stopped retrying. Common causes:
nfs-commonis not installed.- The export path is wrong (recheck with
showmount -e). - The NFS version does not match what the server supports.
Fix the cause, then clear the failed state:
sudo systemctl reset-failed 'mnt-nas-*.automount' 'mnt-nas-*.mount'
sudo systemctl restart 'mnt-nas-*.automount'
The drive mounts but comes up at the wrong place, or vanishes after a reboot
This is the classic /dev/sdX trap on a local disk. Switch the fstab entry to UUID= (see Part 1, Step 3). Device letters are not stable, UUIDs are.
mount -a throws an error and I cannot boot
If you added a bad line and the machine drops to an emergency shell, remount root as writable, fix the file and continue:
mount -o remount,rw /
sudoedit /etc/fstab # correct or comment out the bad line
This is exactly why nofail matters. With it on every non-root line, a missing drive or offline NAS becomes a warning instead of a failed boot. Add it before you reboot, not after.
Files on the NFS share are owned by the wrong user
NFS maps by user ID, not name. If your user ID on the desktop does not match the one that owns the files on the NAS, permissions will look off. Line the UIDs up on both ends, or set share-level permissions on the NAS.
Summary
- Local disks: mount by
UUID, usedefaults,nofailandpassof2. - NAS shares: install
nfs-common, then usenoautowithx-systemd.automountfor on-demand mounting. - Use
_netdevandx-systemd.requires=network-online.targetso network mounts wait for the network. - Put
nofailon everything except root so a missing drive never blocks boot. - Escape spaces in paths as
\040. - Always run
sudo systemctl daemon-reloadafter editingfstaband test withsudo mount -abefore you trust it across a reboot.
References
Do not take my word or anyone else’s for how these options behave. The official documentation is the source of truth:
- fstab(5) man page - the file format and fields
- mount(8) man page - mount options, including filesystem-independent ones like
nofail - nfs(5) man page - NFS-specific mount options like
vers=and_netdev - systemd.mount(5) man page - the
x-systemd.*options and how fstab becomes systemd units - systemd.automount(5) man page - on-demand mounting behavior
- blkid(8) man page - finding UUIDs
- Ubuntu: install and configure an NFS client - the official Ubuntu server guide
- Ubuntu community wiki: Fstab and NFSv4Howto
Related reading:
- Pop!_OS: Adding a Secondary Encrypted Drive With Auto-Unlock
- Expanding an LVM Volume on Ubuntu 24.04, No Reboot Required
- Stop Saving Work to C: Smarter Storage Habits
- The 3-2-1 Backup Rule: How to Never Lose Your Data
Running a different NAS or a distribution that is not Ubuntu-based? Post your setup below and we can work through the options.
// comments