Before learning how to create and format a partition, we must know what a partition is. First, think of it this way, if you need to run multiple operating systems on one computer or you have different types of raw data that need a huge space and you want to categorize it while storing it on your computer then you will be needing multiple partitions. A partition is merely a specified closed space on a disk that acts as a storage container. This storage container can be called a separate disk and stores data and information. One disk can be divided into multiple partitions based on the requirements.
Partitioning is the process of dividing a physical storage device into separate sections, allowing each to function as an independent drive. This is useful for organizing data, dual-booting multiple operating systems, or ensuring system stability by keeping user files separate from system files. Formatting, on the other hand, prepares a partition for use by creating a filesystem, such as ext4, NTFS, FAT32, or XFS, making it readable and writable by the OS.
If you're working with Linux, you may need to partition or format a drive when installing a new hard disk, setting up a USB drive, or troubleshooting storage issues. Fortunately, Linux offers various tools for these tasks, ranging from user-friendly GUI applications like GParted to powerful command-line utilities like fdisk, parted, and mkfs.
In this guide, we'll walk you through the entire process of partitioning and formatting a drive on Linux, covering both GUI and terminal-based methods for Linux. Whether you're a beginner looking for an easy way to manage storage or an advanced user needing precise control over partitions, this guide has you covered.
First off, you need to install Gparted which is a great tool when it comes to creating partitions and formatting them.
Make certain that your repository is refreshed and up to date.
sudo apt update
For Debian Based Linux:
sudo apt install gparted
For Fedora Linux:
sudo dnf install gparted
For Arch Linux:
sudo pacman -S gparted
After Gparted has been installed, you can either launch it from the terminal or find it in the Apps section on your Linux OS:
To launch it from the terminal, use:
sudo gparted
Within the interface of Gparted, click in the right top corner on the pointed box.
Now, two options will appear:
/dev/sda
/dev/sdb
Select /dev/sdb
which appears as your secondary drive. Be careful before making any changes to /dev/sda
, as it is typically your main system drive.
First off, let's start by looking at how to delete a partition, which is quite straightforward in GParted. Select the /dev/sdb
and then right-click on it and you will see the option to delete it. Clicking the highlighted Delete option will mark the selected partition for deletion. You’ll need to apply the changes to finalize it.
If you need to create a new partition then simply right-click on the unallocated space and you will see an option that says New.
Choose the desired size for the new partition, and more importantly, select a suitable file system. In most cases, ext4
is recommended for Linux systems due to its stability and wide support. However, if you're creating a partition for use with Windows, you might prefer NTFS, or FAT32 for USB drives that need cross-platform compatibility.
I’ll keep the size the same but I’ll adjust the label as Hostman D.
Now comes the key step, formatting the partition. Right-click on the new partition, select Format to, and choose the same file system you selected earlier, such as ext4, FAT32, or NTFS. The format you choose should align with how you plan to use the drive, ext4 for Linux systems, NTFS for Windows compatibility, or FAT32 for broader device support.
To apply the changes, click on the tick icon as shown in the screenshot.
A pop-up will appear that prompts you to confirm applying these changes. Click Apply.
You will see a success window confirming that the changes have been made.
Now let’s look at how to handle partitioning, formatting, and mounting using the terminal, a more hands on approach suited for those comfortable with command line tools.
Before starting, make sure to list all connected disks and identify the one you plan to work with. To do that, run the following command:
lsblk
Or run the fdisk
command:
sudo fdisk -l
I will work with the disk /dev/sdb
. Now, let’s head towards the next step to make a partition.
It's very simple to partition the drive using fdisk
.
sudo fdisk /dev/sdb
Once you run the above command it will open the fdisk
menu where you can type in different letters for different actions such as n
can be used for creating a new partition, p
to display the partition table, d
for deletion, and w
for write and exit.
To create the partition, use n
:
To print the partition table, use p
:
To delete the partition, use d
:
To write changes and exit, use w
:
If you are using GUID partition tables then use the parted
command with sudo
:
sudo parted /dev/sdb
After the partitions have been created, you can format them according to the file system required.
For ext4 (Linux systems):
sudo mkfs.ext4 /dev/sdb5
For NTFS (Windows compatibility):
sudo mkfs.ntfs /dev/sdb5
For FAT32 (USB drives, older systems):
sudo mkfs.vfat -F 32 /dev/sdb5
Create a mount point:
sudo mkdir /mnt/mydrive
Mount the partition:
sudo mount /dev/sdb5 /mnt/mydrive
If you want to auto-mount at the start-up, you need to first acquire UUID:
sudo blkid
Then, add it to /etc/fstab
:
UUID=your_uuid /mnt/mydrive ext4 defaults 0 2
Simply press CTRL+O to write out and save, then press CTRL+X to exit from the nano editor.
Either for creating partitions or formatting the disk, managing disks is a great skill to have up your sleeves. Fundamentally, Windows and Mac OS have a graphical user interface where you can create partitions and format them while Linux provides you the flexibility to do so from the terminal. You can also use the GUI option in Linux to do essentially the same thing. It’s not impossible though to create partitions and format them in Windows and Mac OS from the command line but the popular and heavily used option is the GUI choice by Windows and Mac OS users.
Creating partitions within Linux is a top skill when it comes to Linux administration tasks. Even if you are a general Linux user, this could be an interesting area to explore. If you are not familiar with creating, deleting, and formatting partitions then this article could be your guide to understand these concepts in a simple way. We have followed two approaches, one where we used the graphical user interface and a tool called Gparted, and the second approach where we do and handle everything inside the terminal.
The main ease comes from knowing that you can format the partition to any file system you choose like NTFS, ext4 etc. We have talked about them in significant detail in this article and we have discussed how to format your partition with one of the many file systems.