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
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 line examples to illustrate its utility.
Efficiently managing storage is a critical aspect of IT infrastructure. Whether you’re setting up servers, workstations, or virtual machines, understanding how to create partitions is essential. This article provides a comprehensive guide on creating Master Boot Record (MBR) partitions on systems running Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu, or any other flavor of Linux. We’ll explore the significance of MBR partitions, delve into the procedure using the fdisk and parted
tool, and provide clear command line examples to illustrate its utility.
The concept of partitioning dates back to the early days of computing, when storage capacity was limited, and optimizing data organization was crucial. The Master Boot Record (MBR) partitioning scheme emerged as a standard for organizing data on hard drives. It allows you to divide a single physical drive into multiple logical sections, each of which can be formatted and utilized independently. MBR partitions are still relevant today, especially in scenarios where compatibility with older systems is a concern.
Before we dive into partition creation, ensure that you have access to the command line interface. On any Linux distribution, you can launch the terminal by searching for “Terminal” in the search bar or application menu.
To start, identify the disk you want to partition. You can use the lsblk
command to list all available disks and their partitions. For instance:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 2G 0 part /boot
└─vda2 252:2 0 48G 0 part
├─vg00-root 253:0 0 15G 0 lvm /
├─vg00-swap 253:1 0 4G 0 lvm [SWAP]
└─vg00-home 253:2 0 10G 0 lvm /home
vdb 252:16 0 25G 0 disk
vdc 252:32 0 25G 0 disk
As you can see (above), this command will display a list of disks along with their sizes and partitions.
Let’s assume you want to partition /dev/vdb
. To begin, use the fdisk
command followed by the disk name:
# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
This will launch the interactive fdisk
utility. As you can see in the example above (launched on RHEL9).
Inside the fdisk
utility, you can create partitions as follows:
n
to create a new partition.p
) and extended (e
) partition types. For MBR partitions, you can create up to four primary partitions, or three primary partitions and one extended partition.t
to change the partition’s system ID (partition type).83
for Linux partitions.Repeat these steps for each partition you want to create.
After creating partitions, press w
to write the changes to the disk. This step is crucial, as changes made within fdisk
are only applied when you save them.
Once you’ve created the partitions, you need to format them using filesystems. For instance, to format a partition as ext4:
# mkfs.ext4 /dev/vdb1
In this instance, /dev/vdb1
is the appropriate partition name.
In the Creating MBR partitions using fdisk section, we reviewed how to identify a disk. Partitioning a disk using parted
is similar:
# parted /dev/vdb
GNU Parted 3.5
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
In the example (above), we replaced fdisk
with parted
.
Inside the parted
utility, follow these steps to create partitions:
mklabel msdos
command to create an MBR partition table on the disk.mkpart
command. Specify the partition type (primary) and the file system type (ext4, XFS, etc.).Here’s an example to create a primary ext4 partition using 50% of the disk:
# parted /dev/vdb mklabel msdos
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.
# parted /dev/vdb mkpart primary ext4 0% 50%
Information: You may need to update /etc/fstab.
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 2G 0 part /boot
└─vda2 252:2 0 48G 0 part
├─vg00-root 253:0 0 15G 0 lvm /
├─vg00-swap 253:1 0 4G 0 lvm [SWAP]
└─vg00-home 253:2 0 10G 0 lvm /home
vdb 252:16 0 25G 0 disk
└─vdb1 252:17 0 12.5G 0 part
vdc 252:32 0 25G 0 disk
The /dev/vdb1
partition (above) is now using half of the available size.
Here’s an example to create a primary ext4 partition of a 5GiB in size:
# parted /dev/vdb mklabel msdos
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.
# parted /dev/vdb mkpart primary ext4 2048s 5GiB
Information: You may need to update /etc/fstab.
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 2G 0 part /boot
└─vda2 252:2 0 48G 0 part
├─vg00-root 253:0 0 15G 0 lvm /
├─vg00-swap 253:1 0 4G 0 lvm [SWAP]
└─vg00-home 253:2 0 10G 0 lvm /home
vdb 252:16 0 25G 0 disk
└─vdb1 252:17 0 5G 0 part
vdc 252:32 0 25G 0 disk
The /dev/vdb1 is now using 5GiB of the available size. To ensure proper alignment, set the starting sector to 2048.
After creating partitions, exit the parted
utility:
(parted) quit
You can exit by entering quit
or q
. Also, to format the partition use the same mkfs.ext4
command following the previous example:
# mkfs.ext4 /dev/vdb1
Finally, mount the formatted partitions to directory paths of your choice. Create directories if needed:
# mkdir /mnt/mydata
# mount /dev/vdb1 /mnt/mydata
To ensure these partitions are mounted automatically after system reboots, add entries to the /etc/fstab
file.
In this guide, you’ve learned how to create MBR partitions using the fdisk
and parted
tool in Linux. Partitioning remains a fundamental skill in managing storage for various IT scenarios. By following the outlined steps and examples, you’re better equipped to organize and optimize your system’s storage. Stay informed about evolving technologies, but also recognize the continued relevance of established methods like MBR partitions.
Related Posts
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
In this article, we will review the top 10 most commonly used Git commands. You can’t call yourself a competent DevOps Engineer or IT professional
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