Loading...

Lab 124: Create and Delete GPT Partitions with parted

Initialize an unused disk (/dev/sdb) with a GPT label, create a small test partition with parted, verify the kernel view with lsblk and /proc/partitions, then remove the partition and confirm the disk returns to a clean state.

storage parted gpt rhel

Scenario

A new 2G disk was attached to a RHEL VM for a temporary data staging task. Before handing the VM to an automation pipeline, you need to initialize the disk with GPT, create a small partition to validate the workflow, verify the kernel sees it, then remove the partition to return the disk to a clean state.

Safety note

Confirm the target disk before writing labels or deleting partitions. GPT operations will destroy any existing partition layout on the selected device.

Objective

  • Confirm /dev/sdb exists and is not mounted.
  • Detect an unknown or uninitialized partition table.
  • Write a GPT disk label with parted mklabel gpt.
  • Create a MiB-aligned partition with explicit boundaries.
  • Verify the partition via parted, lsblk, and /proc/partitions.
  • Remove the partition and re-verify a clean kernel view.

Concepts

  • GPT is the modern default partition table and supports larger disks and more partitions than MBR.
  • Starting at 1MiB is a common alignment practice and avoids reserved areas at the beginning of the disk.
  • parted writes the partition table, but the kernel may need to re-read it before /dev/sdb1 appears or disappears.
  • /proc/partitions is a kernel-exported view that helps confirm whether the kernel sees the partition even if a userspace tool seems stale.
  • Removing a partition deletes the entry from GPT but does not wipe disk blocks.

Walkthrough

Step 1: Confirm /dev/sdb is present and not mounted.
Command
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS

This is your fast safety check: the disk exists, has the expected size, and has no mountpoints.

NAME   MAJ:MIN RM SIZE RO TYPE FSTYPE MOUNTPOINTS
sda      8:0    0  20G  0 disk
└─sda1   8:1    0  20G  0 part xfs    /
sdb      8:16   0   2G  0 disk
Step 2: Check current partition table state on /dev/sdb.
Command
sudo parted /dev/sdb print

On a blank disk, parted reports an unrecognized label. That’s expected and confirms you are starting clean.

Error: /dev/sdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
Step 3: Create a GPT disk label.
Command
sudo parted /dev/sdb mklabel gpt

This initializes the disk with GPT. On real systems, always do this only after you have confirmed the correct target device.

Information: You may need to update /etc/fstab.
Step 4: Confirm GPT is applied.
Command
sudo parted /dev/sdb print

Your verification signal is the Partition Table: gpt line.

Model: Virtio Block Device (virtblk)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags
Step 5: Create a 100MiB partition starting at 1MiB.
Command
sudo parted /dev/sdb mkpart primary 1MiB 101MiB

Starting at 1MiB keeps boundaries aligned. The goal here is repeatable, deterministic partition creation.

Information: You may need to update /etc/fstab.
Step 6: Verify the partition exists in parted.
Command
sudo parted /dev/sdb print

Confirm you see partition 1 with the expected start and end.

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  106MB   105MB                primary
Step 7: Confirm the kernel created /dev/sdb1.
Command
lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS

This checks device node creation and the kernel’s current block device layout.

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda      8:0    0  20G  0 disk
└─sda1   8:1    0  20G  0 part /
sdb      8:16   0   2G  0 disk
└─sdb1   8:17   0 100M  0 part
Step 8: Confirm /proc/partitions reflects the partition.
Command
tail /proc/partitions

/proc/partitions is the kernel-exported view. This is useful when userspace tools disagree or a device node seems stale.

major minor  #blocks  name
  8       0  20971520 sda
  8       1  20970496 sda1
  8      16   2097152 sdb
  8      17    102400 sdb1
Step 9: Remove partition 1.
Command
sudo parted /dev/sdb rm 1

This removes the partition entry from the GPT. It does not wipe blocks, but it returns the partition layout to no partitions.

Information: You may need to update /etc/fstab.
Step 10: Confirm the partition is gone in parted.
Command
sudo parted /dev/sdb print
Model: Virtio Block Device (virtblk)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags
Step 11: Confirm /proc/partitions no longer lists sdb1.
Command
tail /proc/partitions
major minor  #blocks  name
  8       0  20971520 sda
  8       1  20970496 sda1
  8      16   2097152 sdb
Step 12: Verify sdb1 is gone in lsblk.
Command
lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS

You should only see the disk now. If sdb1 still appears, the kernel may not have re-read the table yet.

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda      8:0    0  20G  0 disk
└─sda1   8:1    0  20G  0 part /
sdb      8:16   0   2G  0 disk

Common breakpoints

sdb1 doesn’t appear after mkpart

The kernel may not have re-read the partition table yet. In real ops, you might run partprobe or trigger a rescan so the new partition device node is created.

sdb1 still appears after rm

You removed the partition entry, but userspace still sees a stale device. Re-check with parted print first, then refresh the kernel view if needed.

Disk selection mistake

Always verify identity and size before writing labels: lsblk -o NAME,SIZE,MODEL,SERIAL (fields depend on platform). The fastest way to lose a system is to partition the wrong disk.

Units mismatch (MB vs MiB)

parted may display in MB/GB while you create partitions in MiB. That’s normal. Keep using explicit MiB boundaries when you need repeatability.

Cleanup checklist

Confirm the partition entry is removed and only the base disk remains visible.

Commands
sudo parted /dev/sdb print
lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS | grep -E '^sdb'
grep -E 'sdb$|sdb1$' /proc/partitions || true
Success signal

parted shows no partitions, and lsblk does not list sdb1.

Reference

  • lsblk: Validate device presence and mounts.
    • -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS: Show fields used for safety checks.
  • parted: Inspect and modify partition tables.
    • print: Show disk geometry and current partition table.
    • mklabel gpt: Write GPT partition table to disk.
    • mkpart primary 1MiB 101MiB: Create a partition using MiB boundaries.
    • rm 1: Remove a partition by number.
  • /proc/partitions: Kernel-exported view of block devices and partitions.
    • Useful to confirm kernel state when userspace appears stale.
Ops habit

After every write operation (mklabel, mkpart, rm), verify with parted print immediately, then confirm kernel view with lsblk or /proc/partitions.