How-to

How to Delete a Partition on a Linux Server

Deleting a partition is one command. The care goes into what comes before: unmounting it, removing every reference to it and making sure it is the right one.

What should I check before deleting?

  • Confirm the device path with lsblk -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINTS. Partition numbers are easy to mix up.
  • Copy off anything you still need. Deleting the entry does not erase data at once, but the next format will.
  • Check that it is not part of the system disk; findmnt -n -o SOURCE / shows the root device.
  • Look for users of the partition: fstab entries, LVM, mdadm arrays, swap and container volumes.

How do I release the partition first?

sudo umount /scratch
sudo swapoff /dev/nvme1n1p3          # only if it is swap
grep -n 'nvme1n1p2\|scratch' /etc/fstab
sudo pvs; sudo mdadm --detail --scan

Comment out or remove its line in /etc/fstab; a missing device with a plain fstab entry can stop the next boot. If pvs lists the partition as an LVM physical volume, remove its logical volumes and run sudo vgreduce and sudo pvremove before deleting. If it belongs to an mdadm array, stop or shrink the array first and remove its line from /etc/mdadm/mdadm.conf (or /etc/mdadm.conf on the RHEL family).

How do I delete it with parted?

sudo parted /dev/nvme1n1 print
sudo parted /dev/nvme1n1 rm 2
sudo parted /dev/nvme1n1 print

The number after rm is the partition number from print. parted applies the change at once; there is no separate write step, so read the print output carefully first.

How do I delete it with fdisk?

sudo fdisk /dev/nvme1n1
  p      # list partitions
  d      # delete, then type the number
  p      # check again
  w      # write

fdisk only changes the disk when you press w. If you deleted the wrong one, press q and nothing happens. That makes fdisk the friendlier choice when you are nervous.

How do I delete it from a script?

sudo sgdisk --delete=2 /dev/nvme1n1
sudo partprobe /dev/nvme1n1

sgdisk is non interactive and returns a clean exit code, which suits provisioning scripts. Follow any table change with partprobe so the kernel drops the old device node. If partprobe complains that the device is busy, something still uses it; go back to the release step.

How do I remove the whole partition table?

sudo wipefs --all --backup /dev/nvme1n1
sudo sgdisk --zap-all /dev/nvme1n1

Use this when you want a blank drive, for example before building a new RAID mirror or an LVM group across the disk. wipefs removes filesystem, RAID and partition table signatures, and --backup saves what it erased to files in your current folder, a small safety net. --zap-all also clears the backup GPT copy at the end of the disk, which otherwise makes some tools think a table still exists.

Does deleting a partition erase the data?

No. It only removes the entry in the partition table. The blocks stay on the drive until something overwrites them, and a tool like testdisk can often recover a partition deleted by mistake if you act before writing anything new. To actually destroy data on an SSD, the right tool is a secure erase or discard of the whole device:

sudo blkdiscard /dev/nvme1n1        # whole drive, instant on NVMe
sudo nvme format /dev/nvme1n1 --ses=1

Both are irreversible. Use them when you are done with a drive, never on one that holds your system.

Can I delete the partition my system runs on?

Not while it is running. The root filesystem cannot be unmounted on a live system, and without a rescue console there is no safe way to repartition the boot disk in place. If you want a different layout on the system drive, reinstall the image from the panel and set up the layout on the remaining space, or move data to the second drive. Before a reinstall, back up with Back up data with rsync.

What do I do with the free space now?

Create a new partition with Create a partition in Linux, or grow a neighbor partition into the gap with parted resizepart followed by xfs_growfs or resize2fs. Growing works while mounted on both XFS and ext4. Shrinking is a different story: XFS cannot shrink at all, and ext4 only shrinks unmounted.

Machines With Two Drives You Can Lay Out Freely

ServerProcessorCores / threadsMemoryStorageNetworkPer monthSmallest order
S3Intel Xeon E-2356G6 / 1264 GB DDR42x 1 TB NVMe2x 10 Gbps$80.38$80.38 (1 month)
S6Intel Xeon E-2288G8 / 1664 GB DDR42x 1 TB NVMe2x 10 Gbps$89.92$89.92 (1 month)
D92x Intel Xeon Gold 632632 / 64256 GB DDR42x 2 TB NVMe2x 25 Gbps$400.25$400.25 (1 month)

Keep Reading

Create a partition in Linux

Partition an empty drive on a Linux server with parted, fdisk or sgdisk, using GPT and proper alignment, without risking the system disk.

Open

Linux mount command

Mount drives, partitions and network shares on Linux, make them permanent in fstab with UUIDs, and unmount safely when something is busy.

Open

Format a disk on Linux

Turn the blank second NVMe drive into usable space: identify it, partition with GPT, choose ext4 or XFS, mount by UUID and keep TRIM on.

Open

fsck command

Check and repair Linux filesystems with fsck, e2fsck and xfs_repair, including how to run them safely on a remote server with no console.

Open

FAQ

Quick Answers

Often yes, if nothing was written since. testdisk can find the old start and end and restore the entry.

Something still uses the partition: a mount, swap, LVM or an mdadm array. Release it first.

It frees space in the partition table for new partitions. The data blocks stay until overwritten.

Use blkdiscard on the whole device or nvme format with a secure erase setting. Both are permanent.

Yes. A line pointing at a missing partition can stop the boot unless it has the nofail option.