Course Info / Syllabus

Labs

Lecture Topics

Exam Reviews

Source Code & Other Resources


Operating Systems Concepts & Design

Partition Tables

A partition table is essentially the “Map of the World” for your hard drive. It tells the BIOS or UEFI exactly where one partition ends and the next begins. Without it, the computer would see the entire disk as a giant, unorganized pile of raw binary data.

There are two main standards you will encounter: MBR (Master Boot Record) and GPT (GUID Partition Table).


1. MBR (Master Boot Record)

Introduced in 1983, MBR is the “Legacy” standard. It stores the partition table in the very first sector of the disk (Sector 0).


2. GPT (GUID Partition Table)

GPT is the modern standard that replaced MBR. it is part of the UEFI (Unified Extensible Firmware Interface) standard.


3. Key Components of a Partition Table

Regardless of the type, every entry in a partition table contains four vital pieces of information:

  1. Start Sector: The physical address where the partition begins.
  2. End Sector: The physical address where it stops.
  3. Type Code/UUID: A code that tells the OS what is inside (e.g., 83 for Linux, 07 for NTFS, or a long UUID for GPT).
  4. Bootable Flag: A marker (mostly used by MBR) indicating which partition contains the bootloader.

4. How to View Your Partition Table

You can use several tools to see which “map” your drives are currently using:


Summary Comparison

Feature MBR (Legacy) GPT (Modern)
Max Disk Size 2 TB 9.4 ZB (Zettabytes)
Max Partitions 4 Primary 128+
Redundancy None (Risk of data loss) Backup header at end of disk
Firmware BIOS UEFI
Identifier 32-bit Disk ID 128-bit GUID

gdisk, fdisk, and parted

When managing partitions from the CLI, the tool you choose often depends on whether you are dealing with “Legacy” MBR disks or modern GPT disks. While they all perform the same basic task—editing the partition table—their interfaces and safety mechanisms differ significantly.


1. fdisk (The Classic)

fdisk is the most famous partitioning tool in the Linux world. For decades, it was strictly for MBR disks, but modern versions (util-linux 2.26+) now have full support for GPT.


2. gdisk (The GPT Specialist)

gdisk (GPT fdisk) was created specifically to handle GPT disks with the same user-friendly menu style as fdisk.


3. parted (The Power User / Scripting Tool)

parted (Partition Editor) is a more versatile tool that supports many partition table types (MBR, GPT, Sun, Mac, etc.) and is unique because it can resize partitions.


Feature Comparison Table

Feature fdisk gdisk parted
Primary Table MBR (now GPT) GPT Only Both + others
Commit Style Buffered (Save at end) Buffered (Save at end) Live (Immediate)
Ease of Use High (Menu-driven) High (Menu-driven) Moderate (CLI-driven)
Scripting Difficult (needs printf) Difficult Excellent
Resize Support No (Delete/Recreate) No Yes
MBR to GPT Conv. No Yes No

Which one should you use?


The Boot Partition

The boot partition (often mounted at /boot) is a dedicated section of your storage drive that contains the essential files needed to start the Linux operating system.

While the “root” (/) partition holds your applications and data, the boot partition is the “key” that starts the engine. It must be readable by the bootloader (GRUB) before the full operating system is even loaded.


1. What stays inside the Boot Partition?

The /boot directory typically contains four critical types of files:


2. Why is it often a separate partition?

In modern Linux installations, /boot is frequently its own small partition (usually 512 MB to 1 GB) rather than just a folder on the root drive. There are three main reasons for this:

  1. Bootloader Limitations: Older BIOS systems and some bootloaders cannot read certain advanced file systems (like encrypted LUKS volumes, complex LVM setups, or Btrfs/ZFS arrays). By making /boot a simple Ext4 or FAT32 partition, the bootloader can easily find the kernel.
  2. Encryption: If your entire root partition is encrypted, the computer can’t read the kernel to start the decryption process. A plain-text boot partition holds the “unlocking” tools (initramfs) needed to ask you for your password.
  3. Stability: Keeping the boot files separate prevents them from being accidentally overwritten if the root partition fills up or becomes corrupted.

3. The EFI System Partition (ESP) vs. /boot

On modern UEFI systems (almost all computers made after 2012), you will actually see two “boot-related” partitions:


4. Managing the Boot Partition

Because the boot partition is small, it can eventually “fill up” as you update your system. Every time you update your Linux kernel, a new vmlinuz and initrd file are added.


Summary Checklist

Property Typical Value
Mount Point /boot
Recommended Size 512 MB – 1024 MB
File System Ext4 (Standard) or FAT32 (EFI)
Primary Files vmlinuz, initrd.img, grub.cfg

Bonus: Cleaning up kernels

To manage your boot partition, you need to identify which kernels are currently installed and which one you are actively using. Deleting the kernel you are currently running will crash your system, so we must be precise.

1. Identify Your Active Kernel

Before deleting anything, check which kernel version is currently loaded into RAM:

uname -r

Take note of this version. You must never remove the files associated with this number.


2. View Files in the Boot Partition

You can see exactly how much space each kernel and its associated “initrd” (Initial RAM Disk) is taking up:

du -sh /boot/vmlinuz* /boot/initrd*


3. Check for “Orphaned” Kernels

Most modern Linux distributions use a package manager (like apt or dnf) to track kernels. To see all installed kernels (even those you aren’t using):

On Debian/Ubuntu:

dpkg --list | grep linux-image

On RHEL/CentOS/Fedora:

rpm -q kernel


4. Safely Remove Old Kernels

Do not use the rm command to delete files in /boot. If you manually delete the files, the package manager will think the kernel is still there and may cause errors during future updates.

Most systems have a built-in “autoremove” feature that keeps the current kernel and the one previous (as a backup) while deleting everything else.

# For Ubuntu/Debian
sudo apt autoremove --purge

# For Fedora/RHEL
sudo dnf autoremove

The “Manual” Way (If autoremove fails)

If your /boot is 100% full, apt might fail because it can’t write temporary files. In this specific case, you can manually remove a specific old version:

sudo apt purge linux-image-5.15.0-XX-generic

(Replace 5.15.0-XX with an old version number you found in step 3, ensuring it is NOT the one from uname -r).


5. Final Step: Update the Bootloader

After removing kernels, you must tell the GRUB bootloader that those options are gone so they don’t appear in the menu when you restart.

sudo update-grub

(On Fedora/RHEL, this is usually sudo grub2-mkconfig -o /boot/grub2/grub.cfg).


Summary Checklist

Action Command
Check Active Kernel uname -r
Check Disk Space df -h /boot
Clean Old Kernels sudo apt autoremove
Sync Bootloader sudo update-grub