Linux Partition HOWTO: Disk partitioning guide
- Partition Scheme: Always use GUID Partition Tables (GPT) for all drives unless strictly constrained by legacy 1980s BIOS systems.
- Sector Alignment: Align all partition boundaries to exact 1 MiB (2048 sector) multiples to guarantee alignment with 4Kn physical sectors and SSD flash erase blocks.
- Persistent Mounting: Reference partitions by filesystem
UUID=or GPTPARTUUID=in/etc/fstabrather than raw kernel node paths (/dev/sda).
Table of contents
- 1. Fundamentals of Linux disk partitioning
- 2. Block device identification and naming conventions
- 3. Partition table standards: GPT vs. MBR
- 4. Partition requirements, sizing & subvolume strategies
- 5. Creating partitions with fdisk, gdisk, and parted
- 6. Filesystem creation (Ext4, Btrfs, XFS, VFAT)
- 7. Persistent labeling & device identification (UUID / PARTUUID)
- 8. Swap space: zram, swapfiles, and dedicated partitions
- 9. Partition table recovery and repair
- 10. Full-disk encryption with LUKS
- 11. UEFI boot flow and the EFI System Partition
- 12. Storage geometries: LBA, 4Kn Advanced Format, and NVMe FTL
1. Fundamentals of Linux disk partitioning
A partition is a continuous region of logical blocks on a storage device that is isolated from other regions on the same drive. The operating system treats each partition as a separate block device, so different filesystems, LUKS encryption layers, and swap areas can coexist on one disk.
Partitioning serves several operational requirements:
- System and Data Isolation: Separating the root filesystem (
/) from user data in/homeor variable system data in/varprevents user activities or log surges from halting core services. - Firmware and Boot Standards: Providing the dedicated FAT32/VFAT EFI System Partition (ESP) required by UEFI firmware for bootloaders.
- Security Policies: Enabling granular mount options (such as
nodev,nosuid, andnoexec) on directories like/tmpand/var/tmp. - Multi-Boot and Maintenance: Allowing multiple operating systems or dedicated rescue environments on a single storage drive.
2. Block device identification and naming conventions
Linux exposes storage devices as special block device nodes in /dev/. The device prefix reflects the underlying hardware interface:
| Device Path | Storage Interface | Drive Example | Partition Example |
|---|---|---|---|
/dev/nvmeXnYpZ | PCIe NVMe SSD | /dev/nvme0n1 (Controller 0, Namespace 1) | /dev/nvme0n1p1 (Partition 1) |
/dev/sdX | SATA / SAS / USB SCSI | /dev/sda (First SATA drive) | /dev/sda1 (Partition 1) |
/dev/vdX | VirtIO Block (KVM/QEMU) | /dev/vda (First virtual disk) | /dev/vda1 (Partition 1) |
/dev/mmcblkXpY | eMMC / SD Storage | /dev/mmcblk0 | /dev/mmcblk0p1 |
Kernel device names like /dev/sda and /dev/nvme0n1 are assigned dynamically during boot depending on controller detection timing. In production configurations, always reference partitions using persistent identifiers (such as UUID= or PARTUUID=) in /etc/fstab.
3. Partition table standards: GPT vs. MBR
The partition table defines the layout, boundaries, and types of all partitions on a drive. Modern systems use GPT; MBR remains only for legacy BIOS compatibility.
- GUID Partition Table (GPT): Standard partition table format defined by the UEFI specification. GPT supports disk sizes up to 8 ZiB (9.44 ZB, $9.44 \times 10^21$ bytes) on 512-byte sector drives, provides 128 primary partition slots by default (with no extended partition workarounds), assigns unique 128-bit GUIDs to all disks and partitions, and maintains a backup partition table at the end of the disk with CRC32 integrity verification.
- Master Boot Record (MBR): Legacy partition table format defined by IBM PC DOS 2.0. Limited to 2.2 TB drive capacity (32-bit LBA, $2^32 - 1$ sectors at 512 bytes each), a maximum of 4 primary partitions (requiring extended and logical partitions for additional volumes), and lacks redundant backup headers or checksums. A single corrupted sector at LBA 0 renders the entire disk unbootable.
GPT on-disk layout
GPT stores redundant metadata at both ends of the disk. The UEFI specification (section 5) defines the following structure:
| LBA | Structure | Purpose |
|---|---|---|
LBA 0 | Protective MBR | A legacy MBR with a single partition entry of type 0xEE spanning the disk. Prevents GPT-unaware utilities from accidentally overwriting GPT structures. |
LBA 1 | Primary GPT Header | Contains the EFI PART signature, disk GUID, partition entry array location, CRC32 checksums, and pointers to the backup header. |
LBA 2 to 33 | Primary Partition Entry Array | 128 entries of 128 bytes each (16 KiB total). Each entry holds a partition type GUID, unique partition GUID, start/end LBA, and partition name. |
LBA 34 to n-34 | Usable disk space | Partition data area. First usable LBA is typically 34; last usable LBA is disk_size - 34. |
LBA n-33 to n-2 | Backup Partition Entry Array | Mirror of the primary entry array for recovery. |
LBA n-1 | Backup GPT Header | Mirror of the primary header. Its My LBA and Alternate LBA fields are reversed relative to the primary. |
MBR on-disk layout
MBR packs all metadata into a single 512-byte sector at LBA 0:
| Offset | Size | Content |
|---|---|---|
0x000 | 440 bytes | Bootstrap code (master boot code) |
0x1B8 | 4 bytes | Optional unique disk signature |
0x1BE | 64 bytes | Four 16-byte partition table entries (primary partitions) |
0x1FE | 2 bytes | Boot signature 0x55AA |
Each 16-byte MBR partition entry contains a bootable flag, CHS start/end addresses, a 1-byte partition type code, and a 32-bit LBA start and sector count. The 32-bit LBA limit is what caps MBR at 2.2 TB. Extended partitions (type 0x05, 0x0F, or 0x85) create a linked list of partition table sectors for logical volumes beyond the 4 primary slots.
For detailed GUID mappings, see Partition Types, GPT GUIDs & Discoverable Partitions →.
4. Partition requirements, sizing & subvolume strategies
Partition layout requirements depend on whether you are using traditional fixed partitions or a Copy-on-Write (CoW) filesystem with subvolumes (such as Btrfs or ZFS):
| Mount Point | Partition Type | Typical Allocation | Filesystem | Description |
|---|---|---|---|---|
/boot/efi or /efi | EFI System Partition (ESP) | 512 MB to 1 GB | VFAT (FAT32) | Required by UEFI firmware for bootloaders and Unified Kernel Images. |
/ (Root) | Linux Root | 50 GB to 100 GB+ | Ext4, Btrfs, or XFS | Operating system binaries, libraries, system configurations, and containers. |
/home | Linux Home | Remaining Disk Space | Ext4, Btrfs, or XFS | User directories, configurations, and personal data. |
[SWAP] | Linux Swap | 0 (zram) or 4 to 16 GB | Swap Space | In-memory zram swap device or dedicated swapfile on disk. |
Detailed sizing rules and subvolume considerations are available in Partition Requirements & Sizing Guide →.
5. Creating partitions with fdisk, gdisk, and parted
Partitions can be managed from the command line using standard utilities:
fdisk: Interactive utility in util-linux with full GPT support and automatic 1MiB sector alignment.gdisk: Dedicated GPT tool for GUID configuration and partition table repair.parted: Scriptable CLI partition manager suited for automation and provisioning scripts.
# Start fdisk on an NVMe drive
sudo fdisk /dev/nvme0n1
# Key fdisk interactive commands:
# g -> Initialize a new GPT partition table
# n -> Create a new partition
# t -> Set partition type (e.g., 1 for EFI, 23 for Linux Root)
# p -> Display the partition table
# w -> Write changes to disk and exitScriptable partitioning with parted
For provisioning scripts, Kickstart files, and cloud image builds, parted accepts multiple commands in a single non-interactive invocation. Use --script (or -s) to suppress prompts and -a optimal to enforce 1MiB alignment:
# Create a full UEFI/GPT layout in one scripted call
sudo parted --script -a optimal /dev/nvme0n1 \
mklabel gpt \
mkpart "EFI system partition" fat32 1MiB 1025MiB \
set 1 esp on \
mkpart "swap" linux-swap 1025MiB 17GiB \
mkpart "root" ext4 17GiB 100%
# Verify the result
sudo parted --script /dev/nvme0n1 printNote that mkpart does not create the filesystem. The fs-type parameter only sets the partition type GUID on GPT disks. Run mkfs.* separately after partitioning.
Follow the full tutorial in How to Partition with fdisk, gdisk & parted →.
6. Filesystem creation
After creating partitions, format them with the appropriate filesystem:
# Format the EFI System Partition (FAT32)
sudo mkfs.vfat -F 32 -n "EFI-SYSTEM" /dev/nvme0n1p1
# Format Root with Ext4 (64-bit metadata checksums enabled)
sudo mkfs.ext4 -L "ROOT_FS" /dev/nvme0n1p2
# Format Data partition with Btrfs
sudo mkfs.btrfs -L "DATA_POOL" /dev/nvme0n1p3
# Format High-Performance storage with XFS
sudo mkfs.xfs -L "DATABASE" /dev/nvme0n1p4Filesystem comparison
The three dominant Linux filesystems serve different workloads. Ext4 is the default on Debian and Ubuntu. XFS is the default on RHEL, AlmaLinux, and Rocky Linux. Btrfs is the default on Fedora and openSUSE.
| Feature | Ext4 | XFS | Btrfs |
|---|---|---|---|
| Max volume size | 16 TiB (default) / 64 ZiB (with 64bit feature) | 8 EiB | 16 EiB |
| Max file size | 16 TiB | 8 EiB (VFS limit) | 8 EiB (practical VFS limit; 16 EiB theoretical) |
| Journaling | Metadata only (data=ordered default) | Metadata only | Copy-on-write |
| Online grow | Yes | Yes | Yes |
| Online shrink | No (offline only) | No | Yes |
| Snapshots | No | No (native reflink for file-level CoW) | Yes (native) |
| Compression | No | No | Yes (zstd, lzo, zlib) |
| Data checksums | Metadata only | Metadata only | Data + metadata |
| Subvolumes | No | No | Yes |
| Default on | Debian, Ubuntu | RHEL, AlmaLinux, Rocky | Fedora, openSUSE |
Ext4 is the safest general-purpose choice with the longest production track record (stable since 2008). XFS excels at large-file sequential I/O and parallel workloads. Btrfs provides snapshots, compression, and self-healing checksums. For deep dives and enterprise volume management, explore the Ext4 Architecture & Tuning Guide, XFS Optimization Guide, Btrfs Deep Dive, OpenZFS on Linux Guide, and LVM Tutorial.
7. Persistent labeling & device identification
Use lsblk to verify filesystem labels, UUIDs, and mount points across all block devices:
# View all devices with filesystem metadata
lsblk -f
# Sample /etc/fstab configuration using persistent UUIDs:
UUID=4f923b7a-9a81-4b72-9d33-871d8a11a2bc / ext4 defaults,noatime 0 1
UUID=7A29-C412 /boot/efi vfat umask=0077 0 2
UUID=e2f8910a-31b4-482a-bc91-2a8190cba718 /home ext4 defaults,noatime 0 2Learn more in Filesystem Labels & Persistent Naming → and e2label Command Reference →.
8. Swap space: zram, swapfiles, and dedicated partitions
Linux supports several swap mechanisms:
- zram: Compressed RAM swap block device. The kernel default compression algorithm is
lzo-rle;zstdis a common high-ratio alternative configurable viazram-generator. Delivers high throughput without disk latency or SSD write cycles. - Swapfiles: Stored on standard filesystems (Ext4, XFS, Btrfs), enabling dynamic resizing without repartitioning.
- Swap Priority: Tiering fast zram swap (
pri=100) ahead of disk swapfiles (pri=10).
Read the complete configuration guide in Configuring Swap Space & zram →.
9. Partition table recovery and repair
GPT includes built-in recovery capabilities via its secondary partition table stored at the end of the disk. Because the backup header and entry array mirror the primary, a corrupted primary can be rebuilt from the backup.
Verifying and repairing GPT with gdisk
gdisk provides a dedicated recovery and transformation menu (accessed with r from the main menu). The v command on the main menu verifies disk integrity by checking CRC32 values and comparing the primary and backup structures:
# Launch gdisk on the damaged disk
sudo gdisk /dev/nvme0n1
# Verify integrity from the main menu
Command (? for help): v
# Enter the recovery menu if problems are found
Command (? for help): r
# Recovery and transformation options:
# b -> Rebuild primary GPT header from backup
# c -> Load backup partition table (rebuilds main)
# d -> Use main GPT header (rebuilds backup)
# e -> Load main partition table from disk (rebuilds backup)
# f -> Load MBR and build fresh GPT from it
# Write repaired table and exit
recovery/transformation command (? for help): wRecovering deleted partitions with testdisk
When a partition has been deleted or the table is severely damaged, testdisk can scan the disk surface for filesystem signatures and reconstruct the partition table. It performs a quick search first, then an optional deeper search that scans the entire disk:
# Launch testdisk on the damaged disk
sudo testdisk /dev/nvme0n1
# Select partition table type (auto-detected, usually correct)
# Choose "Analyse" to inspect the current partition table
# Choose "Quick Search" to scan for deleted partitions
# Use "Deeper Search" if Quick Search misses partitions
# Mark found partitions as P (primary) or L (logical)
# Write the recovered partition table to diskAlways back up the GPT header before attempting repairs. In gdisk, use b from the main menu to save a binary backup of the protective MBR, primary header, backup header, and partition table to a file. For corrupted superblock repair, inode rebuilding, and disaster recovery strategies, see the Filesystem Repair Guide (e2fsck, xfs_repair, btrfs check) and the Linux Backup & Disaster Recovery Reference.
10. Full-disk encryption with LUKS
LUKS (Linux Unified Key Setup) is the standard for full-disk encryption on Linux, implemented by cryptsetup on top of the kernel's dm-crypt subsystem. LUKS2 is the default format since cryptsetup 2.1 and stores metadata in a redundant header at the start of the partition.
# Format a partition with LUKS2 (default)
sudo cryptsetup luksFormat /dev/nvme0n1p3
# Open the encrypted partition, mapping it to /dev/mapper/data
sudo cryptsetup open /dev/nvme0n1p3 data
# Format the decrypted mapper device with ext4
sudo mkfs.ext4 -L "ENCRYPTED" /dev/mapper/data
# Close the encrypted partition when done
sudo cryptsetup close dataThe LUKS2 header occupies 16 MiB by default (configurable via --offset), providing space for up to 32 keyslots and online reencryption. The header is stored twice (primary and secondary) for resilience against corruption. Back up the header with cryptsetup luksHeaderBackup before any potentially destructive operation, as losing the header renders the encrypted data permanently unrecoverable.
For detailed performance optimizations (such as bypassing CPU workqueues on NVMe drives) and automated boot unlocking via TPM2 or Clevis/Tang network key escrow, see the LUKS2 & dm-crypt Encryption Guide and the Automated TPM2 / NBDE Encryption Guide.
11. UEFI boot flow and the EFI System Partition
On UEFI systems, the firmware boot manager reads EFI executables (PE format .efi files) from the EFI System Partition (ESP), a FAT32 partition identified by GPT type GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B. The boot flow is:
- Firmware initialization: UEFI firmware reads the
BootOrderNVRAM variable to determine which boot entry to load. - Boot loader execution: The firmware loads the EFI executable specified by the boot entry. For removable media, it falls back to
\EFI\BOOT\BOOTX64.EFI. - Kernel handoff: The boot loader (such as
systemd-bootor GRUB) loads the Linux kernel and initramfs, then callsExitBootServices()to transfer control from firmware to the kernel. - Initramfs: The initramfs mounts the root filesystem, then pivots to it as PID 1.
systemd-boot is a simple UEFI boot manager and the reference implementation of the Boot Loader Specification. It reads Boot Loader Specification Type #1 entries from /loader/entries/ on the ESP and Type #2 Unified Kernel Images from /EFI/Linux/. UKIs combine systemd-stub, the kernel, initramfs, and kernel command line into a single signed .efi binary for Secure Boot.
Frequently asked questions
What is a disk partition in Linux?
A partition is a continuous region of logical blocks on a storage device, isolated from other regions on the same drive. The operating system treats each partition as a separate block device for different filesystems, LUKS encryption layers, or swap areas.
Should I use GPT or MBR partition table?
Use GPT for all drives unless constrained by legacy BIOS systems. GPT supports disk sizes up to 8 ZiB, 128 primary partitions by default, and stores a backup partition table at the end of the disk with CRC32 integrity verification. MBR is limited to 2.2 TB and 4 primary partitions.
How should I reference partitions in /etc/fstab?
Reference partitions by filesystem UUID= or GPT PARTUUID= rather than raw device paths like /dev/sda. Kernel device names are assigned dynamically at boot and can change order depending on controller detection timing.
What sector alignment should I use for partitions?
Align all partition boundaries to 1 MiB (2048 sector) multiples. This guarantees alignment with 4Kn physical sectors and SSD flash erase blocks, eliminating read-modify-write performance penalties.
What filesystem should I choose: Ext4, XFS, or Btrfs?
Ext4 is the default on Debian and Ubuntu with the longest production track record (stable since 2008). XFS is the default on RHEL and excels at large-file sequential I/O. Btrfs provides snapshots, compression, and self-healing checksums via copy-on-write.
How do I recover a corrupted GPT partition table?
GPT stores a backup partition table at the end of the disk. Use gdisk's recovery menu (press r from the main menu) to rebuild the primary header from the backup. For deleted partitions, testdisk can scan the disk surface for filesystem signatures.
What is LUKS full-disk encryption?
LUKS (Linux Unified Key Setup) is the standard for full-disk encryption on Linux, implemented by cryptsetup on top of dm-crypt. LUKS2 is the default format since cryptsetup 2.1 and stores metadata in a redundant header at the start of the partition.