How to Delete a Partition in Linux

Do you have a hard drive partition in your Linux OS and need a way to delete it?

Hard drive partitions are used across all operating systems and are a useful way of managing and organizing the available space on a computer’s physical or virtual disks. The ability to create, manage, and delete hard drive partitions in Linux is an easy skill that anyone can learn to help with their operating system’s security, robustness, and performance.

What is a Partition?

A hard drive or hard ‘disk’ partition is a logical region of a physical or virtual hard drive. Partitions are created so that your hard drive is actually usable. When a partition is created, it is assigned a specific portion of the total hard drive space so that it can be used for a designated purpose. It is also set up with a specific file system, such as NTFS for Windows or ext4 for Linux. Without a partition, you would not be able to use your computer’s hard drive.

The partitions required for an operating system to run are generally created automatically during the installation process, and for many day-to-day computer users, their existence is not something that requires much thought or attention. Partitions can also be manually created, altered, modified, and deleted during the installation of an OS or at a later stage as needed.

Why Partition a Hard Drive?

The benefits of having multiple partitions on a physical hard drive are so each partition can be managed separately. By default, operating systems such as Linux, Windows, and MacOS will ship with separate partitions to store the operating system files, recovery files, application data, and user data.

Partitions are also used for security and robustness. If an incident occurs on one partition, it is isolated to this partition only, without affecting any of the other partitions. Swap Partitions are also commonly created for performance purposes.

Using fdisk to Manage a Partition

Managing partitions within Linux can be done using the fdisk command-line utility, which comes pre-installed in most Linux distributions.

Step 1: List Linux Hard Drive Partitions

To quickly start using the fdisk utility, we can list all of the available hard drives in the operating system, along with any partitions that belong to each hard drive. Open a terminal window and enter the following command:

sudo fdisk -l
Terminal output of the fdisk -l command

The output of the fdisk -l command informs us that there are two disks available, each with its own partitions. The first disk: /dev/sda contains the OS; hence deleting its partitions is not an option. The second disk outlined in red: /dev/sdb contains a separate partition which is outlined in yellow. This is the partition we want to delete.

Step 2: Select Linux Hard Drive Partition

To get started, we will run the fdisk utility on the disk that has the partition we want to delete by entering the following command:

sudo fdisk /dev/sdb
Terminal output of the fdisk command using specific hard drive partition

With the fdisk utility running, here are the most important fdisk options and what they do:

• The p option. Typing p will print the partition table

• The n option. Typing n will create a new partition

• The d option. Typing d deletes a partition

• The q option. Typing q quits the fdisk utility without saving changes

• The w option. Typing w writes the new partition table and exit

Step 3: Delete Linux Hard Drive Partition

To delete the partition, use the d option. It’s important to mention that if a disk contains multiple partitions, type in the number of the partition. If there is only a single partition, it is selected by default. The terminal window will print out a message confirming that the partition has been deleted:

Terminal output of the fdisk delete command

In order to verify the partition has been successfully deleted, run the p command in the fdisk utility:

Terminal output of the fdisk p command

As a result of this command, we will see an output that is similar to the fdisk -l command we ran earlier; however, the partition on disk number 2 has been successfully deleted and is no longer visible. 

Finally, use the w command to write and save the changes made to the disk:

Terminal output of the fdisk write hard drive partition command

That’s it! You have successfully completed the steps to delete a Linux hard drive partition.

Leave a Reply
Related Posts