How to delete partition in linux

How to Delete Partition in Linux Step-by-Step

Sometimes, you might want to delete some disk partitions on your Linux system to recover or regain some storage space. You can easily accomplish this on the command line with a few simple steps.

In this guide, we will demonstrate how you can delete a partition in Linux step-by-step. We will start off by deleting a standard partition and then deleting an LVM partition.

Delete a standard partition using the fdisk utility

The fdisk tool, also known as format disk, is a Linux utility that ships by default with every modern Linux distribution. The tool provides disk partitioning functions such as creating and deleting disk partitions, modifying the partition table, and printing the disk partitions to mention just a few.

Before deleting a partition, it is always advised to back up any data on it.

In our setup, we have a USB drive attached to the system with two partitions: /dev/sdc1 and /dev/sdc2 . To confirm the existence of the partitions, we will run the fdisk utility as follows.

list-partitions-on-disk-fdisk-command-linux

You can also run the command to list the partitions on the block volume as shown.

list-partitions-on-disk-with-lsblk

We are going to delete the second partition /dev/sdc2 using the fdisk utility.

To get started, invoke the fdisk command-line tool.

This launches an interactive command-line prompt. Type ‘p’ to print the current partition table of the drive. The output below confirms the existence of the two partitions.

fdisk-command-print-partitions-linux

Since our mission is to delete the second partition, we will type ‘d’ for delete and press ENTER. Next, specify the partition number of the drive to be deleted – in this case, partition number 2 which corresponds to /dev/sdc2 .

You will get the message: Partition 2 has been deleted .

To save the changes made to the partition table, type ‘w’ to write changes and press ENTER .

Select-partition-number-for-deletion-fdisk-command

To verify that the volume has been deleted, once again, run the fdisk utility as follows.

When prompted for the command, type ‘p’ for print to view the partition table. This time around, only one partition is listed – /dev/sdc1 . This confirms that we have successfully deleted the second partition.

Verify-Partitions-After-Deletion-Fdisk-Command

How to delete an LVM partition

LVM (Logical Volume Management ) is a storage concept that combines multiple disk partitions or hard drives into a single volume group (VG). The volume group can, hence, be used as a single large volume or sub-divided into other logical volumes (LV)

In this setup, we have a volume group called vg01 mounted on a mount point called /data .

df-command-for-particualr-partition

You can also run the lvs command to list the Logical Volume and Volume Groups.

List-LVM-partition-with-lvs-command

We are going to delete lv01 Logical Volume from the vg01 Volume Group.

To do so, first, delete the Logical Volume entry from the /etc/fstab file.

$ cat /etc/fstab . /dev/mapper/vg01-lv01 /data ext4 defaults 0 0 .

Save the changes and exit the file. Next, unmount the directory on which the Logical Volume is mounted.

Читайте также:  Wot linux нет звука

Next, disable the Logical Volume Group.

$ sudo lvchange -an /dev/vg01/lv01

Be sure to delete the LVM volume. When prompted, type ‘y’ to proceed

$ sudo lvremove /dev/vg01/lv01

Next, disable the Volume Group.

Thereafter, delete the Volume Group.

Finally, delete the physical volumes that were used to create the Volume Group called vg01 . In this case, these were /dev/sdb1 and /dev/sdb2 .

$ sudo pvremove /dev/sdb1 /dev/sdb2

Deleting-LVM-Partition-Linux-Commands

When you run the lvs command again, you won’t get any output. This is a confirmation that the LVM volume has successfully been deleted.

lvs-command-after-deleting-lvm-partition-linux

Conclusion

And it’s a wrap. We have successfully demonstrated how you can delete a standard and an LVM partition in Linux. We hope you were able to follow along and implement the steps to delete disk partitions on your system.

Источник

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.

Читайте также:  Linux mint или linux xfce

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.

Источник

How to Delete Partition in Linux

Linux users create partitions to organize their data in an efficient manner. As easy as they are created, Linux partitions can be deleted to reformat a storage device and regain storage space.

In this step-by-step tutorial, you will learn how to delete a partition on a Linux system.

How to Delete Partition in Linux

  • A system running Linux
  • A user account with sudo or root privileges
  • Access to a terminal window / command line (Activities >Search >Terminal)
  • The fdisk command-line utility
Читайте также:  Linux способы установки пакетов

Delete a Partition in Linux

Deleting a partition in Linux requires selecting the disk containing the partition and using the fdisk command-line utility to delete it.

Follow the steps outlined in the sections below to delete partitions in Linux.

Note: The fdisk command-line utility is a text-based partition table manipulator. It is used for partitioning and repartitioning storage devices.

Step 1: List Partition Scheme

Before deleting a partition, run the following command to list the partition scheme.

In our case, the terminal prints out information about two disks: /dev/sda and /dev/sdb . Disk /dev/sda contains the operating system, therefore its partitions should not be deleted.

Listing the partition scheme

On the /dev/sdb disk, there is a /dev/sdb1 partition which we are about to delete.

Note: The number 1 in /dev/sdb1 indicates the partition number. Make a note of the number of the partition you intend to delete.

Step 2: Select the Disk

Select the disk that contains the partition you intend to delete.

Common disk names on Linux include:

Type of disk Disk names Commonly used disk names
IDE /dev/hd[a-h] /dev/hda, /dev/hdb
SCSI /dev/sd[a-p] /dev/sda, /dev/sdb
ESDI /dev/ed[a-d] /dev/eda
XT /dev/xd[ab] /dev/xda

To select a disk, run the following command:

Selecting storage disk with fdisk command.

Step 3: Delete Partitions

Before deleting a partition, back up your data. All data is automatically deleted when a partition is deleted.

To delete partition, run the d command in the fdisk command-line utility.

The partition is automatically selected if there are no other partitions on the disk. If the disk contains multiple partitions, select a partition by typing its number.

The terminal prints out a message confirming that the partition is deleted.

Deleting partition.

Note: If you wish to delete multiple partitions, repeat this step as many times as necessary.

Step 4: Verify Partition Deletion

Reload the partition table to verify that the partition has been deleted. To do so, run the p command.

The terminal prints out the partition structure of the disk selected in Step 2.

Partition table reload.

Step 5: Save Changes and Quit

Run the w command to write and save changes made to the disk.

Quitting fdisk command-line utility and saving changes to the disk.

After following the instructions in this tutorial, you should have learned how to delete a partition in Linux.

If you want to learn more about partition manipulation, we recommend reading our tutorial on creating partitions in Linux or if you are running NTFS partitions, check out our article on how to mount NTFS partitions in Linux.

Dejan is the Head of Content at phoenixNAP with over 8 years of experience in Web publishing and technical writing. Prior to joining PNAP, he was Chief Editor of several websites striving to advocate for emerging technologies. He is dedicated to simplifying complex notions and providing meaningful insight into data center and cloud technology.

In Linux systems, in order to use storage devices such as Hard Drives and USB drives, you need to understand.

sudo stands for SuperUser DO, and it’s used to temporarily elevate privileges in Linux. This guide will show.

The ls command (short for list) lists information about directories and any type of files in the working.

A list of all the important Linux commands in one place. Find the command you need, whenever you need it or.

Источник

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