appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Storage, filesystems and mounts

Lesson 2 of 412 minAdvanced

Find disks, format and mount them, and make mounts survive a reboot without breaking boot.

lsblk -f                 # devices, filesystems, UUIDs and mount points
blkid                    # UUID of each filesystem
findmnt                  # what is mounted where

Adding a disk

sudo mkfs.ext4 /dev/sdb1          # DESTROYS existing data on sdb1
sudo mkdir -p /data
sudo mount /dev/sdb1 /data

Carefulmkfs erases the partition. Check the device name twice with lsblk before you run it. Writing to the wrong disk is unrecoverable.

Make it persistent: /etc/fstab

# /etc/fstab
UUID=3f2b1c9e-8a74-4f0a-9d5b-0c1e2a7b5d11  /data  ext4  defaults,nofail  0  2
  • Use the UUID, not /dev/sdb1. Device names can change between boots.
  • nofail lets the system boot even when the disk is missing.
  • The last number orders filesystem checks at boot (2 for non-root).
  • Test with sudo mount -a before you reboot. A broken line can stop the boot.

LVM in one paragraph

LVM adds a layer between disks and filesystems. Physical disks become physical volumes (PV), are pooled in a volume group (VG) and are cut into logical volumes (LV) that you can grow while mounted: lvextend -r -L +10G /dev/vg0/data extends the volume and its filesystem.

NoteRAID and LVM are not backups. A deleted file is deleted on every copy. Keep separate backups and test restoring them.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. Why use a UUID in /etc/fstab?
2. What should you run after editing /etc/fstab, before rebooting?
3. What does the nofail option do?

Key terms