Skip to content

Partitions

Disks and Block Devices covered how to identify and inspect a disk. The next step is dividing that disk into partitions for actual use. A partition is a defined-boundary section of a disk that can hold its own filesystem or serve as swap. This article covers the difference between the MBR and GPT partition tables, the fdisk, gdisk, and parted tools, and a complete hands-on partitioning scenario. If the next step is combining multiple disks or resizable, layered storage, that's RAID (mdadm) or LVM — both of which are commonly built on top of the partitions created here.

What You Will Learn

By the end of this article you will be able to:

  • explain the main differences between the MBR and GPT partition tables;
  • distinguish primary, extended, and logical partitions;
  • create an MBR partition with fdisk and a GPT partition with gdisk;
  • use parted for scriptable, one-line partition management;
  • explain why the kernel needs to be told about a newly created partition (partprobe);
  • understand the risks of deleting or modifying a partition and how to avoid them.

MBR and GPT: Partition Table Types

A disk's partition table is a structure stored at the start of the disk that records which byte ranges belong to which partition. Linux uses two main standards.

MBR (Master Boot Record)

MBR is the older standard, stored in the 512-byte boot sector at the very start of the disk. It has real limitations:

  • it can address only up to 2 TB of disk space;
  • a maximum of 4 primary partitions can be created;
  • if more than 4 partitions are needed, one becomes an extended partition (a container), inside which an unlimited number of logical partitions can be created.
MBR disk (4-primary limit):
┌─────────┬─────────┬─────────────────────────────┐
│ sda1    │ sda2    │ sda3 (extended)               │
│ primary │ primary │  ┌─────────┬─────────┐        │
│         │         │  │ sda5    │ sda6    │  ...   │
│         │         │  │ logical │ logical │        │
└─────────┴─────────┴──┴─────────┴─────────┴────────┘

Logical partitions always start numbering at 5 (sda5, sda6, ...), since numbers 14 are reserved for primary/extended partitions — even if the partition doesn't physically sit in the fifth position.

GPT (GUID Partition Table)

GPT is the modern partition table, part of the UEFI standard:

  • supports disks up to 9.4 ZB (effectively no practical limit);
  • supports up to 128 partitions by default, with no primary/extended distinction;
  • every partition gets a unique GUID (globally unique identifier);
  • keeps a backup copy at the end of the disk — if the table at the start is damaged, it can be recovered (MBR has no such backup).
Feature MBR GPT
Max disk size 2 TB 9.4 ZB
Max partition count 4 primary (or 3 + extended) 128 (default)
Backup table No Yes (end of disk)
UEFI compatibility Legacy BIOS mode only Part of the UEFI standard
Legacy OS compatibility Good Some older systems don't support it

Info

GPT is recommended for new servers and disks larger than 2 TB. MBR mostly shows up on legacy systems or small (< 2 TB) environments running an older BIOS.

Tools: fdisk, gdisk, parted

Tool MBR GPT Mode
fdisk Yes Yes (modern versions) Interactive menu
gdisk No Yes Interactive menu, similar to fdisk
parted Yes Yes Interactive and scriptable (--script)

fdisk is the most common, traditional tool for MBR, with modern versions also supporting GPT. gdisk has a menu in the same style as fdisk, but works only with GPT. parted allows creating a partition in a single command-line invocation — convenient for scripts and automation.

sudo apt install gdisk parted   # Debian/Ubuntu; fdisk is usually preinstalled

Danger

fdisk, gdisk, and parted modify a disk's partition table. Deleting or incorrectly changing the partition table can destroy all the data on the disk. Run every example below only on an empty, unused disk, ideally in a disposable test VM, and always take a full backup before applying any of this to a production disk.

Practical Scenario: Dividing a New Disk into Three Partitions with MBR

Situation. /dev/sdb is a new, 30 GiB, unpartitioned disk. It needs to be split into three partitions: 1 GiB for swap, 20 GiB for data, and the remaining space as a third partition.

1. Check the disk's current state (read-only)

sudo fdisk -l /dev/sdb
lsblk /dev/sdb

Confirm the disk has no partition table and is empty.

2. Start fdisk in interactive mode

sudo fdisk /dev/sdb

fdisk opens an interactive command prompt (Command (m for help):). Press m for help.

3. Create a new MBR (DOS) partition table

Command (m for help): o

o creates a new, empty DOS (MBR) partition table. This completely wipes any existing partition table on the disk.

4. First partition — 1 GiB swap

Command (m for help): n
Partition type: p
Partition number (1-4, default 1): [Enter]
First sector: [Enter]
Last sector: +1G

Once the partition is created, its type needs to be changed to swap:

Command (m for help): t
Partition number: 1
Hex code: 82

82 is the Linux swap type code (fdisk's default type is 83 — an ordinary Linux filesystem).

5. Second partition — 20 GiB

Command (m for help): n
Partition type: p
Partition number (2-4, default 2): [Enter]
First sector: [Enter]
Last sector: +20G

6. Third partition — the rest of the disk

Command (m for help): n
Partition type: p
Partition number (3,4, default 3): [Enter]
First sector: [Enter]
Last sector: [Enter]

Pressing Enter for the last sector assigns all remaining free space on the disk to this partition.

7. Review before writing

Command (m for help): p
Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        2048  2099199  2097152    1G 82 Linux swap
/dev/sdb2     2099200 43907071 41807872   20G 83 Linux
/dev/sdb3    43907072 62914559 19007488  9.1G 83 Linux

8. Write to disk

Command (m for help): w

w writes all changes to disk and exits fdisk. Up to this point nothing has been physically written to disk — exiting with q would have discarded everything.

9. Tell the kernel about the new partition table

sudo partprobe /dev/sdb

Sometimes, even after fdisk writes new partitions, the running kernel can't apply the update automatically if the disk is in use (Device or resource busy). partprobe forces the kernel to reread the partition table — a reboot works as an alternative if needed.

10. Confirm the result

lsblk /dev/sdb
sudo fdisk -l /dev/sdb
sdb      8:16   0   30G  0 disk
├─sdb1   8:17   0    1G  0 part
├─sdb2   8:18   0   20G  0 part
└─sdb3   8:19   0  9.1G  0 part

Conclusion. Three partitions were created successfully. The next step is preparing the swap partition with mkswap/swapon (Swap Management) and creating a filesystem on the remaining two partitions (Filesystem Types).

Creating a GPT Partition with gdisk

When a GPT partition table is needed, gdisk presents a menu similar to fdisk:

sudo gdisk /dev/sdc
Command (? for help): o        # create a new, empty GPT table
Command (? for help): n        # new partition
Partition number (1-128, default 1): [Enter]
First sector: [Enter]
Last sector: [Enter]           # the whole disk as one partition
Hex code or GUID: [Enter]      # default: Linux filesystem
Command (? for help): p        # review
Command (? for help): w        # write to disk

Modern versions of fdisk also support GPT directly — the g command inside fdisk /dev/sdc creates a new GPT table, and the remaining steps (n, p, w) are the same as for MBR.

parted: Single-Line, Scriptable Partitioning

parted works both interactively and, with the --script flag, in automated mode — useful in Ansible or bash scripts.

sudo parted /dev/sdd --script mklabel gpt
sudo parted /dev/sdd --script mkpart primary ext4 0% 100%
  • mklabel gpt — creates a new GPT partition table (mklabel msdos for MBR);
  • mkpart primary ext4 0% 100% — allocates the disk's entire capacity (0% to 100%) to a single partition, with ext4 given as the filesystem hint (this is only metadata — the actual filesystem hasn't been created yet).

Creating several partitions in sequence:

sudo parted /dev/sdd --script \
  mklabel gpt \
  mkpart primary ext4 0% 30% \
  mkpart primary ext4 30% 100%

Checking the result:

sudo parted /dev/sdd --script print
Model: VMware Virtual disk (scsi)
Disk /dev/sdd: 21.5GB
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  6459MB  6458MB               primary
 2      6459MB  21.5GB  15.0GB               primary

Growing a Partition After a Disk Was Enlarged

One of the most common real tasks — and interview questions — is: "The cloud provider grew the underlying disk from 30 GiB to 50 GiB. How do you use the extra space?" Enlarging the disk does not enlarge the partition or the filesystem on it; both are separate steps.

The trap with fdisk is that its usual "delete and recreate the partition at a larger size" trick works only if the partition is the last one on the disk and its start sector is kept identical — otherwise data is lost. The safe, purpose-built tool is growpart (from the cloud-guest-utils package):

sudo apt install cloud-guest-utils
# grow partition 1 on /dev/sdb to fill the free space after it
sudo growpart /dev/sdb 1

Note the space between the disk and the partition number (/dev/sdb 1, not /dev/sdb1) — growpart takes them as two arguments.

After the partition is larger, the filesystem still has to be grown to match:

sudo resize2fs /dev/sdb1     # ext4
sudo xfs_growfs /mnt/data    # xfs (by mount point, online only)

Info

If growpart or lsblk still show the old disk size, the kernel hasn't re-read the resized device yet — rescan it with echo 1 | sudo tee /sys/class/block/sdb/device/rescan (see Disks and Block Devices) before growing the partition.

Deleting a Partition

sudo fdisk /dev/sdb
Command (m for help): d
Partition number: 3
Command (m for help): w

d is the delete-partition command, which then asks which partition number to delete. Like everything else, the deletion isn't written to disk until w is pressed.

Danger

Removing an entry from the partition table doesn't immediately delete the filesystem or data on it, but the OS starts treating that partition as "nonexistent," and recreating it or using it for another purpose overwrites the old data, making it unrecoverable. Before deleting, confirm the partition isn't mounted (umount) and that any needed data has been backed up.

Common Mistakes

Assuming Commands Have Already Been Applied Before Pressing w

In fdisk and gdisk, every n, t, d command is only held in memory — it's written to disk only when w is pressed. Exiting with q discards every change. This lets you back out of a mistake, but there's no undo once w has run.

The Kernel Not Immediately Seeing a New Partition

On some systems, a new partition table written with fdisk/parted doesn't immediately show up in lsblk. Try sudo partprobe <disk> or sudo udevadm settle; if that doesn't help, a reboot is a guaranteed fix.

Trying to Create More Than 4 Primary Partitions Under MBR

MBR supports only 4 primary partitions (or 3 primary + 1 extended). If more are needed, the fourth partition needs to become extended, with logical partitions created inside it — or switch to GPT entirely.

Forgetting the Partition Type Code (the t Command)

fdisk creates a new partition with type 83 (Linux) by default. Codes like 82 for swap or ef for an EFI System Partition need to be set manually — otherwise mkswap or the bootloader might misidentify the partition.

Exercises

  1. In a disposable VM, add a new virtual disk and split it into two partitions with fdisk under an MBR scheme (for example, 5 GiB and the rest).
  2. On the same or another new disk, create a GPT partition table with gdisk and allocate a single partition spanning the whole disk.
  3. Using parted --script, create two partitions on a third disk in a single command sequence (as a script), then compare the result with parted print and lsblk.
  4. Delete one partition from a test disk through fdisk and confirm the result with partprobe.

Verification criterion: given a target layout (number of partitions and their sizes), you should be able to say whether MBR is sufficient or GPT is required, and justify the choice.

Summary

A partition table is the basis for dividing a disk into logical sections; MBR is the older standard, limited to 2 TB and 4 primary partitions, while GPT is the modern standard supporting large sizes and many partitions. fdisk and gdisk are interactive, while parted --script is convenient for automation. Every change is temporary until w is pressed, but irreversible afterward — which is why it's always worth checking with read-only commands first (fdisk -l, lsblk) and proceeding with a backup in hand. The next step for spreading partitions across multiple disks for redundancy or performance is RAID (mdadm).

References