Skip to content

Intermediate · Storage: partitions, file systems and LVM · topic 24 of 57 · 35 min

Disks and partitions: MBR, GPT, fdisk and parted

Explanation

A new disk must be divided into partitions before most uses. Two partition table types exist: the old MBR (up to 4 primary partitions and 2 TiB) and the modern GPT (128 partitions, huge disks). lsblk shows disks and partitions; fdisk, gdisk and parted create them.

Block devices and their names

A disk appears in /dev as a block device: a file that represents storage read and written in blocks. The name tells you the kind of disk. SATA, SAS and many virtual disks are /dev/sda, /dev/sdb and so on. KVM virtual disks are /dev/vda, /dev/vdb. NVMe drives are /dev/nvme0n1. Partitions add a number: /dev/sdb1, /dev/vdb2, or for NVMe /dev/nvme0n1p1.

bash
$ lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda           252:0    0   20G  0 disk
├─vda1        252:1    0    1G  0 part /boot
└─vda2        252:2    0   19G  0 part
  ├─rhel-root 253:0    0   17G  0 lvm  /
  └─rhel-swap 253:1    0    2G  0 lvm  [SWAP]
vdb           252:16   0    5G  0 disk
vdc           252:32   0    5G  0 disk
vdb and vdc are new, empty disks: no partitions, no mount points.

Why partition?

A partition is a fixed slice of a disk that the system treats as a separate area. You partition to keep things apart (so a full log area cannot fill the root file system), to use different file systems, or to hand space to LVM or swap. The partition table, at the start of the disk, records where each partition begins and ends.

Think of it like this: A disk is a plot of land; partitions are the walls you build to divide it into rooms. The partition table is the house plan pinned at the entrance. MBR is an old plan format that allows only four main rooms and a limited plot size; GPT is the modern format with room for 128 rooms on a plot of almost any size.
MBR (msdos)GPT
Max disk size2 TiBFar beyond any real disk (8 ZiB)
Partitions4 primary, or 3 primary + 1 extended with logical partitions inside128 by default
Boot firmwareClassic BIOSUEFI (and BIOS with a small BIOS boot partition)
SafetyOne copy of the tableTable copied at the end of the disk, with checksums

For new disks, use GPT unless you have a reason not to.

Creating partitions with parted

bash
# parted /dev/vdb mklabel gpt
# parted /dev/vdb mkpart data xfs 1MiB 2GiB
# parted /dev/vdb mkpart lvmpart 2GiB 4GiB
# parted /dev/vdb set 2 lvm on
# parted /dev/vdb print
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  2147MB  2146MB               data
 2      2147MB  4295MB  2147MB               lvmpart  lvm
# udevadm settle          # wait until /dev/vdb1 and /dev/vdb2 appear
parted writes changes at once (no "save" step). Start at 1MiB so partitions are aligned with the disk's physical blocks.

The file-system word in mkpart (xfs above) only sets a type hint; it does not create a file system. You still run mkfs in the next lesson.

The same with fdisk (interactive)

bash
# fdisk /dev/vdc
Command (m for help): g                 # new empty GPT table (o = MBR)
Command (m for help): n                 # new partition
Partition number (1-128, default 1): 1
First sector (2048-10485726, default 2048): <Enter>
Last sector, +/-sectors or +/-size{K,M,G,T,P} (...): +1G
Command (m for help): t                 # change type
Partition type or alias (type L to list all): swap
Command (m for help): p                 # print, to check
Command (m for help): w                 # write and quit (q quits WITHOUT saving)
fdisk keeps changes in memory until you press w. gdisk is a similar tool made only for GPT.

Partition types tell tools what a partition is for: Linux filesystem, Linux LVM, Linux swap. On MBR they are hex codes (83 Linux, 8e LVM, 82 swap). If the kernel does not see new partitions on a disk that is in use, run partprobe /dev/vdc or udevadm settle.

Common mistakes

  • Partitioning the wrong disk. Always run lsblk first and check the size and that there are no mount points. Mistakes here destroy data.
  • Writing a new label (mklabel or fdisk g/o) on a disk that has data. It wipes the table and every partition with it.
  • Expecting MBR to use a 4 TB disk fully. It cannot go past 2 TiB; use GPT.
  • Forgetting to set the LVM or swap type. Many tools still work, but people and installers can be confused later.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Disks and partitions: MBR, GPT, fdisk and parted · 1/6

/dev/sda · /dev/vda · /dev/nvme0n1

Disks appear as block devices in slash dev: sda, vda or nvme zero n one.

Prefer a video by a teacher? Find free videos on “rhel 9 fdisk parted gpt partition tutorial rhcsa” on YouTube ↗

In real life: Adding a disk for CCTV recordings at a Jaipur hotel

A hotel in Jaipur stores CCTV recordings on a RHEL server, and the old disk is full. The vendor adds a new 8 TB disk. The admin checks with lsblk that /dev/sdb is the new, empty 8 TB disk, creates a GPT label (MBR could not use more than 2 TiB of it), and makes one partition across the whole disk for the recordings.

bash
# lsblk /dev/sdb
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdb    8:16   0  7.3T  0 disk
# parted /dev/sdb mklabel gpt
# parted /dev/sdb mkpart cctv xfs 1MiB 100%
# lsblk /dev/sdb
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdb      8:16   0  7.3T  0 disk
└─sdb1   8:17   0  7.3T  0 part

Practice (0/4 done)

Task 1 · Question

You must use all of a 6 TB disk as one partition. Which partition table do you choose?

Task 2 · Question

In fdisk, which key writes the changes to disk?

Task 3 · Code · Python

Write fits_mbr(disk_tib, partitions) that returns True if a disk layout is possible with an MBR table using only primary partitions: the disk must be at most 2 TiB AND there must be at most 4 partitions.

Task 4 · Practice

On your lab VM's first spare disk, create a GPT label and three partitions: 1 GiB for a file system, 1 GiB for swap (type swap), and 2 GiB for LVM (lvm flag).

Quick quiz

Question 1

1.What is the first partition on /dev/nvme0n1 called?

Question 2

2.How many partitions does a GPT table allow by default?

Question 3

3.What does "parted /dev/vdb mkpart data xfs 1MiB 2GiB" NOT do?

Question 4

4.Which command should you ALWAYS run before partitioning?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What is the first partition on /dev/nvme0n1 called?

Answer: /dev/nvme0n1p1

NVMe partitions add p and a number.

How many partitions does a GPT table allow by default?

Answer: 128

GPT reserves room for 128 entries.

What does "parted /dev/vdb mkpart data xfs 1MiB 2GiB" NOT do?

Answer: Create an XFS file system

The xfs word is only a hint; run mkfs.xfs afterwards.

Which command should you ALWAYS run before partitioning?

Answer: lsblk (to check the disk)

Confirm the disk name, size and that it is not in use.

Which creates an LV using all remaining space in vg01?Related

Answer: lvcreate -n lv1 -l 100%FREE vg01

Percentages go with -l, e.g. 100%FREE.

From LVM: physical volumes, volume groups and logical volumes

employees has 11 rows. How many rows does SELECT name, AVG(salary) OVER (PARTITION BY dept_id) FROM employees return?Related

Answer: 11

A window function never removes rows; each of the 11 rows gets its department average.

From OVER and PARTITION BY

Which command shows file system types and UUIDs of block devices?Related

Answer: lsblk -f

lsblk -f (or blkid) shows FSTYPE and UUID.

From File systems and mounting: XFS, ext4, mount and df

Which command grows a mounted XFS file system to fill its LV?Related

Answer: xfs_growfs /data

xfs_growfs takes the mount point.

From Growing storage and adding swap

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 4 more topics in “Storage: partitions, file systems and LVM” before its exam: File systems and mounting: XFS, ext4, mount and df, Permanent mounts with /etc/fstab and UUIDs, LVM: physical volumes, volume groups and logical volumes, Growing storage and adding swap.
  2. Module 5 exam: Storage · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, SELinux and SSH. 57 topics left in the course before the final exam.

← Previous: firewalld: zones, services and ports