Intermediate · 14 min · practise every command in the built-in terminal

Mounting Disks — mount and /etc/fstab

A formatted partition is still not anywhere you can cd to. Mounting attaches it to a folder — its mount point — and from then on whatever you write there lands on that disk.

sudo mkdir /srv/data
sudo mount /dev/sdb1 /srv/data
df -h /srv/data
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1        20G   24K   19G   1% /srv/data

findmnt /srv/data and lsblk show it too. Files in a folder from before the mount aren't deleted — they're hidden under the disk until it's unmounted.

sudo umount /srv/data

It's umount — no "n". target is busy: something still uses it, often your own shell — cd out first.

Every boot: /etc/fstab

A mount lasts until the next reboot. What should be mounted at every boot is listed in /etc/fstab:

cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
UUID=6f1c2b7a-…  /               ext4    errors=remount-ro 0       1
UUID=7C1A-3E2F   /boot/efi       vfat    umask=0077      0       1

Add one line for the data disk — by UUID, not /dev/sdb1: device names can change when disks are added or removed, the UUID never does.

sudo blkid -s UUID -o value /dev/sdb1
sudo nano /etc/fstab
UUID=d4a70b1e-7e2a-4c1d-9f5b-3a8e6c2d1f07  /srv/data  ext4  defaults,nofail  0  2
FieldHereMeans
1UUID=…which filesystem
2/srv/datawhere
3ext4its type
4defaults,nofailoptions — nofail: boot anyway if the disk is missing
50dump (not used)
62check order at boot: 1 for /, 2 for the others, 0 never

Test before you reboot

sudo systemctl daemon-reload
sudo mount -a
sudo findmnt --verify

mount -a mounts everything in fstab that isn't mounted yet — a mistake shows up now, not at the next boot. findmnt --verify checks every line.

⚠️ A broken fstab line can stop a server from booting (emergency mode — no ssh). So: mount -a and findmnt --verify after every change, and nofail for disks that might be missing.

Then the real test — the server forgets every hand-made mount on the way:

sudo reboot

Practice tasks

  1. Make the mount point /srv/data
  2. Mount /dev/sdb1 on /srv/data
  3. Check its size and free space
  4. Unmount it again
  5. Add /srv/data to /etc/fstab, by the filesystem's UUID
  6. Mount everything in fstab — the test before any reboot
  7. Let findmnt check every line of /etc/fstab
  8. Reboot — and see that /srv/data is mounted again

Commands in this lesson

Disk & Memory