Skip to content

Partitions: MBR and GPT

Practical 4.3 partitions-mbr-gpt-annex.pdf · PDF

A laptop has one SSD. Yet Windows shows C:, sometimes D:, and a hidden Recovery area. How can one disk be three?

Because it has been divided. Every computer you have ever used has a disk cut into pieces, and a tiny table at the very start of the disk says where each piece begins and ends. Lose that table and your files are still there — but nobody can find them. Today you add a brand-new disk to deb-lab and cut it yourself, twice: once the 1983 way, once the modern way.

What you will learn

  • Give three reasons to split a disk into partitions, and say what the partition table is
  • Compare MBR and GPT: age, number of partitions, largest disk, safety copy
  • Read device names like /dev/sda, /dev/nvme0n1p2, /dev/vdb1, and the output of lsblk and fdisk -l
  • Create primary, extended and logical partitions on an MBR disk with fdisk
  • Create named partitions on a GPT disk with parted
  • Why partitioning is not formatting, and why MBR stops at 2 TiB

Rooms in the pantry

A partition is a piece of a disk with a fixed start and end, used as if it were a separate disk.

The disk is the kitchen's pantry (Unit 1). Partitioning builds walls inside it: each room is a partition. Why bother?

Reason Example
Keep the system apart from the data Reinstall the operating system in one room; the room with your files is not touched
Two operating systems on one disk Windows in one room, Linux in another (dual boot)
Rooms with a special job The EFI System Partition from Boot, where the firmware finds the bootloader; swap on Linux
Stop a flood If the logs fill their room, the rest of the system keeps working

The plan by the door: the partition table

The partition table is a small map at the start of the disk that says where each partition starts and ends.

It is the plan of the pantry pinned by the door. Lose it and the rooms are still there, but nobody knows where the walls are. There are two formats:

MBR (Master Boot Record) GPT (GUID Partition Table)
Born 1983, with IBM's PC DOS 2.0 and the IBM PC XT, the first IBM PC with a hard disk (10 MB) Part of the UEFI specification (see Boot)
Where Inside the first sector of the disk (512 bytes) At the start of the disk, with a second copy at the end
Partitions 4 primary. For more: 3 primary + 1 extended holding logical ones 128 by default, all equal, each with a name
Largest disk 2 TiB Far beyond any disk on sale
Protection None Checksums: a damaged table is detected
Goes with BIOS, old PCs, many USB sticks UEFI: every PC sold today, Windows 11

Why MBR stops at 2 TiB

MBR stores each position in 32 bits, and counts in sectors of 512 bytes. So the biggest disk it can describe is:

2³² sectors × 512 bytes = 2³² × 2⁹ bytes = 2⁴¹ bytes = 2 TiB

A 4 TB disk with an MBR table loses half of itself. That is the binary maths from Binary with real consequences.

The extended trick

In 1983, four rooms looked like plenty. When they were not, nobody could change the table, so one of the four entries became a container: the extended partition. Inside it, as many logical partitions as you like. Linux always numbers logical partitions from 5, even if 3 and 4 are free.

flowchart LR
    subgraph MBR ["One MBR disk"]
        direction LR
        P1["<b>vdb1</b><br>primary"]
        P2["<b>vdb2</b><br>primary"]
        subgraph EXT ["vdb3 · extended: only a container"]
            direction LR
            L5["<b>vdb5</b><br>logical"]
            L6["<b>vdb6</b><br>logical"]
        end
    end
    P1 --- P2 --- EXT

Careful: partitioning is not formatting

Two different jobs. Partitioning builds the walls. Formatting puts shelves and an inventory book inside one room — the file system, on its own page. Today: only walls.

Disks have names

On Linux every disk is a file in /dev (remember the directory tree). The name tells how the disk is connected:

Disk Its 2nd partition Connected through
/dev/sda, sdb... /dev/sda2 SATA, USB
/dev/nvme0n1 /dev/nvme0n1p2 NVMe (the fast corridor from Storage)
/dev/vda, vdb... /dev/vdb2 VirtIO: the virtual disks of our VMs

Add a disk to deb-lab

With deb-lab shut down, in its virt-manager window: View → Details (the light bulb) → Add Hardware → Storage → Create a disk image for the virtual machine: 5 GiB → Device type: Disk device → Bus type: VirtIO → Finish. Start the VM. Then look:

student@deb-lab:~$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda    254:0    0   25G  0 disk
├─vda1 254:1    0  ...   0 part /
└─...
vdb    254:16   0    5G  0 disk
student@deb-lab:~$ sudo fdisk -l /dev/vdb
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes

The new disk is the one with 5G and nothing hanging under it. There is no Disklabel type line: it has no partition table yet. If your names differ (for example if the system disk is sda), use your names everywhere below.

The ritual before every command that writes to a disk

  1. Run lsblk.
  2. Read the size.
  3. Say the name aloud.

The system disk is 25 G. Ours is 5 G. If you are about to type vda, take your hands off the keyboard.

The old table: MBR with fdisk

fdisk is a small program with one-letter commands, and it works on a draft: nothing touches the disk until you type w.

Letter Does
m Show the menu
p Print the plan so far
n New partition
d Delete a partition
o New empty MBR table
g New empty GPT table
w Write to the disk and exit
q Quit without saving

Making one partition, slowly:

student@deb-lab:~$ sudo fdisk /dev/vdb
Welcome to fdisk (util-linux 2.41.5).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485759, default 10485759): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Three things to notice:

  • "0 primary, 0 extended, 4 free": MBR's limit of four, on the screen.
  • The first sector is 2048, not 0: the first mebibyte is left for the table.
  • The end is given as a size, +2G.

In Practical 4.3, part 1, you build two primary partitions (2 GiB and 1 GiB), one extended with the rest, and two logical ones inside it. The result, after w:

student@deb-lab:~$ sudo fdisk -l /dev/vdb
Disklabel type: dos

Device     Boot   Start      End Sectors  Size Id Type
/dev/vdb1          2048  4196351 4194304    2G 83 Linux
/dev/vdb2       4196352  6293503 2097152    1G 83 Linux
/dev/vdb3       6293504 10485759 4192256    2G  5 Extended
/dev/vdb5       6295552  8392703 2097152    1G 83 Linux
/dev/vdb6       8394752 10485759 2091008 1021M 83 Linux
  • dos is the name fdisk gives to MBR.
  • The numbers jump from 3 to 5: logical partitions always start at 5.
  • vdb6 is 1021M, not 1G: each logical partition needs a little room in front of it for its own small table.

q is your way out

Made a mess in the draft? d deletes one partition. Or q to quit without saving, and start again. Only w makes it real.

The modern table: GPT with parted

Five rooms, but one of them is a box with two rooms inside, and the numbers jump from 3 to 5. That is 1983 leaking into 2026. Now the modern table, with a second tool, parted. Two differences from fdisk:

  • No draft. Every parted command is written to the disk at once. There is no w and no q to save you.
  • You give start and end, with units. Use the binary units MiB and GiB (the 931 GB trap from Storage) so the walls fall on exact boundaries.

parted is not installed by default: sudo apt install parted. Then sudo parted /dev/vdb, and inside it:

(parted) mklabel gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart dev 1MiB 2GiB
(parted) mkpart design 2GiB 4GiB
(parted) mkpart exchange 4GiB 100%
(parted) print
(parted) quit
  • mklabel gpt = a new, empty partition table (parted calls the table a disk label). The warning is real: the five MBR partitions disappear with that Yes.
  • mkpart NAME START END = a new partition with a name.

This is the disk Tramuntana Apps wants for the office: dev and design get 2 GiB each, and the rest is exchange, a room for moving files to and from clients' Windows laptops.

student@deb-lab:~$ lsblk -o NAME,SIZE,TYPE,PARTLABEL /dev/vdb
NAME    SIZE TYPE PARTLABEL
vdb       5G disk
├─vdb1    2G part dev
├─vdb2    2G part design
└─vdb3 1023M part exchange

vdb3 is 1023M, not 1G: the last mebibyte of the disk is kept for the second copy of the GPT. The safety copy from the table above, visible with your own eyes.

Keep this disk exactly as it is

These three partitions — dev, design, exchange — get a file system in File systems and a place in the tree in Mounting file systems. Do not delete the disk.

fdisk or parted?

fdisk parted
Writes when Only at w At every command
Undo q throws the draft away None: fix with rm N or start again
Sizes +2G from the start sector Start and end: 1MiB 2GiB, 100%
Installed on Debian By default sudo apt install parted

Key takeaways

  • A partition is a room of the disk; the partition table at the start of the disk is the plan of the walls.
  • MBR (1983): 4 primary partitions, or 3 + 1 extended container with logical ones numbered from 5; at most 2 TiB (2³² × 512 bytes); no safety copy.
  • GPT (UEFI): 128 named partitions, a second copy at the end, checksums, no practical size limit. It is the normal table today.
  • Linux names disks by connection: sda (SATA/USB), nvme0n1 (NVMe), vda (VirtIO); partitions add a number (vdb1, nvme0n1p2).
  • fdisk works on a draft until w; parted writes every command at once. Always lsblk, read the size, say the name.

Quick check

1. How many primary partitions fit in an MBR partition table?
  • 1
  • 2
  • 4
  • 128

MBR has room for 4 entries. To get more, one entry becomes an extended partition that contains logical ones. 128 is GPT's default.

2. In fdisk, when do your changes reach the disk?
  • When you type w
  • When you type n
  • When you type p
  • When you type q

fdisk works on a draft in memory. w writes it to the disk; q throws it away. parted, by contrast, writes every command at once.

3. Tramuntana Apps buys a 4 TB disk. Which partition table, and why?
  • MBR, because it is the standard one
  • GPT, because MBR stops at 2 TiB
  • MBR, because GPT is only for SSDs
  • Either, because the size does not matter

MBR counts 2³² sectors of 512 bytes = 2 TiB. A 4 TB disk with MBR would lose half its space. GPT has no such limit and is the normal table today anyway.

4. What is /dev/vdb2?
  • The second virtual disk
  • A directory inside /dev/vdb
  • Two disks joined together
  • The second partition of the disk vdb

vdb is the second VirtIO disk (vda is the first); the number after it is the partition. On NVMe the same idea is written nvme0n1p2.

5. On an MBR disk, which number does the first logical partition get on Linux?
  • 1
  • 4
  • 5
  • 0

Numbers 1–4 are reserved for the four entries of the MBR table. Logical partitions always start at 5, even when 3 and 4 are free.

6. After mkpart exchange 4GiB 100% on a 5 GiB GPT disk, the partition is 1023M instead of 1G. Why?
  • The last mebibyte holds the second copy of the GPT
  • Each GPT partition loses 1 MiB to its name
  • parted rounds every partition down by 1 MiB
  • The file system on it uses 1 MiB already

GPT keeps a backup copy of the table at the end of the disk, so that space cannot belong to a partition. There is no file system yet: partitioning only builds walls.

7. A classmate says: “I partitioned the disk, so now it is formatted.” Select the two that are true.
  • Partitioning only builds the walls of each room
  • Formatting writes a file system inside one partition
  • Partitioning and formatting are two names for one job
  • A new partition can store files straight away

Partitioning writes the partition table: where each room starts and ends. Formatting puts a file system (shelves and an inventory) inside a room. Without it, there is nowhere to save a file.

The partitions exist, but they are still empty rooms with no shelves. Next: give them a file system — File systems.