Lesson 1 of 12 · Disks and RAID
GPT disks and partitions in the enterprise
Objective
Know which disk you are touching before you touch it, understand what a GPT table contains, partition in a reproducible way (with a script) and repair a damaged table without losing data.
Key points
- On a server, a disk is identified by its serial number or its WWN, never by its
sdXname, which can change at every boot. - GPT keeps two copies of the table: a primary header at the start of the disk and a backup copy at the end, each protected by a CRC32 checksum.
- Each GPT partition has a type (a GUID: Linux, LVM, RAID, swap, EFI…) and a unique identifier (
PARTUUID). - Partitions are aligned on 1 MiB (sector 2048): the right multiple for 4K disks, SSDs and storage arrays.
- In production, you partition with a script (
sfdisk,sgdisk): the same command gives the same result on ten servers.
1. Identify the right disk
The most expensive mistake in the job: wiping the wrong disk. Before any operation, cross-check several pieces of information.
lsblk -o NAME,SIZE,TYPE,ROTA,MODEL,SERIAL,WWN,MOUNTPOINTS
# NAME SIZE TYPE ROTA MODEL SERIAL WWN
# sda 480G disk 0 SAMSUNG MZ7LH480 S45PNA0M512345 0x5002538e40a1b2c3
# sdb 3.6T disk 1 ST4000NM0035 ZC1A2B3C 0x5000c500a1b2c3d4
# sdc 3.6T disk 1 ST4000NM0035 ZC1A9X8Y 0x5000c500a1b2c999
ls -l /dev/disk/by-id/ # stable names: ata-…, scsi-…, wwn-0x…, nvme-eui.…
ls -l /dev/disk/by-path/ # physical position: controller, port, bay
cat /sys/block/sdb/queue/rotational # 1 = spinning disk, 0 = SSD
cat /sys/block/sdb/queue/logical_block_size /sys/block/sdb/queue/physical_block_size
# 512 4096 → "512e" disk: 512-byte logical sectors, 4 KiB physical sectors
In a server room, the on-site technician only sees the disk's label (serial number) and sometimes an LED. Always give them the serial number, and turn on the LED if the controller allows it (ledctl locate=/dev/sdb with the ledmon package).
2. What a GPT table contains
Secteur 0 MBR « protecteur » : un seul type 0xEE qui couvre tout le disque
Secteur 1 En-tête GPT principal (signature « EFI PART », CRC32, GUID du disque)
Secteurs 2 à 33 Table des partitions (128 entrées de 128 octets)
… Partitions
Avant-derniers Copie de la table des partitions
Dernier secteur En-tête GPT de secours
In other words: sector 0 holds the "protective" MBR (a single 0xEE partition covering the whole disk), sector 1 the primary GPT header ("EFI PART" signature, CRC32, disk GUID), sectors 2 to 33 the partition table (128 entries of 128 bytes), then the partitions, then a copy of the partition table and, in the very last sector, the backup GPT header.
The protective MBR prevents an old tool that only knows MBR from believing the disk is empty. The two headers let you survive the start of the disk being overwritten (a hasty dd, a badly installed boot loader).
| Point | MBR (msdos) | GPT |
|---|---|---|
| Maximum addressable size | 2 TiB (512-byte sectors) | 8 ZiB, unlimited in practice |
| Number of partitions | 4 primary (or extended + logical) | 128 by default |
| Backup copy | no | yes, at the end of the disk |
| Integrity check | no | CRC32 of the header and of the table |
| Partition name | no | yes (PARTLABEL) |
3. Partition types you must know
| Use | sgdisk code |
sfdisk shortcut |
Type GUID |
|---|---|---|---|
| EFI system (ESP) | ef00 |
U |
C12A7328-F81F-11D2-BA4B-00A0C93EC93B |
| BIOS boot (GRUB on GPT without UEFI) | ef02 |
— | 21686148-6449-6E6F-744E-656564454649 |
| Linux file system | 8300 |
L |
0FC63DAF-8483-4772-8E79-3D69D8477DE4 |
| Linux swap | 8200 |
S |
0657FD6D-A4AB-43C4-84E5-0933C84B4F4F |
| Linux LVM | 8e00 |
V |
E6D6D379-F507-44C2-A23C-238F2A3DF928 |
| Linux RAID | fd00 |
R |
A19D880F-05FC-4D3B-A006-743F0F84911E |
The type does not change what the kernel can do with the partition, but it informs tools and humans: a RAID member marked "Linux RAID" will not be mistaken for an empty partition by the next technician.
4. Partitioning with a script
With sgdisk (gdisk package)
sgdisk --zap-all /dev/sdb # wipes MBR + primary GPT + backup GPT
sgdisk -n 1:0:+1G -t 1:8e00 -c 1:lvm-donnees /dev/sdb # partition 1: 1 GiB, LVM, named
sgdisk -n 2:0:0 -t 2:fd00 -c 2:raid-membre /dev/sdb # partition 2: the rest, RAID
sgdisk -p /dev/sdb # print
sgdisk -v /dev/sdb # check consistency
-n num:start:end: 0 means "the first free, aligned position" or "up to the end".
With sfdisk (util-linux, available everywhere)
# One partition per line; fields without a value take the default (aligned start, end of disk)
sfdisk /dev/sdb <<'EOF'
label: gpt
size=1GiB, type=V, name=lvm-donnees
type=R, name=raid-membre
EOF
sfdisk -d /dev/sdb > /root/sdb.gpt # text backup of the table
sfdisk /dev/sdb < /root/sdb.gpt # identical restore (same GUIDs)
sfdisk --part-type /dev/sdb 2 # read the type of a partition
sfdisk --part-label /dev/sdb 1 archives # rename partition 1
sfdisk --verify /dev/sdb # check the table
sfdisk also works on a disk image file: this is how you practise without risk, and how you prepare virtual machine images. On a file, add --no-tell-kernel: sfdisk then neither tries to notify the kernel nor to synchronise every disk of the system (sync), which makes no sense for an image.
Tell the kernel the table has changed
partprobe /dev/sdb # (parted) re-reads the table
partx -u /dev/sdb # (util-linux) updates the partitions known to the kernel
udevadm settle # wait for /dev/sdb1, /dev/disk/by-partlabel/… to appear
5. Identifiers: UUID, PARTUUID, LABEL, PARTLABEL
blkid /dev/sdb1
# /dev/sdb1: UUID="7c1e…" TYPE="LVM2_member" PARTLABEL="lvm-donnees" PARTUUID="cb73…"
| Identifier | Carried by | Changes if… |
|---|---|---|
UUID |
the file system (or the LVM/RAID member) | you reformat |
LABEL |
the file system | you rename it (e2label, xfs_admin -L) |
PARTUUID |
the GPT entry | you recreate the table |
PARTLABEL |
the GPT entry | you rename the partition |
In /etc/fstab, prefer UUID= for a file system. PARTUUID= is mostly used by the boot loader (root=PARTUUID=…).
6. Cleanly wiping a reused disk
A disk coming from another server often keeps signatures (old RAID, old LVM, old ZFS). They cause surprise mounts or "ghost" arrays at boot.
wipefs /dev/sdb # lists the signatures, without erasing anything
wipefs -a /dev/sdb1 # erases the signatures of the partition
wipefs -a /dev/sdb # then those of the disk (primary GPT, backup GPT, MBR)
7. Repairing a GPT table
sfdisk -l /dev/sdb
# The primary GPT table is corrupt, but the backup appears OK, so that will be used.
The message says it all: the start of the disk is damaged, but the copy at the end is healthy. You rewrite the primary table from the copy:
sfdisk -d /dev/sdb > /root/sdb-secours.gpt # sfdisk has read the backup copy
sfdisk /dev/sdb < /root/sdb-secours.gpt # and rewrites both copies
# With gdisk: gdisk /dev/sdb, then r (recovery), b (rebuild the main header), w
Another common case: an enlarged LUN or virtual disk (SAN, VMware, cloud). The backup copy is no longer at the end of the disk, and the added space is invisible.
sfdisk -l /dev/sdb
# GPT PMBR size mismatch (209715199 != 419430399) will be corrected by write.
sgdisk -e /dev/sdb # moves the backup GPT to the real end
# or: sfdisk --relocate gpt-bak-std /dev/sdb
growpart /dev/sdb 2 # grows partition 2 (cloud-utils-growpart package)
By version
| Point | Rocky 9 | Debian 12 | Ubuntu 24.04 |
|---|---|---|---|
sfdisk, wipefs, partx |
util-linux (installed) | fdisk package for sfdisk |
fdisk package (installed) |
sgdisk / gdisk |
gdisk package |
gdisk package |
gdisk package |
growpart |
cloud-utils-growpart |
cloud-guest-utils |
cloud-guest-utils (installed on cloud images) |
| Table created by the installer | GPT | GPT with UEFI, MBR possible with BIOS | GPT |
Common pitfalls
- Trusting
/dev/sdb: after adding a controller or a USB stick,sdbbecomessdc. Check the serial number right before acting. - Copying a table along with its GUIDs:
sfdisk -d sdb | sfdisk sdcgives two disks with the samePARTUUIDs. To clone a layout, usesgdisk -R /dev/sdc /dev/sdbthensgdisk -G /dev/sdc(new GUIDs), or remove thelabel-idanduuid=lines from the file. wipefs -aon the disk only: the signatures inside the partitions stay on the sectors and reappear if you recreate the same table. Wipe the partitions first.- A partition starting at sector 63 or 34: a legacy of old tools, misaligned on 4K disks. Write performance collapses.
Lab
On Rocky 9, you work on disk images (files) with the real tools:
- create a 2 GiB disk as a sparse file;
- write a GPT table on it with a script, with a named LVM partition and a RAID partition;
- back up that table in text format;
- repair another disk whose primary GPT header has been overwritten.
Quiz
- Why should you not refer to a disk as
/dev/sdbin a procedure? - Where is the backup copy of a GPT table?
- Which GPT type do you give to a member of an mdadm array?
- A 100 GiB LUN grows to 200 GiB: what must you do before growing the partition?
- What does
wipefsdo without any option?
Answers
sdXnames are assigned in detection order and can change at boot. Use the serial number, the WWN or/dev/disk/by-id/.- At the end of the disk: the copy of the partition table, then the backup header in the last sector.
- "Linux RAID" (
fd00in sgdisk,Rin sfdisk, GUIDA19D880F-…). - Move the backup GPT header to the new end of the disk (
sgdisk -eorsfdisk --relocate gpt-bak-std). - It lists the signatures found (file systems, RAID, LVM, tables) without erasing anything.