Pages

Jan 26, 2023

Linux Disk Partitioning Deep Dive: MBR, Extended Partitions, Logical Partitions, and fdisk Commands

Linux Disk Partitioning Deep Dive: MBR, Extended Partitions, Logical Partitions, and fdisk Commands

Disk partitioning is one of the most fundamental concepts in Linux system administration. Whether you are installing Linux, managing storage on a server, expanding disk capacity, or preparing disks for databases and applications, understanding partitioning is essential.

Many Linux administrators learn how to create partitions using tools such as fdisk, but often lack a deeper understanding of how disks are organized internally. To effectively manage storage, it is important to understand the relationship between physical disks, sectors, partition tables, MBR, extended partitions, logical partitions, filesystems, and memory structures used by the operating system.

This guide explores Linux disk partitioning from the ground up and includes practical examples using the fdisk utility.




Understanding Storage Hierarchy

Before discussing partitions, let's understand the storage hierarchy.

Physical Disk
      │
      ▼
Partition Table
      │
      ▼
Partitions
      │
      ▼
Filesystem
      │
      ▼
Mount Point
      │
      ▼
User Data

Example:

/dev/sda
    │
    ├── /dev/sda1
    ├── /dev/sda2
    └── /dev/sda5

Here:

  • /dev/sda = Entire Disk

  • /dev/sda1 = Primary Partition

  • /dev/sda2 = Extended Partition

  • /dev/sda5 = Logical Partition


How Data Is Stored on a Disk

A hard disk or SSD is divided into sectors.

Historically:

1 Sector = 512 Bytes

Modern disks often use:

1 Sector = 4096 Bytes

Disk layout:

+------------------------------------+
| Sector 0                           |
| MBR / Boot Record                  |
+------------------------------------+
| Partition Data                     |
+------------------------------------+
| Partition Data                     |
+------------------------------------+
| Filesystems                        |
+------------------------------------+

Every partition begins at a specific sector and occupies a range of sectors.


What Is a Partition Table?

The partition table is a data structure stored on the disk.

It tells the operating system:

  • Where partitions start

  • Where partitions end

  • Partition type

  • Boot information

Without a partition table:

Disk Exists
    │
    ▼
OS Cannot Locate Data

MBR (Master Boot Record)

The Master Boot Record is the traditional partitioning scheme.

Location:

Sector 0

Size:

512 Bytes

Structure:

+---------------------------+
| Bootloader Code (446 B)   |
+---------------------------+
| Partition Table (64 B)    |
+---------------------------+
| Signature (2 B)           |
+---------------------------+

The partition table portion can store information for only:

4 Primary Partitions

This limitation led to the creation of extended and logical partitions.


Primary Partitions

MBR supports up to four primary partitions.

Example:

/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4

Layout:

+---------+
| sda1    |
+---------+
| sda2    |
+---------+
| sda3    |
+---------+
| sda4    |
+---------+

No additional partitions can be created after all four entries are used.


Why Extended Partitions Exist

Users often need more than four partitions.

To solve this limitation:

One Primary Partition
          │
          ▼
Converted Into
          │
          ▼
Extended Partition

Example:

/dev/sda1  Primary
/dev/sda2  Primary
/dev/sda3  Primary
/dev/sda4  Extended

Logical Partitions

Logical partitions exist inside an extended partition.

Example:

/dev/sda5
/dev/sda6
/dev/sda7
/dev/sda8

Layout:

Disk
│
├── sda1
├── sda2
├── sda3
└── sda4 (Extended)
      │
      ├── sda5
      ├── sda6
      ├── sda7
      └── sda8

Notice:

Logical partitions start at 5

because partitions 1–4 are reserved for primary/extended entries.


Memory View of MBR Logical Partitions

Internally, Linux reads partition metadata into kernel memory.

Conceptually:

Kernel Memory
│
├── Partition Entry 1
├── Partition Entry 2
├── Partition Entry 3
└── Extended Entry
        │
        ▼
    EBR Chain
        │
        ├── Logical 5
        ├── Logical 6
        ├── Logical 7
        └── Logical 8

Each logical partition is described by an EBR (Extended Boot Record).


Extended Boot Record (EBR)

Unlike primary partitions stored directly in the MBR:

Primary → MBR Entry

Logical partitions use:

Logical → EBR Entry

Structure:

Extended Partition
│
├── EBR 1 → Logical 5
├── EBR 2 → Logical 6
├── EBR 3 → Logical 7
└── EBR 4 → Logical 8

This creates a linked-list style structure.


Viewing Existing Partitions

Display all disks:

lsblk

Example:

NAME   SIZE TYPE
sda    100G disk
├─sda1  20G part
├─sda2  20G part
└─sda5  60G part

Detailed view:

sudo fdisk -l

Creating a Logical Partition Using fdisk

Open the disk:

sudo fdisk /dev/sdb

Display current table:

p

Output:

Disk /dev/sdb

Create an Extended Partition

Press:

n

Choose:

e

Example:

Partition Type
p = primary
e = extended

Select:

e

Create a Logical Partition

Again press:

n

Choose:

l

Specify:

First Sector
Last Sector
Size

Example:

+20G

Verify Partition Table

Display:

p

Example:

/dev/sdb1
/dev/sdb2
/dev/sdb5

Write Changes

Save:

w

Kernel notification:

sudo partprobe

or

sudo partx -a /dev/sdb

Format the Logical Partition

Create ext4 filesystem:

sudo mkfs.ext4 /dev/sdb5

Output:

Creating filesystem
Writing superblocks
Done

Create Mount Point

sudo mkdir /data

Mount:

sudo mount /dev/sdb5 /data

Verify:

df -h

Output:

/dev/sdb5 20G mounted on /data

Persistent Mounting

Find UUID:

sudo blkid /dev/sdb5

Example:

UUID="8dfe-2345"

Edit:

sudo vi /etc/fstab

Add:

UUID=8dfe-2345 /data ext4 defaults 0 0

Test:

sudo mount -a

Important fdisk Commands

CommandPurpose
mHelp menu
pPrint partition table
nNew partition
dDelete partition
tChange partition type
lList partition types
aToggle boot flag
wWrite changes
qQuit without saving

MBR vs GPT

FeatureMBRGPT
Maximum Partitions4 Primary128+
Maximum Disk Size2 TB9.4 ZB
RedundancyNoYes
UEFI SupportLimitedFull
Modern SystemsLegacyRecommended

Most modern Linux systems use GPT instead of MBR, but understanding MBR, extended partitions, EBRs, and logical partitions remains important because many enterprise environments and legacy systems still rely on this partitioning scheme.


Conclusion

Logical partitions were introduced to overcome the four-partition limitation of the MBR partitioning scheme. By using an extended partition and a chain of Extended Boot Records (EBRs), Linux can support multiple logical partitions while maintaining compatibility with traditional MBR layouts.

Understanding how MBR stores partition metadata, how logical partitions are organized inside extended partitions, and how Linux discovers and mounts them provides a strong foundation for system administration, storage management, and troubleshooting. Combined with practical tools such as fdisk, lsblk, blkid, partprobe, and mkfs, administrators can confidently manage disk storage across a wide range of Linux environments.

No comments:

Post a Comment