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. The commands here are the ones that come up in real situations, not a comprehensive survey of every filesystem type.
Checking Disk Space
| Command | What it does |
|---|---|
df -h | Disk usage by mounted filesystem, human-readable sizes |
df -h /home | Usage of a specific mount point |
du -sh /var/log | How much space a directory tree uses |
du -sh /var/log/* | Break it down by subdirectory |
du -sh * | sort -rh | head -20 | Find the biggest things in the current directory |
lsof | grep deleted | Find deleted files still held open (still taking space) |
When `df` shows 100% but you can't find the files consuming space: $ lsof | grep deleted A deleted file still held open by a process still occupies disk space. Restarting (or sending SIGHUP to) the process that has the file open frees it. This is a common cause of "disk full but can't find anything" on busy log servers.
Listing Block Devices
$ lsblk # tree view of all block devices $ lsblk -f # include filesystem type and UUID $ blkid /dev/sdb1 # filesystem UUID for a specific device $ fdisk -l /dev/sdb # partition table details
Always run lsblk before touching a disk to confirm what you're looking at. Device names like sdb vs sdc can flip between boots if you're adding/removing drives.
Creating File Systems
| Command | Filesystem | Notes |
|---|---|---|
mkfs.ext4 /dev/sdb1 | ext4 | Most common Linux filesystem; mature, reliable |
mkfs.xfs /dev/sdb1 | XFS | Better for large files; default on RHEL/Rocky |
mkfs.btrfs /dev/sdb1 | Btrfs | Snapshots, checksums, copy-on-write |
mkfs.vfat -F 32 /dev/sdc1 | FAT32 | USB drives, cross-platform compatibility |
There is no undo for mkfs. Double-check the device name with lsblk before running it.
Mounting
$ mount /dev/sdb1 /mnt # basic mount (auto-detects type) $ 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 as read-write $ umount /mnt # unmount $ umount -l /mnt # lazy unmount — waits until device is idle
Persistent Mounts via /etc/fstab
Entries in /etc/fstab mount automatically at boot. Use UUIDs rather than device names — device names can change, UUIDs don't:
# Get the UUID $ blkid /dev/sdb1 /dev/sdb1: UUID="a1b2c3d4-..." TYPE="ext4" # /etc/fstab entry UUID=a1b2c3d4-... /mnt/data ext4 defaults,noatime 0 2 Columns: device | mountpoint | type | options | dump | fsck-order dump: almost always 0 fsck-order: 1 for root, 2 for others, 0 to skip After editing fstab: test with `mount -a` before rebooting. A bad fstab entry can prevent the system from booting.
Common Mount Options
| Option | Effect | Use case |
|---|---|---|
noatime | Don't update access time on reads | Better performance; SSDs especially benefit |
nodiratime | Same, for directories only | Complement to noatime |
noexec | Don't allow executing binaries | Data partitions, extra security for /tmp |
nosuid | Ignore setuid/setgid bits | Good for /tmp and shared data directories |
ro | Read-only | Backups, forensics, protecting source media |
Checking and Repairing File Systems
Run fsck only on unmounted filesystems. Running it on a live mounted filesystem will cause damage:
$ umount /dev/sdb1 $ fsck /dev/sdb1 # check (auto-detects type) $ fsck -y /dev/sdb1 # check and auto-fix without interactive prompts $ fsck.ext4 -f /dev/sdb1 # force check even if filesystem appears clean For the root filesystem (can't unmount while running): $ tune2fs -C 1 /dev/sda1 # force fsck on next boot (ext filesystems)
LVM — Logical Volume Management
LVM separates physical disks from logical volumes, allowing you to resize and move storage without partitioning constraints. Many Linux installations use it by default.
| Command | Purpose |
|---|---|
pvdisplay | Show physical volumes |
vgdisplay | Show volume groups |
lvdisplay | Show logical volumes |
lvextend -L +10G /dev/vg0/data | Extend a logical volume by 10GB |
resize2fs /dev/vg0/data | Grow ext4 to use the new space |
xfs_growfs /mnt/data | Grow XFS to use the new space (can do live) |
Growing vs. shrinking: XFS: can grow while mounted; shrinking is not supported at all ext4: can grow online; shrinking requires unmounting and a specific approach Btrfs: can grow and shrink while mounted (with `btrfs filesystem resize`)
ZFS
ZFS combines filesystem and volume management in one tool — checksums, snapshots, copy-on-write, and pool-based storage. Native to FreeBSD; available on Linux as OpenZFS.
$ zpool status # pool health and device status $ zpool list # pool sizes and usage $ zfs list # datasets (filesystems/volumes within pools) $ zpool scrub mypool # verify all data against checksums — run monthly $ zfs snapshot mypool/data@$(date +%Y%m%d) # point-in-time snapshot $ zfs list -t snapshot # list all snapshots $ zfs rollback mypool/data@20250209 # revert to a snapshot $ zfs clone mypool/data@snap mypool/test # writable clone from a snapshot
ZFS scrub finds and corrects silent data corruption — bit rot that other filesystems would never notice. On a pool with redundancy (RAIDZ, mirror), it can fix errors. Without redundancy, it at least tells you the data is bad before you find out the hard way.
dispelled