Linux › Section D · Disks and filesystems › Topic D.1
Partitioning disk devices
Before a new disk can hold files it needs a partition table, a small map that divides the disk into regions. Knowing the two table formats, the tools that edit them and the units they report keeps you from wiping the wrong disk.
Layers on a disk
A whole disk appears as one block device, such as /dev/sdb or /dev/nvme0n1 (the topic "Device name summary" explains the names). Inside it, a partition table divides the sectors into partitions, and the kernel presents each one as a block device of its own: /dev/sdb1, /dev/sdb2, or /dev/nvme0n1p1 for NVMe drives. Each partition then normally holds a filesystem, swap space or an LVM physical volume, all covered later in this section. The partition table itself is just a few sectors of data that record where each region starts and ends. That is why it is cheap to change and also why a careless change can make every file on the disk unreachable.
The MBR partition table
The older format lives in the Master Boot Record (MBR), the disk's first 512-byte sector; tools such as parted and fdisk call it msdos or dos. It has room for only four primary partitions. To get more, one primary slot becomes an extended partition that holds logical partitions, numbered from 5 upwards. Each entry carries a one-byte type ID: 83 for a Linux filesystem, 82 for Linux swap, 8e for LVM. Because sector addresses are 32-bit, an MBR can describe at most \(2^{32}\) sectors, which with 512-byte sectors is 2 TiB (about 2.2 TB). Larger disks need GPT.
The GUID Partition Table
GPT, part of the UEFI standard, replaces the MBR on current systems. It keeps a protective MBR in sector 0 so that old tools see the disk as full rather than empty. The GPT header sits in sector 1, followed by an array of partition entries: 128 entries by default, each 128 bytes. A backup copy of the header and entries is stored at the end of the disk, so one damaged copy can be repaired from the other. Addresses are 64-bit, which removes the 2 TiB limit, and there are no extended or logical partitions. Each partition has a type GUID, its own unique GUID (shown as PARTUUID) and an optional name.
Tools for viewing and editing
Start by looking. lsblk lists disks and partitions as a tree with sizes and mount points; fdisk -l and parted -l print the partition tables; blkid shows what each partition contains. To edit, the util-linux fdisk is interactive and supports both MBR and GPT; gdisk is a GPT-only alternative, sfdisk is for scripts, and parted (with its graphical front end gparted) can also resize. The two main editors behave differently. fdisk builds your changes in memory and touches the disk only when you type w, while q quits without writing. parted applies each command as you enter it, with no review step. On an empty disk, released versions of fdisk start an MBR table by default (the coming util-linux 2.43 picks GPT on UEFI machines), so type g for GPT or o for MBR to choose explicitly.
Sectors, units and alignment
Partition tools count in sectors, almost always 512-byte logical sectors, even when the physical sectors are 4,096 bytes. Sizes also come in two families: fdisk's +500M means 500 MiB (powers of two), while drive makers sell in decimal units, so a "1 TB" disk holds \(10^{12}\) bytes, about 931.3 GiB. Performance depends on alignment: a partition should start on a boundary that suits the device's internal page or block size. Modern tools start the first partition at sector 2048, which is exactly 1 MiB, a multiple of 4,096, 8,192 and every other common size. You can read a partition's start sector from a file such as /sys/block/sdb/sdb1/start.
Safety before you write
Changing a partition table is one of the most destructive things an administrator does, so follow a routine. 1. Identify the disk by size, model and serial number with lsblk -o NAME,SIZE,MODEL,SERIAL, because names such as /dev/sdb can change between boots. 2. Check that nothing on it is mounted or in use as swap; many desktops automatically mount inserted drives. 3. Back up anything of value: deleting or moving a partition entry loses track of where its filesystem began. 4. Review the layout with p before writing. Practising on a spare USB stick or a virtual machine's disk is the safest way to learn.
Worked example: a GPT layout with fdisk
Goal: give a blank 1 TB disk, found with lsblk at /dev/sdX, an EFI system partition of 512 MiB and one Linux partition for the rest. The disk name here is a placeholder; confirm yours first. 1. Run fdisk /dev/sdX as root. 2. Type g to create a new, empty GPT in memory. 3. Type n, accept partition number 1 and first sector 2048, then enter +512M as the last sector. 4. Type t and choose the EFI System type (L lists all types). 5. Type n again and accept every default, so partition 2 fills the remaining space with the Linux filesystem type. 6. Type p and check both entries. 7. Type w to write the table; fdisk asks the kernel to reread it and exits.
Worked example: checking the numbers
Verify the layout from the previous card in sectors of 512 bytes. 1. Disk size: \(10^{12} \div 512 = 1{,}953{,}125{,}000\) sectors, about 931.3 GiB. 2. Partition 1 is 512 MiB, which is \(536{,}870{,}912 \div 512 = 1{,}048{,}576\) sectors. Starting at 2048, it ends at \(2048 + 1{,}048{,}576 - 1 = 1{,}050{,}623\). 3. Partition 2 therefore starts at sector 1,050,624 and runs to near the end, stopping short of the 33 sectors that hold the backup GPT. 4. Alignment: the start sector 2048 is a byte offset of 1,048,576, and \(1{,}048{,}576 \div 4096 = 256\) exactly, so the start is aligned. A partition starting at sector 1,953,126 would not be, because that number is not a multiple of 8.
Telling the kernel
Partition editors work entirely in user space, writing the table through the disk's device file. The kernel must then reread the table before /dev/sdX1 and /dev/sdX2 appear. fdisk requests a reread when it writes, and the kernel logs a line listing the partitions it found, which journalctl -k shows. If the disk is busy, the kernel may keep its old view; partprobe or blockdev --rereadpt /dev/sdX asks it to try again, and a reboot always works. Run lsblk again to confirm the new partitions.
Common mistakes to avoid
First, partitioning the wrong disk: never rely on a device name alone; match the size, model and serial number. Second, editing a disk whose partitions are mounted. Third, assuming parted lets you review changes: it writes each command immediately, unlike fdisk. Fourth, mixing units: 500M in fdisk means MiB, and fdisk -l reports sizes in 512-byte sectors, so a raw sector count looks about twice as large as the size in KiB. Fifth, choosing MBR for a disk larger than 2 TiB, which leaves the extra space unusable. Sixth, forgetting that partitioning alone creates no filesystem: that is the next topic.
Key takeaways
A partition table maps a disk's sectors into partitions, each presented as its own block device. MBR allows four primary partitions (or extended plus logical ones), uses type IDs such as 83, 82 and 8e, and tops out at 2 TiB with 512-byte sectors. GPT has a protective MBR, a header in sector 1, 128 entries by default, a backup copy at the end and 64-bit addresses. View with lsblk, fdisk -l and parted -l; edit with fdisk (writes only on w) or parted (writes at once). Count in 512-byte sectors, align partitions on 1 MiB, identify disks carefully and back up first.
Flashcards
Flashcard
Data that records where each partition on a disk starts and ends
Test your understanding
Question 1 of 5
You need to partition a new 4 TB disk so that all its space is usable. Which choice is right?
Question 2 of 5
In fdisk you deleted a partition by mistake but have not typed w. What happens if you type q?
Question 3 of 5
A partition's start sector, in 512-byte units, is 1,953,126. Is it aligned for a device with 4,096-byte pages?
Question 4 of 5
In fdisk a new partition starts at sector 2048 and you enter +512M for its size. What is its last sector?
Question 5 of 5
Which statement about the GPT layout is correct?
