Skip to content
Intermediate LinuxLesson 18 of 27 4 min read

Disks and Filesystems

Block devices, partitions, mount points, df vs du, inodes, and hard vs symbolic links.

On this page8 sections

Every byte you've written in this course - every file you touched, every directory you mkdir'd - lives on a block device, formatted with a filesystem that knows how to organize bytes into files and directories. This lesson is about seeing that structure instead of taking it for granted.

Block devices and partitions

lsblk ("list block devices") shows the physical (or virtual) disks attached to a machine, and how each one is sliced into partitions:

bash
lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
sda           8:0    0    50G  0 disk
├─sda1        8:1    0    50G  0 part  /
└─sda2        8:2    0   512M  0 part  [SWAP]

sda is the whole disk; sda1 and sda2 are partitions carved out of it. One partition holds the root filesystem (/); another is swap - disk space the kernel uses as overflow memory when RAM runs low.

Mounting: attaching a filesystem to a path

A partition on its own isn't usable - it has to be mounted: attached to a directory (a "mount point") so its files appear as part of the single filesystem tree everything in Linux lives under. The kernel remembers these attachments in /etc/fstab so they're restored automatically at every boot:

bash
mount /dev/sdb1 /mnt/data      # attach sdb1's filesystem at /mnt/data
umount /mnt/data               # detach it again

This is exactly why Linux has no drive letters like C: or D: - a second disk doesn't get its own root, it gets grafted into the existing tree at whatever path you choose.

Filesystem types

The partition also has a filesystem format - the on-disk data structure that actually tracks which blocks belong to which file:

FilesystemCommon on
ext4The default on most Linux distributions; mature and reliable
xfsHigh-performance, common on RHEL/CentOS and large storage servers
btrfsSnapshots and built-in RAID-like features; default on some SUSE and Fedora installs
vfat / exFATUSB drives and interoperability with Windows
ntfsWindows' native filesystem, readable (and writable) from Linux

df vs. du: the question everyone confuses

Both report disk usage, but at different levels:

bash
df -h          # how full is each MOUNTED FILESYSTEM?
du -sh /var    # how much space does this one DIRECTORY use?

df answers "is this disk about to fill up?" du answers "which directory is the one filling it?" A classic troubleshooting sequence runs both back to back: df -h to spot a filesystem that's nearly full, then du -sh /* on it to find the directory responsible.

Inodes: the other thing that can run out

Every file has metadata - owner, permissions, timestamps, and where its data blocks live - stored in a structure called an inode. stat shows you a file's inode number directly:

bash
stat notes.txt

A filesystem has a fixed number of inodes set aside when it's formatted. It's entirely possible to have free disk space (per df -h) but zero free inodes - usually caused by millions of tiny files - and get "No space left on device" anyway. df -i reports inode usage instead of byte usage on a real system.

ln creates a link, but there are two different kinds:

bash
ln source.txt hardlink.txt        # hard link: another name for the SAME inode
ln -s source.txt symlink.txt      # symbolic link: a small file that just points at a path

A hard link is indistinguishable from the original - both names point at the same data, and deleting either one leaves the file intact under its other name. A symbolic link ("symlink") is its own tiny file containing a path; delete the original and the symlink is left pointing at nothing (a "broken link").

Try it

Run these in the practice terminal (opens in a new tab). It opens in a new tab, so you keep your place here.
bash
lsblk
df -h
du -sh /var
stat welcome.txt
mount /dev/sdb1 /mnt/data
mount
umount /mnt/data

Further reading

  • "How Linux Works" by Brian Ward (No Starch Press) - its filesystem chapter explains inodes, mounting, and how ext4 actually lays out data on disk.
  • "The Linux Command Line" by William Shotts (No Starch Press) - practical coverage of df, du, mount, and /etc/fstab.

Challenge

Show human-readable free space for every mounted filesystem, then show a human-readable, summarized size of the /var directory. Do both in one line joined with &&.

Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.

Quiz

Lock in the concepts. Score at least 80% to mark the lesson complete.

0 of 3 answered

Done with this one?

Skipped the challenge? You can mark the lesson complete by hand.

Your notes

Kept on this browser only.