Linux: How to delete a partition with fdisk command

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/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.

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

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

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 31 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
31 comments… add one
  • Annamalai.M Sep 26, 2006 @ 15:17

    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

  • 🐧 nixCraft Sep 27, 2006 @ 20:28

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

  • Luca Jul 20, 2008 @ 15:37

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

    You saved my soul!

  • Ashish S Jan 20, 2009 @ 18:18

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

  • excellent Feb 27, 2009 @ 12:35
  • meetei Sep 9, 2009 @ 5:39

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

  • Mani Oct 1, 2009 @ 7:08

    Very Nice tut…

  • Syed Mustafa Jul 27, 2010 @ 17:45

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

  • tati Aug 11, 2010 @ 5:57

    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

    • Raju Enuula Oct 23, 2010 @ 6:56

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

  • nelsone Jan 26, 2011 @ 5:28

    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.

    • friendlyzz Aug 19, 2020 @ 4:04

      I can’ reboot the system.
      The message shown > PolicyKit daemon disconnected from the bus.
      We are no longer a registered authentication agent.

      How to solve this??

  • Erufailon Apr 6, 2011 @ 5:03

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

  • M jagadeesh Varma Sep 23, 2011 @ 2:35

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

  • kaya Sep 28, 2011 @ 13:25

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

  • jagadeesh varma Oct 19, 2011 @ 12:58

    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

  • anser Nov 22, 2011 @ 17:07

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

  • BBoy Nov 27, 2011 @ 14:35

    Thank u bro!!! ;)

  • passerby Dec 26, 2011 @ 9:06

    Thanks a lot!

  • Gigi B Feb 16, 2012 @ 10:47

    Nice tutorial! Thanks!

  • EH59 Mar 26, 2012 @ 17:17

    I followed all the steps suggested above, but when reboot my machine, it will not completely reboot. The following are the error showing:
    Checking filesystem:
    fsck.ext3: No such file or directory while trying to open /dev/sda7 [FAILED]

    /dev/sda7 was the partition I deleted. Any suggestion as to how I can resolve this will be highly appreciated. Thanks all in advance

  • nalini May 11, 2012 @ 15:07

    Thanks For helping me….

    I was complete step by step procedure….

  • letuma May 18, 2012 @ 4:21

    I am using Ubuntu bootable disk to delete the partition which has intalled Ubuntu. This is the only partition in my hard disk. The fdisk utility doest not respond to the command: “fdisk -l”, after sending this command, i get the command promp immediately below, without the system listing the partitions. As for “p” and “d” commands, the massage i get is “command not found”.
    PLEASE help

  • venugopal May 26, 2012 @ 20:13

    I have dual boot( winxp and fedora 10 ) installed in my PC(i installed Xp first and then fedora). xp got corrupted due to some virus. now i can login to Fedora only. but really i need Xp.
    i tried to boot from WINDOWS installation disk but a blank screen is coming due to no partitions available.

    with the help of above command i am able to delete partition and able to boot Xp

    Thanks A Lot…

  • Unreal Aug 2, 2012 @ 10:41


    I want to ask, can we use fdisk to mount HDD aswell ?
    When using cfdisk to make partitions on my 2nd HDD, its cannot write my partition table as no partition is marked as bootable

    I dont want bootable partition but just for /home and /var on my 2nd HDD

  • sundeep Aug 6, 2013 @ 5:05

    i installed RHEL 6.2 in my machine and when i am trying to delete my partition it is saying your partition table is not valid what may be the problem.

  • Oleksandr Jul 16, 2015 @ 10:34

    was very easy even for the beginner like me

  • Ben Aug 30, 2015 @ 22:23

    Hey, I enabled “developer mode” on my chromebook, and am trying to remove both sdc1 & 8 from my sandisk 64gb flash drive, labled sdc.I found out the partitions from the df command, but when I try to do anything with the fdisk command, it says “bash: fdisk: command not found”. What do I do.?? HELP!!!

  • Jobin Jan 2, 2016 @ 5:14

    Great tutorial it helps me lot.. :)

  • Bruno Jun 4, 2016 @ 22:36

    Simply Awesome!
    This tutorial was clear, concise and helpful. Please keep it up!
    Cheers Lad.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum