Sub topic 12
Mounting at Boot with `/etc/fstab`
This chapter assumes you can mount filesystems manually, edit text files, use systemctl, and understand Linux users, groups, and permissions. You also need working Samba and NFS shares, a client hostname such as fileserver, and mount-point directories on the client.
Why persistent mounts matter
A manual mount disappears after reboot. The /etc/fstab file defines filesystems that Linux should mount automatically during boot. Each entry contains six fields:
| Field | Purpose |
|---|---|
| Device or remote share | The local device or network export |
| Mount point | The directory where it appears |
| Filesystem type | Such as `nfs4` or `cifs` |
| Options | Mount behavior and credentials |
| Dump | Usually `0` for network filesystems |
| Pass | Boot-time filesystem check order, usually `0` for network filesystems |
For network shares, _netdev tells the system that the mount requires networking. This helps systemd order the mount after the network is available.
Add NFS and Samba mounts
Create the mount points first:
sudo mkdir -p /mnt/nfs-projects /mnt/smb-projectsFor an NFSv4 export and a Samba share, add entries like these to /etc/fstab:
fileserver:/srv/nfs/projects /mnt/nfs-projects nfs4 defaults,_netdev 0 0
//fileserver/projects /mnt/smb-projects cifs credentials=/root/.smbcreds,vers=3.0,uid=1000,gid=1000,_netdev 0 0NFS normally uses the server's numeric user ID and group ID directly. The uid and gid options in the CIFS entry map files to local numeric IDs on the client. Replace 1000 with the intended local user and group IDs.
Create the Samba credentials file with root-only permissions:
sudo sh -c 'printf "username=alice\npassword=REPLACE_WITH_PASSWORD\n" > /root/.smbcreds'
sudo chmod 600 /root/.smbcredsThe file must not be readable by ordinary users because it contains a Samba password. Avoid placing the password directly in /etc/fstab.
Test before rebooting
Always test new entries without restarting the machine:
sudo mount -a
findmnt /mnt/nfs-projects
findmnt /mnt/smb-projectsmount -a reads /etc/fstab and attempts every entry that is not marked noauto. If it reports an error, inspect the spelling, credentials, network name, permissions, and client packages before rebooting.
How boot mounting works
Systemd reads /etc/fstab and generates mount units. The _netdev option identifies network storage, while x-systemd.automount can delay the connection until a process first accesses the directory.
Exercise
Why should a network share in /etc/fstab include _netdev?
Show answer
It tells the boot system that the mount depends on networking, so it should not be treated like a local disk.