Skip to content

Disk_partitioning

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


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

  • 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