What is Disk Partitioning?
Disk partitioning is the process of dividing a disk into smaller, manageable sections called partitions. Each partition behaves as if it were a a distinct disk, enabling the OS to manage data more efficiently. Partitions can store different types of data, including system files, user data, and swap space.
Partitioning splits one physical drive into multiple logical segments. Each segment can be format with its own file system and used for different purposes.
Why is Disk Partitioning Important?
- Efficient Storage Management: Partitioning helps in organizing data and separating system files from user files. This separation improves data management and recovery processes.
- Performance Optimization: Different types of data can be stored in different partitions to optimize disk performance. For example, frequently accessed files can be placed in a faster partition.
- Enhanced Security: Partitioning allows for the isolation of sensitive data, reducing the risk of unauthorized access.
- Flexible Multi-OS Setup: Multiple operating systems can be installed on separate partitions, enabling dual-boot or multi-boot configurations.
Types of Partitions
- Primary Partitions: These are the main partitions on a disk. A disk can have up to four primary partitions, one of which can be marked as active to boot the OS.
- Extended Partitions: These are used when more than four partitions are needed. An extended partition can contain multiple logical partitions. A type of partition that can hold multiple logical partitions, allowing you to bypass the four-partition limit.
- Logical Partitions: These are subdivisions of an extended partition, allowing for more flexible disk management.
Partition Table Schemes
- Master Boot Record (MBR): An older partitioning scheme supporting up to four primary partitions. The MBR is limited to disks smaller than 2TB.
- GUID Partition Table (GPT): A modern partitioning scheme supporting larger disks and more partitions. GPT is essential for UEFI-based systems and supports disks larger than 2TB.
1. Structure of a Physical Disk Without Partitions
A physical disk without partitions is a contiguous block of storage space. It has no logical divisions, and the entire disk is treated as a single storage unit.
+------------------------------------------------+
| Entire Disk |
+------------------------------------------------+
Description:
- Entire Disk: The whole disk is treated as one large storage space with no subdivisions. This means all data is stored in a single continuous area. This structure is simple but not efficient for managing different types of data separately.
2. Structure of a Physical Disk With Partitions
When a disk is partitioned, it is divided into several logical sections, each of which can be managed independently. Below is a visual representation and a detailed explanation.
2.1 Master Boot Record (MBR) Partitioning
+------------------------------------------------+
| MBR |
+------------------------------------------------+
| Primary Partition 1 | |
+---------------------------+ |
| Primary Partition 2 | |
+---------------------------+ Extended |
| Primary Partition 3 | |
+---------------------------+ |
| Primary Partition 4 | |
+---------------------------+ |
| Logical Partition 1 | |
+---------------------------+ |
| Logical Partition 2 | |
+---------------------------+ |
| Logical Partition 3 | |
+------------------------------------------------+
Description:
- MBR (Master Boot Record): The first 512 bytes of the disk, containing the bootloader and the partition table. The partition table holds information about up to four primary partitions.
- Primary Partitions (1-4): The MBR scheme allows up to four primary partitions. One of these can be marked as active for booting.
- Extended Partition: If more than four partitions are needed, one primary partition can be designated as an extended partition. It acts as a container for multiple logical partitions.
- Logical Partitions: These reside within the extended partition and can be used to create more partitions beyond the four-primary limit.
2.2 GUID Partition Table (GPT) Partitioning
+------------------------------------------------+
| GPT Header |
+------------------------------------------------+
| Partition Table |
+------------------------------------------------+
| Partition 1 | |
+------------------------+ |
| Partition 2 | |
+------------------------+ |
| Partition 3 | |
+------------------------+ |
| Partition 4 | |
+------------------------+ |
| Partition 5 | |
+------------------------+ |
| Partition 6 | |
+------------------------+ |
| Partition 7 | |
+------------------------+ |
| Partition 8 | |
+------------------------------------------------+
Description:
- GPT Header: Located at the beginning of the disk, it contains the GUID Partition Table header, which describes the partition layout and provides redundancy with a backup header at the end of the disk.
- Partition Table: Follows the GPT header and includes entries for each partition. GPT supports a large number of partitions, typically up to 128 per disk.
- Partitions (1-8): The disk is divided into multiple partitions, each with its own GUID and attributes. Unlike MBR, there is no distinction between primary, extended, or logical partitions; all are treated equally.
Creating Partitions
Tools for Partitioning in Linux
- fdisk: A command-line utility for partitioning hard disks.
- parted: Another command-line tool, which supports both MBR and GPT partition tables.
- GParted: A graphical partition editor based on
parted
, available in many Linux distributions.
Creating Partitions with fdisk
- Open
fdisk
:
sudo fdisk /dev/sdX
Replace /dev/sdX
with your actual disk device.
- List Partitions: Type
p
to print the partition table. - Create a New Partition: Type
n
to create a new partition.- Choose
p
for a primary partition ore
for an extended partition. - Enter the partition number (1-4 for primary, or logical within extended).
- Specify the start and end sectors or accept defaults.
- Choose
- Change Partition Type: Type
t
to change the partition type (e.g.,82
for swap). - Write Changes: Type
w
to write the changes to disk and exit.