• 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. How to add a Custom Script to systemd in CentOS/RHEL 7
  2. Hostname change not reflecting in sar report for CentOS/RHEL
  3. Getting info with the vsish command (esxi only)
  4. How to use “xfs_admin” command to change parameters of an XFS filesystem
  5. How to use command line shell functions in Linux
  6. /etc/rsyslog.conf – Setup a Filter to Discard or Redirect Messages
  7. How to use Magic SysRq tool in CentOS / RHEL
  8. getfacl Command Examples in Linux
  9. How To Configure Separate Override.conf For Multiple MySQL Instances Using Systemd
  10. How to disable Ctrl+Alt+Del causing system reboot in CentOS/RHEL 6

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright