How to Delete a Partition in Linux: A Step-by-Step Guide

Delete a partition in linux

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Partitions are logical disc divisions that enable data organization and administration in an efficient manner. Therefore, like any other operating system, you need to divide your files, user data, and other storage requirements into different partitions. But, as your system grows and you need to scale your storage, you may need to change or delete a partition in Linux. 

Deleting a partition in Linux allows your system to free up space, consolidate partitions, or even just change your disc structure to meet the new requirements. 

While removing a partition may appear to be a difficult procedure, Linux supports powerful tools and utilities to make the process easier. Partitions can also protect data from being overwritten or corrupted by isolating it from other data. 

Why Do You Need to Delete a Partition in Linux?

Here are some reasons where it would be a smart idea to delete a partition in Linux. 

  1. Reorganize your disk space for creating new partitions or resizing existing ones. 
  2. Remove unwanted or redundant partitions to clean up the disk partitions that are no longer in use. 
  3. Change partition structure to modify the layout for better disk management. 
  4. Prepare for a new file system and remove old partitions. 
  5. Fixing partition errors of a corrupted or unresponsive partition. 
  6. Installing a new operating system to allocate space for a fresh OS installation.  
  7. Improving system performance to optimise storage and improve system efficiency by reorganising partitions. 
  8. To handle disk encryption or security concerns by wiping an entire disk for repurposing. 

Prerequisites for Deleting a Partition in Linux

To delete a partition in Linux, you need to follow some basic prerequisites. 

  1. Backup the data 

Backup your data on the partition to avoid accidental data loss. 

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

  1. Check Mounted Status

Make sure that you verify if the partition is mounted using lsblk or de -h commands. Use the following command to unmount, if it is not already mounted:
umount /dev/<partition-name>

  1. Identify the Correct Partition

Use tools like lsblk, fdisk -l, or parted to identify the partition you want to delete. Double-check to avoid deleting the wrong partition.

  1. Verify Disk Usage

Before you move forward with the process make sure that no processes or applications are using the partition. Use fuser command to check:
fuser -m /dev/<partition-name>

  1. Ensure Sufficient Permissions

You would need superuser access to delete a partition. Use sudo if you are not logged as in a root. 

  1. Prepare for System Impact

If the partition is a part of a crucial process, make yourself familiar with the consequences of the removal and prepare for a mitigation act. 

  1. Check Partition Table Compatibility

Confirm if your disk uses MBR or GPT partitioning schemes and use the right tool for it. 

Step-by-Step Guide to Delete a Partition in Linux

To delete a partition in Linux, you can follow these easy steps:

  1. Identify the Partition to Be Deleted

Use the lsblk or fdisk -I command to view the partitions on your system, using the command: 

fdisk -l

fdisk -l
  1. Unmount the Partition (If Mounted)

Unmount the partition to ensure that it is not in use, using the command:
umount /dev/<partition-name>

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

  1. Open the Disk Partition Tool

Use fdisk or parted to manage partitions. For example, with fdisk:
sudo fdisk /dev/<disk-name>

open disk partition tool
  1. Select the Partition

List the partitions within the tool and note the number of the partitions to be deleted.

  1. Delete the Partition

In fdisk, use the d command to delete the partition. You’ll be prompted to select the partition number.

  1. Save Changes

After deletion, save the changes to the partition table:
w

This writes the changes and exits the tool.

  1. Update the Kernel Partition Table

Refresh the kernel’s partition table to reflect the changes:
sudo partprobe /dev/<disk-name>

How to Verify the Partition Deletion

Verify if you disk has actually been deleted, using the following methods: 

  1. Use lsblk or fdisk -l to confirm the partition no longer exists.
  2. Run the parted tool to inspect the updated partition table:
    sudo parted /dev/<disk-name> print
  3. Check if the space previously occupied by the partition is now marked as free.

Common Errors & How to Resolve Them

ErrorCauseResolution
“Partition is in use”The partition is mounted or being used by a process.– Unmount the partition: sudo umount /dev/<partition-name>- Check processes with: fuser -m /dev/<partition-name>- Kill processes: sudo kill <process-id>
“Permission denied”Insufficient privileges to delete the partition.Run commands with sudo or as root: sudo fdisk /dev/<disk-name>
“Cannot write changes to partition table”Disk is read-only or partition table issue.– Remount the disk as writable: mount -o remount,rw /dev/<disk-name>- Repair disk issues: sudo fsck /dev/<partition-name>
“Failed to refresh kernel partition table”Unable to update kernel’s partition table.– Use partprobe to refresh: sudo partprobe /dev/<disk-name>- Reboot the system if needed.
“Invalid partition number”Incorrect partition number entered during deletion.List partitions and verify details: sudo fdisk -l
“Data loss due to incorrect partition selection”Wrong partition deleted by mistake.– Double-check partition details before deletion.- Use recovery tools like testdisk to attempt data recovery: sudo testdisk
“Disk partitioning tool not found”Tools like fdisk or parted are not installed.Install the required tools: sudo apt install fdisk or sudo apt install parted
“Cannot delete a system partition”Attempt to delete a critical system partition.– Avoid deleting essential partitions like / or /boot.- Boot from a live USB to manage non-essential partitions safely.

Conclusion

Deleting a partition in Linux is a super easy and streamlined process when done right. Proceed with caution and use the right tools, ensuring proper prerequisites, and double checking each step. 

Whether you are reorganizing your space, resolving space issues, or preparing for a new system, follow the best practices to delete a partition in Linux! 

Frequently Asked Questions

1. Do I need to reboot after deleting a partition?

In most cases, a reboot isn’t required. Use partprobe to refresh the partition table if the changes don’t reflect immediately.

2. What is the difference between MBR and GPT partitions?

MBR (Master Boot Record) supports up to 4 primary partitions, while GPT (GUID Partition Table) supports larger disks and more partitions. Ensure your tools support your disk’s partitioning scheme.

3. How do I verify a partition is deleted?

Run the lsblk or fdisk -l command to ensure the partition no longer appears in the list.

Marium Fahim
Hi! I am Marium, and I am a full-time content marketer fueled by an iced coffee. I mainly write about tech, and I absolutely love doing opinion-based pieces. Hit me up at [email protected].
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!