- How to Delete Partitions in Linux [Beginner’s Guide]
- Remove disk partition using GParted [GUI Method]
- Delete partitions using fdisk command
- Wrapping up
- How to Delete Partition in Linux
- Delete a Partition in Linux
- Step 1: List Partition Scheme
- Step 2: Select the Disk
- Step 3: Delete Partitions
- Step 4: Verify Partition Deletion
- Step 5: Save Changes and Quit
- How to Delete a Partition in Linux?
- Delete a Partition Using the fdisk Command-line Tool
- Delete a Partition Using the GParted Tool
- Conclusion
- About the author
- Karim Buzdar
How to Delete Partitions in Linux [Beginner’s Guide]
Managing partitions is serious business, especially when you have to remove them. I find myself doing this frequently, especially after using thumb drives as live disks and Linux installers because they create several partitions that I won’t need afterwards.
In this tutorial, I will show you how to remove partitions in Linux using both command line and GUI tools.
You delete the partition, you lose your data. Whenever you are playing with partitions, make sure backup your data. A slight typo or slip of finger could prove costly. Don’t say we didn’t warn you!
Remove disk partition using GParted [GUI Method]
As a desktop Linux user, you probably will be more comfortable and perhaps safer with a GUI-based tool.
There are several tools that let you manage partitions on Linux. Depending on your distribution you will have one or even more such tool already installed on your system.
For this tutorial, I am going to use GParted. It is a popular open source tool and it’s very easy and intuitive to use.
The first step is installing GParted if it isn’t already in your system. You should be able to find it in the software center of your distribution.
Alternatively, you can use your distribution’s package manager for installing it. In Debian and Ubuntu-based Linux distributions, you can use the apt install command:
Once installed, let’s open GParted. Since you are dealing with disk partitions, you’ll be required to have root access. It will ask for authentication and once it opens you should see a window like this one:
On the right-upper corner you can select the disk and in the lower screen the partition you want to remove.
Next, select the option Delete from the Partition menu:
The process is incomplete until you rewrite the partition table. This is a safety measure and it gives you the option to review the changes before confirming it.
To do this just click on the Apply All Operations button located in the toolbar and then Apply when asked for confirmation.
After hitting Apply, you will see a progress bar and a results message saying that all the operations were successful. You can close the message and the main window and consider your partition completely deleted from our disk.
Now that you are aware of the GUI method, let’s move on to the command line.
Delete partitions using fdisk command
Almost every Linux distribution comes with fdisk by default and we are going to use this tool today. The first thing you need to know is what device is assigned to the disk with the partitions you want to remove. To do that, type the following in the terminal:
This will print all the drives and partitions in our system as well as the assigned devices. You need to have root access in order for it work.
In this example, I will work with a USB drive that contains two partitions as shown below:
The device assigned in the system is /sdb and it has two partitions, sdb1 and sdb2. Now that you identified which device contains the partitions, you can start working on it by using fdisk and the path to the device:
This will start fdisk in command mode. You can always press m to see a list of options.
Next, type p and press Enter to view the partition information and confirm that you are using the right device. If the wrong device is in use you can use the q command to exit fdisk and start the procedure again.
Now enter d to delete a partition and it will immediately ask for the partition number, that corresponds to the number listed in the Device column, which in this case are numbers 1 and 2 (as can be seen in the screen capture below) but can and will vary according to the current partition table.
Let’s remove the second partition by typing 2 and pressing Enter . You should see a message saying “Partition 2 has been deleted“, but actually, it hasn’t been removed yet. fdisk needs one more step to rewrite the partition table and apply the changes. Safety net, you see.
You need to type w and press Enter to make the changes permanent. No confirmation is asked.
After this, you should receive some feedback like the one here:
Now, use sudo fdisk —list /dev/sdb to view the current partition table of the device and you can see that the second partition is completely gone. You are done removing your partition using the terminal and fdisk command. Success!
Wrapping up
And so I end this tutorial on how to remove partitions in Linux using both the terminal and GUI tools. Remember, stay always on the safe side, backup your files before manipulating your partitions and double check that you are using the right device. Deleting a partition will delete everything in it with little to no chance of recovering it.
How to Delete Partition in Linux
Linux users create partitions to organize their data in an efficient manner. As easy as they are created, Linux partitions can be deleted to reformat a storage device and regain storage space.
In this step-by-step tutorial, you will learn how to delete a partition on a Linux system.
- A system running Linux
- A user account with sudo or root privileges
- Access to a terminal window / command line (Activities >Search >Terminal)
- The fdisk command-line utility
Delete a Partition in Linux
Deleting a partition in Linux requires selecting the disk containing the partition and using the fdisk command-line utility to delete it.
Follow the steps outlined in the sections below to delete partitions in Linux.
Note: The fdisk command-line utility is a text-based partition table manipulator. It is used for partitioning and repartitioning storage devices.
Step 1: List Partition Scheme
Before deleting a partition, run the following command to list the partition scheme.
In our case, the terminal prints out information about two disks: /dev/sda and /dev/sdb . Disk /dev/sda contains the operating system, therefore its partitions should not be deleted.
On the /dev/sdb disk, there is a /dev/sdb1 partition which we are about to delete.
Note: The number 1 in /dev/sdb1 indicates the partition number. Make a note of the number of the partition you intend to delete.
Step 2: Select the Disk
Select the disk that contains the partition you intend to delete.
Common disk names on Linux include:
Type of disk | Disk names | Commonly used disk names |
IDE | /dev/hd[a-h] | /dev/hda, /dev/hdb |
SCSI | /dev/sd[a-p] | /dev/sda, /dev/sdb |
ESDI | /dev/ed[a-d] | /dev/eda |
XT | /dev/xd[ab] | /dev/xda |
To select a disk, run the following command:
Step 3: Delete Partitions
Before deleting a partition, back up your data. All data is automatically deleted when a partition is deleted.
To delete partition, run the d command in the fdisk command-line utility.
The partition is automatically selected if there are no other partitions on the disk. If the disk contains multiple partitions, select a partition by typing its number.
The terminal prints out a message confirming that the partition is deleted.
Note: If you wish to delete multiple partitions, repeat this step as many times as necessary.
Step 4: Verify Partition Deletion
Reload the partition table to verify that the partition has been deleted. To do so, run the p command.
The terminal prints out the partition structure of the disk selected in Step 2.
Step 5: Save Changes and Quit
Run the w command to write and save changes made to the disk.
After following the instructions in this tutorial, you should have learned how to delete a partition in Linux.
If you want to learn more about partition manipulation, we recommend reading our tutorial on creating partitions in Linux or if you are running NTFS partitions, check out our article on how to mount NTFS partitions in Linux.
Dejan is the Head of Content at phoenixNAP with over 8 years of experience in Web publishing and technical writing. Prior to joining PNAP, he was Chief Editor of several websites striving to advocate for emerging technologies. He is dedicated to simplifying complex notions and providing meaningful insight into data center and cloud technology.
In Linux systems, in order to use storage devices such as Hard Drives and USB drives, you need to understand.
sudo stands for SuperUser DO, and it’s used to temporarily elevate privileges in Linux. This guide will show.
The ls command (short for list) lists information about directories and any type of files in the working.
A list of all the important Linux commands in one place. Find the command you need, whenever you need it or.
How to Delete a Partition in Linux?
Your hard drive is usually partitioned into logical volumes called partitions. Partitions help you organize your data and hence allow you to easily retrieve your saved files and folders. You can easily create partitions to make space for data storage as well as delete them.
There are 2 ways you can delete a partition in Linux:
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
For CentOS-based systems, first, install EPEL. Then install Gparted using the yum package manager:
For Arch
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.
Conclusion
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.
About the author
Karim Buzdar
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.