Disk Management
Learn to partition disks, manage filesystems, and monitor storage.
Checking Disk Usage
$ df -h # Filesystem disk usage
$ du -sh /var/log # Size of directory
$ du -h --max-depth=1 # Subdirectory sizes
$ lsblk # List block devices
$ du -sh /var/log # Size of directory
$ du -h --max-depth=1 # Subdirectory sizes
$ lsblk # List block devices
Mounting Filesystems
$ mount /dev/sdb1 /mnt/data
$ umount /mnt/data
$ cat /etc/fstab # Persistent mounts
$ umount /mnt/data
$ cat /etc/fstab # Persistent mounts
Partitions and Filesystems
Disks usually contain partitions (or volumes) formatted with a filesystem (ext4, xfs, btrfs, etc.). On cloud systems you’ll also see network and virtual disks.
# Identify disks + partitions
$ lsblk -f
$ sudo fdisk -l | head
# Create filesystem (example: ext4) — destructive
$ sudo mkfs.ext4 /dev/sdb1
$ sudo mkfs.xfs /dev/sdb1
$ lsblk -f
$ sudo fdisk -l | head
# Create filesystem (example: ext4) — destructive
$ sudo mkfs.ext4 /dev/sdb1
$ sudo mkfs.xfs /dev/sdb1
⚠️ Formatting erases data. Only do this on new disks or after backups.
fstab Best Practices: use UUIDs
Device names like /dev/sdb1 can change across reboots. Use UUIDs in /etc/fstab for stable mounts.
$ blkid | head
# Example fstab line
UUID=xxxx-xxxx /mnt/data ext4 defaults,noatime 0 2
# Validate fstab safely
$ sudo findmnt --verify
# Example fstab line
UUID=xxxx-xxxx /mnt/data ext4 defaults,noatime 0 2
# Validate fstab safely
$ sudo findmnt --verify
When “Disk Full” isn’t space: inodes
ext-family filesystems track metadata using inodes. You can run out of inodes even with free disk space, typically due to millions of tiny files.
$ df -h
$ df -i
$ df -i
Finding What’s Using Space
Start broad (df) then zoom in (du). Be careful with du on huge directories—it can be slow.
$ df -hT
$ sudo du -xhd 1 /var | sort -h | tail
$ sudo du -xhd 1 /home | sort -h | tail
# Friendly interactive explorer (if installed)
$ ncdu /var
$ sudo du -xhd 1 /var | sort -h | tail
$ sudo du -xhd 1 /home | sort -h | tail
# Friendly interactive explorer (if installed)
$ ncdu /var
Storage Building Blocks (LVM & RAID)
In production, you’ll often see storage layers:
- •LVM: flexible logical volumes that can be resized/snapshotted
- •RAID: redundancy or performance across disks
$ sudo pvs
$ sudo vgs
$ sudo lvs
$ cat /proc/mdstat # RAID status
$ sudo vgs
$ sudo lvs
$ cat /proc/mdstat # RAID status
✅ Practice (15–20 minutes)
- Use
lsblk -fto map disks → partitions → mount points. - Run
du -xhd 1 /varand identify top space consumers. - Inspect
/etc/fstaband explain each column (device, mountpoint, fs type, options, dump, fsck).