Disk management: fdisk, lsblk, df, du, mount, umount, /etc/fstab

Linux Essentials Preparation · lesson 16 of 23 · 25 min

Disk and Partition Management

Linux represents disks as device files in /dev. SATA/SAS disks: /dev/sda, /dev/sdb. NVMe: /dev/nvme0n1. Partitions: /dev/sda1, /dev/sda2.

lsblk — lists block devices in a tree format. Shows disks, partitions, and mount points. lsblk -f shows filesystem types.

fdisk /dev/sda — interactive partition editor for MBR disks. Commands: p (print), n (new), d (delete), w (write/save), q (quit without saving). Use gdisk or parted for GPT disks.

mkfs — creates a filesystem on a partition. mkfs.ext4 /dev/sda1 formats with ext4. mkfs.xfs /dev/sda2 for XFS.

Common Linux filesystems: ext4 (most common), XFS (high performance, RHEL default), Btrfs (snapshots, checksums), FAT32/exFAT (USB drives, cross-platform).

Mounting and Disk Usage

mount — attaches a filesystem to the directory tree. mount /dev/sda1 /mnt/data. mount -t ext4 /dev/sda1 /mnt specifies filesystem type.

umount — detaches a filesystem. umount /mnt/data. Cannot unmount if the filesystem is in use.

/etc/fstab — filesystem table. Defines filesystems to mount automatically at boot. Fields: device, mount point, filesystem type, options, dump, pass.

df — disk free. Shows disk space usage for mounted filesystems. df -h human-readable. df -T shows filesystem type.

du — disk usage. Shows space used by files and directories. du -sh /var/log — summary of /var/log in human-readable format. du -sh * — size of each item in current directory.

Exam Tip

df = disk free (mounted filesystems). du = disk usage (files/directories). /etc/fstab = auto-mount at boot. lsblk shows the disk tree. mkfs creates a filesystem. mount attaches it.

Key Terms

Key Terms

Knowledge Check — 8 Questions

Linux Essentials — Disk Management

Which command shows disk space usage for mounted filesystems?

  • du
  • df
  • lsblk
  • fdisk

Answer: df
df (disk free) shows space used and available on mounted filesystems. du shows space used by specific files/directories.

/etc/fstab is used to:

  • List running processes
  • Define filesystems to mount automatically at boot
  • Configure network interfaces
  • Store user passwords
  • Answer: Define filesystems to mount automatically at boot

/etc/fstab entries are processed at boot — each line defines a device, mount point, filesystem type, and options.

mkfs.ext4 /dev/sda1 does what?

  • Mounts /dev/sda1
  • Creates an ext4 filesystem on /dev/sda1
  • Lists partitions on sda
  • Checks the filesystem for errors

Answer: Creates an ext4 filesystem on /dev/sda1
mkfs (make filesystem) formats a partition. mkfs.ext4 creates an ext4 filesystem — this erases all data on the partition.

du -sh /var/log shows:

  • Free space in /var/log
  • The total size of /var/log in human-readable format
  • Files in /var/log
  • Log file timestamps
  • Answer: The total size of /var/log in human-readable format

du -s = summary (total only, not per-file). -h = human-readable. Shows total disk space used by /var/log. lsblk -f shows:

  • File permissions
  • Filesystem types for each block device
  • Free space
  • File sizes
  • Answer: Filesystem types for each block device

lsblk -f adds filesystem type, label, UUID, and mount point columns to the block device tree. The most common Linux filesystem for general use is:

  • FAT32
  • NTFS
  • ext4
  • HFS+
  • Answer: ext4

ext4 (Fourth Extended Filesystem) is the default on most Linux distributions — journaling, reliable, widely supported. umount fails with “device is busy” because:

  • The filesystem is corrupted
  • A process has a file open or is in the directory
  • The disk is full
  • The mount point does not exist
  • Answer: A process has a file open or is in the directory

Cannot unmount a filesystem while it is in use. Use lsof or fuser to find which process is using it.

NVMe drives appear in /dev as _____ (e.g., nvme0n1).

Answer: nvme0n1
NVMe drives use the naming convention /dev/nvme[controller]n[namespace] — e.g., /dev/nvme0n1. SATA drives use /dev/sda, /dev/sdb.


Previous lesson: Processes and hardware: ps, top, kill, systemctl, journalctl, hardware info commands
Back to Linux Essentials Preparation
Next lesson: Networking on Linux: ip addr, ip route, ss, ping, traceroute, /etc/hosts, /etc/resolv.conf