How to delete all linux partitions

How to Delete Partitions in Linux [Beginner’s Guide]

Managing partitions is serious business, especially when you have to remove them. I find myself doing this frequently, especially after using thumb drives as live disks and Linux installers because they create several partitions that I won’t need afterwards.

In this tutorial, I will show you how to remove partitions in Linux using both command line and GUI tools.

You delete the partition, you lose your data. Whenever you are playing with partitions, make sure backup your data. A slight typo or slip of finger could prove costly. Don’t say we didn’t warn you!

Remove disk partition using GParted [GUI Method]

As a desktop Linux user, you probably will be more comfortable and perhaps safer with a GUI-based tool.

There are several tools that let you manage partitions on Linux. Depending on your distribution you will have one or even more such tool already installed on your system.

For this tutorial, I am going to use GParted. It is a popular open source tool and it’s very easy and intuitive to use.

The first step is installing GParted if it isn’t already in your system. You should be able to find it in the software center of your distribution.

gparted ubuntu software center

Alternatively, you can use your distribution’s package manager for installing it. In Debian and Ubuntu-based Linux distributions, you can use the apt install command:

Once installed, let’s open GParted. Since you are dealing with disk partitions, you’ll be required to have root access. It will ask for authentication and once it opens you should see a window like this one:

removing partitions linux 004

On the right-upper corner you can select the disk and in the lower screen the partition you want to remove.

Next, select the option Delete from the Partition menu:

Removing partitions in Linux with GParted

The process is incomplete until you rewrite the partition table. This is a safety measure and it gives you the option to review the changes before confirming it.

To do this just click on the Apply All Operations button located in the toolbar and then Apply when asked for confirmation.

Confirm changes to partitions in GParted

After hitting Apply, you will see a progress bar and a results message saying that all the operations were successful. You can close the message and the main window and consider your partition completely deleted from our disk.

Now that you are aware of the GUI method, let’s move on to the command line.

Delete partitions using fdisk command

Almost every Linux distribution comes with fdisk by default and we are going to use this tool today. The first thing you need to know is what device is assigned to the disk with the partitions you want to remove. To do that, type the following in the terminal:

This will print all the drives and partitions in our system as well as the assigned devices. You need to have root access in order for it work.

Читайте также:  Linux mint 20 настройка vlan

In this example, I will work with a USB drive that contains two partitions as shown below:

Using fdisk for partitions in Linux

The device assigned in the system is /sdb and it has two partitions, sdb1 and sdb2. Now that you identified which device contains the partitions, you can start working on it by using fdisk and the path to the device:

This will start fdisk in command mode. You can always press m to see a list of options.

Next, type p and press Enter to view the partition information and confirm that you are using the right device. If the wrong device is in use you can use the q command to exit fdisk and start the procedure again.

Now enter d to delete a partition and it will immediately ask for the partition number, that corresponds to the number listed in the Device column, which in this case are numbers 1 and 2 (as can be seen in the screen capture below) but can and will vary according to the current partition table.

Remove partitions in Linux using fdisk

Let’s remove the second partition by typing 2 and pressing Enter . You should see a message saying “Partition 2 has been deleted“, but actually, it hasn’t been removed yet. fdisk needs one more step to rewrite the partition table and apply the changes. Safety net, you see.

You need to type w and press Enter to make the changes permanent. No confirmation is asked.

After this, you should receive some feedback like the one here:

Delete partition in Linux with fdisk

Now, use sudo fdisk —list /dev/sdb to view the current partition table of the device and you can see that the second partition is completely gone. You are done removing your partition using the terminal and fdisk command. Success!

Wrapping up

And so I end this tutorial on how to remove partitions in Linux using both the terminal and GUI tools. Remember, stay always on the safe side, backup your files before manipulating your partitions and double check that you are using the right device. Deleting a partition will delete everything in it with little to no chance of recovering it.

Источник

Three Ways to Delete the Partitions Under Linux

This tutorial explains how to remove the partitions under Linux using different tools including fdisk, cfdisk and gparted.

After reading this article, you will be able to delete the partitions in Linux by applying a few steps. The command line techniques that are shared in the following examples are valid for all the Linux distributions. In some cases, some additional packages need to be installed. Additionally, we also included the steps for the users who are looking for a graphical method.

All the instructions in this document contain screenshots to make it easy for every Linux user to understand and implement them independently of their experience level.

Deleting Partitions Under Linux Using Cfdisk

The first section of this tutorial shows how to delete the partitions in Linux using the cfdisk partitioning tool.

The cfdisk utility is a command line that is interactive and a user friendly partitioner. This is the partitioning tool of choice for the users without too much experience with the Linux terminal. It is the easy version of the popular fdisk tool.

Читайте также:  Самый сложный дистрибутив линукс

Before we start, let’s see our partition table, including all the storage attached devices. To do it, we can use the fdisk command followed by the -l (list) flag as shown in the following screenshot:

Note: The fdisk utility can be executed by the root and privileged users.

As you can see in the given output, there is a /dev/sdc device with two partitions: /dev/sdc1 and /dev/sdc2.

In our case, we want to delete the /dev/sdc2 partition (white arrow).

Run the cfdisk using sudo or as root, followed by the device whose partition is what you want to remove.

Note: Specify the /dev/sdX device, not the specific partition (/dev/sdX2).

As said previously, cfdisk is an interactive partitioning tool.

To start deleting a partition, use the Up/Down keys to select the partition to remove. And use the Left/Right keys to select the Delete option as shown in the following figure, and press ENTER.

Then, use the Left/Right keys to select Write and press ENTER.

After pressing ENTER, you will be requested to confirm the operation by typing “yes” (without quotation marks) and pressing ENTER.

Note: After this step, the partition will be fully deleted.

As you can see now, the old partition /dev/sd2 was deleted and its space is now unallocated.

To quit the cfdisk, just move to the Quit option and press ENTER.

That’s how you can easily remove the Linux partitions from the command line.

How to Remove Partitions Under Linux Using Fdisk

Despite not being very user friendly, the fdisk partitioning tool is the most popular among the Linux operating systems. It is even present in the Microsoft operating systems.

To show the connected storage devices and partitions, run the fdisk followed by the –l (list) flag as we did in the previous section of this tutorial.

As done in the first example of this tutorial, we delete the /dev/sdc2 partition.

Use sudo to run the fdisk followed by the device that contains the partition that you want to delete. In our case, it is the /dev/sdc.

Note: Specify the /dev/sdX device, not the specific partition (/dev/sdX2).

After executing the sudo fdisk /dev/sdX (upper arrow), you will get a command prompt to execute the instructions.

The first instruction to indicate that you want to delete a partition is delete, which you can choose by typing the letter d, then pressing ENTER (second arrow).

Then, you will be asked to select the partition number to remove. In our case, we remove the /dev/sdc2 partition. Therefore, we type 2 and press ENTER (third arrow).

To apply the changes on the device and confirm the deletion of the partition, type w (Write) and press ENTER (lower arrow).

You can confirm whether the operation is successful by executing the sudo fdisk -l again.

As you can see, the partition was successfully removed.

How to Delete Partitions Under Linux Using Gparted (GUI)

This section shows a graphical alternative to remove the partitions under Linux called Gparted.

This is a good way for the users who are not used to the Linux terminal.

To begin, install the Gparted on the Debian based Linux distributions like Ubuntu using the apt command as instructed in the following image:

Читайте также:  Linux настройка смены языка

Once installed, execute the gparted from the console or from the Applications menu bar.

Type the sudo password when requested and press ENTER.

On the upper right corner, there is a dropdown menu to select the drive that contains the partition that you want to remove.

In our case, we selected the /dev/sdc device.

To remove the /dev/sdc2 partition, right-click it and press Delete.

You will notice that the partition now appears as unallocated, but changes were not yet made.

As you can see at the bottom of the window, the operation is still pending. To write the changes, press the green checkmark (upper arrow).

You will be asked to confirm the operation. After confirming it, your partition will be removed. This step cannot be undone.

After the partition is removed, press the Close button.

Now, you can close the Gparted.

That’s all. We hope that some of the given methods were good for you to delete your Linux partitions.

Conclusion

As you can see, removing the partitions in Linux is pretty simple. Linux offers different methods to achieve this, all of them can be implemented by any Linux user independently of their knowledge level. The command line techniques are applicable for all the Linux distributions, while Gparted is obviously only available for the operating systems with X Window managers or graphical environments.

It is important to remember that the instructions which are detailed in this article cannot be undone. If you remove a partition, the data won’t be easily recovered. By following the steps explained, you can remove all types of partitions including FAT, FAT32 and NTFS.

Thank you for reading this Linux tutorial which explains how to delete the partitions. Keep following us for additional Linux tips and articles.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.

Источник

How to clear/delete all the partition table from a disk or partition in Linux

Disk /dev/sdb: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x1410600c

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 10487807 3145728 83 Linux

Now I would like to clear the partition table from this disk
To do so below commands can be used

Check the partition table

Here I have a dos partition table

Clear the partition table

Using the below command you can wipe » dos » partition table

# wipefs -a -t dos -f /dev/sdb
/dev/sdb: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
/dev/sdb: calling ioclt to re-read partition table: Success

If I had a GPT partition table then to clear the same

To clear all the partition tables

You can also delete a partition table using the offset value as shown above

Once the above command returns success, check the partition table using fdisk

Disk /dev/sdb: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

As you both my partitions are cleared/deleted.

Источник

Оцените статью
Adblock
detector