How To Delete Partition In Linux Using Command Line (fdisk)

Sometimes we stuck in a situation where we just have access to the terminal and need to delete partition, or you have stepped down in Linux, and your logical mind pushes you to delete the partition using a command.

But you don’t know how to delete the partition using the terminal, not a big deal, and I’m here to rescue you just follow the instruction, and your motive will be accomplished.

In this article, we will use fdisk command-line based utility to delete the partition.

Prerequisites

  • Privilege account (sudo users)
  • Terminal
  • fdisk (Already preinstalled in Linux)
  • A partition should exist (If you think you can delete unallocated partition, then I suppose you might be wrong)

Delete a Partition in Linux using fdisk

To Delete partition first, we need to list out the available partitions and select the appropriate disk. For that, we can use the fdisk command to list out and delete the selected partition.

If you don’t know what is fdisk read these short descriptions and move ahead to delete partitions.

What is fdisk?

In short fdisk is a command-line utility tool to manage disk it allow you to view, create, delete, change, resize, copy and move partitions on a hard drive.

Note:- This below step will format your USB drive, so it requests you to make a backup of your USB drive else you may lose your valuable data.

Step 1: List Partitions using fdisk

This is necessary to list out and identify partitions to prevent from selecting wrong partitions and losing valuable data. It is actually a facepalm moment, so ensure that you are choosing a correct disk.

To list out partitions, we can take help of fdisk command and pass the following command into your terminal screen.

$ sudo fdisk -l

This will show a number of partition and Disk, which is attached to our system.

Disk /dev/sda: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Samsung SSD 860 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3C473EA7-C207-4FD2-A49A-D899D2CB47DD

Device         Start       End   Sectors   Size Type
/dev/sda1       2048    206847    204800   100M EFI System
/dev/sda2     206848    239615     32768    16M Microsoft reserved
/dev/sda3     239616 232740863 232501248 110.9G Microsoft basic data
/dev/sda4  306163712 307197951   1034240   505M Windows recovery environment
/dev/sda5  307200000 614399999 307200000 146.5G Microsoft basic data
/dev/sda6  614400000 897210367 282810368 134.9G Microsoft basic data
/dev/sda7  897210368 899307519   2097152     1G Linux filesystem
/dev/sda8  232740864 306163711  73422848    35G Linux filesystem
/dev/sda9  899307520 901404671   2097152     1G Linux filesystem
/dev/sda10 901404672 976773119  75368448    36G Linux LVM

From the above output we need to select correct disk, In my case, I want to delete the partition from /dev/sda that is /dev/sda10.

Step 2: Select Partitions using fdisk

Now we know which partition we want to delete so, we have to type the following command in terminal along with above partition name:

$ sudo fdisk /dev/sda

Password: 

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): 

Now fdisk command will be in interactive mode, so we have to provide specific commands to execute. At some point, you feel lost type m (for help) and press the enter button to show available command.

Optional command but this will make sure that you have selected correct Disk to avoid mishap type the below command to get confirm:

p
Type command p
Type command p

Step 3: Delete Partitions using fdisk

We are one step back to delete partition, from the above measure we confirmed we had selected correct Disk.

In this step we will delete partition If you have important data, please make sure to take a backup and proceed next.

To delete partition type d or del command in the fdisk command-line utility followed by partition number in case of multiple partitions.

Command (m for help): d  
Partition number (1-10, default 10): 10

Partition 10 has been deleted.

Command (m for help): 

In my case, multiple partitions are available to /dev/sda because of that, and I have to pass partition number manually.

If you are thinking How to get the partition number, check the above output of p command and note it down.

Delete partitions
Delete partitions

Step 4: Verify changes

From the above command, we are able to delete selected partitions, To make sure whether the partition is deleted pass the p command in the fdisk command-line utility.

Verify partition is deleted
Verify partition is deleted

We can see the change earlier total of 10 partitions was available in /dev/sda now it’s 9, hold on our work is not completed one last command is required to type.

Step 5: Save and exit

This is the last step to delete partition, after that you will not be able to revert changes.

Inside the same terminal type w command to write changes once the changes apply you will get the exit from fdisk utility tool.

Type w command to save changes
Type w command to save changes

This is a demo of the above explanation you can a look at the below output screen.

Complete step to delete partitions using fdisk
Complete step to delete partitions using fdisk

Read this How to Format USB Drive or Pendrive on Linux using CLI?

Wrap-up

That’s all my friend to delete the partition using the fdisk command-line utility. In case you need some assistance from my end, feel free to comment Down.

If you want to share some feedback or any topic feel free to comment down.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments