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

CommandWhat it does
df -hDisk usage by mounted filesystem, human-readable sizes
df -h /homeUsage of a specific mount point
du -sh /var/logHow much space a directory tree uses
du -sh /var/log/*Break it down by subdirectory
du -sh * | sort -rh | head -20Find the biggest things in the current directory
lsof | grep deletedFind 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

CommandFilesystemNotes
mkfs.ext4 /dev/sdb1ext4Most common Linux filesystem; mature, reliable
mkfs.xfs /dev/sdb1XFSBetter for large files; default on RHEL/Rocky
mkfs.btrfs /dev/sdb1BtrfsSnapshots, checksums, copy-on-write
mkfs.vfat -F 32 /dev/sdc1FAT32USB 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

OptionEffectUse case
noatimeDon't update access time on readsBetter performance; SSDs especially benefit
nodiratimeSame, for directories onlyComplement to noatime
noexecDon't allow executing binariesData partitions, extra security for /tmp
nosuidIgnore setuid/setgid bitsGood for /tmp and shared data directories
roRead-onlyBackups, 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.

CommandPurpose
pvdisplayShow physical volumes
vgdisplayShow volume groups
lvdisplayShow logical volumes
lvextend -L +10G /dev/vg0/dataExtend a logical volume by 10GB
resize2fs /dev/vg0/dataGrow ext4 to use the new space
xfs_growfs /mnt/dataGrow 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.

References