7.1 Block Devices, fdisk & gdisk (104.1)
Key Takeaways
- Linux represents physical and virtual storage hardware as block device nodes in `/dev/`, classified by subsystem naming conventions: IDE/PATA (`/dev/hd*`), SCSI/SATA/SAS/USB (`/dev/sd*`), NVMe (`/dev/nvmeXnYpZ`), and VirtIO (`/dev/vd*`).
- The Master Boot Record (MBR) partition scheme is constrained by a 32-bit Logical Block Addressing limit (max 2 TiB capacity) and supports at most 4 primary partitions (or up to 3 primary and 1 extended partition containing logical partitions numbered 5 and higher).
- The `fdisk` utility operates interactively in memory and commits changes only upon typing `w`; essential MBR type hex codes include `83` (Linux), `82` (Swap), `8e` (LVM), and `fd` (RAID auto).
- The GUID Partition Table (GPT) scheme utilizes 64-bit LBAs supporting up to 8 ZiB with a default 128 partitions, managed via `gdisk` using 4-digit hex codes (`8300` Linux native, `8200` swap, `8e00` LVM, `ef00` EFI System Partition).
- Changes to partition tables are registered with the running Linux kernel without requiring a system reboot using `partprobe` or `partx`.
7.1 Block Devices, fdisk & gdisk
Quick Summary: In Linux, storage devices are exposed to userspace as special block device nodes within the
/dev/filesystem hierarchy. Storage drives are divided into distinct storage boundaries using either legacy Master Boot Record (MBR/DOS) partition tables or modern GUID Partition Tables (GPT). System administrators manage MBR partitions usingfdiskand GPT partitions usinggdisk. Because partitioning utilities initially stage alterations in volatile memory, changes must be written to disk and synchronized with the running kernel using tools likepartprobeorpartxbefore filesystems can be formatted.
1. Linux Storage Architecture & Block Device Taxonomy
In Unix-like operating systems, the Linux kernel abstracts underlying storage hardware into block devices. Unlike character devices (which stream data sequentially byte-by-byte, such as serial ports or terminal lines), block devices transfer data in fixed-size blocks (typically 512 bytes or 4096 bytes) and support random-access read and write operations via hardware sector addressing.
Block device special files reside in /dev/ and are created dynamically by the udev daemon. You can distinguish block devices in directory listings by the leading b character in the file permission string:
$ ls -l /dev/sda /dev/sda1 /dev/tty0
brw-rw---- 1 root disk 8, 0 Aug 29 10:00 /dev/sda
brw-rw---- 1 root disk 8, 1 Aug 29 10:00 /dev/sda1
crw--w---- 1 root tty 4, 0 Aug 29 10:00 /dev/tty0
In the output above, the numbers 8, 0 and 8, 1 represent the major device number (identifying the device driver subsystem, where 8 corresponds to SCSI/SATA disk drivers) and the minor device number (identifying the unique physical drive unit or partition index).
Comprehensive Block Device Naming Conventions
Linux assigns device node names deterministically based on the underlying hardware controller bus and storage protocol:
| Device Interface / Subsystem | Whole Disk Device Node | First Partition | Second Partition | Technical Architecture & Description |
|---|---|---|---|---|
| SCSI / SATA / SAS / USB | /dev/sda, /dev/sdb | /dev/sda1 | /dev/sda2 | Standard modern storage interfaces managed by the sd_mod kernel SCSI disk driver subsystem. Disk letters increment alphabetically (a through z, then aa, ab). |
| Legacy IDE / PATA | /dev/hda, /dev/hdb | /dev/hda1 | /dev/hda2 | Legacy Parallel ATA controllers. Primary Master (hda), Primary Slave (hdb), Secondary Master (hdc), Secondary Slave (hdd). |
| NVMe (PCIe SSD) | /dev/nvme0n1 | /dev/nvme0n1p1 | /dev/nvme0n1p2 | Non-Volatile Memory Express storage attached via PCIe. nvme0 is controller index 0, n1 is namespace 1, and p1 designates partition 1. |
| MMC / SD Cards / eMMC | /dev/mmcblk0 | /dev/mmcblk0p1 | /dev/mmcblk0p2 | MultiMediaCard and Secure Digital storage devices. Partition numbers are preceded by the letter p. |
| VirtIO (KVM / QEMU) | /dev/vda, /dev/vdb | /dev/vda1 | /dev/vda2 | Paravirtualized block storage devices optimized for hypervisors running KVM/QEMU Linux virtual machines. |
| Xen Virtual Disk | /dev/xvda, /dev/xvdb | /dev/xvda1 | /dev/xvda2 | Paravirtualized block devices used under the Xen hypervisor architecture. |
⚠️ LPIC-1 Trap — NVMe & MMC Partition Syntax: Notice the partition numbering syntax difference: SCSI/SATA partitions append the integer directly to the drive letter (
/dev/sdb1), whereas NVMe and MMC/SD device partitions require an explicitpseparator before the partition index (/dev/nvme0n1p1,/dev/mmcblk0p1). Forgetting thepon NVMe device names is a frequent exam mistake.
2. Master Boot Record (MBR / DOS) Partitioning Architecture
The Master Boot Record (MBR) partitioning structure was introduced by IBM in 1983. It is located in the very first 512-byte physical sector (Sector 0, LBA 0) of the storage drive.
MBR 512-Byte Sector Layout (LBA 0):
┌────────────────────────────────────────────────────────┬────────────────────────────────────────────┬─────────────┐
│ Bootstrap Code (446 Bytes) │ Partition Table (64 Bytes) │ Magic Boot │
│ Primary bootloader stage code │ 4 entries × 16 bytes per entry │ Signature │
│ │ [Part 1] [Part 2] [Part 3] [Part 4] │ (0x55 0xAA) │
└────────────────────────────────────────────────────────┴────────────────────────────────────────────┴─────────────┘
0 446 510 512
MBR Structural Constraints
- The 2 TiB Disk Limit: The MBR partition table allocates exactly 32 bits for the starting sector Logical Block Address (LBA) and 32 bits for the partition sector count. With standard 512-byte sector sizes, 2^32 × 512 bytes = 2,199,023,255,552 bytes = 2 TiB. MBR cannot address or partition disk space beyond 2.19 TB.
- Four Primary Partitions Maximum: Because the MBR partition table is only 64 bytes wide and each partition entry requires 16 bytes (64 / 16 = 4), an MBR drive can hold a maximum of 4 Primary Partitions.
- Extended & Logical Partitions: To bypass the 4-partition limitation, one primary partition entry can be designated as an Extended Partition (Hex code
0x05or0x0f). The extended partition acts as a container holding a linked list of Extended Boot Records (EBRs), which define an arbitrary number of Logical Partitions.
MBR Partition Numbering Rules for Linux
- Primary Partitions: Always assigned numbers
1through4(e.g.,/dev/sda1,/dev/sda2,/dev/sda3,/dev/sda4). - Extended Partition: Consumes one of the primary numbers (1 through 4).
- Logical Partitions: Always start numbering at
5(e.g.,/dev/sda5,/dev/sda6,/dev/sda7), regardless of how many primary partitions actually exist on the disk!
💡 LPIC-1 Exam Fill-in-the-Blank Alert: If a SATA disk
/dev/sdacontains exactly one primary partition (/dev/sda1) and one extended partition (/dev/sda2), what device node name does Linux assign to the first logical partition created inside the extended partition? Answer:/dev/sda5
3. Interactive MBR Partitioning with fdisk
The fdisk utility (from the util-linux package) is the traditional, menu-driven command-line partitioning tool for MBR partition tables on Linux.
To partition a block device, execute fdisk followed by the device node path (e.g., fdisk /dev/sdb):
# Launch fdisk on secondary SATA drive
# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
Essential fdisk Interactive Commands Reference
| Command Key | Operational Function | LPIC-1 Exam Significance |
|---|---|---|
m | Print the help menu | Displays all available single-letter interactive commands. |
p | Print the partition table | Shows current disk size, identifier, geometry, sector count, and all existing partition boundaries. |
n | Create a new partition | Prompts to select partition type (p for primary, e for extended, or l for logical), partition number, first sector, and last sector. |
d | Delete a partition | Prompts for the partition index number to remove from the in-memory table. |
t | Change partition system ID | Prompts for partition number and the target hex type code (e.g., 83 for Linux, 82 for Swap, 8e for LVM). |
l | List known partition types | Prints all supported partition type hex codes and their descriptive operating system labels. |
w | Write table to disk and exit | Commits all in-memory changes to the physical disk sector and instructs the kernel to re-read the table. |
q | Quit without saving | Exits fdisk immediately, discarding all modifications made during the current interactive session. |
v | Verify the partition table | Scans the partition table for unallocated sectors, overlaps, or structural anomalies. |
o | Create a new empty DOS table | Initializes a blank MBR partition table in memory, erasing existing partition references. |
g | Create a new empty GPT table | Initializes a blank GUID partition table in memory (modern fdisk feature). |
Practical fdisk Step-by-Step Partition Creation
When creating a partition with n, specify partition boundaries. Linux administrators almost never calculate raw sector numbers manually for the end boundary; instead, use the +size{K,M,G,T,P} notation:
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-41943039, default 2048): [Press Enter for 2048]
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): +10G
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Command (m for help): t
Selected partition 1
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
4. Essential MBR Partition Type Hex Codes
Every MBR partition entry includes a 1-byte system ID (hexadecimal) designating what filesystem or subsystem owns the partition. The LPIC-1 exam requires exact recall of these key codes:
| Hex Code | Partition System Type Description | Operational Role in Linux Administration |
|---|---|---|
83 | Linux native filesystem | Standard default type for Linux filesystems (ext2, ext3, ext4, XFS, btrfs). |
82 | Linux swap / Solaris | Dedicated virtual memory swap partition. |
8e | Linux LVM | Physical Volume (PV) dedicated to the Logical Volume Manager subsystem. |
fd | Linux RAID auto-detect | Software RAID array member managed by mdadm with kernel autodetect support. |
05 / 0f | Extended Partition | Container partition for logical drives (05 for CHS addressing, 0f for LBA addressing). |
0b / 0c | W95 FAT32 / FAT32 (LBA) | Windows FAT32 filesystem commonly used on USB flash drives and shared media. |
07 | HPFS / NTFS / exFAT | Windows NT filesystem and Microsoft exFAT storage media. |
ef | EFI System Partition (ESP) | UEFI boot partition formatted as FAT32 containing .efi bootloader binaries. |
💡 LPIC-1 Exam Fill-in-the-Blank Alert: What hexadecimal code must be entered in
fdiskto set a partition's type to Linux LVM? Answer:8e
5. GUID Partition Table (GPT) & gdisk Management
Modern hardware with Unified Extensible Firmware Interface (UEFI) firmware replaces legacy MBR with the GUID Partition Table (GPT) standard (defined under the UEFI specification):
Key Architectural Features of GPT
- Massive Capacity & 64-Bit LBAs: GPT utilizes 64-bit logical block addresses, supporting maximum partition and disk capacities up to 8 Zebibytes (8 ZiB = 9.44 x 10^21 bytes).
- Arbitrary Partition Count: The standard GPT specification reserves 33 sectors for partition entries. With each entry sized at 128 bytes, GPT natively supports 128 primary partitions by default without requiring extended or logical containers.
- Redundant Backup Headers: GPT writes a Primary GPT Header at LBA 1 and duplicates the entire table as a Secondary (Backup) GPT Header at the final physical sectors of the disk, protecting against header corruption.
- Protective MBR (LBA 0): GPT places a legacy MBR structure at LBA 0 with a single partition of type
0xeecovering the entire disk. This prevents legacy MBR-only tools from misidentifying the disk as blank and overwriting data. - Globally Unique Identifiers (GUIDs): Every GPT partition is assigned a unique 128-bit GUID (e.g.,
UUID="a1b2c3d4-..."), allowing persistent identification regardless of hardware bus reordering.
The gdisk (GPT fdisk) Utility
gdisk provides an interactive, text-mode command interface specifically engineered for GPT disks, matching the keystroke semantics of fdisk:
# Launch gdisk on secondary drive
# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.8
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help):
gdisk Commands & 4-Digit Hex Codes
While gdisk shares standard commands (p print, n new, d delete, w write, q quit, v verify), it introduces the x command to access the expert / advanced functionality menu (for partition table alignment, GUID alteration, and backup header recovery).
Furthermore, gdisk uses 4-digit hexadecimal type codes by taking the legacy 2-digit MBR code and appending 00:
gdisk 4-Digit Code | Partition Type | Equivalent MBR Code |
|---|---|---|
8300 | Linux filesystem (ext4, xfs, btrfs) | 83 |
8200 | Linux swap | 82 |
8e00 | Linux LVM | 8e |
ef00 | EFI System Partition (ESP) | ef |
fd00 | Linux RAID | fd |
0700 | Microsoft basic data (NTFS / FAT) | 07 |
6. Partition Discovery & Kernel Table Synchronization
When you modify and write a partition table on an active system, the Linux kernel may still hold the old partition map in memory if any partition on that device is currently mounted. If the kernel cannot automatically reload the table, fdisk outputs the warning:
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at the next reboot.
To force the running Linux kernel to re-read the partition table without rebooting the server, administrators use partprobe or partx.
1. partprobe
Part of the GNU parted package, partprobe requests that the operating system kernel re-read the partition tables on all disks or a specific block device:
# Inform kernel of partition changes on all attached drives
# partprobe
# Inform kernel of partition changes on a specific device
# partprobe /dev/sdb
2. partx
Part of util-linux, partx tells the kernel driver about the presence and numbering of on-disk partitions:
# Update the kernel's partition table map for /dev/sdb
# partx -u /dev/sdb
# Add all partitions found on /dev/sdb to the kernel map
# partx -a /dev/sdb
# Delete partition 3 from the kernel's runtime device map
# partx -d --nr 3 /dev/sdb
3. lsblk and blkid for Partition Discovery
# List all block devices in a visual hierarchy with filesystem types and UUIDs
$ lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 vfat FAT32 BOOT 5A21-098F 480.2M 6% /boot/efi
├─sda2 ext4 1.0 ROOT a28b12f4-7e11-42b8-a6d1-817290123456 38.4G 42% /
└─sda3 swap 1 SWAP d1e02934-8c01-4478-b112-998877665544 [SWAP]
sdb
└─sdb1 xfs DATA 7f31c201-3810-47b2-8431-a0b1c2d3e4f5 192.5G 3% /mnt/data
# Inspect block device attributes including UUID and filesystem TYPE
# blkid /dev/sda2
/dev/sda2: UUID="a28b12f4-7e11-42b8-a6d1-817290123456" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="00084321-02"
💡 LPIC-1 Exam Fill-in-the-Blank Alert: What utility informs the Linux operating system kernel of partition table changes without requiring a system reboot? Answer:
partprobe(orpartx)
A Linux administrator is creating a partition on /dev/sda using fdisk to be used as a physical volume in a Logical Volume Management (LVM) volume group. Which hexadecimal partition type code must be entered in fdisk?
An administrator installs a high-speed PCIe NVMe solid-state drive into a Linux server. The kernel registers the whole drive under controller 0, namespace 1. What is the standard device node path for the first partition on this drive?
While using the interactive fdisk utility to partition a new 1 TiB hard drive, which command must be entered to commit the newly created partition table entries to disk and exit the tool?