
In this article, we’ll learn about creating MBR partitions in Linux, delve into the procedure using the fdisk and parted tool, and provide clear command
Learn how to manage GPT and MBR partitions in Linux using powerful CLI tools like fdisk, gdisk, and parted. This guide covers creating, deleting, resizing, and formatting partitions.
In modern Linux systems, managing disk partitions is an essential task for system administrators and enthusiasts alike. Whether you’re working with a fresh installation or performing maintenance on an existing system, knowing how to manage GPT (GUID Partition Table) and MBR (Master Boot Record) partitions is vital. Understanding the differences between these partitioning schemes, as well as how to interact with them through the command line interface (CLI), will give you the tools needed to effectively organize your disk space.
In this blog post, we’ll explore how to manage GPT and MBR partitions using CLI tools in Linux. You’ll learn how to create, delete, resize, and format partitions, along with practical examples and best practices.
Understanding GPT vs MBR |
Before diving into the tools and commands, let’s briefly explain what GPT and MBR are.
The Master Boot Record is the older of the two partitioning schemes, first introduced in the early 1980s. It supports up to four primary partitions or three primary partitions and one extended partition, which can then be subdivided into logical partitions. MBR is limited to a maximum disk size of 2 TB and doesn’t handle modern hardware as efficiently as GPT.
Key Features of MBR |
GPT (GUID Partition Table) |
GPT is a more modern partitioning scheme, designed to overcome the limitations of MBR. GPT is part of the UEFI (Unified Extensible Firmware Interface) standard, which replaces BIOS on newer systems. GPT supports disks larger than 2 TB and allows for up to 128 partitions without the need for extended partitions. It is more robust, providing redundancy by storing a copy of the partition table at both the beginning and end of the disk.
Key Features of GPT |
Now that we have a basic understanding of both partitioning schemes, let’s dive into the tools you’ll use to manage partitions on Linux systems.
Linux offers a variety of command-line tools for partition management. Below are some of the most commonly used utilities for working with MBR and GPT partitions.
Tool | Description | Partitioning Scheme Supported |
---|---|---|
fdisk | A popular tool for managing MBR partitions. | MBR |
gdisk | A tool similar to fdisk but designed for GPT partitions. | GPT |
parted | A flexible partitioning tool that supports both GPT and MBR. | MBR & GPT |
lsblk | A command-line tool to list information about block devices. Useful for viewing partition tables. | MBR & GPT |
mkfs | A utility to create file systems on partitions. | MBR & GPT |
fdisk – Managing MBR Partitions |
The fdisk
tool is used to create, delete, and manage MBR partitions. It’s a widely known tool that’s been around for decades. Below are some common tasks you’ll perform with fdisk
.
Viewing Partitions |
To view the partition table on a disk, use the following command:
sudo fdisk -l
This will list all available disks and their partitions, including size, type, and partition number.
Photo by admingeek from Infotechys
Creating a New Partition |
To create a new partition, use the fdisk
command to select the disk and follow the interactive prompts:
sudo fdisk /dev/sda
n
to create a new partition.primary
or extended
).w
.Deleting a Partition |
To delete a partition, select the disk using fdisk
and type:
sudo fdisk /dev/sda
Then, type d
to delete a partition and specify the partition number.
Formatting the Partition |
Once a partition is created, you’ll want to format it. To format it with the ext4 file system, for example:
sudo mkfs.ext4 /dev/sda1
This command creates an ext4 file system on the first partition of the disk.
gdisk – Managing GPT Partitions |
The gdisk
tool is designed for managing GPT partitions and offers a similar interface to fdisk
. It’s a straightforward tool for working with GPT disks.
Viewing Partitions |
To list GPT partitions:
sudo gdisk -l /dev/sda
This shows detailed information about the partitions, including GUID and partition types.
Creating a New GPT Partition |
To create a new partition on a GPT disk:
sudo gdisk /dev/sda
n
to create a new partition.w
to write the changes to disk.Deleting a Partition |
To delete a partition with gdisk
:
sudo gdisk /dev/sda
d
to delete the partition.w
to save changes.parted – Managing Both MBR and GPT Partitions |
parted
is a more advanced partitioning tool that works with both MBR and GPT partitioning schemes. It’s particularly useful for managing larger disks and creating complex partition layouts.
Viewing Partitions |
To list partitions on a disk:
sudo parted /dev/sda print
This will display partition details, including size, type, and file system.
Creating a New Partition |
For a GPT disk:
sudo parted /dev/sda mkpart primary ext4 0% 50%
This command creates a new primary partition with the ext4 file system that spans from the start of the disk (0%) to 50% of the total disk size. For an MBR disk, use the following:
sudo parted /dev/sda mkpart primary ext4 1MiB 2GB
This will create a partition from 1MiB to 2GB.
Resizing Partitions |
To resize a partition:
sudo parted /dev/sda resizepart 1 100GB
This resizes partition 1 to 100GB.
Formatting Partitions |
Once the partition is created or resized, you can format it with the following command:
sudo mkfs.ext4 /dev/sda1
This formats the first partition (/dev/sda1
) with the ext4 file system.
Advanced Partition Management with |
lsblk
is an excellent tool for viewing detailed information about your disks and partitions. To see a list of all available block devices:
lsblk
This will display all disks and their partitions in a tree-like structure. It’s particularly useful when managing large systems with multiple disks.
Best Practices for Partitioning |
Managing disk partitions in Linux using CLI tools is an essential skill for system administrators and users. By using utilities like fdisk
, gdisk
, and parted
, you can efficiently create, delete, and resize partitions. Understanding the differences between GPT and MBR partitioning schemes ensures that you can choose the best option for your needs, especially when dealing with larger disks or modern hardware.
With this guide, you should feel confident in managing your disk partitions from the command line, whether you’re dealing with legacy MBR partitions or modern GPT disks.
Did you find this article useful? Your feedback is invaluable to us! Please feel free to share this post!
In this article, we’ll learn about creating MBR partitions in Linux, delve into the procedure using the fdisk and parted tool, and provide clear command
In the ever-evolving landscape of IT infrastructure, one fundamental decision stands out when setting up storage solutions: choosing the right partitioning scheme. This article takes
Creating GPT partitions in Linux empowers IT professionals with a modern and robust method for efficient storage management, offering advantages like larger drive support, data