• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to delete a partition using fdisk

by admin

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.

How to view linux disk partitions (partition table)

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.

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. RHEL 7 – RHCSA Notes – vi/vim editor
  2. Linux Interview Questions : Open Files / Open File Descriptors
  3. adduser Command Examples in Linux
  4. iperf Command Examples in Linux
  5. CentOS / RHEL : How to create and host yum repository over httpd
  6. CentOS / RHEL 6,7 : How to recover an interrupted yum package installation
  7. nmcli device Command Examples in Linux
  8. How to Change Default Permission of /var/log/messages in CentOS/RHEL
  9. How to change the Default Log Directory(/var/log) in Rsyslog for CentOS/RHEL 6,7
  10. How to Setup SSH keys for “passwordless” SSH Login on CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright