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] DEVICEMain 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
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Install gdisk
dnf install -y gdiskIn the BaseOS repository.
2List a GPT table
gdisk -l /dev/vdbShows the type codes and names.
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): w8e00 = Linux LVM.
4Swap partition type
gdisk /dev/vdb Hex code or GUID (L to show codes, Enter = 8300): 82008200 = Linux swap.
5Name a partition
gdisk /dev/vdb Command (? for help): cGPT partitions can have names (PARTLABEL).
6Verify a disk
gdisk /dev/vdb Command (? for help): vFinds problems in the table.
7Repair a damaged main table from the backup
gdisk /dev/vdb Command (? for help): r Recovery/transformation command (? for help): bUses the backup header at the end of the disk.
8Convert MBR to GPT (keep data)
gdisk /dev/vdcgdisk offers the conversion when it finds MBR; write with w. Back up first.
9Script with sgdisk
sgdisk -n 1:0:+2G -t 1:8300 -c 1:data /dev/vdbOne partition of 2 GiB, Linux type, name data.
10Back up the GPT table
sgdisk --backup=/root/vdb-gpt.bin /dev/vdbRestore with
sgdisk --load-backup=.
Nothing matches this filter.
Exit codes
0 | Done. |
1 | Error. |