File Systems and Disk Management

File systems are something most people take for granted until a disk fills up or something won't unmount. This covers the practical side — creating and mounting file systems, checking what's using your space, and keeping things healthy. I'll focus on the stuff that comes up in real situations rather than exhaustive coverage of every filesystem type.

Checking Disk Space

The first two commands you reach for when a disk is filling up:

$ df -h                 # disk usage by mounted filesystem, human-readable
$ df -h /home           # just a specific mount point
$ du -sh /var/log       # how much space a directory is using
$ du -sh /var/log/*     # break it down by subdirectory
$ du -sh * | sort -rh | head -20   # find the biggest things in current dir

When df shows a filesystem at 100% but you can't find the files taking the space, check for deleted files still held open by processes:

$ lsof | grep deleted   # files deleted but still open (still taking space)

Restarting the process holding them will free the space.

Creating File Systems

$ mkfs.ext4 /dev/sdb1       # format a partition as ext4
$ mkfs.xfs /dev/sdb1        # XFS (better for large files, common on RHEL)
$ mkfs.btrfs /dev/sdb1      # Btrfs (snapshots, checksums, modern)
$ mkfs.vfat -F 32 /dev/sdc1 # FAT32 for USB drives / cross-platform

Double-check your device name before running mkfs — there's no undo. lsblk is the safest way to confirm what's what:

$ lsblk                 # list block devices in a tree
$ lsblk -f              # include filesystem type and UUID
$ fdisk -l /dev/sdb     # partition table details

Mounting

$ mount /dev/sdb1 /mnt              # basic mount
$ mount -t ext4 /dev/sdb1 /mnt      # explicit filesystem type
$ mount -o ro /dev/sdb1 /mnt        # read-only
$ mount -o remount,rw /mnt          # remount existing mount read-write
$ umount /mnt                        # unmount
$ umount -l /mnt                     # lazy unmount (waits for idle)

fstab for Persistent Mounts

Entries in /etc/fstab mount automatically at boot. Use UUIDs rather than device names — device names can change, UUIDs don't:

# Find the UUID
$ blkid /dev/sdb1

# /etc/fstab entry
UUID=1234-5678  /mnt/data  ext4  defaults,noatime  0  2

The last two fields are dump (almost always 0) and fsck order (root = 1, others = 2, 0 = skip). After editing fstab, test with mount -a before rebooting — a bad fstab entry can prevent the system from booting.

Useful Mount Options

noatime        # don't update access time on reads (better performance)
nodiratime     # same, just for directories
noexec         # don't allow executing binaries (good for data partitions)
nosuid         # ignore setuid bits (good security practice for /tmp)
ro             # read-only

Checking and Repairing File Systems

Only run fsck on unmounted filesystems. Running it on a mounted filesystem will cause damage:

$ umount /dev/sdb1
$ fsck /dev/sdb1             # check (auto-detect type)
$ fsck -y /dev/sdb1          # check and auto-fix without prompting
$ fsck.ext4 -f /dev/sdb1     # force check even if filesystem looks clean

For the root filesystem, you can't unmount it while running. Schedule a check at next boot:

$ touch /forcefsck           # old method
$ tune2fs -C 1 /dev/sda1     # force fsck after 1 mount (ext filesystems)

LVM — Logical Volume Management

LVM lets you resize volumes without touching partitions. Worth understanding even if you don't set it up yourself — many Linux installations default to it.

$ pvdisplay          # physical volumes
$ vgdisplay          # volume groups
$ lvdisplay          # logical volumes

# Extend a logical volume and its filesystem
$ lvextend -L +10G /dev/vg0/data
$ resize2fs /dev/vg0/data       # for ext4
$ xfs_growfs /mnt/data          # for XFS (grows the mounted filesystem)

XFS can be grown while mounted; shrinking XFS isn't supported. ext4 can be grown online, but shrinking requires unmounting.

ZFS (If You Have It)

ZFS is its own world — it combines filesystem and volume management, and includes checksumming and snapshots. Common on FreeBSD, and available on Linux via OpenZFS.

$ zpool status              # pool health
$ zpool list                # pool usage
$ zfs list                  # datasets
$ zpool scrub mypool        # verify all data against checksums (run monthly)
$ zfs snapshot mypool/data@$(date +%Y%m%d)   # create a snapshot
$ zfs list -t snapshot      # list snapshots
$ zfs rollback mypool/data@20250209          # roll back to a snapshot

ZFS's scrub is genuinely useful — it catches silent data corruption that other filesystems would never notice.