The post list out the steps to delete a disk partition using fdisk command. Please note the procedure to delete a primary and extended partition is same. For the example in the post we are using the disk /dev/sdc and the partition to be deleted is /dev/sdc1.
Umount the filesystem
Make sure you have umounted the filesystem using the partition to be deleted. To view if the partition is mounted use the below command.
# cat /proc/mounts
To umount the mount point use the below command.
# umount /data
Listing the partition to be deleted
To get a listing of your current partition scheme use “fdisk -/dev/sdc
“. Use the print command (p
) to list your partition table:
# fdisk /dev/sdc Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x085579f4 Device Boot Start End Blocks Id System /dev/sdc1 2048 2099199 1048576 83 Linux /dev/sdc2 2099200 4196351 1048576 83 Linux
You can also use the command “fdisk -l
” to view all the partitions available on the system.
Deleting the partition
Use the the delete command (d
) to delete a partition, it will prompt you for the partition number. For this example we are going to remove /dev/sdc1. So use the number 1 when prompted for partition number to be deleted.
Command (m for help): d Partition number (1,2, default 2): 1 Partition 1 is deleted
If you have the last partition left to be deleted, using the deleted command will not prompt for partition number to be deleted and will delete the last partition directly.
Save the partition table and verify
Use the print command (p
) to list your partition table again and confirm if the partition 1 is deleted:
Command (m for help): p Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x085579f4 Device Boot Start End Blocks Id System /dev/sdc2 2099200 4196351 1048576 83 Linux
Finally save and exit fdisk with the write/quit command (w). Changes will be permanent after this command is executed.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. 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 or after you run partprobe(8) or kpartx(8) Syncing disks.