Disk Structure & Layout

Learn how logical block addressing, GPT, and UEFI organize disks, with CHS explained as historical context.

published: reading time: 33 min read author: Geek Workbench
Quick Summary

Learn how logical block addressing, GPT, and UEFI organize disks, with CHS explained as historical context.

Disk Structure & Layout

A storage device presents logical blocks to the operating system. Partition tables describe ranges of those blocks, and filesystems organize data inside the ranges. Older BIOS interfaces also exposed Cylinder-Head-Sector (CHS) addressing; that geometry is useful for understanding historical limits, not for describing the physical layout of a modern SSD or NVMe drive.

MBR and GPT still describe partition layouts. CHS appears in legacy boot and compatibility material, while current operating systems address storage with logical block addresses (LBAs). A drive controller or virtualized storage layer maps those logical addresses to its own internal media; host software cannot infer an SSD’s physical geometry from CHS values.

Introduction

Disk structure and layout describes how storage devices organize data at the lowest level—from the raw sectors on magnetic platters or NAND flash cells up to the partition tables and file systems that operating systems use. Every storage device, whether a spinning hard drive or a modern NVMe SSD, presents a linear array of addressable sectors. How those sectors get divided into partitions, identified by type codes, and aligned to physical characteristics forms the subject of disk layout.

The partition table records where partitions begin and end, their type, and, in a boot setup, which firmware path can use them. MBR’s 32-bit sector fields created a size limit with 512-byte sectors; GPT uses 64-bit LBAs and keeps a backup header. Alignment and logical sector size still matter, but a CHS conversion is only a teaching model for legacy addressing.

This guide covers CHS as a historical compatibility scheme, current LBA addressing, MBR and GPT, and the UEFI boot path. The commands use disposable image files. Partition repair and formatting can destroy data, so do not point them at a live disk.

When to Use / When Not to Use

Understanding disk structure is essential for system administration, troubleshooting, and performance optimization.

When disk structure knowledge matters:

  • Setting up new systems with proper partitioning
  • Troubleshooting boot issues and partition problems
  • Recovering data from damaged partitions
  • Working with legacy systems that hit addressing limits
  • Configuring RAID and understanding redundancy

When you can ignore it:

  • Working purely with cloud block storage (abstracted away)
  • Using container systems with volumes
  • Dealing with fully abstracted storage (some NAS systems)
  • High-level application development (file I/O handles this)

Architecture or Flow Diagram

graph TD
    A[Logical Block Address LBA] --> B[Host System]
    B --> C[Storage Controller]
    C --> D[Disk Firmware]
    D --> E[Physical Media]

    F[CHS Geometry] --> C
    G[Partition Table MBR/GPT] --> F

    style A stroke:#ff00ff,stroke-width:2px
    style G stroke:#ff00ff,stroke-width:2px

The diagram shows the translation from logical addressing (LBA) to physical media. The partition table sits between the host’s view of the drive and the actual physical layout.

Core Concepts

CHS Addressing: The Old Geometry

Cylinder-Head-Sector (CHS) is a historical addressing scheme. Its fields described a compatibility geometry presented to firmware and software; they should not be read as the physical layout of modern storage. In the teaching model, each component means:

  • Cylinder: The set of tracks at the same radial position across all surfaces
  • Head: Which read/write head is active (which surface)
  • Sector: Which sector within the track (typically 512 bytes)
graph TD
    A[Disk Platter] --> B[Concentric Tracks]
    B --> C[Track 0 outermost]
    B --> D[Track N innermost]

    E[Cylinder] --> F[Track on Surface 0]
    E --> G[Track on Surface 1]
    E --> H[Track on Surface N]

    style C stroke:#ff00ff
    style D stroke:#ff00ff

In the old rotating-disk model, a CHS address selected a cylinder, head, and sector. Modern drives and SSDs translate logical block requests internally; the host does not position a head using these values.

Limitations:

  • Legacy BIOS CHS fields and translation conventions imposed capacity limits; the exact limit depended on the interface and translation scheme
  • Drives often reported compatibility geometry that did not match their physical media
  • LBA replaced CHS in normal host I/O

LBA: Logical addressing

Logical Block Addressing (LBA) presents storage as numbered logical sectors. The device or storage stack maps those addresses internally; they do not reveal physical NAND placement or platter geometry.

  • LBA 0 = first sector (cylinder 0, head 0, sector 1)
  • LBA 1 = second sector
  • LBA n = (n+1)th sector
// LBA to CHS conversion (simplified)
void lba_to_chs(uint32_t lba, uint16_t *cyl, uint8_t *head, uint8_t *sector) {
    uint32_t sectors_per_track = 63;  // Traditional value
    uint32_t tracks_per_cylinder = 16; // Traditional value

    *sector = (lba % sectors_per_track) + 1;
    uint32_t temp = lba / sectors_per_track;
    *head = temp % tracks_per_cylinder;
    *cyl = temp / tracks_per_cylinder;
}

LBA-48 (48-bit LBA) supports drives up to 144 petabytes—more than enough for current storage needs.

Disk Geometry and Zones

Modern drives use zones to pack more data onto the platter without choking read speeds. The reasoning is basic physics: a platter spins at a fixed RPM, so the outer edge sweeps through more territory per rotation than the inner tracks. Drives take advantage of this by fitting more sectors into outer tracks and fewer into inner ones.

graph LR
    A[Zone 0<br/>Outer tracks<br/>Higher density<br/>Faster] --> B[Zone 1]
    B --> C[Zone N<br/>Inner tracks<br/>Lower density<br/>Slower]

    style A stroke:#ff00ff,stroke-width:2px
    style C stroke:#ff00ff,stroke-width:1px

This technique goes by a few names—zoned recording, zoned bit recording, or multi-zone recording. It splits the platter into radial bands. Each band keeps a constant sectors-per-track count. Zone 0 (outermost) might hold 2000 sectors per track while Zone N (innermost) holds 1000. The drive firmware handles the conversion to LBA transparently, so your OS just sees a flat sequence of sectors.

The upshot is that you get more storage and decent read speeds without having to make trade-offs. Without zoning, you’d either waste space on the inner tracks or watch throughput tank as the head moved inward. The firmware adjusts data rate depending on which zone you’re reading from, which smooths out the transfer curve.

You can see this when benchmarking or setting up RAID. Two drives with identical RPM ratings can post very different transfer curves if their zone layouts differ. SMART data sometimes reports zone information, and hdparm -I occasionally surfaces the sectors-per-track profile. For partitioning, zone alignment doesn’t matter much on modern hardware—the firmware handles it—but on older drives with cruder translation logic, starting a partition at a zone boundary can sidestep some odd behavior.

Sector Size and Advanced Format

Modern drives present different sector sizes to the host system. Three models exist:

  • 512n (512-byte native): Traditional drives where both logical and physical sectors are 512 bytes. No translation needed.

  • 512e (512-byte emulation): Most modern drives use 4KB physical sectors internally but emulate 512-byte logical sectors for compatibility. When the host writes to what it believes is a 512-byte sector, the drive actually reads the 4KB physical sector, modifies the 512 bytes, and writes the whole 4KB back. Misaligned writes cause read-modify-write penalties that degrade performance.

  • 4Kn (4KB native): Enterprise drives that present 4KB logical sectors directly. Benefits include more efficient large sequential I/O and eliminated emulation overhead. Some legacy operating systems and tools still assume 512-byte sectors and struggle with 4Kn drives.

The “Advanced Format (AF)” designation applies to drives using 4KB physical sectors, whether 512e or 4Kn. When partitioning 512e drives, alignment to 4KB boundaries (or at minimum 8-sector boundaries) prevents the read-modify-write penalty.

Partition Schemes

The MBR lives in the first 512 bytes of the disk—a design decision rooted in early disk hardware. Spinning platters standardized on 512-byte sectors, so reading the first sector meant reading exactly 512 bytes. That single sector became the natural place to store boot code: something small enough to fit, predictable enough for the BIOS to find, and isolated enough to be written without touching user data. The 512-byte boot sector stuck around even as drive capacities grew from megabytes to terabytes. Every BIOS in every x86 system expects to find valid boot code at this fixed location, making the MBR the de facto gatekeeper for every spinning drive ever made.

The MBR must do several things in that 512 bytes. First, it holds a small executable that the CPU runs after POST. Second, it stores the partition table—the map of where partitions begin and end, what type of data they hold, and which one is bootable. Third, it ends with a magic number (0x55AA) at offset 510-511. The BIOS checks that magic byte before attempting to boot. If it’s missing, the BIOS treats the disk as unformatted and refuses to boot from it. This simple validation prevents the system from trying to execute random data as code.

When a drive powers on and the BIOS selects it as the boot device, the disk controller reads exactly 512 bytes from LBA 0 into memory at address 0x7C00. The CPU then begins executing whatever instruction sits there. If the boot code is corrupted, the system hangs or prints a cryptic error. If the partition table is wiped, the OS cannot find where its own partitions begin—every file system on the drive becomes inaccessible even if the data itself is intact. The boot sector is the single point of failure for the entire boot process.

The partition table portion of the MBR is deliberately small: 64 bytes divided into four 16-byte entries. This is why MBR supports a maximum of four primary partitions. Each entry records the starting cylinder-head-sector address, the ending address, the partition type byte, and the starting LBA as a 32-bit value. The type byte is what tells the OS which file system lives in that partition—0x83 for Linux, 0x07 for NTFS, 0x0C for FAT32. When this table is overwritten (by malware, accidental dd, or a failed partition resize), the OS loses all knowledge of the drive’s layout. The data remains on disk but becomes unreachable without recovery tools that scan for file system signatures.

MBR: The Legacy Standard

Master Boot Record occupies the first 512 bytes of the disk:

graph TD
    A[MBR Structure 512 bytes] --> B[Boot Code 446 bytes]
    A --> C[Partition Table 64 bytes]
    A --> D[Magic Number 0x55AA 2 bytes]

    C --> E[Partition 1 16 bytes]
    C --> F[Partition 2 16 bytes]
    C --> G[Partition 3 16 bytes]
    C --> H[Partition 4 16 bytes]

    style B stroke:#ff00ff
    style D stroke:#ff00ff

Each partition entry stores:

  • Boot flag: 0x80 for bootable, 0x00 otherwise
  • Starting CHS: First sector location
  • Partition type: File system identifier (0x83 = Linux, 0x07 = NTFS, 0x0C = FAT32)
  • Ending CHS: Last sector location
  • Starting LBA: First sector as 32-bit value
  • Size: Number of sectors as 32-bit value

MBR Limitations:

  • Maximum 2TB per partition (32-bit sector count)
  • Maximum 4 primary partitions (or 3 primary + 1 extended)
  • No backup partition table
  • No checksum for partition data

GPT: The Modern Standard

GUID Partition Table removes MBR’s limitations:

graph TD
    A[GPT Layout] --> B[Protective MBR 512 bytes]
    A --> C[Primary GPT Header 92 bytes]
    A --> D[Primary GPT Array 16KB min]
    A --> E[Backup GPT Header]
    A --> F[Backup GPT Array]

    style B stroke:#00fff9
    style C stroke:#ff00ff
    style E stroke:#00fff9
    style F stroke:#00fff9

GPT Advantages:

  • Supports drives up to 8ZB (using 64-bit sector addresses)
  • Unlimited partitions (practical limit ~128)
  • Backup GPT headers at end of disk
  • CRC32 checksums for integrity
  • Unique partition GUIDs for reliable identification

UEFI Boot and GPT

UEFI firmware can locate an EFI System Partition (ESP) on a GPT disk and load a boot application from it. The firmware and bootloader path is separate from the operating system’s later filesystem access:

flowchart LR
    A[UEFI firmware] --> B[GPT partition map]
    B --> C[EFI System Partition]
    C --> D[EFI boot application]
    D --> E[Operating system loader]
    E --> F[Kernel]

The boot process differs from legacy BIOS/MBR:

  1. UEFI firmware initializes and looks for an EFI System Partition (ESP)
  2. ESP contains bootloaders in EFI/BOOT/BOOTX64.EFI (or platform-specific paths)
  3. UEFI firmware reads the ESP’s FAT32 file system directly—no boot sector code needed
  4. Bootloader loads the operating system kernel

The Protective MBR exists at sector 0 for backward compatibility. Legacy tools that don’t understand GPT see a single partition of type 0xEE spanning the entire disk, preventing them from offering to “initialize” or re-partition the drive.

UEFI Secure Boot extends this process with digital signature validation:

  1. Firmware verifies bootloader signature against keys in NVRAM (Platform Key, KEK, db)
  2. Signed bootloaders (like Microsoft-signed Windows bootloaders) pass validation
  3. Bootloader must also verify the kernel signature before transferring control

For dual-boot setups with Windows and Linux on GPT, both OSes must boot via UEFI. Mixing BIOS-mode and UEFI-mode installations on the same disk causes boot failures.

Safe disposable-image exercise

This exercise creates a GPT on a temporary file, not a physical device. Run it from a directory where you have space for a small image:

lab_dir=$(mktemp -d)
lab_image="$lab_dir/lab.img"
truncate -s 64M "$lab_image"
sgdisk --clear --new=1:2048:0 "$lab_image"
sgdisk --print "$lab_image"

The file is temporary and the command writes only to that file. Do not replace lab_image with a /dev/ path. Delete the temporary directory when you are done.

Partition Type Identifiers

Common MBR partition types:

Type Description
0x83 Linux
0x82 Linux swap
0x8E Linux LVM
0x07 Windows NTFS
0x0C FAT32
0xEE GPT protective
0xEF EFI System Partition

Production Failure Scenarios

The examples below are diagnostic walkthroughs, not instructions to repair a live disk. Use a copy or disposable disk image. Any command that writes a partition table, filesystem, or boot metadata can make recovery harder.

Scenario 1: MBR Corruption

What happened: A server’s first drive failed catastrophically. The data recovery team retrieved most files, but the partition table was gone. Without it, the operating system couldn’t find where partitions began and ended.

Detection:

# Check for valid GPT/MBR signature
sudo fdisk -l disk-lab/lab.img | grep -E "Disklabel|GPT|MBR"

# Try to identify partitions with testdisk
sudo testdisk disk-lab/lab.img

Mitigation:

  • Backup partition table regularly:

    sudo sfdisk -d disk-lab/lab.img > partitions_backup.txt
  • Use GPT which has backup headers

  • Keep rescue media with partition tools

  • Clone partition table when setting up similar systems

Scenario 2: Overlapping Partitions

What happened: A user attempted to resize a partition using a disk management tool. The tool crashed mid-operation, leaving overlapping partitions. The kernel refused to mount the file system, and fsck failed.

Detection:

# Use parted to detect overlaps
sudo parted disk-lab/lab.img
(parted) align-check optimal 1  # Check partition 1 alignment
(parted) align-check optimal 2  # Check partition 2 alignment

# Check partition table for overlaps
sudo gdisk -l disk-lab/lab.img | grep -A 4 "unique GUIDs"

Mitigation:

  • Always backup before partition operations
  • Use tools that handle interruptions gracefully (parted vs fdisk)
  • Use rescue mode with TestDisk for recovery
  • Consider recreating partitions and restoring from backup

Scenario 3: 2TB Limit Encounter

What happened: A company purchased a 4TB drive for backup. The system only saw 2TB. The drive was using MBR partitioning, which maxes out at 2TB with 512-byte sectors.

Detection:

# Check partition table type
sudo parted disk-lab/lab.img
(parted) print

# See output like:
# Model: ATA ST4000DM000-1F2 (scsi)
# Example disk: 4000GB
# Partition table: msdos  <-- This is MBR!

Mitigation:

  • Convert to GPT using gdisk:

    sudo gdisk disk-lab/lab.img
    # Type 'w' to convert MBR to GPT (backup MBR first!)
  • For boot drives, ensure UEFI boot support exists

  • Plan for GPT on drives larger than 2TB

Trade-off Table

Aspect MBR GPT Notes
Max Drive Size 2TB 8ZB MBR limited by 32-bit sector count
Max Partitions 4 primary 128 primary GPT practical limits
Backup None Header + array at end Automatic with GPT
Boot Support BIOS only UEFI required for boot Legacy systems use MBR
Integrity None CRC32 checksums GPT validates structure
Partition IDs 1-byte type 128-bit GUID GPT more precise

Implementation Snippet

Reading Partition Table with Python

import struct

def read_mbr(device_path):
    """Read and parse MBR partition table."""
    with open(device_path, 'rb') as f:
        # Read boot sector (512 bytes)
        boot_sector = f.read(512)

        # Verify magic number
        if boot_sector[510:512] != b'\x55\xaa':
            raise ValueError("Invalid MBR signature")

        # Parse partition table (64 bytes starting at offset 446)
        partitions = []
        for i in range(4):
            entry_offset = 446 + (i * 16)
            entry = boot_sector[entry_offset:entry_offset + 16]

            if entry[0] == 0:  # Empty partition
                continue

            partition = {
                'boot_flag': entry[0],
                'start_head': entry[1],
                'start_sector_cylinder': struct.unpack('<H', entry[2:4])[0],
                'type': entry[4],
                'end_head': entry[5],
                'end_sector_cylinder': struct.unpack('<H', entry[6:8])[0],
                'start_lba': struct.unpack('<I', entry[8:12])[0],
                'size_sectors': struct.unpack('<I', entry[12:16])[0],
            }
            partitions.append(partition)

        return partitions

def print_partitions(device_path):
    """Display partition information."""
    TYPE_NAMES = {
        0x07: 'NTFS/HFS+',
        0x83: 'Linux',
        0x82: 'Linux Swap',
        0x8E: 'Linux LVM',
        0x0C: 'FAT32',
        0xEE: 'GPT Protective',
        0xEF: 'EFI',
    }

    parts = read_mbr(device_path)
    for i, p in enumerate(parts):
        ptype = TYPE_NAMES.get(p['type'], f'Unknown (0x{p:02x})')
        size_gb = (p['size_sectors'] * 512) / (1024**3)
        print(f"Partition {i+1}: {ptype}, Start LBA: {p['start_lba']}, "
              f"Size: {size_gb:.2f} GB")

if __name__ == "__main__":
    import sys
    print_partitions(sys.argv[1] if len(sys.argv) > 1 else "disk-lab/lab.img")

Inspecting GPT with bash

#!/bin/bash
# gpt_inspect.sh - Display GPT partition information

DEVICE=${1:-disk-lab/lab.img}

echo "=== GPT Partition Table for $DEVICE ==="

# Check for GPT
if ! sudo gdisk -l "$DEVICE" 2>/dev/null | grep -q "GPT:"; then
    echo "Not a GPT disk"
    exit 1
fi

# List partitions
sudo gdisk -l "$DEVICE" <<< "p"

# Show partition details
echo ""
echo "=== Detailed Partition Info ==="
for part_num in $(seq 1 128); do
    info=$(sudo gdisk -l "$DEVICE" 2>/dev/null | grep "^$part_num ")
    if [ -n "$info" ]; then
        echo "$info"
    fi
done

# Show backup GPT location
echo ""
echo "=== GPT Backup Header Location ==="
sudo gdisk -l "$DEVICE" | grep -E "Backup|Sector"

Observability Checklist

Monitoring disk structure health:

  • fdisk -l /dev/sdX: List partition table and verify signatures
  • gdisk -l /dev/sdX: Show GPT information and GUIDs
  • parted /dev/sdX print: Display partition layout
  • lsblk: Show block devices and their hierarchy
  • blkid: Show UUID and TYPE for each partition

Key checks:

# Verify MBR/GPT signatures
sudo fdisk -l disk-lab/lab.img 2>/dev/null | grep "Disklabel"
# Should show: Disklabel type: dos (MBR) or gpt

# Check for backup GPT
sudo gdisk -l disk-lab/lab.img | grep "Backup GPT"
# Should show location at end of disk

# Monitor partition alignment
sudo parted disk-lab/lab.img align-check opt
# Should show "1 aligned" for each partition

# Verify partition doesn't exceed disk size
cat /proc/partitions

Common Pitfalls / Anti-Patterns

The following write examples target disk-lab/lab.img, a disposable file. Do not substitute a live /dev/ device. Keep a separate copy before changing a partition table.

Partition Table Manipulation

Converting MBR to GPT without a backup is a common mistake that causes data loss when the conversion is interrupted:

# BAD: Converting without backup
sudo gdisk disk-lab/lab.img
Command: m  # Load MBR, convert in place
Command: w  # WRITE (data loss possible if interrupted!)

# GOOD: Backup first, then convert
sudo sfdisk -d disk-lab/lab.img > mbr_backup.txt
sudo dd if=disk-lab/lab.img of=mbr_sector_512.img bs=512 count=1
# Now safe to convert

Manually calculating partition boundaries often causes overlap. Tools like parted validate boundaries and prevent this:

# BAD: Manually calculating can cause overlap
# Partition 1: 2048-4096 (1MB)
# Partition 2: 4095-8192 (overlaps!)
#                 ^^^ Should be 4096, not 4095

# GOOD: Use tools that prevent overlap
sudo parted disk-lab/lab.img mkpart primary ext4 2048s 4096s
sudo parted disk-lab/lab.img mkpart primary ext4 4096s 8192s
# parted validates and prevents overlap

Partition Alignment

Misaligned partitions cause performance problems on SSDs and modern HDDs. Modern drives require 1MB alignment (2048 sectors of 512 bytes):

# BAD: Default alignment might be wrong
sudo fdisk disk-lab/lab.img  # May create misaligned partitions

# GOOD: Specify alignment
sudo parted disk-lab/lab.img mkpart primary ext4 2048s 100%
# Use sector numbers that are multiples of 2048

The MBR boot flag causes confusion because it only matters for BIOS boot. Modern UEFI ignores it entirely:

# Set boot flag (only matters for legacy BIOS boot)
sudo fdisk disk-lab/lab.img a 1  # Set boot flag on partition 1

# Clear boot flag
sudo fdisk disk-lab/lab.img a 0  # Clear boot flag

UEFI and Secure Boot

When setting up UEFI systems, the EFI System Partition (ESP) has specific requirements:

  • ESP must be formatted as FAT32
  • ESP size recommendation: 100-500MB (1GB to accommodate multiple OS bootloaders)
  • ESP must have partition type code EF00 in GPT
# Create EFI partition with gdisk
# Type: EF00 (EFI System Partition)
sudo gdisk disk-lab/lab.img
Command: n
Partition number: 1
First sector: [default]
Last sector: +512M
Hex code: EF00

Data Security and Compliance

Simply deleting a partition doesn’t erase the data—it only removes the partition table entry. For secure erasure, use the storage vendor’s documented sanitize or secure-erase procedure only after confirming the target device, backups, and applicable retention requirements. Do not run a wipe command on a production or mounted device. A partition-table deletion does not erase the underlying data. GPT assigns unique GUIDs to each partition. Document these for compliance and disaster recovery:

# List partition UUIDs
sudo blkid

# Or with gdisk
sudo gdisk -l disk-lab/lab.img | grep -E "Partition GUID|unique"

# Export for documentation
sudo blkid -s UUID -s TYPE -s LABEL > partition_ids.txt

Quick Recap Checklist

  • CHS is a historical compatibility model; current host I/O uses logical block addresses
  • MBR supports max 2TB and 4 primary partitions; GPT removes these limits
  • GPT includes backup headers at end of disk for recovery
  • Always backup partition table before making changes
  • Convert MBR to GPT for drives larger than 2TB
  • Use sector alignment of 2048 (1MB) for modern disks
  • Partition type codes identify the file system; GPT uses 128-bit GUIDs

Interview Questions

1. Explain the difference between CHS and LBA addressing.

CHS (Cylinder-Head-Sector) is a historical compatibility addressing scheme. Its cylinder, head, and sector values do not describe the physical layout of a modern SSD or NVMe drive. Legacy firmware used translated geometry, which imposed addressing limits that helped motivate LBA.

LBA (Logical Block Addressing) treats the disk as a simple linear array of sectors numbered from 0. The drive firmware translates LBA addresses to physical geometry internally. LBA-28 supports up to 128GB, LBA-48 supports up to 144PB. This is the universal standard today.

Modern host I/O uses logical block addresses. The storage device or virtualized layer maps them internally; this is not a CHS conversion that applications can observe.

2. What are the key differences between MBR and GPT partition tables?

MBR (Master Boot Record) occupies the first 512 bytes of the disk and contains:

  • Boot code (446 bytes)
  • Partition table (64 bytes) — only 4 entries
  • Magic number (0x55AA)

Limitations: 2TB max partition size, 4 primary partitions, no backup, no integrity checking.

GPT (GUID Partition Table) uses:

  • Protective MBR (first 512 bytes) for legacy compatibility
  • Primary GPT header at sector 1 (92 bytes)
  • Partition entry array (minimum 16KB, typically 128 entries of 128 bytes each)
  • Backup GPT at end of disk

Advantages: 8ZB max, 128+ partitions, CRC32 checksums, unique GUIDs for each partition.

3. Why can't a 3TB drive work with MBR partitioning?

MBR stores partition size as a 32-bit sector count. With standard 512-byte sectors, this limits the maximum addressable capacity to:

2^32 sectors × 512 bytes/sector = 2,199,023,255,552 bytes ≈ 2.2 TB

A 3TB drive has more than 2^32 sectors, so the partition size value overflows. The operating system either shows only 2TB or behaves erratically.

The solution is GPT partitioning, which uses 64-bit sector counts (allowing 8ZB) and doesn't have this limitation.

4. What happens when you delete a partition in Linux?

When you delete a partition (e.g., with fdisk or parted):

  1. The partition table entry is cleared (zeroed out)
  2. No data on disk is modified — only the partition table
  3. Until you run partprobe or reboot, the kernel may still use old table
  4. Data remains on disk but is now "orphaned"

To actually recover the partition, tools like TestDisk scan the disk for file system signatures and can often reconstruct the partition table by finding the begin and end markers of each partition.

This is why backing up the partition table before making changes is critical—you can restore it if something goes wrong.

5. How would you recover a accidentally deleted GPT partition?

Recovery steps:

  1. Don't write anything to the disk — every write could overwrite backup GPT structures
  2. Work from a copy: preserve the original image and inspect the copy with read-only tools.
  3. Use TestDisk on the copy: testdisk disk-lab/lab.img
    • Select the disk and choose EFI/GPT
    • Analyze to find partition boundaries
    • Search for lost partitions
    • Write the recovered partition table
  4. Or use gdisk: The backup GPT at end of disk can be restored: gdisk disk-lab/lab.img then inspect the recovery menu; do not write changes until the image has been copied and the proposed table reviewed
  5. Verify: reopen the image in a partition tool and compare the proposed layout with the backup; do not run mount -a on a host system.

Before changing a partition table, make a separate copy of the image and save a partition-table dump. For real recovery, work from a verified forensic copy and follow your organization's recovery procedure.

6. What is LBA-48 and why was it needed?

LBA-48 extended the original LBA standard (LBA-28) from 28 bits to 48 bits of sector addressing. This was necessary because:

2^28 sectors × 512 bytes = 128 GB maximum addressable capacity

As drives grew past 128GB, a new standard was required. LBA-48 uses 48-bit sector addresses:

2^48 sectors × 512 bytes = 144 PB (petabytes)

LBA-48 support is required for drives larger than 128GB. Most modern drives and controllers support LBA-48, and the operating system automatically negotiates the highest supported mode.

7. Why do SSDs still show the same partition schemes (MBR/GPT) as HDDs?

SSDs present themselves as block devices just like HDDs—they share the same logical interface. The partition scheme (MBR or GPT) is a software concept, not a hardware requirement. SSDs use:

  • Same addressing: SSDs use LBA addressing just like HDDs, making them compatible with existing partitioning tools
  • Wear leveling: The SSD controller handles physical to logical block mapping internally, presenting a clean linear LBA space to the host
  • Trim and garbage collection: The SSD manages free space internally; partition alignment just ensures efficient block erasure

The partition table still matters for boot loaders, file system boundaries, and OS recognition, but the underlying storage technology is abstracted away.

8. What is the difference between primary, extended, and logical partitions in MBR?

Primary partitions: The only partitions that can boot an OS. MBR supports maximum 4 primary partitions. All data storage happens in primary partitions.

Extended partition: A special primary partition that acts as a container. It consumes one of the 4 primary partition slots but doesn't hold data directly—instead, it holds logical partitions.

Logical partitions: Created within the extended partition. The extended partition's partition table (stored differently from MBR's main table) can hold many logical partitions—practical limit is typically 12-15 due to drive geometry constraints.

This design allowed more than 4 partitions while maintaining backward compatibility. A typical setup: sda1 (Windows), sda2 (Linux), sda3 (extended containing sda5, sda6, sda7 for data).

9. How does sector size (512-byte vs 4KB) affect storage capacity calculations?

Storage capacity is calculated as: total sectors × sector size

With 512-byte sectors, a drive with 4,094,496,000 addressable sectors = 2TB (4,094,496,000 × 512 = 2,199,023,555,200 bytes).

With native 4KB sectors, the same drive would have 511,812,000 addressable sectors = 2TB (511,812,000 × 4096 = 2,097,152,000,000 bytes).

4KB native drives (4Kn): The drive reports 4KB sectors to the host. Benefits: more efficient for large sequential I/O, better for RAID alignment.

512e (512-byte emulation): The drive internally uses 4KB sectors but presents 512-byte sectors to the host for compatibility. Performance can degrade if writes aren't aligned to 4KB boundaries.

10. What is the EFI System Partition (ESP) and what are its requirements?

The EFI System Partition (ESP) is a partition required for UEFI boot. It contains:

  • Bootloader files (e.g., EFI/Microsoft/Boot/bootmgfw.efi)
  • UEFI firmware drivers for file systems
  • Startup NVRAM configuration

Requirements:

  • File system: Must be FAT32 (per UEFI specification)
  • Size: 100MB minimum, 500MB recommended
  • Partition type: GPT partition type GUID = C12A7328-F81F-11D2-BA4B-00A0C93EC93B (EFI System Partition)
  • Location: Must be accessible without additional drivers (typically first partition)

Without a properly configured ESP, UEFI systems cannot boot. Some Linux installers create a 1GB ESP to accommodate multiple OS bootloaders.

11. How does BIOS disk I/O differ from direct ATA/IDE access in OS development?

BIOS disk I/O (int 0x13): Works only in 16-bit real mode, uses 24-bit segment:offset addressing (limited to 8GB), no DMA support, slow. Once the OS switches to protected mode, BIOS interrupts are unavailable — this is why OS developers must use direct I/O.

Direct ATA/IDE: The IDE controller exposes I/O ports (0x1F0-0x1F7 for primary channel). Reading/writing to these ports triggers DMA transfers, supports LBA48 addressing (>137GB), and works in protected mode. A minimal driver writes ATA registers to select drive, sector, and count, then triggers I/O. The in/out assembly instructions access these ports directly.

Modern SATA uses AHCI (Advanced Host Controller Interface) with memory-mapped registers and command queuing (NCQ) — a significant upgrade from legacy IDE.

12. What is the CHS to LBA translation and why does the 8GB barrier exist?

Teaching formula only: for a fixed legacy geometry, LBA = (C × heads_per_cylinder + H) × sectors_per_track + S - 1. The assumed heads and sectors describe a compatibility translation, not real SSD/NVMe geometry. Historical BIOS field widths and translation rules produced different limits.

Historical CHS limits: A geometry of 1024 cylinders, 16 heads, and 63 sectors yields about 528 MB. Other BIOS translation conventions exposed larger limits, including the often-cited 8.4 GB barrier. These figures describe legacy compatibility interfaces, not modern drive geometry; LBA and GPT removed the practical need for CHS addressing.

Solution: Use LBA addressing directly, bypass BIOS, use OS-native ATA drivers.

13. What happens during the MBR boot process and how does it locate the OS?

The MBR boot sequence:

  1. Power-on: CPU starts at physical address 0xFFFFFFF0 (reset vector) in ROM
  2. BIOS/UEFI initialization: POST (Power-On Self Test), detect boot device
  3. BIOS reads first 512 bytes (MBR) from boot device to 0x7C00
  4. BIOS validates 0xAA55 signature at offset 510-511
  5. If valid, BIOS jumps to 0x7C00 (transfer control to boot sector code)
  6. Boot sector code: parse partition table, find active (bootable) partition
  7. Load boot loader from first sector of active partition (or stage 2 from known location)
  8. Boot loader (e.g., GRUB) loads kernel from file system, passes control to kernel

For modern UEFI: BIOS is replaced by UEFI firmware which understands GPT and can directly read FAT32 filesystems to load bootloaders from the ESP — no MBR needed.

14. What is the protective MBR in GPT and why does it exist?

The protective MBR occupies the first 512 bytes of a GPT disk, identical to a standard MBR structure. It exists for backward compatibility:

  • Legacy tools (fdisk, older OS installers) see it and recognize the disk as " GPT" (partition type 0xEE) rather than "empty/unallocated"
  • Prevents tools from offering to "initialize" or "convert" the disk, which would destroy the GPT header
  • Protective MBR's partition entry spans the entire disk (or up to 2TB), marking all space as GPT-protected

If a legacy tool writes a new MBR over the protective MBR, it corrupts GPT. GPT-aware tools check for protective MBR but won't use it for partitioning — the actual partition data lives in the GPT header at sector 1.

15. Why does partition alignment matter for SSDs and what is the optimal alignment?

SSD partition alignment: Modern SSDs have erase block sizes (typically 4MB) larger than file system block sizes (4KB). Misaligned partitions cause read-modify-erase penalties:

  1. Write to a 4KB block that spans two erase blocks
  2. SSD must read both erase blocks, modify the 4KB, write both back
  3. This "read-modify-write" degrades performance and increases write amplification

Optimal alignment: 1MB (2048 sectors of 512 bytes) or 4MB (8192 sectors). Partition starting sector divisible by 2048 ensures alignment with SSD erase boundaries and RAID stripe sizes. Most modern tools (gdisk, parted) default to 2048-sector alignment.

Check with: sudo parted disk-lab/lab.img align-check opt — should report "1 aligned" for all partitions.

16. How does LVM interact with partition tables and what are the trade-offs?

LVM over partitions vs raw disks: LVM (Logical Volume Manager) sits on top of partitions or raw disks, adding a logical abstraction layer:

  • Partition: Single physical partition (for example, a partition in a lab image) becomes one Physical Volume (PV)
  • Volume Group: Combines multiple PVs into one storage pool
  • Logical Volumes: Virtual partitions carved from VG (e.g., /dev/vg0/home)

Trade-offs: Benefits — snapshot support, dynamic resizing, striping across disks. Drawbacks — added complexity, potential performance overhead from indirection, boot loaders may not understand LVM (use separate /boot partition), recovery more complex.

Typical setup: MBR/GPT partition table → Physical partitions → LVM PVs → VG → LVs → File systems.

17. What is the difference between physical sector size and logical sector size in modern storage?

Logical sector size: What the host system believes the sector size to be (typically 512 bytes for compatibility).

Physical sector size: The actual storage atom on the media (increasingly 4KB native).

Three models:

  • 512-byte native (512n): Old HDDs, some SSDs — both logical and physical are 512 bytes
  • 512-byte emulation (512e): Most modern drives — 4KB physical, 512-byte logical. Must handle unaligned writes correctly to avoid read-modify-write penalties.
  • 4KB native (4Kn): Enterprise drives — both are 4KB. Benefits: more efficient for large sequential I/O, eliminates emulation overhead. Drawback: some OSes and tools assume 512-byte sectors.

Storage capacity calculations depend on which sector size is used as the base unit.

18. How does disk firmware handle bad sectors and what is the role of remapping?

Bad sector remapping: HDD/SSD firmware maintains a "spare area" of extra sectors and a remapping table (G-list for grown defects):

  1. Factory defects: Sectors identified during manufacturing are remapped and recorded in P-list (primary defect list) — these are invisible to host
  2. Reallocated sectors: During operation, failing sectors are remapped — reported as "Reallocated Sectors" in SMART data
  3. Pending sectors: Weak sectors awaiting remapping — count indicates impending failure

When OS writes to LBA and firmware detects ECC error, it: (1) attempts to read with retries, (2) if unrecoverable, remaps to spare sector, (3) updates G-list, (4) returns success to OS. The OS never sees a bad sector — only the remapped address.

For a physical drive, `smartctl -a /dev/disk/by-id/your-drive-id` reads health data; replace the placeholder with the intended device and do not use it as a repair command.

19. How does Secure Boot interact with the partition table and boot process?

Secure Boot is a UEFI feature that validates digital signatures before executing boot code:

  1. UEFI firmware loads from ESP — looks for EFI/BOOT/BOOTX64.EFI (or platform-specific path)
  2. Verifies signature against keys stored in UEFI NVRAM (Platform Key, KEK, db)
  3. If signature valid, firmware transfers control to bootmanager
  4. Bootmanager (e.g., GRUB) must also be signed, loads kernel, verifies kernel signature

Interaction with partition table: Secure Boot doesn't care about MBR vs GPT — it only needs an accessible ESP with signed binaries. However, if MBR is corrupted, the system may not boot to the point where Secure Boot validation occurs. Secure Boot also requires the boot partition to be FAT32 (UEFI spec requirement).

20. How does RAID configuration affect partition table design and disk addressing?

RAID and partition tables: RAID can be implemented at hardware (RAID controller) or software (mdadm):

  • Hardware RAID: The RAID controller presents a "logical disk" to the OS. The OS partitions this logical disk without awareness of underlying physical disks. RAID controller handles striping, mirroring, and reconstruction.
  • Software RAID (Linux md): Multiple partitions on multiple physical disks are combined into a RAID array. Partition alignment must match RAID stripe size (typically 64KB-1MB) for optimal performance.

Addressing considerations: RAID changes the relationship between LBA addressing and physical storage. A single logical LBA may correspond to multiple physical locations (mirrored) or be striped across multiple drives. Partition boundaries should align with stripe boundaries to avoid partial-stripe writes that require read-modify-write cycles.

Further Reading

  • UEFI Specification: UEFI Forum — official UEFI specification including boot flow and ESP requirements
  • GPT and UEFI Boot: Intel Documentation — practical guide to GPT disk layout and UEFI boot process
  • Linux Partition Alignment: Red Hat Performance Tuning Guide — covers alignment for SSDs and RAID stripe sizes
  • GNU Parted Manual: parted.html — official documentation for partition manipulation tools
  • SMART Monitoring: smartmontools — tools for monitoring disk health and bad sector remapping
  • File System Abstraction: /blog/technical/file-system-abstraction/ — how operating systems layer file system components from application calls to physical storage
  • Boot Process: /blog/technical/boot-process/ — how the system transitions from firmware to operating system loader

Conclusion

Storage devices expose logical blocks; their internal media layout is not described by CHS. CHS remains useful as historical context for legacy firmware and MBR. Modern systems use LBA, while GPT stores partition ranges and a backup header. UEFI can load a boot application from an EFI System Partition.

Partition schemes define the layout, but file systems define the organization within those partitions. The partition table itself is just the starting point—understanding how the OS interprets that table and locates file system structures underneath prepares you for recovery scenarios, capacity planning, and dual-boot configurations. The fundamentals of disk geometry underpin everything from storage array configuration to data recovery.

Category

Related Posts

ASLR & Stack Protection

Explore ASLR, PIE, stack canaries, and NX on Linux with GCC, then inspect a harmless C program to see what each mitigation does and where it falls short.

#operating-systems #aslr-stack-protection #computer-science

Assembly Language Basics: Writing Code the CPU Understands

Learn x86-64 Linux assembly with the System V ABI: track registers, assemble and run a small program, debug it in GDB, then compare AArch64.

#operating-systems #assembly-language-basics #computer-science

Boolean Logic & Gates

Understanding AND, OR, NOT gates and how they combine into arithmetic logic units — the building blocks of every processor.

#operating-systems #boolean-logic-gates #computer-science