GPT Disk Partitioning

List, create, and delete partitions on GPT disks

CIS126RH | RHEL System Administration 1
Mesa Community College

Before a disk can store data it must be partitioned — divided into regions that the operating system manages independently. RHEL 9 uses the GUID Partition Table (GPT) standard on all modern systems. Administrators must be able to inspect existing partition layouts, create new partitions for additional storage, and safely remove partitions that are no longer needed. This module covers disk and partition concepts and the parted and gdisk tools. These skills are tested on the RHCSA exam.

Learning Objectives

  1. Explain disk and partition concepts — Describe block devices, GPT vs MBR, partition types, and how Linux names disks and partitions
  2. List and inspect partitions — Use lsblk, fdisk -l, and parted print to display current disk and partition information
  3. Create partitions on a GPT disk — Use parted and gdisk to create new partitions, specifying size, type, and position
  4. Delete partitions safely — Remove partitions using parted or gdisk and update the kernel's partition table view with partprobe

Block Devices and Disk Names

In Linux, disks and their partitions are accessed as block devices — special files in /dev/ that represent storage hardware.

Device name Represents Example partitions
/dev/sda First SCSI/SATA/SAS disk /dev/sda1, /dev/sda2, /dev/sda3
/dev/sdb Second SCSI/SATA/SAS disk /dev/sdb1, /dev/sdb2
/dev/nvme0n1 First NVMe SSD (namespace 1) /dev/nvme0n1p1, /dev/nvme0n1p2
/dev/vda First VirtIO disk (in KVM VMs) /dev/vda1, /dev/vda2
/dev/mmcblk0 First eMMC/SD card /dev/mmcblk0p1, /dev/mmcblk0p2
Disk = whole device; Partition = numbered subdivision

The disk device (/dev/sda) represents the entire physical disk. Each partition is a numbered device (/dev/sda1 is partition 1 on sda). Filesystems, LVM physical volumes, and swap are placed on partitions, not on the whole disk directly.

GPT vs MBR Partition Tables

Every partitioned disk has a partition table — a data structure at the beginning of the disk that describes where each partition starts and ends.

Feature MBR (Master Boot Record) GPT (GUID Partition Table)
Maximum disk size2 TB9.4 ZB — effectively unlimited
Maximum partitions4 primary (or 3 primary + extended)128 partitions (default on Linux)
Partition IDsSingle byte type code128-bit GUID — unique per partition
Boot firmwareBIOSUEFI (also works with BIOS + biosboot partition)
Backup tableNo redundancyBackup GPT header at end of disk
RHEL 9 defaultOnly for legacy systemsStandard on all new installations
RHCSA Exam: GPT is the standard

The exam uses GPT disks. Know that GPT supports up to 128 partitions and disks larger than 2 TB. Use parted or gdisk for GPT work.

Listing Partitions: lsblk and fdisk

Before creating or deleting partitions, always inspect the current layout with listing tools.

# lsblk — tree view of all block devices and partitions
$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1G  0 part /boot
├─sda2        8:2    0    2G  0 part [SWAP]
└─sda3        8:3    0   17G  0 part /
sdb           8:16   0   10G  0 disk      ← unpartitioned disk

# lsblk with filesystem info
$ lsblk -f
NAME   FSTYPE FSVER LABEL UUID                                 MOUNTPOINTS
sda1   xfs          boot  abc-123...                           /boot
sda2   swap   1           def-456...                           [SWAP]
sda3   xfs          root  ghi-789...                           /

# fdisk -l — detailed partition table listing (requires root)
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Disklabel type: gpt

Device       Start      End  Sectors  Size Type
/dev/sda1     2048  2099199  2097152    1G Linux filesystem
/dev/sda2  2099200  6293503  4194304    2G Linux swap
/dev/sda3  6293504 41943006 35649503   17G Linux filesystem

Listing Partitions with parted

parted is the primary GPT partitioning tool on RHEL. Its print command shows the partition table in a human-readable format.

# Print the partition table of a specific disk
$ sudo parted /dev/sda print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name  Flags
 1      1049kB  1075MB  1074MB  xfs                   boot
 2      1075MB  3222MB  2147MB  linux-swap(v1)        swap
 3      3222MB  21.5GB  18.3GB  xfs

# Print all disks
$ sudo parted -l

# Check if a disk is GPT or MBR
$ sudo parted /dev/sdb print
...
Partition Table: unknown    ← no partition table yet
parted uses megabytes, not sectors

parted displays and accepts partition sizes in megabytes (MB), gigabytes (GB), and percentages — not in sectors. This is more intuitive than fdisk's sector-based approach and is the reason parted is preferred for GPT disk work.

Creating a GPT Partition Table

A fresh disk has no partition table. The first step is to create a GPT label on the disk before creating any partitions.

# Interactive mode — enter the parted shell for /dev/sdb
$ sudo parted /dev/sdb
GNU Parted 3.4
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data
on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) print
Partition Table: gpt
(parted) quit

# Non-interactive (scripting) mode — single command
$ sudo parted /dev/sdb --script mklabel gpt
mklabel destroys all existing data

Creating a new partition table with mklabel erases the existing partition table and all data on the disk. Always confirm you are working on the correct device before running this command.

Creating Partitions with parted

The mkpart command creates a new partition. Sizes are specified in megabytes (MB) or gigabytes (GB) as start and end positions.

# Open parted on the target disk
$ sudo parted /dev/sdb

# Create a 1 GB partition starting at 1 MB
(parted) mkpart primary xfs 1MiB 1025MiB

# Create a 2 GB swap partition after the first
(parted) mkpart primary linux-swap 1025MiB 3073MiB

# Create a partition using all remaining space
(parted) mkpart primary xfs 3073MiB 100%

# Review the result
(parted) print
Number  Start    End      Size     File system  Name     Flags
 1      1049kB   1075MB   1074MB   xfs          primary
 2      1075MB   3222MB   2147MB   linux-swap   primary  swap
 3      3222MB   10.7GB   7478MB   xfs          primary
(parted) quit

Non-Interactive parted (Scripting Mode)

The --script flag suppresses all interactive prompts, making parted suitable for shell scripts and automation.

# Create a complete partition layout in one shell command
$ sudo parted --script /dev/sdb \
    mklabel gpt \
    mkpart primary xfs 1MiB 1025MiB \
    mkpart primary linux-swap 1025MiB 3073MiB \
    mkpart primary xfs 3073MiB 100%

# Set a partition flag (e.g. boot flag on partition 1)
$ sudo parted --script /dev/sdb set 1 boot on

# Verify the result
$ sudo parted /dev/sdb print

# Tell the kernel about the new partitions without rebooting
$ sudo partprobe /dev/sdb

# Confirm the kernel sees the new partitions
$ lsblk /dev/sdb
Always run partprobe after partitioning

partprobe forces the kernel to re-read the partition table on a disk without requiring a reboot. After creating or deleting partitions, run sudo partprobe /dev/DISK so the new devices appear immediately.

Creating Partitions with gdisk

gdisk (GPT fdisk) is an interactive partitioning tool specifically designed for GPT disks. It uses a familiar fdisk-style menu interface.

# Open gdisk on a disk
$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (?  for help): ?
b  back up GPT data to a file         o  create a new empty GUID table
d  delete a partition                 p  print the partition table
i  show detailed info about partition q  quit (no save)
l  list known partition types         r  recovery and transformation options
n  add a new partition                s  sort partitions
t  change a partition's type code     v  verify disk
w  write table to disk and exit       ?  print this menu
gdisk key commands

n = new partition, d = delete, p = print, w = write and exit, q = quit without saving. Changes are only written to disk when you type w.

gdisk: Creating a Partition

Command (?  for help): n     # new partition
Partition number (1-128, default 1):       # press Enter for default
First sector (2048-20971486, default 2048):  # press Enter for first available
Last sector (2048-20971486, default 20971486): +2G   # +size syntax
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300):   # Enter for Linux filesystem

Command (?  for help): p     # verify before writing
Number  Start (sector)  End (sector)  Size   Code  Name
   1            2048       4196351   2.0 GiB  8300  Linux filesystem

Command (?  for help): w     # write to disk
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.

# Update the kernel's view of the partition table
$ sudo partprobe /dev/sdb

GPT Partition Type Codes

Every GPT partition has a type code that identifies its intended use. The code is metadata — it does not affect how the partition functions, but it helps tools and administrators identify partition purposes.

gdisk code Type name Use
8300Linux filesystemext4, XFS, or any Linux filesystem
8200Linux swapSwap partition
8e00Linux LVMLVM physical volume
fd00Linux RAIDSoftware RAID member
ef00EFI System PartitionUEFI bootloader
ef02BIOS bootGRUB2 stage 1.5 on BIOS+GPT
Type code is metadata only

The type code does not create a filesystem, enable swap, or initialise LVM. It is a label. You still must run mkfs, mkswap, or pvcreate after creating the partition to make it usable.

Deleting Partitions

Deleting a partition removes it from the partition table but does not wipe the data it contained. Always unmount and stop using the partition before deleting it.

Deleting with parted

# Open parted and delete partition 3
$ sudo parted /dev/sdb
(parted) print           # confirm partition numbers
(parted) rm 3            # delete partition 3 — immediate, no undo!
(parted) print           # confirm partition 3 is gone
(parted) quit

Deleting with gdisk

# Open gdisk and delete partition 3
$ sudo gdisk /dev/sdb
Command (?  for help): d
Partition number (1-3): 3
Command (?  for help): p   # verify before writing
Command (?  for help): w   # write to disk

# Update the kernel after deletion
$ sudo partprobe /dev/sdb
parted rm is immediate; gdisk d is buffered

In parted, rm takes effect immediately — there is no separate write step. In gdisk, d marks the partition for deletion in memory; changes are only written when you type w. You can still abort with q after typing d in gdisk.

partprobe: Updating the Kernel

After modifying a partition table, the running kernel must be told about the changes. Without this step, new partition devices do not appear in /dev/.

# Update kernel for a specific disk
$ sudo partprobe /dev/sdb

# Update kernel for all disks
$ sudo partprobe

# Alternative: kpartx (for multipath or mapper devices)
$ sudo kpartx -a /dev/sdb

# Verify the kernel now sees the new partitions
$ lsblk /dev/sdb
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdb      8:16   0   10G  0 disk
├─sdb1   8:17   0    2G  0 part
└─sdb2   8:18   0    8G  0 part

# cat /proc/partitions also shows kernel's view
$ cat /proc/partitions | grep sdb
When partprobe cannot update in place

If a partition on the disk is currently mounted or in use (as part of LVM or RAID), the kernel may refuse to update the table for that disk. In this case, a reboot is required to pick up the changes.

Partition Management Quick Reference

Task Command
List all block devices (tree)lsblk
List with filesystem typeslsblk -f
List partition table (fdisk)sudo fdisk -l /dev/sda
Print partition table (parted)sudo parted /dev/sda print
Print all disks (parted)sudo parted -l
Open parted interactivelysudo parted /dev/sdb
Create GPT partition tablemklabel gpt (inside parted)
Create a partition (parted)mkpart primary xfs 1MiB 1025MiB
Create partition using rest of diskmkpart primary xfs 1025MiB 100%
Delete a partition (parted)rm NUMBER (inside parted)
Open gdisk interactivelysudo gdisk /dev/sdb
New partition (gdisk)n then follow prompts; use +2G for size
Delete partition (gdisk)d then partition number; write with w
Update kernel partition tablesudo partprobe /dev/sdb

Common Mistakes

Mistake What goes wrong Correct approach
Working on the wrong disk (e.g. /dev/sda instead of /dev/sdb) Existing data, OS, or boot partitions are destroyed Run lsblk first to confirm the target disk, then double-check before writing
Forgetting to run partprobe after partitioning New partition devices do not appear in /dev/; mkfs fails Always run sudo partprobe /dev/DISK after creating or deleting partitions
Thinking the partition type code creates a filesystem Partition exists but has no filesystem; mount fails Run mkfs.xfs /dev/sdb1 (or appropriate mkfs) after creating the partition
Starting a partition at sector 0 or 1 (not aligned) Misaligned partition causes performance degradation Start at 1MiB in parted; use default first sector in gdisk (2048)
Deleting a mounted partition Partition removed from table but filesystem still in use — errors at next boot Unmount with umount and deactivate with lvchange or mdadm before deleting
Using parted rm on a disk with a mounted partition parted may succeed but the kernel cannot update — inconsistent state Only delete unmounted partitions; verify with lsblk before deletion

Knowledge Check

Answer these before moving to the next slide.

  1. What is the difference between a disk device (/dev/sdb) and a partition device (/dev/sdb1)?
  2. List two advantages of GPT over MBR partition tables.
  3. Write the parted commands (inside an interactive session on /dev/sdb) to create a GPT partition table, then create a single 5 GB partition using the XFS filesystem type.
  4. After creating the partition in question 3, what must you run so the kernel recognises the new partition device?
  5. What is the difference between how parted rm and gdisk d handle partition deletion?
  6. In gdisk, you create a partition and then change your mind. How do you exit without saving the change?

Knowledge Check — Answers

  1. /dev/sdb is the whole disk device — it represents all physical sectors on the disk including the partition table. /dev/sdb1 is a partition device — it represents only the sectors assigned to partition 1. Filesystems are created on partitions, not on the whole disk device.
  2. Any two of: GPT supports disks larger than 2 TB (MBR is limited to 2 TB); GPT supports up to 128 partitions (MBR supports only 4 primary); GPT uses 128-bit GUIDs for unique partition identification; GPT maintains a backup partition table at the end of the disk; GPT is required for UEFI boot.
  3. Inside sudo parted /dev/sdb:
    mklabel gpt — creates the GPT partition table
    mkpart primary xfs 1MiB 5121MiB — creates a 5 GB partition starting at 1 MiB
  4. sudo partprobe /dev/sdb — this tells the kernel to re-read the partition table for /dev/sdb so the new /dev/sdb1 device appears in /dev/.
  5. In parted, rm is immediate — the change is written to the disk as soon as you press Enter. In gdisk, d marks the partition for deletion in memory only — the change is not applied until you type w (write). You can still abort with q after typing d in gdisk.
  6. Type q at the gdisk command prompt to quit without saving. gdisk will warn that changes will be lost and ask for confirmation. Any partitions created or deleted with n or d during the session are discarded and the disk is unchanged.

Key Takeaways

  1. GPT is the standard partition table on RHEL 9. It supports up to 128 partitions and disks larger than 2 TB. Use lsblk and sudo parted /dev/DISK print to inspect the current layout before making any changes. Always confirm the correct device.
  2. Create partitions with parted or gdisk. parted: mklabel gpt then mkpart primary xfs START END. Start at 1MiB for alignment. Use 100% as the end of the last partition. gdisk: type n, accept defaults, specify size with +2G, then w to write.
  3. Run partprobe after every partition change. sudo partprobe /dev/DISK tells the kernel about the new partition table without a reboot. Without it, new partition devices do not appear in /dev/.
  4. Creating a partition does not create a filesystem. The partition type code is metadata only. After partitioning, you must still run mkfs, mkswap, or pvcreate before the partition can be used.

Graded Lab

  • Run lsblk to identify a second disk in your lab VM (typically /dev/sdb or /dev/vdb). Confirm it has no existing partitions. Run sudo parted /dev/sdb print to check its partition table.
  • Use sudo parted /dev/sdb to create a GPT partition table with mklabel gpt. Confirm with print then quit.
  • Create two partitions on /dev/sdb using parted: a 2 GB partition starting at 1 MiB, and a second partition using all remaining space. Confirm with print before quitting.
  • Run sudo partprobe /dev/sdb then lsblk /dev/sdb to confirm the kernel sees both partitions.
  • Use sudo gdisk /dev/sdb to view the partition table with p. Delete partition 2 with d. Verify with p again, then write with w. Run partprobe and confirm with lsblk.
  • Recreate partition 2 using gdisk. Format partition 1 with sudo mkfs.xfs /dev/sdb1. Confirm the filesystem exists with lsblk -f /dev/sdb.
RHCSA Objective

"List, create, and delete partitions on GPT disks." Always check with lsblk first. Use parted mklabel gpt then mkpart to create. Run partprobe after every change.