List, Create, and Delete Partitions on MBR and GPT Disks

LinuxLinuxBeginner
Practice Now

Introduction

In this challenge, you will learn how to list, create, and delete partitions on both Master Boot Record (MBR) and GUID Partition Table (GPT) disks using command-line tools. This is a fundamental skill required for the RHCSA (Red Hat Certified System Administrator) exam, as it covers the configuration of local storage on Linux systems.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") subgraph Lab Skills linux/echo -.-> lab-389485{{"`List, Create, and Delete Partitions on MBR and GPT Disks`"}} end

Manage Partitions on an MBR Disk

Tasks

  • List the partitions on an MBR disk
  • Create a new partition on an MBR disk
  • Delete a partition on an MBR disk

Requirements

  • Use the fdisk command to manage partitions on an MBR disk
  • Perform all operations in the /home/labex directory
  • Create a new partition with a size of 500 MB
  • Delete the partition you created

Example

After creating a new partition on an MBR disk, the output of fdisk -l should include the new partition:

Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: 0x4d2d4a2d

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        2048 41943039 41940992   20G 83 Linux
/dev/sdb2     41943040 41943039        0    0B 5  Extended
/dev/sdb5     41943040 41943039        0    0B 82 Linux swap / Solaris

Manage Partitions on a GPT Disk

Tasks

  • List the partitions on a GPT disk
  • Create a new partition on a GPT disk
  • Delete a partition on a GPT disk

Requirements

  • Use the gdisk command to manage partitions on a GPT disk
  • Perform all operations in the /home/labex directory
  • Create a new partition with a size of 1 GB
  • Delete the partition you created

Example

After creating a new partition on a GPT disk, the output of gdisk -l /dev/sdc should include the new partition:

Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors
Logical sector size: 512 bytes
Disk identifier (GUID): 4D2D4A2D-0000-0000-0000-000000000000
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 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 41942973 sectors (20.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        41943006   20.0 GiB    8300  Linux filesystem
   2        41943040        41943039   0 B        8200  Linux swap

Summary

In this challenge, you learned how to list, create, and delete partitions on both MBR and GPT disks using the fdisk and gdisk commands. This is an essential skill for system administrators, as it allows you to configure local storage on Linux systems. By completing this challenge, you have demonstrated your understanding of partition management and are one step closer to passing the RHCSA exam.

If you need to initialize the challenge environment, you can use the following setup.sh script:

#!/bin/bash

## Create MBR disk
dd if=/dev/zero of=/tmp/mbrtest.img bs=1M count=20
sudo losetup /dev/loop0 /tmp/mbrtest.img
sudo fdisk /dev/loop0 << EOF
n
p
1

+20G
w
EOF

## Create GPT disk
dd if=/dev/zero of=/tmp/gpttest.img bs=1M count=20
sudo losetup /dev/loop1 /tmp/gpttest.img
sudo gdisk /dev/loop1 << EOF
n
1

+20G
w
y
EOF

The script creates two virtual disks, one with an MBR partition table and the other with a GPT partition table. You can use these disks to practice the partition management tasks in this challenge.

Other Linux Tutorials you may like