Partitioning Disks for Linux: A Comprehensive Guide
Understanding Disk Partitioning
Disk partitioning is the process of dividing a hard disk into multiple logical sections, called partitions. Each partition functions as a separate disk, allowing you to organize data, manage resources, and install multiple operating systems on a single physical disk.
Types of Partitions
- Primary Partitions: You can create up to four primary partitions on a single disk. Each primary partition can host a file system or an operating system.
- Extended Partitions: An extended partition acts as a container for logical partitions. You can create one extended partition per disk, and within it, multiple logical partitions.
- Logical Partitions: These reside within an extended partition and allow for more flexible disk organization. They function similarly to primary partitions but do not have the same limitations.
Common File Systems for Linux
- ext4: The most widely used file system for Linux, known for its stability, performance, and support for large files.
- XFS: A high-performance file system suitable for large volumes and parallel I/O operations.
- Btrfs: Offers advanced features like snapshots, subvolumes, and RAID support, making it ideal for complex storage setups.
Tools for Disk Partitioning
- GParted: A graphical partition editor that allows you to create, resize, and manage partitions using a user-friendly interface.
- fdisk: A command-line utility for creating and managing disk partitions. It is suitable for MBR (Master Boot Record) disks.
- parted: A versatile command-line tool that supports both MBR and GPT (GUID Partition Table) disks.
Steps for Partitioning Disks
Using GParted
- Install GParted:
sudo apt-get install gparted
- Launch GParted:
sudo gparted
- Select the Target Disk: Choose the disk you want to partition from the drop-down menu.
- Create a New Partition Table: Go to Device > Create Partition Table and select the partition table type (MBR or GPT).
- Create Partitions: Right-click on the unallocated space and select New. Configure the partition size, file system, and label. Repeat this step for additional partitions.
- Apply Changes: Click the green checkmark to apply the changes.
Using fdisk
- Launch fdisk:
sudo fdisk /dev/sdX
(Replace/dev/sdX
with the target disk, e.g.,/dev/sda
). - Create a New Partition:
- Type
n
and press Enter. - Select the partition type (primary or extended).
- Specify the partition number, starting sector, and size.
- Type
- Write Changes: Type
w
and press Enter to write the changes to the disk.
Using parted
- Launch parted:
sudo parted /dev/sdX
(Replace/dev/sdX
with the target disk, e.g.,/dev/sda
). - Create a New Partition Table:
mklabel gpt
- Create Partitions:
mkpart primary ext4 1MiB 20GiB
mkpart primary linux-swap 20GiB 22GiB
mkpart primary ext4 22GiB 100%
- Quit parted:
quit
Post-Partitioning Steps
- Format the Partitions:
sudo mkfs.ext4 /dev/sdX1
sudo mkfs.ext4 /dev/sdX3
sudo mkswap /dev/sdX2
- Mount the Partitions:
sudo mount /dev/sdX1 /mnt
sudo mkdir /mnt/home
sudo mount /dev/sdX3 /mnt/home
sudo swapon /dev/sdX2
Comments
Post a Comment