LearnRHCSA (EX200)Local Storage

MBR and GPT Partitioning

fdisk - a hands-on Linux lab on a real virtual machine.

Partition a spare disk on RHEL 10. Survey with lsblk, read a disk table with fdisk -l, then carve a sized, typed partition with the interactive fdisk sequence (n, Enter the number, Enter the start, +2G, t and the type alias lvm or swap, then w to write), and partprobe so the kernel sees it. GPT is the default; fdisk writes both MBR and GPT; parted is the scriptable alternative. Serves EX200 local-storage: list, create, delete partitions on MBR and GPT disks.

The exam hands you a machine and one line of instruction: put a 2 gigabyte partition on the spare disk and mark it for LVM. You log in, run lsblk, and there it is: a device named vdb, five gigabytes wide, with nothing under it. No partitions, no filesystem, no name. Just raw space the system will not let you use until you carve it up.

A brand-new disk is like a blank field with no property lines. Before anyone can build on it, someone has to draw the boundaries and write them into a record everyone agrees on. That record is the partition table, and drawing those lines is partitioning. It is the first move in the highest-weight domain on EX200, storage, and this lesson is where you learn to make it.

The black boxes below are a practice terminal: a safe sandbox that checks the one command each step teaches. The outputs shown are from a real RHEL 10 machine (AlmaLinux 10.2) with two spare disks, vdb (5G) and vdc (2G), worked on as root. Device names and exact sizes on your own machine may read differently. What stays true everywhere is the SHAPE of each command and the order of the steps, and that is the lesson.

A partition is a section of a disk fenced off for one purpose. Before you can put a filesystem on a disk, or hand it to LVM, or turn it into swap, you must partition it. The partition table is the small record at the front of the disk that says where each partition starts and where it ends. The system reads that table to know the disk has any usable sections at all.

The prompt in every box below is [root@servera ~]#. That hash sign, and the word root, mean you are the superuser. Storage work touches raw devices, so it is always done as root. On the exam you either log in as root or prefix each command with sudo.

There are two formats for the partition table, and the exam objective names both: 'List, create, delete partitions on MBR and GPT disks.' The older format is MBR (Master Boot Record). The modern one is GPT (GUID Partition Table). You should be able to recognize each and know when to reach for it.

GPT is what modern RHEL 10 systems use, and it is the safe default when a task does not say otherwise. Reach for MBR only when a question specifically asks for it or names a disk that must boot a legacy BIOS. On RHEL 10, one tool, fdisk, writes BOTH formats, so you do not need a separate program for each.

You never partition a disk you have not looked at first. The tool that shows you the whole storage layout is lsblk, for 'list block devices'. It draws a tree: each physical disk on top, and any partitions or logical volumes nested underneath. Run it and you can see at a glance which disks are in use and which are blank.

Before you run it, decide what you expect: the main system disk should have partitions under it, and the spare disks the exam gave you should be bare. Run the survey:

lsblk

prompt: [root@servera ~]# answer: lsblk output: NAME SIZE TYPE MOUNTPOINTS vda 15G disk

-vda3 14G part |-rhel-root 13G lvm / -rhel-swap 1G lvm [SWAP] vdb 5G disk vdc 2G disk hint: The command is five letters, no flags: lsblk

Read the tree top to bottom. vda is the system disk: it has three partitions, and the last one holds the LVM volumes mounted at / and swap. That disk is busy, leave it alone. Then two lines with nothing indented under them: vdb at 5G and vdc at 2G. No partitions, no mountpoints. Those are your blank spares, the raw fields with no property lines yet. vdb is where the rest of this lesson works.

Your machine may name its disks sda, sdb (SCSI/SATA style) instead of vda, vdb (virtio style), and the sizes will differ. What matters is the SHAPE: lsblk shows disks with disk in the TYPE column and their partitions nested under them with part. A disk with nothing indented beneath it is unpartitioned and free to work on.

lsblk shows the layout as a tree. When you want the partition table itself, the disk's geometry and the exact list of partitions, you use fdisk -l (lowercase L, for 'list') and name the disk. On a disk that has never been partitioned, there is no table to print, so you see only the size and sector geometry and then nothing more.

Ask fdisk to list the spare disk you are about to carve:

fdisk -l /dev/vdb

prompt: [root@servera ~]# answer: fdisk -l /dev/vdb output: Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes hint: The list flag is -l, then the device path: fdisk -l /dev/vdb

Four lines of geometry, and then it stops. fdisk told you the disk is 5 GiB across 10485760 sectors of 512 bytes each, but there is no Device table underneath because the disk has no partitions and no label yet. That empty result is exactly what a fresh exam disk looks like. The sector unit matters for one reason: sizes are counted in 512-byte sectors, which is why the friendlier way to ask for size is +2G rather than counting sectors by hand, as you will do next.

fdisk is an interactive tool. You do not pass the whole job on one line. You open the disk, then type single-letter commands at its prompt, one per step, and nothing touches the disk until you write. Because it is interactive, learn it as a fixed sequence, the same way you learned i, Esc, :wq in vim. To put a 2G LVM partition on /dev/vdb, you open it and walk these keys:

1. fdisk /dev/vdb opens the disk. If it is blank, fdisk on RHEL 10 starts a GPT label for you automatically. (To force one, press g for GPT or o for an MBR/DOS label.) 2. n adds a new partition. 3. Partition number: press Enter to accept the default 1. 4. First sector: press Enter to accept the default (sector 2048, the aligned start). 5. Last sector / size: type +2G and press Enter. The +2G form means 'two gigabytes from the start', so you never count sectors. 6. t sets the partition type. RHEL 10 fdisk accepts type ALIASES, so at the prompt type lvm (or swap for a swap partition) instead of a hex code. 7. w writes the table to disk and quits. Nothing before this touched the disk; w is the commit. (To abandon everything, press q to quit without saving.)

After w, fdisk has written a gpt label and one 2G Linux LVM partition. In the practice box the scriptable equivalent stands in for the interactive session, but the RESULT is identical. Confirm the new partition exists with lsblk /dev/vdb:

lsblk /dev/vdb

prompt: [root@servera ~]# answer: lsblk /dev/vdb output: NAME SIZE TYPE vdb 5G disk `-vdb1 2G part hint: List just this one disk to see its new child: lsblk /dev/vdb

There it is: vdb1, 2G, nested under the 5G vdb. The backtick-dash connector is lsblk drawing the parent-child link, the partition is a child of the disk. A moment ago vdb had nothing under it; now it has its first partition. Those seven keystrokes drew the property lines and wrote them into the table. The disk went from raw space to usable space.

Creating the partition is half the task. The exam almost always says what the partition is FOR, hand it to LVM, make it swap, and that intent is recorded as the partition type. You set it with t inside fdisk (step 6 above). Now prove it stuck. Run fdisk -l /dev/vdb again, and this time there is a table, because the disk is no longer blank.

fdisk -l /dev/vdb

prompt: [root@servera ~]# answer: fdisk -l /dev/vdb output: Disklabel type: gpt Device Start End Sectors Size Type /dev/vdb1 2048 4196351 4194304 2G Linux LVM hint: Same list command as before, now the disk has a table: fdisk -l /dev/vdb

Now the same command tells a fuller story. Disklabel type: gpt confirms fdisk wrote a GPT table, exactly what step 1 set up. The one row shows /dev/vdb1, starting at sector 2048 (that aligned default you accepted with Enter), 2G in size, and Type reading Linux LVM. That Type column is the grader's checkpoint: it proves the t keystroke landed the lvm alias. If it read Linux filesystem instead, you forgot the type and the exam task would score wrong even though the partition exists.

Setting the size is not the same as setting the type. A common exam miss is creating the partition (steps n through the size) and skipping t. The partition works, pvcreate might even accept it, but the grader checks the type code, and an unlabeled partition reads Linux filesystem, not Linux LVM. Always run t and set the alias (lvm or swap) before you press w.

One more gotcha, and it bites people on exam day. When you write a new table with w, the running kernel does not always re-read it immediately, especially if the disk was in use. Your lsblk might still show the old picture. The fix is partprobe, which asks the kernel to re-read a disk's partition table right now, no reboot needed.

Run it against the disk you just changed:

partprobe /dev/vdb

prompt: [root@servera ~]# answer: partprobe /dev/vdb output: hint: The command is partprobe, then the disk you changed: partprobe /dev/vdb

No output, and that is success. partprobe prints nothing when it works, it just quietly tells the kernel 'this disk's table changed, look again'. After it runs, lsblk and fdisk -l reflect your latest edit. If partprobe ever complains that the device is busy, a reboot always makes the kernel pick up the new table, but on the exam partprobe is the fast path. Make it a reflex: write with w, then partprobe, then verify.

There is a second tool worth naming: parted. It does the same job as fdisk but can run non-interactively, so it fits in scripts: parted /dev/vdb mklabel gpt and parted /dev/vdb mkpart primary 1MiB 2049MiB. On the exam, interactive fdisk is usually faster to type by hand, but parted is the scriptable alternative and worth recognizing if a question shows it.

Scaffolding off. No command is printed this time. You have every piece you need.

You have just partitioned /dev/vdb and you want to confirm the partition table one last time, the disklabel format and the type of the partition you made, before you hand the disk to LVM. Think about which fdisk flag lists a disk's table, and which disk you name. One line.

prompt: [root@servera ~]# answer: fdisk -l /dev/vdb output: Disklabel type: gpt Device Start End Sectors Size Type /dev/vdb1 2048 4196351 4194304 2G Linux LVM hint: The list flag is -l and the disk is /dev/vdb. Build fdisk, then -l, then the path.

fdisk -l /dev/vdb is the whole answer. The -l flag lists the table without opening an interactive session, and naming /dev/vdb limits it to the one disk you care about. You read back Disklabel type: gpt and the /dev/vdb1 ... 2G Linux LVM row, the two facts that prove the partition is the right size and the right type. That single line is how you verify partitioning on the exam before moving to the next task.

You earned this cheat sheet. Every row is a command you ran or a keystroke you walked:

The interactive fdisk sequence to burn in: n new, Enter the number, Enter the start, +2G the size, t then the type alias (lvm or swap), then w to write. Nothing hits the disk until w.

Three exam reflexes for partitioning: GPT is the default (fdisk starts one for you on a blank disk); t and the type alias is NOT optional, the grader reads the Type column; and partprobe after w so the kernel sees your change without a reboot. Miss any one and a correct-looking partition can still score wrong.

The practice terminal has shown you the shape of partitioning: lsblk to survey the disks, fdisk -l to read one disk's table, the fdisk keystroke sequence to carve a sized, typed partition, and partprobe to make the kernel see it. Every one of those you typed yourself.

The local-storage module mission is where you run these against a real RHEL 10 machine. A full VM boots for you with its own spare disks, vdb and vdc, blank and waiting. The mission hands you objectives that use exactly what you practiced here: survey the disks, create a partition of a given size, and label its type. One difference from this lesson: the mission shows no commands. You read the objective, recall the fdisk sequence, and type it. That recall is what makes it stick on exam day.

Finish the other local-storage lessons, then go carve a real disk and build the LVM stack on top of the partition you made.

Practice MBR and GPT Partitioning in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.