LFCS 75 🐧 Partitioning with gdisk (GPT)
gdisk is the GPT-aware counterpart to fdisk. It shares the same interactive, menu-driven interface—the same letters for new, delete, type, print, write, and quit—but it operates on GUID Partition Table disks exclusively. Where fdisk asks whether a partition is primary or extended, gdisk does not, because GPT has no such distinction. Every GPT partition is primary, the default limit is 128, and the partition type is selected by a hex code or GUID rather than an MBR type byte . The tool exists because GPT is the standard for modern disks, and fdisk historically could not read or write GPT tables.
This chapter covers the gdisk workflow: inspecting a disk, creating a GPT table, creating partitions with the correct type codes, and writing the changes. It examines the protective MBR that gdisk maintains, the default 1 MiB alignment, and the commands that differ from fdisk because GPT has different requirements.
Key point: gdisk stages all changes in memory until w is pressed, exactly like fdisk. The o command creates a new empty GPT and destroys the existing partition table. The q command discards every change made in the session. The safety mechanism is the same; only the table format differs.
Why gdisk exists
The GPT compatibility problem. GPT stores partition entries as GUIDs and 64-bit LBA addresses, and it includes a backup header at the end of the disk. fdisk in older util-linux versions did not understand this structure. gdisk was written specifically to read and write GPT without risking the corruption that an MBR-only tool could cause . Modern fdisk handles GPT, but gdisk remains the dedicated tool, and its menu is designed around GPT concepts rather than MBR concepts.
The protective MBR problem. GPT disks contain a protective MBR in the first sector to prevent older tools from misinterpreting the disk as an unpartitioned MBR disk. gdisk maintains this protective MBR automatically when it writes a GPT. The o command creates a new protective MBR along with the GPT header and partition entries . This is why gdisk is safe to use on a disk that previously had an MBR table: it replaces the MBR with a protective MBR and writes the GPT alongside it.
The alignment problem. Modern disks—Advanced Format HDDs, SSDs, and RAID arrays—perform best when partitions start on 1 MiB boundaries (2048 sectors of 512 bytes). gdisk aligns new partitions to this boundary by default . This is not a cosmetic default; misaligned partitions can cause read-modify-write overhead that halves throughput on some devices. fdisk also aligns, but gdisk‘s default is documented explicitly as part of its GPT workflow .
a. Inspecting and Creating a GPT Table
The first step is inspection. gdisk -l lists the partition table without opening the interactive menu, and the output shows the GPT header, the disk size, and the partition entries .
# List the GPT partition table on a disk
sudo gdisk -l /dev/sdb
The output includes the partition number, start and end sectors, size, type code, and name. If the disk has an MBR table, gdisk will report that it found an MBR and ask whether to convert it to GPT. This prompt is a safety check: converting an MBR to GPT rewrites the partition table format, and the existing partitions may not be preserved exactly .
Opening gdisk interactively presents the same Command (? for help): prompt as fdisk. The o command creates a new empty GPT. This is the equivalent of fdisk‘s o for MBR, but it writes a GPT header and a protective MBR instead of a DOS partition table. The command prompts for confirmation because it destroys the existing table .
# Open the disk for interactive GPT editing
sudo gdisk /dev/sdb
# At the prompt:
# o → create a new empty GPT (destroys existing table)
# Y → confirm
The p command prints the current in-memory table. Before any partitions are created, it shows the GPT header information and an empty partition list. After partitions are created, it shows the entries with their type codes and names.
b. Creating Partitions with Type Codes
The n command creates a new partition. Unlike fdisk, it does not ask for primary or extended. It asks for the partition number, the first sector, the last sector, and the type code .
# Create a new partition
# n
# 1 (partition number, 1-128)
# <Enter> (default first sector, aligned to 1 MiB)
# +10G (size, relative to the start)
# 8300 (Linux filesystem type code)
The partition number range is 1 through 128, which is the default limit in gdisk. The first sector defaults to the first available aligned sector after the GPT header. The last sector can be specified as an absolute sector, a relative size with +, or an absolute position with - from the end . The +10G notation is the most common because it specifies the size rather than the ending position.
The type code is where GPT differs most from MBR. gdisk uses hex codes that correspond to GPT type GUIDs. The common codes are 8300 for Linux filesystem, 8200 for Linux swap, and 8e00 for Linux LVM . Typing L at the type prompt lists all available codes. The type is a hint to the operating system and tools; it does not prevent formatting the partition as a different filesystem.
# Create a swap partition
# n
# 2
# <Enter>
# +4G
# 8200 (Linux swap type code)
For a UEFI system, the EFI System Partition uses type ef00. This is the partition that the firmware reads to find the bootloader. A GPT disk intended as a UEFI boot disk must have an EFI System Partition with this type code .
c. Writing, Deleting, and Verifying
The d command deletes a partition. It prompts for the partition number and removes the entry from the in-memory table. The t command changes the type code of an existing partition. Both operations are staged until w is pressed.
# Delete partition 2
# d
# 2
# Change partition 1 to EFI System Partition
# t
# 1
# ef00
The w command writes the in-memory table to disk and exits. gdisk prints a final warning that writing the GPT will overwrite existing partitions and prompts for confirmation. Typing Y commits the changes . The q command exits without writing, discarding every change.
# Write the table and exit
# w
# Y
After writing, the kernel may not re-read the partition table immediately. partprobe forces the update, or a reboot achieves the same result. On a disk that is in use, the kernel may refuse to update the table until the device is released.
The v command verifies the disk, checking the GPT header, the partition entries, and the backup header for consistency. This is useful after a manual edit or after a disk operation that may have damaged the table .
Complete Example Session
# ============================================
# PART 1: INSPECT THE DISK
# ============================================
sudo gdisk -l /dev/sdb
# Shows the current GPT table or reports an MBR
# ============================================
# PART 2: OPEN GDISK
# ============================================
sudo gdisk /dev/sdb
# Prompt: Command (? for help):
# ============================================
# PART 3: CREATE A NEW GPT
# ============================================
# o
# Y
# Destroys the existing table and creates a new GPT
# ============================================
# PART 4: CREATE AN EFI SYSTEM PARTITION
# ============================================
# n
# 1
# <Enter>
# +512M
# ef00 (EFI System Partition)
# ============================================
# PART 5: CREATE A LINUX FILESYSTEM PARTITION
# ============================================
# n
# 2
# <Enter>
# +20G
# 8300 (Linux filesystem)
# ============================================
# PART 6: CREATE A SWAP PARTITION
# ============================================
# n
# 3
# <Enter>
# +4G
# 8200 (Linux swap)
# ============================================
# PART 7: VERIFY THE TABLE
# ============================================
# p
# Confirm partitions 1 (ef00), 2 (8300), 3 (8200)
# ============================================
# PART 8: WRITE THE TABLE
# ============================================
# w
# Y
# gdisk writes the GPT and protective MBR
# ============================================
# PART 9: REFRESH THE KERNEL
# ============================================
sudo partprobe /dev/sdb
# ============================================
# PART 10: VERIFY WITH LSBLK
# ============================================
lsblk -o NAME,SIZE,PARTTYPENAME /dev/sdb
# Shows sdb1 (EFI System), sdb2 (Linux filesystem), sdb3 (Linux swap)
The ten parts trace the creation of a typical UEFI boot disk layout: an EFI System Partition, a root filesystem partition, and a swap partition. The type codes are what distinguish the partitions to the firmware and the OS.
Quick Reference
Essential gdisk Commands
| Key | Action |
|---|---|
? | Display help menu |
p | Print current partition table |
n | Create new partition |
d | Delete partition |
t | Change partition type code |
o | Create new empty GPT |
w | Write table and exit |
q | Quit without writing |
v | Verify disk |
Common GPT Type Codes
| Code | Meaning |
|---|---|
8300 | Linux filesystem |
8200 | Linux swap |
8e00 | Linux LVM |
ef00 | EFI System Partition |
fd00 | Linux RAID |
gdisk vs. fdisk
| Aspect | fdisk (MBR) | gdisk (GPT) |
|---|---|---|
| Partition limit | 4 primary | 128 default |
| Extended/logical | Yes | No |
| Type selection | Hex byte (83) | Hex code (8300) or GUID |
| Protective MBR | N/A | Maintained automatically |
| Default alignment | Varies | 1 MiB (2048 sectors) |
Best Practices
✅ Do This:
# Inspect the disk before modifying it
sudo gdisk -l /dev/sdb # ✅
# Use p to verify the in-memory table before writing
p # ✅
# Use the correct type code for the partition's purpose
ef00 for EFI, 8200 for swap, 8300 for Linux # ✅
# Refresh the kernel table after writing
sudo partprobe /dev/sdb # ✅
# Use v to verify the GPT structure after a repair
v # ✅
❌ Don’t Do This:
# Write without verifying the layout
w # after n, without p first # ❌
# Use gdisk on an MBR disk without confirming the conversion
# The prompt is a safety check; read it before confirming # ❌
# Assume the kernel sees new partitions immediately
# partprobe or reboot is required # ❌
# Use MBR type codes in gdisk
# 83 is not a GPT type code; use 8300 # ❌
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| gdisk reports “MBR found” | Disk has an MBR table | Confirm conversion or use fdisk |
| Partition type is wrong | Used MBR code or default | t to change the type code |
| Kernel does not see partition | Table not re-read | partprobe /dev/sdX |
| EFI partition not bootable | Wrong type code | Set type to ef00 |
| Changes lost after exit | Pressed q instead of w | Press w to write |
Real-World Examples
1. List GPT Partitions
sudo gdisk -l /dev/sdb
2. Open gdisk
sudo gdisk /dev/sdb
3. Create New GPT
o → Y
4. Create EFI System Partition
n → 1 → <Enter> → +512M → ef00
5. Create Linux Partition
n → 2 → <Enter> → +20G → 8300
6. Create Swap Partition
n → 3 → <Enter> → +4G → 8200
7. Delete Partition
d → 3
8. Change Type Code
t → 2 → 8e00
9. Write Table
w → Y
10. Verify Disk
v
Visual
GPT Structure with Protective MBR
┌──────────────────────────────────────────────────────────────┐
│ DISK /dev/sdb │
│ │
│ ┌─────────────────────────────────────────────────────────┐│
│ │ Sector 0: Protective MBR ││
│ │ (marks disk as GPT for legacy tools) ││
│ ├─────────────────────────────────────────────────────────┤│
│ │ Sector 1: GPT Header ││
│ ├─────────────────────────────────────────────────────────┤│
│ │ Partition entries (128 entries) ││
│ ├─────────────────────────────────────────────────────────┤│
│ │ Partition 1: EFI System (ef00) ││
│ │ Partition 2: Linux filesystem (8300) ││
│ │ Partition 3: Linux swap (8200) ││
│ ├─────────────────────────────────────────────────────────┤│
│ │ Backup GPT Header (end of disk) ││
│ └─────────────────────────────────────────────────────────┘│
│ │
│ gdisk maintains the protective MBR and the backup header. │
│ │
└──────────────────────────────────────────────────────────────┘
gdisk Command Flow
┌──────────────────────────────────────────────────────────────┐
│ gdisk /dev/sdb │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ o → new GPT │ Destroys existing table │
│ └────────┬────────┘ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ n → new partition│ Partition number, sectors, type │
│ └────────┬────────┘ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ p → verify │ Check layout before writing │
│ └────────┬────────┘ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ w → write │ Commit to disk │
│ └─────────────────┘ │
│ │
│ q discards all changes without writing. │
│ │
└──────────────────────────────────────────────────────────────┘
GPT Type Codes vs. MBR Type Codes
┌──────────────────────────────────────────────────────────────┐
│ MBR (fdisk) GPT (gdisk) │
│ │
│ 83 Linux filesystem 8300 Linux filesystem │
│ 82 Linux swap 8200 Linux swap │
│ 8e Linux LVM 8e00 Linux LVM │
│ (no EFI type) ef00 EFI System Partition │
│ │
│ The codes are different. │
│ 83 is not a valid GPT type code. │
│ │
└──────────────────────────────────────────────────────────────┘
UEFI Boot Disk Layout
┌──────────────────────────────────────────────────────────────┐
│ GPT DISK FOR UEFI BOOT │
│ │
│ ┌─────────────────┐ │
│ │ Partition 1 │ ef00 (EFI System Partition) │
│ │ 512M │ FAT32, mounted at /boot/efi │
│ └─────────────────┘ │
│ │
│ ┌─────────────────┐ │
│ │ Partition 2 │ 8300 (Linux filesystem) │
│ │ 20G │ ext4 or XFS, mounted at / │
│ └─────────────────┘ │
│ │
│ ┌─────────────────┐ │
│ │ Partition 3 │ 8200 (Linux swap) │
│ │ 4G │ mkswap, swapon │
│ └─────────────────┘ │
│ │
│ The firmware reads the ef00 partition to find the bootloader│
│ │
└──────────────────────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| Tool | gdisk (GPT-aware counterpart to fdisk) |
| Table format | GPT only |
| Partition limit | 128 default |
| Partition numbering | 1–128, all primary |
| Create new GPT | o |
| Create partition | n |
| Delete partition | d |
| Change type | t |
| Print table | p |
| Write | w |
| Quit without writing | q |
| Verify disk | v |
| Linux filesystem type | 8300 |
| Linux swap type | 8200 |
| EFI System Partition type | ef00 |
| Default alignment | 1 MiB (2048 sectors) |
Key takeaways:
gdiskis to GPT whatfdiskis to MBR. The menu interface is nearly identical, but the table format, type codes, and partition limits differ.gdiskdoes not ask for primary or extended because GPT has no such distinction .- The
ocommand creates a new empty GPT. It destroys the existing partition table, including an MBR table if one exists. The command prompts for confirmation because the destruction is irreversible . - GPT type codes are different from MBR type codes.
83infdiskis8300ingdisk.82is8200. The EFI System Partition typeef00has no MBR equivalent in standardfdisk. gdiskmaintains the protective MBR and backup GPT header. These are structural requirements of GPT. Thewcommand writes both, and thevcommand verifies that they are consistent .- The default alignment is 1 MiB. New partitions start on a 2048-sector boundary by default, which is optimal for Advanced Format drives and SSDs. This is a performance default, not a requirement .
- Changes are staged until
w. The in-memory table can be inspected withpand discarded withq. The safety mechanism is identical tofdisk‘s .
Remember: gdisk is the dedicated tool for GPT disks, and its menu is designed around GPT concepts. The partition numbers go to 128 because GPT allows that many. The type codes are four-digit hex values that correspond to GPT type GUIDs. The protective MBR is maintained automatically because GPT requires it. The commands are the same letters as fdisk—n, d, t, p, w, q—because the workflow is the same even though the table format is different. The exam tests the ability to create a GPT disk with the correct type codes, verify the layout, and write the changes without destroying data on the wrong device.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!