Linux: How to delete a partition with fdisk command

by Vivek Gite on September 17, 2006 · 19 comments

Q. My system comes with pre installed Linux and XP. Now I would like to delete a partition. How do I delete a partition?

A. Hard disks can be divided into one or more logical disks called partitions. This division is described in the partition table found in sector 0 of the disk.

You need to use fdisk command. It is a menu driven program for creation and manipulation of partition tables. However this program needs the device name (hard disk name) to manipulate partitions. Usually you use following names
/dev/hda
/dev/hdb
/dev/sda
/dev/sdb

So,
=> /dev/hd[a-h] for IDE disks
=> /dev/sd[a-p] for SCSI disks
=> /dev/ed[a-d] for ESDI disks
=> /dev/xd[ab] for XT disks.

A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings.

Before typing any one of the following command(s) make sure you have the backup of important data.

First, get a listing of your current partition scheme, type the following command:
# fdisk -l.
Output:

Disk /dev/hda: 20.0 GB, 20060651520 bytes
255 heads, 63 sectors/track, 2438 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1        1024     8225248+   b  W95 FAT32
/dev/hda2   *        1025        2438    11357955    c  W95 FAT32 (LBA)
Disk /dev/hdb: 80.0 GB, 80060424192 bytes
255 heads, 63 sectors/track, 9733 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1   *           1        2432    19535008+  83  Linux
/dev/hdb2            2433        2554      979965   82  Linux swap / Solaris
/dev/hdb3            2555        6202    29302560   83  Linux
/dev/hdb4            6203        9733    28362757+   5  Extended
/dev/hdb5            6203        9733    28362726   83  Linux

From above output I have two hard disks:
=> /dev/hda - 20 GB
=> /dev/hdb - 80 GB

Let us assume that you want to remove a partition from /dev/hdb disk. Type the following command:
# fdisk /dev/hdb
Output:

The number of cylinders for this disk is set to 9733.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):

Now type p command to list partition:
Command (m for help): p
Output:

Disk /dev/hdb: 80.0 GB, 80060424192 bytes
255 heads, 63 sectors/track, 9733 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1   *           1        2432    19535008+  83  Linux
/dev/hdb2            2433        2554      979965   82  Linux swap / Solaris
/dev/hdb3            2555        6202    29302560   83  Linux
/dev/hdb4            6203        9733    28362757+   5  Extended
/dev/hdb5            6203        9733    28362726   83  Linux

Now let us say you want to delete /dev/hdb3 (3rd partition). Type the d command to delete a partition:
Command (m for help): d
Partition number (1-4): 3

It will prompt you for the partition number. Type 3:

Verify that partition deleted:
Command (m for help): p

Now save the changes and exit to shell prompt. Type the w command:
Command (m for help): w

Reboot the system.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 19 comments… read them below or add one }

1 Annamalai.M September 26, 2006

hi…
our organization having one server runing on Redhat Linux (scsi device).
now i need to install fedora on that machine.
1.Now my question is ,i can’t delete the older scsi partitions while i insert fedora cd ( to delete and to create partitions )
is there any way to delete this scsi partitions…
help me…
with regards
Annamalai

Reply

2 nixcraft September 27, 2006

Run fdisk /dev/sdX while you are in RedHat itself. Remove the required partition. Save and reboot system.

Reply

3 Luca July 20, 2008

Thank you!!
Nice tutorial! It explain very well, comprehensible also by beginners (like me!).

You saved my soul!

Reply

4 Ashish S January 20, 2009

It’s a really very helpful guidlines ……..

Reply

5 excellent February 27, 2009
6 meetei September 9, 2009

Excellent tutorial … it cleared my doubt ..
THANK YOU very much…

Reply

7 Mani October 1, 2009

Very Nice tut…

Reply

8 Syed Mustafa July 27, 2010

Thank you so much sir.
This tutorial is really very helpful. Thanks aloooooooooooooooooooot!!!!!!!!!!!!!!

Reply

9 tati August 11, 2010

i follow the tutorial above until step> Command (m for help): d
Partition number (1-4): 3
but then it prompt Warning:partition 3 has empty type
i couldn’t delete the partition.

please help
thank

Reply

10 Raju Enuula October 23, 2010

then you insert the new operating system bootable cd/dvd and follow the instructions on the screen it will install

Reply

11 nelsone January 26, 2011

The system can’t boot after restart !!

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Reply

12 Erufailon April 6, 2011

How can I merge the deleted partition of windows with the partition of Ubuntu?

Reply

13 yoh-there April 17, 2011

@Erufailon: for this, you best use gparted, preferably through the (great!) sysrescue CD

http://www.sysresccd.org/Download (burn the iso file and boot with it)

Reply

14 M jagadeesh Varma September 23, 2011

its so helpfull to all the beginners thanx alot u are so clear in explaining without any confusion its really good

Reply

15 kaya September 28, 2011

i want to remove linux from my laptop and remain with windows 7 only

Reply

16 jagadeesh varma October 19, 2011

can any one guide me how to install the red hat linux 5.1 in vmware 7 as it is taking automatically not allowing us to give any configuration manually

Reply

17 anser November 22, 2011

wow greate i need this type of guide to perform create ,delete,extend in my hdd thanks for sharing this

Reply

18 BBoy November 27, 2011

Thank u bro!!! ;)

Reply

19 passerby December 26, 2011

Thanks a lot!

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 10 + 13 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: