Enterprise Storage: RAID, Advanced LVM, ZFS, NFS and iSCSI
Exit

Lesson 1 of 12 · Disks and RAID

GPT disks and partitions in the enterprise

45 min Rocky Linux 9 Versions Rocky 9, Debian 12, Ubuntu 24.04

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 sdX name, 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, sdb becomes sdc. Check the serial number right before acting.
  • Copying a table along with its GUIDs: sfdisk -d sdb | sfdisk sdc gives two disks with the same PARTUUIDs. To clone a layout, use sgdisk -R /dev/sdc /dev/sdb then sgdisk -G /dev/sdc (new GUIDs), or remove the label-id and uuid= lines from the file.
  • wipefs -a on 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:

  1. create a 2 GiB disk as a sparse file;
  2. write a GPT table on it with a script, with a named LVM partition and a RAID partition;
  3. back up that table in text format;
  4. repair another disk whose primary GPT header has been overwritten.

Quiz

  1. Why should you not refer to a disk as /dev/sdb in a procedure?
  2. Where is the backup copy of a GPT table?
  3. Which GPT type do you give to a member of an mdadm array?
  4. A 100 GiB LUN grows to 200 GiB: what must you do before growing the partition?
  5. What does wipefs do without any option?
Answers
  1. sdX names are assigned in detection order and can change at boot. Use the serial number, the WWN or /dev/disk/by-id/.
  2. At the end of the disk: the copy of the partition table, then the backup header in the last sector.
  3. "Linux RAID" (fd00 in sgdisk, R in sfdisk, GUID A19D880F-…).
  4. Move the backup GPT header to the new end of the disk (sgdisk -e or sfdisk --relocate gpt-bak-std).
  5. It lists the signatures found (file systems, RAID, LVM, tables) without erasing anything.

Practical exercises

To do on Rocky Linux 9

Do this lab on your own machine

The terminal is yours: a Linux VM (VirtualBox, VMware, Hyper-V, WSL…) or Docker/Podman. The ml tool prepares the exercise and checks your work; the lesson is validated here automatically.

Create a free account to get your personal command and have your labs checked automatically.

Create my account

Tasks

  1. Create the disk image /srv/disques/sdb.img, exactly 2 GiB, as a sparse file (it must not take up 2 GiB of real space).
    Show a hinttruncate -s 2G creates a sparse file of the requested size.
    Show the solution
    truncate -s 2G /srv/disques/sdb.img

    Check : test "$(stat -c %s /srv/disques/sdb.img)" = 2147483648 && test "$(du -k /srv/disques/sdb.img | cut -f1)" -lt 1024

  2. Write a GPT table on sdb.img with two partitions aligned on 1 MiB: partition 1 is 1 GiB, type "Linux LVM", name "lvm-donnees"; partition 2 takes the rest, type "Linux RAID".
    Show a hintAn sfdisk script: label: gpt, then one line per partition (size=1GiB, type=V, name=lvm-donnees and type=R).
    Show the solution
    printf 'label: gpt\nsize=1GiB, type=V, name=lvm-donnees\ntype=R\n' | sfdisk -q --no-tell-kernel /srv/disques/sdb.img

    Check : D=/srv/disques/sdb.img; sfdisk -d $D 2>/dev/null | grep -q '^label: gpt' && test "$(sfdisk --part-type $D 1)" = E6D6D379-F507-44C2-A23C-238F2A3DF928 && test "$(sfdisk --part-type $D 2)" = A19D880F-05FC-4D3B-A006-743F0F84911E && test "$(sfdisk --part-label $D 1)" = lvm-donnees && sfdisk -d $D | grep -q "${D}1 : start= *2048, size= *2097152,"

  3. Back up the partition table of sdb.img to /root/sdb.gpt, in the text format that sfdisk can read back.
    Show a hintsfdisk --dump (or -d) writes the table to standard output.
    Show the solution
    sfdisk -d /srv/disques/sdb.img > /root/sdb.gpt

    Check : grep -q '^label: gpt' /root/sdb.gpt && grep -q 'name="lvm-donnees"' /root/sdb.gpt && grep -q 'A19D880F-05FC-4D3B-A006-743F0F84911E' /root/sdb.gpt

  4. The primary GPT header of /srv/disques/sdd.img has been overwritten (sector 1). Rewrite it from the backup copy at the end of the disk, without losing the two partitions.
    Show a hintsfdisk reads the backup copy when the primary one is damaged: read the table with -d and write it back unchanged to the same disk.
    Show the solution
    sfdisk -d /srv/disques/sdd.img 2>/dev/null > /root/sdd.gpt && sfdisk -q --no-tell-kernel /srv/disques/sdd.img < /root/sdd.gpt

    Check : D=/srv/disques/sdd.img; dd if=$D bs=512 skip=1 count=1 2>/dev/null | head -c 8 | grep -q 'EFI PART' && test "$(sfdisk --part-label $D 1)" = lvm-archives && test "$(sfdisk --part-type $D 2)" = A19D880F-05FC-4D3B-A006-743F0F84911E