Managing storage is one of the most fundamental tasks in Linux system administration. This post gives you an overview of partitioning schemes and the commands used to create and manage them.
π§ Firmware and Partitioning Schemes
The way a hard drive is partitioned depends on the firmware of the computer. The two most common types are MBR (Master Boot Record) and GPT (GUID Partition Table).
π½ MBR (Master Boot Record)
The MBR is the traditional partitioning scheme that has been widely used for decades.
Limitations of MBR:
- Partition Limit: Supports up to 4 primary partitions. To go beyond, one of them must be an extended partition.
- Disk Size Limit: Can only handle disks up to 2 TB.
- Location: MBR is stored in the first 512 bytes of the disk and contains the bootloader + partition table.
πΎ GPT (GUID Partition Table)
GPT is the modern standard, designed to overcome MBR limitations. Itβs part of the UEFI (Unified Extensible Firmware Interface) standard, replacing legacy BIOS.
Advantages of GPT:
- Partition Limit: Supports up to 128 partitions (no extended partitions needed).
- Disk Size Limit: Handles disks much larger than 2 TB, with a theoretical limit of 9.4 ZB.
- Redundancy: Stores a backup partition table at the end of the disk β more resilient to corruption.
π Standard and Extended Partitions
-
Primary Partitions:
A physical division of the disk that can store a file system and act as a bootable volume.- MBR allows up to 4 primary partitions.
-
Extended Partitions:
A workaround for the 4-partition limit in MBR.- One primary partition can be designated as extended.
- Inside it, you can create multiple logical partitions.
βοΈ Partitioning and Formatting Commands
Linux provides several command-line tools to manage partitions depending on whether you use MBR or GPT.
π₯οΈ fdisk
(MBR)
fdisk
is mainly used for MBR partitioning.
sudo fdisk /dev/sda
Useful commands inside fdisk:
- p β Print current partition table
- n β Create new partition
- d β Delete a partition
- w β Write changes and exit
π₯οΈ gdisk (GPT)
gdisk works like fdisk but is designed for GPT disks.
sudo gdisk /dev/sda
Commands are similar to fdisk:
- p β Print table
- n β Create partition
- d β Delete partition
- w β Write changes
π₯οΈ parted (MBR & GPT)
parted is a versatile tool that supports both MBR and GPT.
sudo parted /dev/sda
Common commands:
print # Show partition table
mklabel gpt # Set disk label to GPT
mkpart primary ext4 1MiB 50GiB # Create a primary ext4 partition
quit # Exit
π Creating a File System
After partitioning, the new partition must be formatted with a file system.
mkfs.ext4 /dev/sda1 # Format as ext4
mkfs.xfs /dev/sda2 # Format as XFS
π Mounting the Partition
To use the new file system, mount it to a directory:
sudo mkdir /mnt/new_partition
sudo mount /dev/sda1 /mnt/new_partition
β‘οΈ> To make the mount permanent, add an entry to /etc/fstab.
β Conclusion
MBR is older and limited, while GPT is modern, scalable, and more reliable.
Tools like fdisk, gdisk, and parted let you create/manage partitions.
Use mkfs to format partitions and mount to access them.
π‘ Knowing these fundamentals is crucial for Linux admins who want to effectively manage storage.
π If you found this useful, donβt forget to share it with your Linux friends!π
Top comments (0)