Partition mini-HOWTO: GPT, EFI partition, swap, LVM and LUKS2

Updated November 2026

For a new Linux disk today, use a GPT partition table, an EFI system partition of about 1 GiB if the machine boots with UEFI, and one large partition for the root file system. Use a swap file or zram instead of a swap partition, and add LVM or LUKS2 encryption if you need them. The tools are fdisk or gdisk for interactive work, sfdisk or sgdisk for scripts, and parted for both.

The 2001 Partition HOWTO counted cylinders and argued about where to put swap on IDE disks. Disks now report their own geometry, tools align partitions to 1 MiB automatically, and an installer does all of this for you. Read on if you are adding a disk, preparing a USB drive, or want to understand what the installer did.

Partitioning can destroy data. Back up first, and check the device name twice. /dev/sda today may be /dev/sdb after a reboot or with a USB stick plugged in. lsblk -o NAME,SIZE,MODEL,SERIAL and the names in /dev/disk/by-id/ help you pick the right disk.

GPT or MBR?

Partition table types
GPT (GUID Partition Table)MBR ("DOS" label)
Largest diskPractically unlimited (64-bit sector numbers)2 TiB with 512-byte sectors (32-bit sector numbers)
Partitions128 in the usual table size4 primary, or 3 primary plus logical partitions in an extended one
SafetyChecksums, backup copy at the end of the diskOne copy in sector 0
FirmwareUEFI; BIOS with a BIOS boot partition for GRUBBIOS; UEFI can read it too
Use forEverything newOld BIOS-only PCs, some small boards and cameras

The 2 TiB limit is simple arithmetic: 232 sectors × 512 bytes = 2,199,023,255,552 bytes = 2 TiB. A GPT disk keeps a "protective MBR" in sector 0 so that old MBR-only tools see the disk as full instead of empty.

Look before you change anything

lsblk -f                 # disks, partitions, file systems, labels, UUIDs, mount points
sudo fdisk -l /dev/nvme0n1
sudo parted -l           # all disks, with the table type ("gpt" or "msdos")
[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS

A sensible layout

Typical single-disk layouts
PartitionUEFI PCBIOS PC, GPT diskType (sfdisk alias / gdisk code)
Boot loaderEFI system partition, FAT32, 550 MiB–1 GiB, mounted at /boot/efi (or /efi, /boot)BIOS boot partition, 1 MiB, no file systemuefi / EF00; BIOS boot: EF02
RootThe rest of the disk: ext4, XFS or Btrfs, or an LVM or LUKS2 containerlinux / 8300 (lvm / 8E00)
SwapA swap file or zram instead (see below); a swap partition only for hibernation setups that need itswap / 8200

A separate /home partition makes reinstalling easier but forces you to guess sizes. Btrfs subvolumes or LVM give the same separation without fixed sizes. If Windows is on the same disk, keep its ESP and use it; do not create a second one (see the dual-boot mini-HOWTO). If you plan to use systemd-boot, which loads kernels from the ESP, make the ESP 1 GiB or more.

Create the partitions

Scripted, with sfdisk

sfdisk reads a short description from standard input. This creates a new GPT with a 1 GiB ESP and a Linux partition filling the rest of a spare disk. It wipes the existing table:

sudo sfdisk /dev/sdX <<'EOF'
label: gpt
size=1GiB, type=uefi, name="EFI"
type=linux, name="root"
EOF

Start positions default to the first free, aligned sector, and the first partition starts at 1 MiB. An empty size means "as much as possible".

Interactive, with fdisk or gdisk

sudo fdisk /dev/sdX works on both GPT and MBR. Press m for help, g to create a new empty GPT, n for a new partition (answer +1G for the size), t to change its type, p to print, and w to write. Nothing changes on disk until w; q quits without saving. gdisk (package gdisk) is a GPT-only tool with the same style and the four-digit type codes shown above. Its scriptable twin is sgdisk:

sudo sgdisk --zap-all /dev/sdX                     # destroys GPT and MBR structures
sudo sgdisk -n 1:0:+1G -t 1:EF00 -c 1:EFI  \
            -n 2:0:0   -t 2:8300 -c 2:root /dev/sdX
sudo sgdisk -p /dev/sdX

With parted

sudo parted --script /dev/sdX \
  mklabel gpt \
  mkpart EFI fat32 1MiB 1025MiB \
  set 1 esp on \
  mkpart root ext4 1025MiB 100%
sudo parted /dev/sdX align-check optimal 1

For a BIOS boot partition on a GPT disk, make a 1 MiB partition and run parted /dev/sdX set 1 bios_grub on. After changing a disk that is in use, sudo partprobe /dev/sdX asks the kernel to reread the table.

Make file systems and mount them

sudo mkfs.fat -F 32 -n EFI /dev/sdX1
sudo mkfs.ext4 -L data /dev/sdX2
sudo blkid /dev/sdX2                  # shows UUID="…"

In /etc/fstab, refer to file systems by UUID= (or LABEL=), never by /dev/sdX names, which can change:

UUID=0a1b2c3d-…  /srv/data  ext4  defaults  0  2

Test with sudo mount -a before rebooting; an error here is much easier to fix than a boot that stops in emergency mode.

Swap: file or zram

A swap file can be resized or removed without repartitioning. With util-linux 2.41 or newer (Debian 13 has 2.41, as of November 2026), one command creates it correctly, even on Btrfs:

sudo mkswap --file /swapfile --size 4G
sudo swapon /swapfile
echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab

On older systems, create it by hand: sudo dd if=/dev/zero of=/swapfile bs=1MiB count=4096, then sudo chmod 600 /swapfile and sudo mkswap /swapfile. On Btrfs, use sudo btrfs filesystem mkswapfile --size 4G /swapfile (btrfs-progs 6.1 and newer), because a swap file there must be preallocated and have copy-on-write turned off, and the subvolume holding it cannot be snapshotted while it is active.

zram is swap in compressed RAM. It is fast and needs no disk space, which suits laptops and small machines. Fedora already sets up zram swap by default (package zram-generator-defaults). Elsewhere, install systemd-zram-generator (Debian, Ubuntu) or zram-generator (Fedora, if removed) and create /etc/systemd/zram-generator.conf:

[zram0]
zram-size = min(ram / 2, 4096)
compression-algorithm = zstd

That size, half the RAM up to 4,096 MiB, is the generator's default. Reboot (or run sudo systemctl daemon-reload and sudo systemctl start /dev/zram0), then check with swapon --show.

LVM: flexible volumes

LVM (Logical Volume Manager) pools partitions or disks into a volume group, then cuts logical volumes from it that you can grow later. Set the partition type to lvm / 8E00, then:

sudo pvcreate /dev/sdX2                      # mark the partition as a physical volume
sudo vgcreate vgdata /dev/sdX2               # create a volume group
sudo lvcreate -n home -L 200G vgdata         # a 200 GiB logical volume
sudo lvcreate -n srv -l 100%FREE vgdata      # the rest
sudo mkfs.ext4 /dev/vgdata/home
sudo lvextend -r -L +50G vgdata/home         # later: grow the volume and its file system

Leave some space free in the volume group; it makes snapshots and later growth easy. sudo pvs, vgs and lvs show the state. For RAID across disks, see the Software RAID HOWTO.

LUKS2: encrypt a partition

cryptsetup creates LUKS2 volumes by default. Encryption protects data on a lost or stolen disk; it does not protect a running, unlocked system.

sudo cryptsetup luksFormat /dev/sdX2         # type YES in capitals, then a passphrase
sudo cryptsetup open /dev/sdX2 cryptdata     # creates /dev/mapper/cryptdata
sudo mkfs.ext4 /dev/mapper/cryptdata
sudo cryptsetup luksHeaderBackup /dev/sdX2 --header-backup-file sdX2-luks-header.img

Store the header backup somewhere safe and off that disk: if the LUKS header is damaged, the data is gone without it. To unlock at boot, add a line to /etc/crypttab and refer to the mapper device in /etc/fstab:

# /etc/crypttab
cryptdata  UUID=<UUID of /dev/sdX2 from blkid>  none  luks,discard
# /etc/fstab
/dev/mapper/cryptdata  /srv/data  ext4  defaults  0  2

none means "ask for the passphrase". For the root file system, let the installer set up encryption, because the initramfs must also be able to unlock it. You can put LVM inside LUKS to encrypt several volumes with one passphrase.

Back up the partition table

sudo sfdisk --dump /dev/sdX > sdX.dump      # text; restore with: sudo sfdisk /dev/sdX < sdX.dump
sudo sgdisk --backup=sdX.gpt /dev/sdX       # binary GPT backup; restore with --load-backup

If a partition table is already lost, stop writing to the disk and use TestDisk from a live system; see the undeletion mini-HOWTO.

Mistakes to avoid

The classic Linux Partition HOWTO is kept by the LDP at tldp.org. For a full installation walk-through, see the Installation HOWTO.

Sources