Disk Management
fdisk, gdisk, parted, mkfs, fsck, blkid, and smartctl for partitioning, formatting, and drive health.
Overview
Disk management is a foundational SRE skill. Whether you are adding a data volume to a database server, replacing a failed drive, or setting up a new host, you need to understand partitioning schemes, filesystem creation, integrity checking, and drive health monitoring.
MBR vs GPT
MBR (Master Boot Record) is the legacy scheme stored in the first 512 bytes of a disk. It supports at most 4 primary partitions (or 3 primary + 1 extended with logical partitions inside) and disks up to 2 TiB. Use fdisk to work with MBR disks.
GPT (GUID Partition Table) is the modern standard. It supports up to 128 partitions per disk and disks beyond 2 TiB. GPT stores a backup partition table at the end of the disk for recovery. Use gdisk or parted for GPT disks. All disks over 2 TiB must use GPT.
Key Tools
- lsblk -f — list block devices with filesystem type, UUID, and mount point in a tree view
- blkid — print UUID and TYPE for all block devices; used in /etc/fstab
- fdisk / gdisk — interactive partition editors for MBR and GPT respectively
- parted — non-interactive partitioning, scriptable, supports both MBR and GPT
- mkfs.ext4 / mkfs.xfs — create filesystems
- fsck — filesystem consistency checker; never run on mounted filesystems
- smartctl — query SMART (Self-Monitoring Analysis and Reporting Technology) data from drive firmware
Why UUID Over Device Name
Device names like /dev/sdb can change between reboots depending on probe order, PCI slot changes, or adding new disks. UUIDs are stable and assigned at filesystem creation. Always reference disks by UUID in /etc/fstab and bootloader configs.
Key concepts
- MBR
- Master Boot Record — legacy partition scheme in the first 512 bytes. Max 4 primary partitions, max 2 TiB disk. Use fdisk to manage.
- GPT
- GUID Partition Table — modern scheme supporting 128+ partitions and disks beyond 2 TiB. Stores a backup partition table at disk end. Use gdisk or parted.
- UUID
- Universally Unique Identifier assigned at filesystem creation. Stable across reboots unlike /dev/sdX names. Retrieve with blkid. Always use in /etc/fstab.
- SMART attributes
- Drive firmware counters exposed via smartctl -a /dev/sda. Key ones: Reallocated_Sector_Ct (bad sectors remapped — rising count = drive failing), Spin_Retry_Count, Uncorrectable_Error_Cnt, Power_On_Hours.
- fsck
- Filesystem check — scans and repairs inconsistencies. Run only on unmounted or read-only filesystems. Use -n flag for a dry-run (read-only check with no writes).
- parted
- Scriptable partition tool supporting both MBR and GPT. Preferred for automation. parted /dev/sdb mklabel gpt mkpart primary 0% 100% creates a single GPT partition.
When to use it
- Adding a new data disk to a database server — partition with parted, format with mkfs.xfs, add UUID to fstab
- Investigating "No space left on device" errors — check df -h for blocks and df -i for inodes
- Proactively monitoring drive health in production — smartctl weekly cron job checking reallocated sectors
- Recovering from filesystem corruption after power loss — fsck.ext4 in single-user mode
- Migrating from MBR to GPT on a disk over 2 TiB — gdisk or parted required
Interview questions
- Walk me through adding a new 4 TiB data disk to a Linux server from raw device to mounted filesystem.
- How do you check if a disk is failing in production without taking downtime?
- What is the difference between fdisk, gdisk, and parted? When do you use each?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio