Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

gdisk

Edit GPT partition tables with a menu (like fdisk, made for GPT).

Level
Extra
Group
Disks and file systems
Needs root
Yes
Package
gdisk

What it does

gdisk (GPT fdisk) works like fdisk but only with GPT. It can convert MBR to GPT, repair GPT tables (the backup at the end of the disk) and uses 4-digit type codes (8300 Linux, 8200 swap, 8e00 LVM, ef00 EFI). The sgdisk command does the same without a menu. On RHEL it may need dnf install gdisk.

How to write it

gdisk [-l] DEVICE

Main parts

?
Help.
p
Print the table.
n
New partition.
d
Delete a partition.
t
Change the type code.
l
List the type codes.
c
Change a partition name.
i
Details of a partition.
o
New empty GPT table.
r
Recovery and transformation menu (rebuild, convert).
x
Expert menu.
v
Verify.
w
Write and quit.
q
Quit without saving.

Options 1

Most used

-l
List the partition table and exit.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Install gdisk

    dnf install -y gdisk

    In the BaseOS repository.

  2. 2List a GPT table

    gdisk -l /dev/vdb

    Shows the type codes and names.

  3. 3Create a Linux LVM partition

    gdisk /dev/vdb
    Command (? for help): n
    Hex code or GUID (L to show codes, Enter = 8300): 8e00
    Command (? for help): w

    8e00 = Linux LVM.

  4. 4Swap partition type

    gdisk /dev/vdb
    Hex code or GUID (L to show codes, Enter = 8300): 8200

    8200 = Linux swap.

  5. 5Name a partition

    gdisk /dev/vdb
    Command (? for help): c

    GPT partitions can have names (PARTLABEL).

  6. 6Verify a disk

    gdisk /dev/vdb
    Command (? for help): v

    Finds problems in the table.

  7. 7Repair a damaged main table from the backup

    gdisk /dev/vdb
    Command (? for help): r
    Recovery/transformation command (? for help): b

    Uses the backup header at the end of the disk.

  8. 8Convert MBR to GPT (keep data)

    gdisk /dev/vdc

    gdisk offers the conversion when it finds MBR; write with w. Back up first.

  9. 9Script with sgdisk

    sgdisk -n 1:0:+2G -t 1:8300 -c 1:data /dev/vdb

    One partition of 2 GiB, Linux type, name data.

  10. 10Back up the GPT table

    sgdisk --backup=/root/vdb-gpt.bin /dev/vdb

    Restore with sgdisk --load-backup=.

Exit codes

0Done.
1Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man 8 gdisk