sysadmin · June 1, 2026 · 13 min read

Partitioning a new disk.
gdisk, GPT, and the type codes that matter.

Procurement delivered a second disk. dbadmin1 needs it carved into an LVM partition, a swap partition, and a plain filesystem partition, with the kernel actually seeing them before hand-off.

// what we’re getting into
  1. The ticket
  2. Concept review. MBR versus GPT, and the type codes.
  3. Inspect the disk first
  4. Partition with gdisk
  5. Make the kernel re-read the table
  6. The MBR alternative with fdisk
  7. parted, the scriptable way
  8. Exam questions
  9. Final checklist: confirm everything works

The ticket: a fresh second disk is attached to the box. dbadmin1 needs three partitions off it. One large one for database files that will become an LVM physical volume, one roughly 512MB for swap, and one roughly 1GB flagged as a plain Linux filesystem. Pick MBR or GPT, document why, and make sure the kernel actually sees the partitions before you hand it off.

The real problem: partitioning is easy to do and easy to do wrong. The two things people miss are setting the correct type code so LVM and swap tools recognize the partition, and telling the running kernel to re-read the table so the new partitions actually appear.

What we are doing: partitioning with gdisk for GPT (and fdisk for MBR), setting type codes, and refreshing the kernel view.

The ticket

This step is the one to be careful with. You need a real second disk, and you must be certain which device it is before you write to it. Writing to the wrong disk is how you lose a system.

bash
lsblk
# you need a SECOND disk, typically /dev/sdb, /dev/vdb, or /dev/nvme1n1
# if only one disk shows, stop and add a virtual disk to your VM first
sudo fdisk -l 2>/dev/null | grep -i "disk /dev"

Concept review. MBR versus GPT, and the type codes.

bash
man fdisk
man gdisk
man parted

MBR is the old scheme. It caps out at 2TB and four primary partitions, and it keeps no backup of the partition table. GPT is the modern scheme. It handles enormous disks, up to 128 partitions, and stores a backup table. On RHEL 9 the default and the right choice is GPT, so that is what this ticket uses. gdisk is the GPT tool, fdisk is the MBR tool.

The type code tells the system what a partition is for. Set it wrong and LVM or swap will not recognize the partition later.

partition type codes
purpose             fdisk (hex)   gdisk
Linux filesystem    83            8300
Linux swap          82            8200
Linux LVM           8e            8e00

Inspect the disk first

Confirm the device path and the size before touching it. Replace /dev/sdb below with whatever your second disk actually is.

bash
lsblk
sudo fdisk -l /dev/sdb
sudo blockdev --getsize64 /dev/sdb    # size in bytes

Partition with gdisk

gdisk is interactive. You create a fresh GPT table if the disk is empty, then add each partition with a number, a size, and a type code, then write. The comments below show the exact keystrokes.

bash
sudo gdisk /dev/sdb

# inside gdisk:
#   o            new empty GPT table (only on a fresh disk), confirm y
#   n            new partition
#     1          partition number
#     <Enter>    default first sector
#     +2G        size
#     8e00       type: Linux LVM
#   n  -> 2 -> <Enter> -> +512M -> 8200   (Linux swap)
#   n  -> 3 -> <Enter> -> +1G   -> 8300   (Linux filesystem)
#   p            print to verify
#   w            write and exit, confirm y

# verify from outside gdisk
lsblk /dev/sdb
sudo gdisk -l /dev/sdb

Make the kernel re-read the table

If lsblk does not show the new partitions, the running kernel is still holding the old table in memory. partprobe forces a re-read without a reboot. This is the reflex that saves you on the exam.

bash
sudo partprobe /dev/sdb
lsblk /dev/sdb
sudo udevadm settle    # if device nodes lag behind

The MBR alternative with fdisk

Worth knowing both tools. fdisk drives MBR the same way, with slightly different keys. Only run this on a spare disk you are willing to wipe.

bash
sudo fdisk /dev/sdc

# inside fdisk:
#   o    new MBR (DOS) partition table
#   n -> p -> 1 -> <Enter> -> +1G
#   t -> 8e    change type to Linux LVM
#   p          verify
#   w          write

sudo partprobe /dev/sdc
lsblk /dev/sdc

parted, the scriptable way

parted does the same job non-interactively, which is handy for automation. Just look at the state for now rather than writing to a full disk.

bash
sudo parted /dev/sdb print
# example of a scripted add (do not run on a full disk):
# sudo parted /dev/sdb mkpart primary 4097MiB 5121MiB

Exam questions

Write the command first.

Q1. List all block devices along with their filesystem types and UUIDs in a single command.

Q2. On a fresh /dev/sdb using GPT, create a 2GB partition tagged for LVM and a 512MB partition tagged for swap, then verify the table.

Q3. You created partitions but lsblk does not see them. What command fixes that without a reboot, and why is it needed?

Answers.

bash
# A1
lsblk -f
# A2
sudo gdisk /dev/sdb   # o (if fresh), n 1 +2G 8e00, n 2 +512M 8200, w
sudo gdisk -l /dev/sdb
# A3
sudo partprobe /dev/sdb
# the running kernel caches the old table; without this the new
# partitions do not appear in /dev or lsblk until a reboot

Final checklist: confirm everything works

If every check passes, the ticket is done.

bash
# 1. three partitions with the right type codes
sudo gdisk -l /dev/sdb

# 2. lsblk reflects all three
lsblk /dev/sdb

# 3. partprobe reflex if the kernel did not see them
# 4. GPT choice documented (recommend GPT on RHEL 9)
# 5. all three exam commands written from scratch
# 6. tracker entry checked off

Reply to ops1: /dev/sdb is partitioned with GPT. sdb1 is 2GB LVM, sdb2 is 512MB swap, sdb3 is 1GB Linux filesystem. Ready for dbadmin1 to build the LVM stack tomorrow.

next post
Building the database LVM stack with online resize