Since 2016 · 50,000+ customers · ★ 5.0 on Google Live chatWhatsAppTelegramOpen a ticket
Get started
Linux

How to Delete a Partition in Linux (CentOS, Rocky, Ubuntu)

How to delete a partition in Linux guide by 99RDP

Deleting a partition frees its space for a new layout or for extending another partition. It also erases access to everything on it, so the safe order matters: back up, unmount, remove it from /etc/fstab, then delete. This guide shows how with fdisk, parted and LVM, on CentOS, Rocky Linux, AlmaLinux, Ubuntu and Debian.

Quick answer(partition /dev/sdb1, not the system disk):

sudo umount /dev/sdb1
sudo sed -i.bak '/sdb1\|UUID-OF-SDB1/d' /etc/fstab     # or edit /etc/fstab by hand
sudo parted /dev/sdb rm 1
lsblk /dev/sdb
lsblk and blkid showing a test disk, its partition and the XFS filesystem before deleting it
Identifying the partition with lsblk -f

Step 1: Identify the partition

lsblk -f
sudo fdisk -l /dev/sdb

Check the device name, size, filesystem and mount point carefully. Never delete partitions on the disk you booted from (usually sda, vda or nvme0n1) unless you know exactly what you're doing; deleting the root, /boot or EFI partition makes the system unbootable.

Safe order to delete a partition in Linux: identify, back up and unmount, remove from fstab, delete, wipe signatures
Delete a partition safely

Step 2: Back up and unmount

Copy anything you need from the partition first. Then unmount it:

sudo umount /dev/sdb1
# "target is busy"? find what's using it:
sudo lsof +f -- /mnt/data

If it's a swap partition, turn it off with sudo swapoff /dev/sdb2.

Step 3: Remove it from /etc/fstab

sudo blkid /dev/sdb1          # note the UUID
sudo nano /etc/fstab          # delete or comment out the line with that UUID or device

Skipping this step can stop the server from booting, because it will try to mount a partition that no longer exists.

Step 4: Delete the partition

With fdisk

sudo fdisk /dev/sdb
  1. Press p to print the partition table.
  2. Press d and enter the partition number to delete.
  3. Press p again to check, then w to write the change. Until you press w, nothing is changed and q quits safely.

With parted

sudo parted /dev/sdb print
sudo parted /dev/sdb rm 1

If the kernel doesn't notice the change, run sudo partprobe /dev/sdb.

fdisk printing the partition table, deleting partition 1 and writing the change
Deleting a partition with fdisk

Deleting an LVM partition

On CentOS and Rocky, data partitions are often LVM logical volumes. Remove them from the top down:

sudo umount /data
sudo lvremove /dev/vg_data/lv_data
sudo vgremove vg_data            # only if the volume group is no longer needed
sudo pvremove /dev/sdb1
sudo parted /dev/sdb rm 1

Wipe leftover signatures (optional)

To remove old filesystem or RAID signatures so the disk looks new:

sudo wipefs -a /dev/sdb1      # before deleting the partition
sudo wipefs -a /dev/sdb       # the whole disk, including the partition table

wipefs doesn't overwrite the data itself. To destroy data securely before disposing of a disk, use your disk's secure-erase feature or overwrite it.

Frequently asked questions

How do I delete a partition in Linux?

Unmount it, remove it from /etc/fstab, then delete it with d in fdisk (and w to save) or parted /dev/sdX rm N.

Can I delete a partition that's in use?

No. Unmount it first (and swapoff for swap). The root partition can't be deleted from the running system.

Does deleting a partition erase the data?

It removes the partition entry, so the data is no longer accessible, but it isn't securely overwritten. Recovery tools may still find it.

How do I delete all partitions on a disk?

Create a new empty partition table with sudo parted /dev/sdb mklabel gpt, or wipe it with sudo wipefs -a /dev/sdb. Both destroy access to everything on the disk.

Nishant Kumar, Sr. Server Engineer at 99RDP
Written byNishant KumarSr. Server Engineer, 99RDP. Part of the team that runs our servers and answers support.
Keep reading

More Linux guides

All Linux guides

Need a server for this?

✓ Setup in minutes✓ Full admin access✓ 7-day refund on new services