Lesson 4.1 · Disks & Filesystems
You’ve used storage since Module 0 without looking underneath it. Now you look. This lesson builds an accurate model of the layers between a physical disk and the files you read and write — block device → partition → filesystem → mount point — plus LVM (the layer that lets you resize storage without pain) and SMART (how a disk warns you it’s dying). These are the fundamentals every later storage decision rests on.
The layers, top to bottom
Section titled “The layers, top to bottom”When you save a file, it passes through a stack of abstractions. Understanding the stack is what lets you reason about storage instead of cargo-culting commands:
graph TD
File[Your files] --> FS[Filesystem<br/>ext4 · organizes files into the block device]
FS --> Part[Partition<br/>a labeled region of the disk]
Part --> Disk[Block device<br/>the raw disk: /dev/sda]
Disk --> Hardware[(Physical SSD / HDD)]
- A block device is the raw disk as the OS sees it — a big array of fixed-size blocks. It
shows up under
/dev(e.g./dev/sda,/dev/nvme0n1). “Block” because it’s read and written in blocks, not byte-by-byte. - A partition is a labeled region of a block device, so one disk can be divided into parts
(e.g.
/dev/sda1,/dev/sda2). The partition table records the layout. - A filesystem is the structure written into a partition that organizes it into files and directories with names, permissions, and timestamps (the Lesson 0.1 stuff). Without a filesystem, a partition is just undifferentiated blocks.
- A mount point is the directory where a filesystem is attached into the single Linux tree
(recall from Lesson 1.1 that Linux has one tree from
/).
Seeing your storage
Section titled “Seeing your storage”Start by looking at what’s there. These are safe, read-only:
lsblk # tree view of disks, partitions, sizes, and mount points — start herelsblk -f # also show filesystem type and labelsudo fdisk -l # detailed partition tables for every diskdf -h # mounted filesystems and their free space (Lesson 2.4)sudo blkid # UUIDs and types of every partitionmount | column -t # what's currently mounted, and howcat /proc/mounts # the authoritative live mount listlsblk is the one to reach for first — it shows the whole hierarchy (disk → partitions →
mounts) at a glance. Learn to read it and you can orient on any machine’s storage in seconds.
Partitioning: GPT and the tools
Section titled “Partitioning: GPT and the tools”A new disk needs a partition table. The modern standard is GPT (GUID Partition Table), which replaced the old MBR scheme — GPT supports large disks and many partitions and is what you should use for anything new.
Tools you’ll meet:
fdisk— the classic interactive partition editor (sudo fdisk /dev/sdX). Menu-driven:pprint,nnew,ddelete,wwrite-and-quit,qquit-without-saving.parted/gparted— alternatives;gpartedis graphical if you ever want it.
The typical flow to prepare a fresh spare disk (in Lab 1): create a GPT table, add one partition spanning the disk, then put a filesystem on it (next section). For a data disk you often don’t even need multiple partitions — one big one is fine.
Filesystems: ext4 (and friends)
Section titled “Filesystems: ext4 (and friends)”Once you have a partition, you write a filesystem into it. On Linux the reliable default is ext4 — mature, fast, and what you’ll use unless you have a reason not to:
sudo mkfs.ext4 /dev/sdX1 # create an ext4 filesystem on partition sdX1 (ERASES it)Other filesystems you’ll hear about: xfs (great for large files/servers), btrfs and ZFS (advanced, with snapshots and checksums — ZFS is covered in Lesson 4.2), and FAT32/exFAT (for USB sticks shared with Windows/Mac). For your homelab data, ext4 is the sensible default.
What “journaling” buys you
Section titled “What “journaling” buys you”ext4 is a journaling filesystem: before making a change, it records its intent in a journal. If power is lost mid-write, on reboot the filesystem replays or discards the journal to stay consistent, rather than being left half-written and corrupt. This is why a modern Linux box survives an unclean shutdown far better than old filesystems did — worth knowing when you reason about what a sudden power loss does (and why a UPS, from the hardware guide, still helps).
Mounting: attaching a filesystem into the tree
Section titled “Mounting: attaching a filesystem into the tree”A filesystem isn’t usable until it’s mounted at a directory:
sudo mkdir /mnt/data # a directory to mount ontosudo mount /dev/sdX1 /mnt/data # attach it — now files under /mnt/data live on that diskdf -h /mnt/data # confirm it's mountedsudo umount /mnt/data # detach itA manual mount doesn’t survive a reboot. To mount automatically at boot, add an entry to
/etc/fstab — and always reference the filesystem by its UUID (from blkid), not
/dev/sdX, because device names can change between boots but UUIDs are stable:
# /etc/fstab — one line per filesystem to mount at bootUUID=xxxx-xxxx /mnt/data ext4 defaults 0 2LVM: storage you can resize
Section titled “LVM: storage you can resize”Here’s a problem raw partitions have: they’re rigid. If /mnt/data fills up, you can’t easily
make its partition bigger without repartitioning. LVM (Logical Volume Management) solves
this by adding a flexible layer between the disk and the filesystem. Three concepts:
graph TD
PV1[Physical Volume<br/>/dev/sdb] --> VG[Volume Group<br/>a pool of storage]
PV2[Physical Volume<br/>/dev/sdc] --> VG
VG --> LV1[Logical Volume<br/>data · resizable]
VG --> LV2[Logical Volume<br/>backups · resizable]
LV1 --> FS1[ext4 filesystem]
LV2 --> FS2[ext4 filesystem]
- Physical Volume (PV): a disk or partition handed to LVM.
- Volume Group (VG): a pool made of one or more PVs — combined free space.
- Logical Volume (LV): a virtual “partition” carved from the VG, which you format and mount. Crucially, an LV can be grown (and, with ext4, even while mounted) as long as the VG has free space — or you add another disk to the VG to get more.
You chose LVM during the Debian install (Lesson 2.1) for exactly this reason. The commands you’ll use in Lab 1:
sudo pvcreate /dev/sdX1 # make a partition into a physical volumesudo vgcreate data-vg /dev/sdX1 # create a volume group from itsudo lvcreate -L 10G -n data-lv data-vg # carve a 10G logical volumesudo mkfs.ext4 /dev/data-vg/data-lv # format it# ...later, when it's filling up:sudo lvextend -L +5G /dev/data-vg/data-lv --resizefs # grow it by 5G AND the filesystem, liveThat last command — growing storage while it’s in use — is the payoff, and it feels like magic the first time. It’s why “use LVM” is standard advice for any server whose storage needs might change (i.e. all of them).
SMART: hearing a disk announce its death
Section titled “SMART: hearing a disk announce its death”Disks fail. Good news: they usually warn you first. SMART (Self-Monitoring, Analysis and
Reporting Technology) is built into drives and tracks health indicators — reallocated sectors,
read errors, temperature. You read it with smartmontools:
sudo apt install smartmontoolssudo smartctl -a /dev/sdX # full health report for a drivesudo smartctl -H /dev/sdX # just the overall health assessment (PASSED/FAILED)sudo smartctl -t short /dev/sdX # run a short self-testThe indicators that predict failure — rising Reallocated_Sector_Ct, Pending sectors,
read error rates — are worth learning to spot. A drive reporting reallocated sectors is telling
you to replace it before it dies. On a real server you’d have smartd email you on trouble;
checking SMART is part of keeping storage healthy, and it sets up why you want the redundancy
and backups of the next two lessons: because “the disk warned me” and “the disk already died”
both happen, and you plan for both.
Quick self-check
Section titled “Quick self-check”- Name the four layers from a physical disk up to your files, in order.
- Which command gives you a tree view of disks, partitions, and mount points?
- Why should
/etc/fstabreference filesystems by UUID rather than/dev/sdX? - What are LVM’s Physical Volume, Volume Group, and Logical Volume, and what does LVM let you do that raw partitions don’t?
- What does journaling protect you from?
- What is SMART, and what would make you decide to replace a drive proactively?