Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


RHCSA - Configure Local Storage: List, Create, Delete Partitions on MBR & GPT Disks

In this lesson we will explore the concepts of MBR (Master Boot Record) and GPT (GUID Partition Table) partitions, along with the corresponding tools utilized for their configuration, fdisk & gdisk.

MBR vs GPT

MBR (Master Boot Record)

The Master Boot Record (MBR) is a fundamental partitioning scheme employed in legacy BIOS systems to manage the layout of a storage device, such as a hard disk. It resides in the first sector of the disk and is only 512 bytes in size. MBR can support up to four primary partitions or three primary partitions and an extended partition, which can further contain multiple logical partitions. One of the primary partitions is marked as active, indicating the partition from which the system boots. Despite its widespread use over the years, MBR has certain limitations, such as a maximum disk size of 2 terabytes and the lack of support for more modern features, which led to the emergence of GPT as an alternative partitioning scheme.

GPT (GUID Partition Table)

The GUID Partition Table (GPT) is a newer and more advanced partitioning scheme commonly used in modern computers with UEFI firmware. Unlike MBR, GPT does not have the limitations on disk size, and it supports up to 128 partitions. GPT employs globally unique identifiers (GUIDs) to uniquely identify each partition on the disk. It also includes redundant copies of critical data, such as the partition table, to enhance data integrity and recovery capabilities. GPT is becoming the standard for new storage devices due to its robustness, flexibility, and support for modern features, making it well-suited for large capacity disks and systems with UEFI-based firmware.

Lesson Setup

To be able to follow along with the exercises, be sure to attach an additional empty disk to your system. In the exercises the additional disk is 1G in size, but use what ever size disk is available for you.

Do not use a disk with data on as following the exercises will mean that data will be deleted.

Once the disk is attached, you should be able to see it by running the lsblk command, which in this example shows as the sdb device:

After rebooting, the disk may not retain the same device name, making it essential to always run lsblk to verify that you are working with the correct disk.

$ lsblk

NAME           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda              8:0    0   20G  0 disk 
├─sda1           8:1    0  600M  0 part /boot/efi
├─sda2           8:2    0    1G  0 part /boot
└─sda3           8:3    0   17G  0 part 
  ├─os_vg-root 253:0    0   15G  0 lvm  /
  └─os_vg-swap 253:1    0    2G  0 lvm  [SWAP]
sdb              8:16   0    1G  0 disk

At at any point during exercises you receive a message that the partition table could not be updated, then try running the partprobe command. If that does not work then ensure to reboot and then check your partitions with lsblk to ensure they display as expected on your exam.

fdisk command

The fdisk is used for managing disk partitions on storage devices like hard drives or SSDs. With fdisk, you can create, delete, and view partitions within the disk's partition table. The utility provides options to create primary and extended partitions as well as logical partitions within the extended partition. It also allows users to set partition types and manage bootable partitions for systems that use the Master Boot Record (MBR) partitioning scheme.

fdisk Exercises

Follow along with the exercises to get comfortable using the fdisk command.

Create a primary partition:

Run the fdisk utility for your attached disk:

sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x5ce8f1fb.

Command (m for help):

Create a new (n) partition:

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):

Type p for primary partition, then press Enter:

Select (default p): p
Partition number (1-4, default 1):

Type 1 to set partition number, then press Enter:

Partition number (1-4, default 1): 1
First sector (2048-2097151, default 2048):

Press Enter to accept the default first sector:

First sector (2048-2097151, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2097151, default 2097151):

Type +250M and press Enter to set the partition to size 250M:

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2097151, default 2097151): +250M

Created a new partition 1 of type 'Linux' and of size 250 MiB.

Command (m for help):

Type p and press Enter to confirm the partition is how you intend it to be:

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 sectors
Disk model: VBOX HARDDISK   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5ce8f1fb

Device     Boot Start    End Sectors  Size Id Type
/dev/sdb1        2048 514047  512000  250M 83 Linux

Command (m for help):

To save the changes & exit the fdisk utility, type w and press Enter:

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Create logical partitions:

Extended partitions are only used to enable the creation of logical partitions. So an extended partition is first created before then creating logical partitions.

Run the fdisk utility for your attached disk:

sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):

Create a new (n) partition:

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p):

Type e for extended partition, then press Enter:

Select (default p): e
Partition number (2-4, default 2):

Type 2 to set partition number, then press Enter:

Partition number (2-4, default 2): 2
First sector (514048-2097151, default 514048):

Press Enter to accept the default first sector:

First sector (514048-2097151, default 514048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (514048-2097151, default 2097151):

Press Enter to accept the default, which is the last available sector:

Last sector, +/-sectors or +/-size{K,M,G,T,P} (514048-2097151, default 2097151): 

Created a new partition 2 of type 'Extended' and of size 773 MiB.

Command (m for help):

Create a new (n) partition:

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (516096-2097151, default 516096):

Press Enter to accept the default first sector:

First sector (516096-2097151, default 516096): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (516096-2097151, default 2097151):

Type +100M and press Enter to set the partition to size 100M:

Last sector, +/-sectors or +/-size{K,M,G,T,P} (516096-2097151, default 2097151): +100M

Created a new partition 5 of type 'Linux' and of size 100 MiB.

Command (m for help):

Type p and press Enter to confirm the partitions are how you intend them to be:

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 sectors
Disk model: VBOX HARDDISK   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5ce8f1fb

Device     Boot  Start     End Sectors  Size Id Type
/dev/sdb1         2048  514047  512000  250M 83 Linux
/dev/sdb2       514048 2097151 1583104  773M  5 Extended
/dev/sdb5       516096  720895  204800  100M 83 Linux

Command (m for help):

To save the changes & exit the fdisk utility, type w and press Enter:

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Delete all created partitions:

Run the fdisk utility for your attached disk:

sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):

Type d and press Enter to start the deletion process:

Command (m for help): d
Partition number (1,2,5, default 5):

Type 5 and press Enter to delete partition 5:

Partition number (1,2,5, default 5): 5

Partition 5 has been deleted.

Command (m for help):

Type d and press Enter to start the deletion process:

Command (m for help): d
Partition number (1,2, default 2):

Type 2 and press Enter to delete partition 2:

Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help):

Type d and press Enter to delete the only remaining partition (partition 1):

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help):

Type p and press Enter to confirm the partitions have been deleted:

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 sectors
Disk model: VBOX HARDDISK   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5ce8f1fb

Command (m for help):

To save the changes & exit the fdisk utility, type w and press Enter:

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Remove dos label:

Upcoming exercises will use the same disk to practice with so removing the disk label will ensure you get no warnings:

sudo wipefs --all /dev/sdb*
/dev/sdb: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
/dev/sdb: calling ioctl to re-read partition table: Success

gdisk Command

gdisk is a command-line partitioning tool primarily designed for managing disk partitions using the GUID Partition Table (GPT) format. Unlike the traditional fdisk utility, which is commonly used with the Master Boot Record (MBR) partitioning scheme, gdisk is specialized for working with modern GPT-based disks. It offers a range of advanced features to create, delete, resize, and modify partitions within the GPT partition table. As GPT is increasingly utilized in modern systems, particularly those with UEFI firmware, gdisk has become a crucial tool for disk management and is often preferred for its ability to handle larger disk sizes, support multiple partitions, and offer improved data integrity features.

gdisk Exercises

Follow along with the exercises to get comfortable using the gdisk command.

Create a primary partition:

Run the gdisk utility for your attached disk:

sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.7

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

Creating new GPT entries in memory.

Command (? for help):

Create a new (n) partition:

Command (? for help): n
Partition number (1-128, default 1):

Type 1 to set partition number, then press Enter:

Partition number (1-128, default 1): 1
First sector (34-2097118, default = 2048) or {+-}size{KMGTP}:

Press Enter to accept the default first sector:

First sector (34-2097118, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-2097118, default = 2097118) or {+-}size{KMGTP}:

Type +250M and press Enter to set the partition to size 250M:

Last sector (2048-2097118, default = 2097118) or {+-}size{KMGTP}: +250M
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300):

The default filesystem is Linux, however you can see all available codes by typing L and pressing Enter twice. A common filesystem type to use is Linux LVM which is code 8e00.

Press Enter to accept the default filesystem:

Hex code or GUID (L to show codes, Enter = 8300):     
Changed type of partition to 'Linux filesystem'

Command (? for help):

Type p and press Enter to confirm the partition is how you intend it to be:

Command (? for help): p
Disk /dev/sdb: 2097152 sectors, 1024.0 MiB
Model: VBOX HARDDISK   
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 30B675F9-A6B4-43AC-8849-54171BB26D7F
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2097118
Partitions will be aligned on 2048-sector boundaries
Total free space is 1585085 sectors (774.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          514047   250.0 MiB   8300  Linux filesystem

Command (? for help):

To save the changes type w and press Enter:

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N):

To confirm the save and exit gdisk, type Y and press Enter:

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

Delete created partition:

Run the gdisk utility for your attached 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):

Type d and press Enter to delete the only partition (partition 1):

Command (? for help): d
Using 1

Command (? for help):

Type p and press Enter to confirm the partitions have been deleted:

Command (? for help): p
Disk /dev/sdb: 2097152 sectors, 1024.0 MiB
Model: VBOX HARDDISK   
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 30B675F9-A6B4-43AC-8849-54171BB26D7F
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2097118
Partitions will be aligned on 2048-sector boundaries
Total free space is 2097085 sectors (1024.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help):

To save the changes type w and press Enter:

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N):

To confirm the save and exit gdisk, type Y and press Enter:

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

Remove GPT & PMBR labels:

sudo wipefs --all /dev/sdb*
/dev/sdb: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 8 bytes were erased at offset 0x3ffffe00 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sdb: calling ioctl to re-read partition table: Success

Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.