Introduction
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.
Prerequisites
- A system running Linux
- A user account with
sudo
orroot
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.
fdisk -l
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:
sudo fdisk /dev/sdb
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.
Conclusion
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.