Skip to content

Disk Partitioning and Tools

This chapter covers disk partitioning tools and techniques for managing storage in Linux systems.


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 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────┐
│ 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 │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘

Terminal window
# List partitions
sudo fdisk -l
sudo fdisk -l /dev/sdb
# Partition disk
sudo 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 table
Terminal window
# Interactive mode
sudo parted /dev/sdb
# Commands:
# mklabel gpt
# mklabel msdos
# mkpart primary ext4 0% 100%
# mkpart primary xfs 1MiB 100%
# rm 1
# print
# quit
# Scripted
sudo parted -s /dev/sdb mklabel gpt
sudo parted -s /dev/sdb mkpart primary ext4 0% 100%
Terminal window
# GPT partitioning
sudo gdisk /dev/sdb
# Commands:
# o - create new GPT
# n - new partition
# w - write
# q - quit
# p - print
# i - partition info

Terminal window
sudo fdisk /dev/sdb
# Example session:
# n (new)
# p (primary)
# 1 (partition number)
# First sector: Enter (default)
# Last sector: +10G
# w (write)
Terminal window
# Scripted partitioning
sudo parted -s /dev/sdb mklabel gpt
sudo parted -s /dev/sdb mkpart primary ext4 0% 1GiB
sudo parted -s /dev/sdb mkpart primary ext4 1GiB 100%
Terminal window
# Set partition type (fdisk)
# t command
# 1 - Linux
# 5 - Extended
# 7 - HPFS/NTFS/exFAT
# 8 - Linux LVM
# a - Boot flag
# Set bootable flag
# a command

Terminal window
# Notify kernel of partition changes
sudo partprobe /dev/sdb
# Without writing to disk
sudo partprobe -s
# For specific partition
sudo partprobe -s /dev/sdb1

Terminal window
# 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 - swap
Terminal window
# 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)

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)

WRONG:

Terminal window
# MBR has 2TB limit - will lose data beyond 2TB
fdisk /dev/sda
# Created 3TB partition but only first 2TB usable

CORRECT:

Terminal window
# Use GPT for large disks
parted /dev/sda
mklabel gpt
# Now you can use full disk capacity

Why: MBR cannot address beyond 2TB; GPT supports up to 256TB.


WRONG:

Terminal window
# One big partition for entire disk
/dev/sda1 mounted at /
# If /tmp fills up, system crashes!

CORRECT:

Terminal window
# Separate partitions for different mount points
/dev/sda1 /boot 1G
/dev/sda2 / 20G
/dev/sda3 /var 10G
/dev/sda4 /tmp 5G
/dev/sda5 /home rest

Why: Prevents one directory from affecting entire system.


WRONG:

Terminal window
# Small /var partition fills up with logs
# No space left for log rotation

CORRECT:

Terminal window
# Plan for growth - especially /var and /var/log
# Monitor usage with: df -h
# Set up alerts at 80% usage

Why: Logs and data grow over time; running out causes failures.


WRONG:

Terminal window
# Using Linux partition type for swap (works but not proper)
# Using LVM partition type without LVM setup

CORRECT:

Terminal window
# Use proper partition IDs
parted /dev/sda
# set 2 linux-swap on
# OR
# set 3 lvm on

Why: Correct IDs help tools recognize partition purpose.


  • MBR: Legacy, 4 primary, 2TB limit
  • GPT: Modern, 128 partitions, UEFI
  • Tools: fdisk, parted, gdisk

Chapter 13: LVM - Logical Volume Manager


Last Updated: February 2026