DEV Community

Cover image for πŸ“¦ Storage Management in Linux: Partitioning Schemes and Commands
SAHIL
SAHIL

Posted on

πŸ“¦ Storage Management in Linux: Partitioning Schemes and Commands

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

πŸ“ 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
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ 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
Enter fullscreen mode Exit fullscreen mode

➑️> 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)