Disk Partitioning and Tools
Chapter 12: Disk Partitioning and Tools
Section titled “Chapter 12: Disk Partitioning and Tools”Overview
Section titled “Overview”This chapter covers disk partitioning tools and techniques for managing storage in Linux systems.
Why This Matters in DevOps/SRE
Section titled “Why This Matters in DevOps/SRE”Proper partitioning is critical for system reliability, security, and recovery. Understanding partition schemes helps prevent data loss, enables proper disk management, and supports disaster recovery procedures.
┌─────────────────────────────────────────────────────────────────────────────┐│ PARTITIONING IN DEVOPS │├─────────────────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────────────────────┐ ││ │ OPERATIONAL IMPACT │ ││ │ │ ││ │ • System Reliability - Separate /tmp prevents DoS │ ││ │ • Security - Separate /home limits privilege escalation │ ││ │ • Recovery - Isolated /var/log aids troubleshooting │ ││ │ • Performance - Separate /opt for applications │ ││ │ • Boot - BIOS/grub needs specific partition layout │ ││ │ │ ││ └─────────────────────────────────────────────────────────────────────┘ ││ ││ ┌─────────────────────────────────────────────────────────────────────┐ ││ │ COMMON DEPLOYMENT SCENARIOS │ ││ │ │ ││ │ Standard Server: │ ││ │ /boot 1GB - Kernel & initramfs │ ││ │ / 20GB - Root filesystem │ ││ │ swap 8GB - Memory swap (or use LVM) │ ││ │ /var 10GB - Logs and variable data │ ││ │ /tmp 10GB - Temporary files │ ││ │ /home Rest - User data │ ││ │ │ ││ │ Database Server: │ ││ │ / 20GB - Root │ ││ │ /var/lib/mysql 100GB+ - Database files │ ││ │ /var/log 20GB - Database logs │ ││ │ │ ││ └─────────────────────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────────────────┘12.1 Partitioning Concepts
Section titled “12.1 Partitioning Concepts”MBR vs GPT
Section titled “MBR vs GPT”┌─────────────────────────────────────────────────────────────────────────┐│ PARTITION TYPES │├─────────────────────────────────────────────────────────────────────────┤│ ││ MBR (Master Boot Record): ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ • Max 4 primary partitions (or 3 + 1 extended) │ ││ │ • Max 2TB disk size limit │ ││ │ • Boot code in first sector (512 bytes) │ ││ │ • Legacy BIOS boot │ ││ │ • 32-bit LBA for addressing │ ││ └─────────────────────────────────────────────────────────────────┘ ││ ││ GPT (GUID Partition Table): ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ • Max 128 partitions (default) │ ││ │ • Max 256TB disk size (theoretical) │ ││ │ • GUID-based unique identifiers │ ││ │ • UEFI required for boot │ ││ │ • CRC32 checksums for integrity │ ││ │ • Backup GPT header at end of disk │ ││ └─────────────────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────────────┘12.2 Partitioning Tools
Section titled “12.2 Partitioning Tools”fdisk (MBR)
Section titled “fdisk (MBR)”# List partitionssudo fdisk -lsudo fdisk -l /dev/sdb
# Partition disksudo fdisk /dev/sdb
# Commands:# n - new partition# p - primary partition# e - extended partition# l - list partition types# t - change partition type# d - delete partition# w - write and quit# q - quit without saving# p - print partition tableparted (GPT)
Section titled “parted (GPT)”# Interactive modesudo parted /dev/sdb
# Commands:# mklabel gpt# mklabel msdos# mkpart primary ext4 0% 100%# mkpart primary xfs 1MiB 100%# rm 1# print# quit
# Scriptedsudo parted -s /dev/sdb mklabel gptsudo parted -s /dev/sdb mkpart primary ext4 0% 100%gdisk (GPT)
Section titled “gdisk (GPT)”# GPT partitioningsudo gdisk /dev/sdb
# Commands:# o - create new GPT# n - new partition# w - write# q - quit# p - print# i - partition info12.3 Partition Examples
Section titled “12.3 Partition Examples”Creating Partitions with fdisk
Section titled “Creating Partitions with fdisk”sudo fdisk /dev/sdb
# Example session:# n (new)# p (primary)# 1 (partition number)# First sector: Enter (default)# Last sector: +10G# w (write)Creating Partitions with parted
Section titled “Creating Partitions with parted”# Scripted partitioningsudo parted -s /dev/sdb mklabel gptsudo parted -s /dev/sdb mkpart primary ext4 0% 1GiBsudo parted -s /dev/sdb mkpart primary ext4 1GiB 100%Setting Partition Types
Section titled “Setting Partition Types”# Set partition type (fdisk)# t command# 1 - Linux# 5 - Extended# 7 - HPFS/NTFS/exFAT# 8 - Linux LVM# a - Boot flag
# Set bootable flag# a command12.4 Partprobe
Section titled “12.4 Partprobe”# Notify kernel of partition changessudo partprobe /dev/sdb
# Without writing to disksudo partprobe -s
# For specific partitionsudo partprobe -s /dev/sdb112.5 Partition Layout
Section titled “12.5 Partition Layout”Common Partition Layouts
Section titled “Common Partition Layouts”# BIOS/MBR Layout:# /dev/sda1 - /boot (512MB-1GB)# /dev/sda2 - / (root, 20-30GB)# /dev/sda3 - /home (remaining)# /dev/sda4 - Extended partition# /dev/sda5 - swap (2x RAM)
# UEFI/GPT Layout:# /dev/sda1 - /boot/efi (ESP, 512MB, EF00 type)# /dev/sda2 - / (root)# /dev/sda3 - /home# /dev/sda4 - swapArch Linux Installation Example
Section titled “Arch Linux Installation Example”# Common partition layout:# /boot - 512MB to 1GB (EFI System Partition)# / - 20-30GB (root)# /home - Remaining (user data)# swap - 2x RAM (optional with btrfs)
# Example with fdisk:# n, p, 1, Enter, +512M # /boot/efi# n, p, 2, Enter, +30G # /# n, p, 3, Enter, Enter # /home# t, 1, 1 # Set ESP type (EF00)12.6 Interview Questions
Section titled “12.6 Interview Questions”Q: What is the difference between MBR and GPT?A: MBR: max 4 partitions, 2TB limit, legacy GPT: max 128 partitions, 256TB+, UEFI
Q: How do you create a partition in Linux?A: fdisk /dev/sdb, then n for new partition
Q: What is partprobe?A: Notifies kernel of partition changes without reboot
Q: What is an extended partition?A: Container for logical partitions (MBR only)Common Mistakes & Anti-Patterns
Section titled “Common Mistakes & Anti-Patterns”1. Using MBR on Large Disks
Section titled “1. Using MBR on Large Disks”WRONG:
# MBR has 2TB limit - will lose data beyond 2TBfdisk /dev/sda# Created 3TB partition but only first 2TB usableCORRECT:
# Use GPT for large disksparted /dev/sdamklabel gpt# Now you can use full disk capacityWhy: MBR cannot address beyond 2TB; GPT supports up to 256TB.
2. Single Partition for Everything
Section titled “2. Single Partition for Everything”WRONG:
# One big partition for entire disk/dev/sda1 mounted at /# If /tmp fills up, system crashes!CORRECT:
# Separate partitions for different mount points/dev/sda1 /boot 1G/dev/sda2 / 20G/dev/sda3 /var 10G/dev/sda4 /tmp 5G/dev/sda5 /home restWhy: Prevents one directory from affecting entire system.
3. Not Planning for Growth
Section titled “3. Not Planning for Growth”WRONG:
# Small /var partition fills up with logs# No space left for log rotationCORRECT:
# Plan for growth - especially /var and /var/log# Monitor usage with: df -h# Set up alerts at 80% usageWhy: Logs and data grow over time; running out causes failures.
4. Incorrect Partition Type IDs
Section titled “4. Incorrect Partition Type IDs”WRONG:
# Using Linux partition type for swap (works but not proper)# Using LVM partition type without LVM setupCORRECT:
# Use proper partition IDsparted /dev/sda# set 2 linux-swap on# OR# set 3 lvm onWhy: Correct IDs help tools recognize partition purpose.
Summary
Section titled “Summary”- MBR: Legacy, 4 primary, 2TB limit
- GPT: Modern, 128 partitions, UEFI
- Tools: fdisk, parted, gdisk
Next Chapter
Section titled “Next Chapter”Chapter 13: LVM - Logical Volume Manager
Last Updated: February 2026