HetznerDocs

Search documentation

Find a Hetzner dedicated Linux topic

Linux partitioning commands

A disk is the whole device. A partition is a slice of that disk. A filesystem (ext4, xfs, vfat) is the format Linux writes inside a slice. Mounting attaches that filesystem to a folder like / or /boot.

The picture

Typical GPT layout on a Hetzner NVMe (then RAID1 + LVM)
EFI 256M/boot/efi
boot 1G/boot
LVM restroot, swap, var

On two-disk RAID1, both disks get the same partition map. Linux then builds /dev/md0, md1, md2 from matching slices.

Device names

You seeWhat it is
/dev/sdaFirst SATA/SAS disk. Partitions: sda1, sda2, …
/dev/nvme0n1First NVMe. Partitions: nvme0n1p1, nvme0n1p2, …
/dev/md2Software RAID array
/dev/mapper/vg0-rootLVM logical volume

See what exists (safe)

Inventory disks and mounts

lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINT,UUIDlsblk -ffindmntdf -hTblkidfdisk -lparted -l

lsblk is the first command to memorize. TYPE tells you disk vs part vs raid vs lvm. MOUNTPOINT tells you what is actually in use.

GPT vs MBR

MBR is the old partition table. It struggles past 2 TiB. GPT is the modern table and is what you want on dedicated servers, together with an EFI System Partition if the box boots UEFI.

See the partition table type

parted /dev/nvme0n1 print# orparted /dev/sda print

parted (manual partitioning)

Use this in Rescue only when installimage cannot express what you want. This example is a single GPT disk:

Create GPT + EFI + boot + LVM (example)

parted /dev/sda mklabel gptparted /dev/sda mkpart ESP fat32 1MiB 257MiBparted /dev/sda set 1 esp onparted /dev/sda mkpart boot ext4 257MiB 1281MiBparted /dev/sda mkpart lvm 1281MiB 100%parted /dev/sda set 3 lvm on

Format those slices

mkfs.vfat -F32 /dev/sda1mkfs.ext4 /dev/sda2pvcreate /dev/sda3vgcreate vg0 /dev/sda3lvcreate -L 50G -n root vg0lvcreate -L 8G -n swap vg0lvcreate -l 100%FREE -n var vg0mkfs.ext4 /dev/vg0/rootmkfs.ext4 /dev/vg0/varmkswap /dev/vg0/swap

fdisk (interactive)

Open fdisk

fdisk /dev/sda

Inside fdisk, common keys are:

  • g — new GPT table
  • n — new partition
  • t — type (EFI, Linux filesystem, LVM)
  • p — print
  • w — write and exit
  • q — quit without saving

LVM in one paragraph

LVM is a second layer on top of a partition (or RAID). Physical volume (PV) → volume group (VG) → logical volumes (LV). You can grow an LV later without repartitioning the whole disk. That is why Hetzner configs often use PART lvm vg0 all then several LV lines.

Inspect LVM

pvsvgslvsls /dev/mapper/

Grow a logical volume and filesystem

lvextend -r -L +20G /dev/vg0/root# or give it all remaining free spacelvextend -r -l +100%FREE /dev/vg0/var

-r resizes the filesystem too (ext4/xfs depending on tools). Always have backups before grow/shrink operations.

installimage partition syntax

PART and LV lines

PART /boot/efi esp 256MPART /boot ext4 1GPART / ext4 50GPART swap swap 8GPART lvm vg0 allLV vg0 root / ext4 50GLV vg0 swap swap swap 8GLV vg0 var /var xfs all
  • First field after PART is the mount point, or lvm, or swap.
  • esp marks the EFI partition.
  • Filesystems you will see: ext4, xfs, swap.
  • Size is 256M, 50G, or all.

Mount, unmount, fstab

Mount by UUID (preferred)

blkidmount UUID=YOUR-UUID /mntumount /mntcat /etc/fstab

/etc/fstab is the table Linux uses at boot. Wrong UUIDs here are a common reason a server needs Rescue.

Wipe a disk (Rescue, reinstall only)

Remove filesystem signatures

wipefs -n /dev/sdawipefs -fa /dev/sda

wipefs -n is a dry run. -fa really erases signatures. Then run installimage.