Partitioning Disks in Linux
Disk partitioning is the process of dividing a disk into distinct sections called partitions. Each partition can be managed separately, allowing for different file systems, operating systems, or data to be stored independently.
Types of Partitions
- Primary Partitions: These are the main divisions of a disk. A disk can have up to four primary partitions.
- Extended Partitions: A special type of primary partition that can contain multiple logical partitions, allowing for more than four partitions on a disk.
- Logical Partitions: Partitions created within an extended partition. These are often used to extend the number of partitions beyond four.
Partition Tables
Partition tables store information about the disk's partitions. The two most common types are:
- MBR (Master Boot Record): Traditional partition table, limited to 2TB disks and four primary partitions.
- GPT (GUID Partition Table): Modern partition table, supports larger disks and more partitions.
Partitioning Tools in Linux
Linux offers several tools to manage disk partitions. Here are the most commonly used:
1. fdisk
fdisk
is a command-line utility for managing MBR partitions.
Usage Example:
This command launches fdisk
to manage partitions on /dev/sda
.
2. parted
parted
supports both MBR and GPT partition tables, making it a versatile tool for managing disks.
Usage Example:
parted
allows you to create, resize, and manage partitions interactively.
3. gdisk
gdisk
is similar to fdisk
but specifically designed for GPT disks.
Usage Example:
Use gdisk
to manage partitions on a GPT disk.
Step-by-Step Partitioning Guide
Step 1: Identify the Disk
Identify the disk you want to partition using the lsblk
or fdisk -l
command.
Step 2: Create or Modify Partitions
Using fdisk
, parted
, or gdisk
, create or modify partitions. For example, with fdisk
:
- Press
n
to create a new partition. - Press
p
to print the partition table. - Press
d
to delete a partition. - Press
w
to write changes and exit.
Step 3: Format the Partition
After creating a partition, format it with a file system:
Step 4: Mount the Partition
Finally, mount the partition to make it accessible:
Step 5: Update /etc/fstab
To ensure the partition mounts automatically at boot, add it to /etc/fstab
:
Dive deeper into Linux storage management.