Mounting Drives in Ubuntu Using fstab
In the Linux ecosystem, the ability to mount drives - including network drives - is crucial for managing data and resources. The fstab file is a system configuration file in Ubuntu and other Linux distributions that contains information about filesystems. This file is located at /etc/fstab and the system reads it to mount additional filesystems at boot time.
It remains the quickest path when I do not need a fully explicit systemd unit.
Mounting with the mount Command
The first step in mounting a remote drive is to use the mount command, which allows us to mount filesystems immediately. If you’re dealing with Samba shares, you will need the cifs-utils package installed. Create the mount point before using it:
sudo mkdir -p /mnt/documents
sudo mount -t cifs -o username=username //server-name/sharename /mnt/documents
For local disks I avoid /dev/sdX, which can change between boots. I find a filesystem UUID or stable device path with:
lsblk -f
ls -l /dev/disk/by-id/
Local Filesystem Entry
An ext4 filesystem by UUID looks like this:
UUID=01234567-89ab-cdef-0123-456789abcdef /mnt/data ext4 defaults,nofail 0 2
nofail is optional: I use it for a non-essential disk when boot should continue if the disk is absent. UUIDs and labels are the recommended stable identifiers in fstab. Ubuntu fstab documentation
Using a Credentials File
For better security, instead of writing the password directly into fstab, I keep it in a separate root-only credentials file:
sudo install -d -m 700 /etc/samba
sudoedit /etc/samba/documents.credentials
sudo chmod 600 /etc/samba/documents.credentials
username=my-user
password=replace-me
domain=WORKGROUP
The concise entry is:
//192.168.1.100/documents /mnt/documents cifs credentials=/etc/samba/documents.credentials,uid=1000,gid=1000,_netdev,nofail,x-systemd.automount 0 0
_netdev marks it as network-dependent. x-systemd.automount mounts on first access instead of delaying boot. I omit nofail when the share is required. These are systemd’s supported fstab extensions. systemd.mount
A bad mount target or options can hide data beneath a mount point or interfere with boot. I confirm the device/share and keep another root session open while testing remote systems.
Validate Before Rebooting
sudo findmnt --verify --verbose
sudo mount -a
findmnt /mnt/documents
findmnt --verify checks parsability and usability without relying on a reboot. findmnt manual
For the longer form with explicit dependencies, timeout behavior, and rollback, I use Mounting Drives in Ubuntu Using systemd.
Buy Me a Coffee