Linux Partitioning Explained

Linux Partitioning Explained

Partitioning is the process of dividing a physical disk into sections that the operating system treats as independent storage units. Understanding partitions helps you make good decisions during installation, diagnose disk issues, and manage storage as your system grows.

Disks and partitions: the basics

A physical disk (SSD or HDD) is a single block device. Partitioning divides it into segments with defined start and end positions. Each segment is a partition. The partition table (stored on the disk itself) describes where each partition starts, ends, and what type it is.

# View the block devices and their partitions
lsblk
# NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
# nvme0n1     259:0    0   500G  0 disk
# ├─nvme0n1p1 259:1    0   512M  0 part /boot/efi
# ├─nvme0n1p2 259:2    0     4G  0 part [SWAP]
# └─nvme0n1p3 259:3    0 495.5G  0 part /

# View with filesystem types and UUIDs
lsblk -f
# NAME        FSTYPE  LABEL  UUID               MOUNTPOINTS
# nvme0n1
# ├─nvme0n1p1 vfat           ABCD-1234          /boot/efi
# ├─nvme0n1p2 swap           ...                [SWAP]
# └─nvme0n1p3 ext4           ...                /

# Detailed partition table info
sudo fdisk -l /dev/nvme0n1
# Disk /dev/nvme0n1: 500 GiB, 536870912000 bytes, 1048576000 sectors
# Disklabel type: gpt
# Device            Start       End   Sectors  Size Type
# /dev/nvme0n1p1     2048   1050623   1048576  512M EFI System
# /dev/nvme0n1p2  1050624   9439231   8388608    4G Linux swap
# /dev/nvme0n1p3  9439232 1048575966 1039136735  495G Linux filesystem

Partition tables: MBR vs GPT

The partition table format determines how partition information is stored on disk.

MBR (Master Boot Record)

MBR stores the partition table in the first 512 bytes of the disk alongside the boot code. This design dates from the early 1980s.

Limitations:

  • Maximum 4 primary partitions
  • Workaround: 3 primary + 1 extended partition, which contains multiple logical partitions
  • Maximum disk size: 2TB (2^32 sectors x 512 bytes)
  • No redundancy: MBR corruption makes the disk unbootable
  • Required for BIOS/legacy boot
# Create MBR partition table with fdisk
sudo fdisk /dev/sdb
Command: o    # create MBR partition table
Command: n    # new partition
  p           # primary
  1           # partition number
  [Enter]     # default start
  +20G        # size
Command: t    # change type
  83          # Linux filesystem (default for MBR)
Command: w    # write and exit

GPT (GUID Partition Table)

GPT is the modern standard, designed for UEFI and large disks.

Advantages over MBR:

  • Up to 128 partitions on a single disk (no extended/logical partition complexity)
  • Maximum disk size: 9.4ZB (zettabytes)
  • Partition table stored at both the start and end of the disk (redundancy)
  • Each partition has a GUID: a unique identifier that does not change if other partitions are added or moved
  • CRC32 checksum to detect partition table corruption
# Create GPT partition table with gdisk
sudo gdisk /dev/sdb
Command: o    # create GPT partition table (confirm with Y)
Command: n    # new partition
  1           # partition number
  [Enter]     # default start
  +512M       # size
  EF00        # type: EFI System Partition
Command: n    # another partition
  2
  [Enter]
  +4G
  8200        # type: Linux swap
Command: n    # root partition
  3
  [Enter]
  [Enter]     # rest of disk
  8300        # type: Linux filesystem
Command: w    # write and exit

# Or use parted for scripting
sudo parted /dev/sdb --script \
  mklabel gpt \
  mkpart ESP fat32 1MiB 513MiB \
  set 1 esp on \
  mkpart swap linux-swap 513MiB 4513MiB \
  mkpart root ext4 4513MiB 100%

Standard Linux partition layout

Device          Size    Type              Mount       Purpose
/dev/sda1       512MB   EFI System        /boot/efi   Bootloaders
/dev/sda2       4GB     Linux swap        [SWAP]      Overflow RAM / hibernation
/dev/sda3       ~rest   Linux filesystem  /           Root: OS + apps + home

UEFI with separate /home

/dev/sda1       512MB   EFI System        /boot/efi
/dev/sda2       4GB     Linux swap        [SWAP]
/dev/sda3       80GB    Linux filesystem  /           OS and applications
/dev/sda4       ~rest   Linux filesystem  /home       User files

BIOS/legacy system

/dev/sda1       1MB     BIOS boot         (none)      Space for GRUB stage 2
/dev/sda2       4GB     Linux swap        [SWAP]
/dev/sda3       ~rest   Linux filesystem  /

Server layout with separate mount points

/dev/sda1       512MB   EFI System        /boot/efi
/dev/sda2       1GB     Linux filesystem  /boot       Kernel and initramfs
/dev/sda3       4GB     Linux swap        [SWAP]
/dev/sda4       30GB    Linux filesystem  /           Root
/dev/sda5       50GB    Linux filesystem  /var        Logs, databases
/dev/sda6       ~rest   Linux filesystem  /home       User data

Separating /var on servers prevents log growth or database activity from filling the root partition and crashing the system.

Filesystems

A partition is just an empty container. The filesystem is the structure written inside it that organizes files and directories.

ext4

ext4 is the standard Linux filesystem, the default on Ubuntu, Debian, and many others.

# Create ext4 filesystem
sudo mkfs.ext4 /dev/sda3

# Create with a label
sudo mkfs.ext4 -L "linux-root" /dev/sda3

# Check filesystem status
sudo tune2fs -l /dev/sda3 | grep -E "Filesystem|Block count|Free blocks|Last check"

# Check for errors (run unmounted)
sudo fsck.ext4 /dev/sda3

# Tune reserved space (default 5% reserved for root -- reduce on large data partitions)
sudo tune2fs -m 1 /dev/sda3    # reduce to 1% reserved

Strengths: stable, fast, compatible with everything, easy to repair. Limitations: no native snapshot support, no transparent compression.

btrfs

btrfs (B-tree filesystem) is a copy-on-write filesystem with advanced features. It is the default on Fedora, openSUSE Tumbleweed, and some others.

# Create btrfs filesystem
sudo mkfs.btrfs /dev/sda3

# Create with label
sudo mkfs.btrfs -L "linux-root" /dev/sda3

# Enable compression when mounting (add to /etc/fstab)
# UUID=...  /  btrfs  defaults,compress=zstd:3  0 0

# Create a snapshot manually
sudo btrfs subvolume snapshot / /.snapshots/before-update

# List subvolumes
sudo btrfs subvolume list /

# Show disk usage (different from df due to COW)
sudo btrfs filesystem df /
sudo btrfs filesystem usage /

# Scrub: verify data integrity
sudo btrfs scrub start /

Strengths: snapshots, transparent compression (zstd reduces typical installs by 20-40%), subvolumes, self-healing with multiple drives, online resize and balance. Limitations: more complex than ext4, higher RAM usage, some corner cases still have quirks.

xfs

xfs is a high-performance filesystem used as the default on Fedora Server, RHEL, and CentOS.

# Create xfs filesystem
sudo mkfs.xfs /dev/sda3

# Check
sudo xfs_info /dev/sda3

# Repair (run unmounted)
sudo xfs_repair /dev/sda3

Strengths: excellent parallel write performance, scales well to large filesystems, reliable. Limitations: cannot be shrunk (only grown), no snapshot support, no compression.

FAT32 / vfat (EFI System Partition only)

The EFI System Partition must be FAT32. This is a firmware requirement.

# Create FAT32 for EFI System Partition
sudo mkfs.vfat -F32 /dev/sda1

# Label it (optional but helpful)
sudo fatlabel /dev/sda1 EFI

swap

Swap space is used as overflow RAM and for hibernation. It is not a filesystem in the usual sense — it has no directory structure.

# Create swap partition
sudo mkswap /dev/sda2
sudo swapon /dev/sda2

# Create swap file (alternative to swap partition)
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096   # 4GB swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# Check swap usage
swapon --show
free -h

# Add to /etc/fstab for permanent mount:
# /swapfile  none  swap  sw  0  0

The /etc/fstab file

/etc/fstab defines which partitions are mounted, where, and with what options at boot.

cat /etc/fstab
# <file system>                           <mount>    <type>  <options>       <dump> <pass>
# UUID=a1b2c3d4-e5f6-...                 /          ext4    errors=remount-ro 0     1
# UUID=abcd-1234                          /boot/efi  vfat    umask=0077      0      1
# UUID=...                                none       swap    sw              0      0

# Always use UUID, not device name (/dev/sda3 can change; UUID does not)
sudo blkid                     # get UUIDs for all partitions

# Test fstab without rebooting
sudo mount -a                  # mount all entries in fstab

Graphical partitioning with GParted

GParted provides a visual interface for partitioning. It is available as:

  • A package: sudo apt install gparted
  • A bootable live ISO for partition operations on unmounted drives (gparted.sourceforge.net)

Operations available in GParted: create, delete, resize, move, format, set partition flags (boot, esp, swap), copy/paste partitions, and check filesystems.

For operations on your running system’s root partition (resize /), you need to boot from the GParted live ISO or your Linux installer USB.

Frequently Asked Questions

What is the difference between MBR and GPT partition tables?

MBR (Master Boot Record) is the legacy partition scheme that stores the partition table in the first 512 bytes of a disk. It supports a maximum of 4 primary partitions and disk sizes up to 2TB. GPT (GUID Partition Table) is the modern standard, used on all UEFI systems. It supports up to 128 partitions, disk sizes up to 9.4ZB, and stores the partition table at both the start and end of the disk for redundancy. GPT also assigns each partition a globally unique identifier (GUID) that persists even if partition positions change. Use GPT on any UEFI machine (essentially any computer made after 2012). MBR is only needed for BIOS/legacy boot or when compatibility with very old systems is required.

What partitions does Linux need at minimum?

On a UEFI system, Linux needs at minimum two partitions: an EFI System Partition (ESP) formatted as FAT32, at least 100MB (512MB recommended), mounted at /boot/efi; and a root partition formatted as ext4, btrfs, or xfs that holds the entire Linux system, mounted at /. A swap partition or swap file is optional but recommended for systems with less than 16GB of RAM or systems that use hibernation. On a BIOS system, you need a root partition (/) and either an MBR with space for the bootloader or a 1MB “BIOS boot” partition, plus optionally swap. A separate /boot partition is no longer required on most modern systems unless the bootloader has trouble reading the filesystem used for /.

What is the difference between ext4, btrfs, and xfs?

ext4 is the most widely used Linux filesystem, mature, well-tested, and the safe default for most installations. It does not support snapshots or transparent compression natively. btrfs is a modern copy-on-write filesystem that supports snapshots (used by Timeshift for instant system rollbacks), transparent compression (zstd reduces disk usage by 20-40% on typical systems), and built-in RAID. Fedora uses btrfs as its default. xfs is a high-performance filesystem optimized for large files and parallel I/O, used as the default on RHEL and CentOS. For a desktop Linux installation, ext4 is the safe conservative choice; btrfs with snapshots and compression is excellent if your distribution supports it well (Fedora, openSUSE).

Should I create a separate /home partition?

A separate /home partition stores user files and settings on a different partition from the OS, which means you can reinstall Linux (wiping /) without losing your files (as long as you tell the installer not to format /home). The trade-offs are: you must decide the size split upfront and cannot easily change it later; if you fill one partition while the other has space, you have a problem; and modern backup tools like Timeshift make /home preservation possible even with a single partition. The simplest approach for most users is a single root partition. Create a separate /home partition if you reinstall Linux frequently or if you want a clear separation between OS and data at the partition level.

What is swap and how much should I have?

Swap is disk space used as overflow when RAM is full. The kernel moves pages from RAM to swap when under memory pressure, preventing out-of-memory crashes at the cost of much slower performance (disk is slower than RAM). Swap is also required for hibernation (suspend-to-disk): the entire contents of RAM are written to swap before power-off. General guidance: for desktops with 16GB+ of RAM and no hibernation, swap is optional; with 8GB of RAM, 4-8GB of swap is reasonable; for hibernation, swap must be at least as large as your RAM. Modern Linux uses a swapfile (a regular file inside the root filesystem) rather than a dedicated swap partition by default on Ubuntu and some other distributions. Both work identically; a swapfile is easier to resize later.

How do I view and modify partitions from the Linux command line?

The primary command-line partitioning tools are fdisk (interactive, supports both MBR and GPT), gdisk (GPT-specific), and parted (scriptable, supports both). To view partitions: lsblk shows a tree view of block devices and partitions; fdisk -l /dev/sda shows detailed partition information; lsblk -f adds filesystem type and UUID information. To create or modify partitions interactively: sudo fdisk /dev/sda (then p to print, n to create new, d to delete, t to change type, w to write changes). GParted is the graphical alternative — it provides a visual representation and is available as a live ISO for partition operations on unmounted drives. Always back up data before modifying partition tables.