There are 2 ways you can delete a partition in Linux:
- Using the fdisk command-line utility
- Using the Gparted GUI tool
Delete a Partition Using the fdisk Command-line Tool
The fdisk command-line utility is a tool that ships with every Linux distribution and comes in handy when you want to create or delete hard disk partitions.
Usually, partitions take naming conventions, as shown below:
For IDE drives: /dev/hdx e.g /dev/hda , /dev/hdb, /dev/hdc
For ISCI disks: /dev/sdx e.g /dev/sda, /dev/sdb, /dev/sdc
Before deleting a partition, it is imperative that you back up all the files and directories since they are going to be wiped out.
In my system, I have attached a removable drive, /dev/sdb, with 2 partitions. To display the partitions, I will execute the fdisk command as shown. If you are using a regular user, ensure to use the sudo command since fdisk requires elevated privileges.
Alternatively, you can use the lsblk command to get a better visual as follows:
The drive has 2 partitions: /dev/sdb1 and /dev/sdb2. I’m going to delete the second partition, which is /dev/sdb2.
To get started, invoke the fdisk command-line tool:
Next, you will be prompted to enter a command to proceed. Type ‘P’ to print the existing partitions on the drive.
Command (m for help): p
To remove the partition, type the letter ‘d’ which stands for delete and
Command (m for help): d
Thereafter, provide the partition number. In my case, I will type 2 and press “ENTER” since this is the partition that I intend to delete.
Partition number (1, 2, default 2): 2
You will be notified that the partition has been removed or deleted. You can cross-check by printing out the partitions again by typing the p command.
At the bottom of the snippet below, only /dev/sdb1 is listed.
To save changes to the disk, type w for write and press “q” to quit the fdisk shell.
As before, confirm the existing partitions using the fdisk tool.
Delete a Partition Using the GParted Tool
Gparted is a powerful graphical tool that allows you to view, resize, create and delete your partitions. It is open-source and absolutely free and can be installed as follows:
For Debian/Ubuntu Distributions
For Debian/Ubuntu distros, run the command below to install Gparted:
For CentOS-based systems, first, install EPEL. Then install Gparted using the yum package manager:
$ sudo yum install gparted
For Arch and Arch-based distros, invoke:
To launch Gparted, run the following command on the terminal:
Also, you can use the application manager to search and launch the GUI utility.
Provide your password to authenticate and hit “ENTER”.
Once authenticated, Gparted will present the partitions on the main hard drive on which Linux is installed, in my case, it’s /dev/sda.
Since the partition to be deleted is located on the removable drive, which is not listed, we will switch to that hard drive.
To do so, we will go to Gparted > Devices > /dev/sdb
We now have the partitions of the second hard drive listed, as shown below:
To delete the second partition (/dev/sdb2), we will unmount it first. So, right-click and select “unmount”.
Next, right-click on the /dev/sdb2 partition, and select the “delete” option, which ultimately removes or deletes the partition.
Immediately, you will realize that the partition is labeled “Unallocated” and at the bottom left corner of the Gparted window, you will notice an alert informing you of a pending operation. The reason you are getting this is that we have not saved the changes to the disk.
Click on the checkmark, as indicated, to apply the changes made.
When prompted whether to proceed with the pending operations, click on “Apply”.
Ultimately, the writing process will conclude and the changes saved. Click on the “close” button.
We have covered two ways that you can employ to delete a logical partition in Linux: fdisk utility and Gparted GUI tool. If you find this informative, send us a like and share this guide.