ArcLibrary

Disks, Filesystems & Mounts

df, du, mount, fstab — minimum knowledge to inspect disks and add partitions.

DiskFilesystemMount
核心 · Key Idea

In one line: Linux has no drive letters — every storage device is mounted under / at some directory. To use a new disk, you partition it → create a filesystem → mount it.

What it is#

disk → partition → filesystem → mount point
/dev/nvme0n1
  └ /dev/nvme0n1p1  (EFI)
  └ /dev/nvme0n1p2  (ext4 → /)
  └ /dev/nvme0n1p3  (ext4 → /var)

Adding /dev/sdb:
  parted /dev/sdb mklabel gpt mkpart primary 0% 100%
  mkfs.ext4 /dev/sdb1
  mount /dev/sdb1 /mnt/data

Analogy#

打个比方 · Analogy

A disk is a warehouse: first wall it off into rooms (partitions), then install a shelving system in each (filesystem), finally nail a sign on the door (mount it under /var/data).

Key concepts#

Block deviceBlock Device
/dev/sda, /dev/nvme0n1, etc. Visualize with lsblk.
Partition tableMBR / GPT
GPT is the modern standard — supports >2 T and unlimited partitions.
FilesystemFS
ext4 (default, stable), xfs (large volumes), btrfs / zfs (snapshots), tmpfs (RAM).
InodeInode
File metadata + pointers to data blocks. Run out of inodes and you can't create files even with free space.
Mount pointMount Point
A directory; once mounted, accessing the directory accesses the device.
fstab/etc/fstab
Mounts to apply at boot.
LVMLogical Volume Manager
Adds an abstraction layer above partitions for easy resize / snapshots.

Common commands#

# View
lsblk -f                    # tree of disks + filesystems + mounts
df -hT                      # mounted partitions, free space, type
du -sh /var/log/*           # directory usage
ncdu /                      # interactive disk usage
 
# Operate
mount /dev/sdb1 /mnt/data
umount /mnt/data
mount -o remount,ro /        # remount read-only
 
# New disk from scratch
sudo mkfs.ext4 -L data /dev/sdb1
sudo mkdir /data
echo 'LABEL=data /data ext4 defaults,noatime 0 2' | sudo tee -a /etc/fstab
sudo mount -a

How it works#

VFS exposes a uniform interface; apps don't see what FS is underneath.

Practical notes#

  • Use UUID= or LABEL= in /etc/fstab — never /dev/sdb1 (device names can change on reboot).

  • noatime disables last-access timestamps — saves a write, friendly to SSDs.

  • Disk full? Check inodes too: df -i shows inode usage.

  • Swap: paging file when RAM is exhausted. Cloud VMs often ship without swap; add a swapfile:

    fallocate -l 4G /swapfile && chmod 600 /swapfile
    mkswap /swapfile && swapon /swapfile
  • du -sh dir/* | sort -h to find the biggest directories.

  • Emergency cleanup: clear old /var/log/*.log and /var/cache, then journalctl --vacuum-size=200M.

  • Big file deleted, disk still full? A process still holds an fd. lsof | grep deleted then restart it.

Easy confusions#

df
Reports free space at the **filesystem level**.
Instant.
du
Recursively sums **file sizes**.
Slower but tells you **who's using the space**.

Further reading#