Mounts don't survive a reboot
A mount command mounts a disk until the machine restarts; then it's gone. To mount a filesystem automatically at every boot, you list it in /etc/fstab (the filesystem table). This machine mounts its root over the network before /etc/fstab is even read, so the file is still empty — we'll add the first entry:
cat /etc/fstab
findmnt /In the terminal
student@vulntech:~$ cat /etc/fstab # UNCONFIGURED FSTAB FOR BASE SYSTEM student@vulntech:~$ findmnt / TARGET SOURCE FSTYPE OPTIONS / host9p 9p rw,relatime,dirsync,loose,access=client,trans=virtio
The six fields
Each line in /etc/fstab describes one filesystem, in six whitespace-separated fields:
| Field | Meaning |
|---|---|
| device | What to mount — best given as UUID=... |
| mount point | The directory to mount it on, e.g. /mnt/store |
| type | The filesystem type, e.g. ext4 |
| options | Mount options, e.g. defaults,nofail |
| dump | Backup flag (almost always 0) |
| pass | fsck order at boot (0 to skip, 2 for data disks) |
Why UUID= and not /dev/sdb1? Because device names can change when disks are added or reordered, but a filesystem's UUID never does. Read it with blkid, then add the line. nofail lets the machine boot even if the disk is missing:
sudo losetup -fP --show data.img
UUID=$(sudo blkid -s UUID -o value /dev/loop0)
echo $UUID
echo "UUID=$UUID /mnt/store ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
sudo mkdir -p /mnt/store
sudo mount -a
findmnt /mnt/storeIn the terminal
student@vulntech:~$ sudo losetup -fP --show data.img [sudo] password for student: /dev/loop0 student@vulntech:~$ UUID=$(sudo blkid -s UUID -o value /dev/loop0) student@vulntech:~$ echo $UUID df71eec3-5c5b-413b-9fce-de92c4eea1ee student@vulntech:~$ echo "UUID=$UUID /mnt/store ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab UUID=df71eec3-5c5b-413b-9fce-de92c4eea1ee /mnt/store ext4 defaults,nofail 0 2 student@vulntech:~$ sudo mkdir -p /mnt/store student@vulntech:~$ sudo mount -a mount: (hint) your fstab has been modified, but systemd still uses the old version; use 'systemctl daemon-reload' to reload. student@vulntech:~$ findmnt /mnt/store TARGET SOURCE FSTYPE OPTIONS /mnt/store /dev/loop0 ext4 rw,relatime
mount -a mounts everything in /etc/fstab that isn't mounted yet — so it applies the new line immediately, and it's also how the system mounts these disks at boot.
Common mistake: A wrong line in
/etc/fstabcan stop the machine booting. Always addnofailfor removable or data disks, and test a new entry withsudo mount -abefore rebooting — if it errors, fix it now.
Tip:
findmnt --verifychecks/etc/fstabfor mistakes without mounting anything. Mounting byLABEL=works too, if you gave the filesystem a label withmkfs -L.
Remember:
/etc/fstablists filesystems to mount at boot, one per line, six fields: device (useUUID=), mount point, type, options, dump, pass.sudo mount -aapplies it now;nofailkeeps a missing disk from blocking boot.