How to Delete Partition in Linux?


Introduction

Linux is an open-source operating system, which is favored by many users for its robustness, flexibility and stability. One of the key features of Linux is its ability to provide users with better control over their system's resources. This is achieved through the use of the partitioning scheme, which divides a hard drive into multiple sections or partitions, allowing for more efficient use of space and resources.

What a partition is in Linux?

A partition in Linux can be thought of as a logical division or section on a hard drive that isolates data from other parts on the disk. It allows users to create separate spaces on their hard disk for different purposes like storing files, installing operating systems, and swap files among others.

Partitions can also be used to protect data from being overwritten or corrupted by isolating it from other data. The partitioning scheme in Linux operates at two levels - primary and extended.

Importance of deleting partitions in Linux

There may come a time when you need to delete a partition in your Linux system. This could be because you want to reorganize your storage space, or you no longer need that particular partition due to changes in your computing needs.

Moreover, if there are hardware issues with your hard drive or if one of the partitions has become corrupt or infected with malware, then deleting that specific partition can help prevent further damage. Deleting a specific partition also frees up space on your device's storage which could be valuable especially when working with large files like videos or photos.

Preparing to Delete a Partition

Backing up important data

Before deleting any partition in Linux, it is crucial to back up all important data stored on that partition. This is because the process of deleting a partition involves wiping out all of its contents permanently.

If you fail to make a backup of your data, you risk losing it forever. Therefore, ensure that you have made a copy of all necessary files and folders on an external hard drive or cloud storage service prior to proceeding.

Checking disk space and usage

It's essential to check the disk space and usage before deleting any partition in Linux. This information will help determine whether the deletion of that partition will free up enough space for other uses or if additional steps need to be taken, such as resizing existing partitions or adding new ones.

To check disk space usage, open the terminal and enter the command `df - h`. This command outputs detailed information about disk usage for each mounted file system in human-readable format.

Identifying the partition to be deleted

Once you have backed up your important data and assessed your disk space situation, identify which partition you want to delete. To do this, use the `fdisk` command in the terminal by following these steps −

  • Login as root user in terminal.

  • Type 'fdisk -l' (without quotes) and press enter.

  • A list of partitions on your hard drive(s) will appear

  • Note down the device name (e.g., /dev/sda1) of the partition you want to delete.

Deleting the Partition Using Command Line Interface (CLI)

Opening the Terminal and Logging in as Root User

The first step to deleting a partition in Linux using CLI is to open the terminal. This can be done by pressing Ctrl + Alt + T or by searching for Terminal in the applications menu.

Once you have opened the terminal, you need to log in as root user. This is because only root can perform administrative tasks such as creating and deleting partitions.

To log in as root, type "su" followed by your root password when prompted. If you do not have a root password set up, you can set one up using the "sudo passwd" command.

Unmounting the Partition to Be Deleted

Before you can delete a partition using CLI, it needs to be unmounted. This is because if a partition is mounted, it is being used and cannot be modified or deleted.

To unmount a partition, use the "umount" command followed by the path of the partition you want to unmount. For example, if your partition is located at /dev/sda1, you would enter "umount /dev/sda1".

If there are any processes actively using that partition, they will need to be stopped before unmounting. You can use the "lsof" command followed by the path of your partition to see which processes are currently using it.

Using fdisk Command to Delete the Partition

Once your desired partition has been successfully unmounted, it's time to delete it permanently using fdisk command. Type "fdisk /dev/sdX" where X represents whichever drive letter pertains to your particular drive on which Linux system resides. Once within fdisk prompt interface type (d) then select partiton number (i.e d 1) that needs to be deleted.

The prompt will ask if you are sure you want to delete the partition. Type "y" to confirm.

Verifying that the Partition has Been Deleted

After the partition has been deleted, you can verify that it is no longer present using the "lsblk" command, which lists all available block devices on your system. If your partition was successfully deleted, it should not appear in this list. You can also use tools like gparted or parted to verify that the partition has been deleted.

It should be noted that deleting a partition will permanently erase all data stored on it, so make sure you have backed up any important data before proceeding with this process.

Deleting the Partition Using Graphical User Interface (GUI)

Opening Disk Utility application on Linux desktop environment

For users who are more comfortable with a graphical user interface (GUI), deleting a partition can also be accomplished using the Disk Utility application. Disk Utility is an all-purpose disk management tool that comes pre-installed with most Linux distributions.

To start this process, you can navigate to the Disk Utility application on your Linux desktop environment by clicking on the "Applications" menu, then selecting "System Tools," and finally choosing "Disk Utility."

Selecting the partition to be deleted

Once you have opened the Disk Utility application, you will need to select the partition that you wish to delete from your hard drive. To do this, simply click on the partition name in the list of available drives and partitions.

Clicking on "Delete" option

After selecting your desired partition, click on the "Delete" button located at the top-left corner of the Disk Utility window. This will open a confirmation dialog box asking if you are sure that you want to delete this partition. Double-check that you have selected the correct partition before proceeding.

Verifying that the partition has been deleted

Once you have confirmed that you wish to delete your selected partition in Disk Utility, it may take a few moments for this process to complete depending on various factors such as disk size and speed. Once finished, verify that your desired partition has indeed been removed by checking its status within Disk Utility or by running system commands such as fdisk or lsblk in terminal mode.

Conclusion

Deleting partitions in Linux can be a simple task when the proper procedures are followed. It is important to always back up important data, check disk space and usage, and identify the partition to be deleted before proceeding with the deletion process. Both Command Line Interface (CLI) and Graphical User Interface (GUI) options were covered in this tutorial.

Updated on: 10-Jul-2023

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements