How to Delete Partitions in Linux Using fdisk 

Try this guide with our instant dedicated server for as low as 40 Euros

delete partitions in fdisk

Managing disk space is a crucial aspect of system administration, especially when dealing with Linux servers that serve business users and applications. 

Whether you’re reallocating space, removing unused partitions, or preparing a disk for a different use, knowing how to safely delete a partition is an essential skill. 

In most Linux distributions, you can use fdisk, a powerful disk management utility that is included in the core util-linux package. This utility has a long history, starting when IBM released the first version in 1983. 

In this focused tutorial, we will describe the steps of the process of using the fdisk utility to delete partitions. After going through this guide, you will be able to manage your disk space effectively without risking your data.

Table Of Contents

  1. Delete Partition in Linux Using the fdisk Utility
    1. The Prerequisites
    2. Step #1: List the Partition Scheme
    3. Step #2: Select the Disk
    4. Step #3: Delete the Partition(s)
    5. Step #4: Verify Partition Deletion
    6. Step #5: Save Changes and Quit
  2. Conclusion
  3. FAQs

Delete Partition in Linux Using the fdisk Utility

Let’s run through the steps of deleting partitions in Linux using the fdisk utility.

But before that, you should make sure you meet the following prerequisite requirements.

The Prerequisites

Before we dive into the partition deletion process, ensure you have the following readily available:

  • A Linux system: This guide is applicable to all mainstream Linux distributions.
  • Root or sudo access: Partition management requires administrative privileges.
  • Back up Important data: Always back up important data before modifying disk partitions to avoid accidental loss.

Step #1: List the Partition Scheme

The first step in deleting a partition is to understand how your disk is partitioned. 

Linux offers several commands to list partitions, but lsblk and fdisk are among the most common.

Use lsblk to View Disk Partitions

Open the terminal and type:

# lsblk

lsblk

The output shows information about block devices and their partitions in a Linux system. On our test system, the command lists devices like sda (a 20GB hard disk) and sr0 (a 1GB CD-ROM), along with partitions such as sda1 (a small 1MB partition, possibly for system use) and sda2 (a 20GB partition mounted as the root filesystem /). 

The columns display each device’s name, size, whether it’s removable, if it’s read-only, its type (disk, partition, or ROM), and mount points. 

Use fdisk to View Disk Partitions

Alternatively, you can use fdisk with the -l option to list all partitions:

# fdisk -l 

fdisk -l

The output shows details about disk partitions on our test Linux system. 

It lists a 20 GB disk (/dev/sda), with a GPT disklabel, indicating it’s formatted with a GUID Partition Table. The disk has two partitions: /dev/sda1, a 1M BIOS boot partition, and /dev/sda2, a 20 GB Linux filesystem partition. The output includes sector sizes, total sectors, and disk identifiers, providing a concise overview of the disk’s layout and usage.

Step #2: Select the Disk

Choose the disk that has the partition you want to remove.

Here’s a simplified table format that outlines the common disk naming conventions in Linux based on the disk type:

selecting the disk

Identifying the Target Disk

Once you’ve listed the partitions, identify the disk from which you want to delete a partition. Disks are usually named /dev/sda, /dev/sdb, etc., with partitions numbered like /dev/sda1, /dev/sda2, and so on.

Step #3: Delete the Partition(s)

 We will now use fdisk to delete a partition from the disk. 

Important: Before proceeding with the tutorial, we strongly recommend selecting the correct disk and partition to avoid data loss. 

Next, type the following command, replacing /dev/sdx with your disk’s actual name (e.g., /dev/sda):

# sudo fdisk /dev/sdx

sudo fdisk

Delete the Partition

In the fdisk menu, type d to delete a partition. If there’s more than one partition, the utility will ask for the partition number. Input the number of the partition you wish to delete and press Enter.

Delete the Partition

Step #4: Verify Partition Deletion

After running a delete operation using fdisk, we recommend confirming the outcome and ensuring the partition is indeed removed. In the fdisk menu, type p to list the current partition table. 

The deleted partition should no longer be listed.

Verify Partition Deletion

Step #5: Save Changes and Quit

At this point, you should note that you need to apply the changes. For this, type w in the fdisk menu. This will write the modified partition table to the disk and exit the utility. 

Alternatively, type q to exit without saving these changes.

Save Changes and Quit

Conclusion

When done carefully, deleting a partition in Linux is a straightforward process. Always ensure you’ve selected the correct partition and have backups of any important data. Managing your server’s partitions can lead to better system performance and organization.

For those looking to host their Linux servers, RedSwitches Bare Metal Hosting provides robust, reliable solutions tailored to your needs. Their dedicated servers ensure your applications run smoothly, offering the flexibility and control required for effective system administration, including partition management.

By following this guide and choosing a reliable hosting provider like RedSwitches, you can manage your Linux server’s disk space efficiently and with confidence.

FAQs

Q. What is fdisk utility in Linux?

fdisk is a command-line utility used to manage disk partitions on a system running Linux.

Q. How can I delete a partition using fdisk?

To delete a partition using the fdisk utility, you must first log into your system as root or use the sudo command to gain superuser privileges. Then, you can run the fdisk command with the appropriate options to delete the desired partition.

Q. Can I use a graphical interface to delete a partition in Linux?

Yes, you can use tools like GParted, which provides a graphical interface to manage disk partitions on Linux systems. It allows you to delete, create, resize, and move partitions using a user-friendly GUI.

Q. Is it necessary to unmount a partition before deleting it?

Yes, it is essential to unmount a partition before attempting to delete it using fdisk or any other partition management tool. This ensures that the partition is not in use and can be safely deleted without causing data corruption.

Q. How can I ensure that the partition has been deleted after using fdisk?

After using fdisk to delete a partition, you can verify that the partition is no longer present by running the appropriate commands or using tools like GParted to view the current partition layout on your system.

Q. Are there any specific precautions to take when deleting a partition in Linux?

When deleting a partition in Linux, it is important to double-check and ensure that you are targeting the correct partition to avoid accidental data loss. Additionally, always make sure to have a backup of important data before making any changes to disk partitions.

Try this guide with our instant dedicated server for as low as 40 Euros