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:
sudo fdisk /dev/sdaThis 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:
sudo parted /dev/sdaparted allows you to create, resize, and manage partitions interactively.
3. gdisk
gdisk is similar to fdisk but specifically designed for GPT disks.
Usage Example:
sudo gdisk /dev/sdaUse 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.
lsblkStep 2: Create or Modify Partitions
Using fdisk, parted, or gdisk, create or modify partitions. For example, with fdisk:
sudo fdisk /dev/sda- Press
nto create a new partition. - Press
pto print the partition table. - Press
dto delete a partition. - Press
wto write changes and exit.
Step 3: Format the Partition
After creating a partition, format it with a file system:
sudo mkfs.ext4 /dev/sda1Step 4: Mount the Partition
Finally, mount the partition to make it accessible:
sudo mount /dev/sda1 /mntStep 5: Update /etc/fstab
To ensure the partition mounts automatically at boot, add it to /etc/fstab:
/dev/sda1 /mnt ext4 defaults 0 0Dive deeper into Linux storage management.