Delete all partition linux

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.

Читайте также:  Remove all files but one in linux

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.

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.

Читайте также:  Astra linux инвентаризация компьютеров

Источник

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.

Источник

How To Delete Partition In Linux Using Command Line (fdisk)

Sometimes we stuck in a situation where we just have access to the terminal and need to delete partition, or you have stepped down in Linux, and your logical mind pushes you to delete the partition using a command.

But you don’t know how to delete the partition using the terminal, not a big deal, and I’m here to rescue you just follow the instruction, and your motive will be accomplished.

In this article, we will use fdisk command-line based utility to delete the partition.

Prerequisites

  • Privilege account (sudo users)
  • Terminal
  • fdisk (Already preinstalled in Linux)
  • A partition should exist (If you think you can delete unallocated partition, then I suppose you might be wrong)

Delete a Partition in Linux using fdisk

To Delete partition first, we need to list out the available partitions and select the appropriate disk. For that, we can use the fdisk command to list out and delete the selected partition.

Читайте также:  How to make commands in linux

If you don’t know what is fdisk read these short descriptions and move ahead to delete partitions.

In short fdisk is a command-line utility tool to manage disk it allow you to view, create, delete, change, resize, copy and move partitions on a hard drive.

Note:- This below step will format your USB drive, so it requests you to make a backup of your USB drive else you may lose your valuable data.

Type command p

Step 3: Delete Partitions using fdisk

We are one step back to delete partition, from the above measure we confirmed we had selected correct Disk.

In this step we will delete partition If you have important data, please make sure to take a backup and proceed next.

To delete partition type d or del command in the fdisk command-line utility followed by partition number in case of multiple partitions.

Command (m for help): d Partition number (1-10, default 10): 10 Partition 10 has been deleted. Command (m for help): 

In my case, multiple partitions are available to /dev/sda because of that, and I have to pass partition number manually.

If you are thinking How to get the partition number, check the above output of p command and note it down.

Delete partitions

Step 4: Verify changes

From the above command, we are able to delete selected partitions, To make sure whether the partition is deleted pass the p command in the fdisk command-line utility.

Verify partition is deleted

We can see the change earlier total of 10 partitions was available in /dev/sda now it’s 9, hold on our work is not completed one last command is required to type.

Step 5: Save and exit

This is the last step to delete partition, after that you will not be able to revert changes.

Inside the same terminal type w command to write changes once the changes apply you will get the exit from fdisk utility tool.

Type w command to save changes

This is a demo of the above explanation you can a look at the below output screen.

Complete step to delete partitions using fdisk

Wrap-up

That’s all my friend to delete the partition using the fdisk command-line utility. In case you need some assistance from my end, feel free to comment Down.

If you want to share some feedback or any topic feel free to comment down.

A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.

Источник

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