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.
- Reorganize your disk space for creating new partitions or resizing existing ones.
- Remove unwanted or redundant partitions to clean up the disk partitions that are no longer in use.
- Change partition structure to modify the layout for better disk management.
- Prepare for a new file system and remove old partitions.
- Fixing partition errors of a corrupted or unresponsive partition.
- Installing a new operating system to allocate space for a fresh OS installation.
- Improving system performance to optimise storage and improve system efficiency by reorganising partitions.
- 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.
- Backup the data
Backup your data on the partition to avoid accidental data loss.
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
- 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>
- 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.
- 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>
- Ensure Sufficient Permissions
You would need superuser access to delete a partition. Use sudo if you are not logged as in a root.
- 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.
- 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:
- 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
- Unmount the Partition (If Mounted)
Unmount the partition to ensure that it is not in use, using the command:
umount /dev/<partition-name>
- Open the Disk Partition Tool
Use fdisk or parted to manage partitions. For example, with fdisk:
sudo fdisk /dev/<disk-name>
- Select the Partition
List the partitions within the tool and note the number of the partitions to be deleted.
- Delete the Partition
In fdisk, use the d command to delete the partition. You’ll be prompted to select the partition number.
- Save Changes
After deletion, save the changes to the partition table:
w
This writes the changes and exits the tool.
- 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:
- Use lsblk or fdisk -l to confirm the partition no longer exists.
- Run the parted tool to inspect the updated partition table:
sudo parted /dev/<disk-name> print - Check if the space previously occupied by the partition is now marked as free.
Common Errors & How to Resolve Them
Error | Cause | Resolution |
“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.