What impact does deleting a partition have on data in Linux?

青灯夜游
Release: 2023-03-14 09:18:05
Original
3519 people have browsed it

In Linux, deleting a partition will also delete the data in the partition, resulting in data loss. How to delete a partition: 1. Install the GParted tool, select the partition you want to delete in the GParted interface, and select the "Delete" option from the partition menu; 2. Use the fdisk command to delete, with the syntax "sudo fdisk --list partition name".

What impact does deleting a partition have on data in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Each partition in the Linux system is a file system and has its own directory hierarchy.

linux What impact does deleting a partition have on data?

Deleting a partition will also delete the data in the partition, resulting in data loss.

So whenever you are working on a partition, be sure to back up your data. A slight typo or slippage can be costly. Don't say we didn't warn you!

Linux disk partition

1. Primary partition, extended partition and logical partition

Linux There are three types of hard disk partitions: primary partition, extended partition and logical partition.

The partitions of the hard disk are mainly divided into two types: primary partition (Primary Partion) and extended partition (Extension Partion). The sum of the number of primary partitions and extended partitions cannot be greater than four.

  • Primary Partion: It can be used immediately but cannot be partitioned again.

  • Extension Partion: It must be partitioned before it can be used, which means it must be partitioned twice.

  • Logical partition ((Logical Partion)): A partition established by an extended partition. There is no limit on the number of logical partitions.

The extended partition is just a "container" for the logical partition. In fact, only the primary partition and the logical partition are used for data storage.

2. The identification of hard disk partition under Linux

The identification of hard disk partition is generally /dev/hd[a-z]X or /dev/sd[a-z]X. Identification, where [a-z] represents the hard disk number, and X represents the partition number in the hard disk.

The block number identification of the entire hard disk partition: under Linux, hda, hdb, sda, sdb, etc. are used to identify different hard disks;

Among them:

  • IDE interface hard disk: represented as /dev/hda1, /dev/hdb...;

  • SCSI interface hard disk and SATA interface hard disk are represented as /dev/sda, /dev/ sdb... ... ;

Partitions in the hard disk: If the value of For example, /dev/hda5 must be a logical partition;

For example:

Use hda1, hda2, hda5, and hda6 to identify different partitions. Among them, the letter a represents the first hard disk, b represents the second hard disk, and so on. The number 1 represents the first partition of a hard disk, 2 represents the second partition, and so on. 1 to 4 correspond to the primary partition (Primary Partition) or extended partition (Extension Partition). Starting from 5, they all correspond to the logical partition of the hard disk (Logical Partition). Even if a hard disk has only one primary partition, the logical partitions are numbered starting from 5, so special attention should be paid to this.

What impact does deleting a partition have on data in Linux?

How to delete a partition in Linux

1. Use GParted to delete a disk partition (GUI Method)

As a desktop Linux user, you may feel more comfortable, and perhaps more secure, with GUI-based tools. There are several tools that let you manage partitions on Linux. Depending on your distribution, you may have one or more of these tools installed on your system. In this tutorial, I will use GParted. It is a popular open source tool that is very simple and intuitive to use.

The first step is to install GParted if it is not already on your system. You should be able to find it in your distribution's Software Center.

What impact does deleting a partition have on data in Linux?

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

sudo apt install gparted
Copy after login

After the installation is complete, let us open GParted. Since you are dealing with disk partitions, you need root access. It will ask for authentication and once it opens, you should see a window similar to this:

What impact does deleting a partition have on data in Linux?

In the upper right corner you can select the disk and below select the one you want to delete Partition.

Next, select the “Delete” option from the partition menu:

What impact does deleting a partition have on data in Linux?

这个过程是没有完整完成的,直到你重写分区表。这是一项安全措施,它让你在确认之前可以选择审查更改。
要完成它,只需点击位于工具栏中的 “应用所有操作” 按钮,然后在要求确认时点击 “应用”。

What impact does deleting a partition have on data in Linux?

点击 “应用” 后,你会看到一个进度条和一个结果消息说所有的操作都成功了。你可以关闭该信息和主窗口,并认为你的分区已从磁盘中完全删除。

现在你已经知道了 GUI 的方法,让我们继续使用命令行。

2、使用 fdisk 命令删除分区(CLI 方法)

几乎每个 Linux 发行版都默认带有 fdisk,我们今天就来使用这个工具。你需要知道的第一件事是,你想删除的分区被分配到哪个设备上了。为此,在终端输入以下内容:

sudo fdisk --list
Copy after login

这将打印出我们系统中所有的驱动器和分区,以及分配的设备。你 需要有 root 权限,以便让它发挥作用。

在本例中,我将使用一个包含两个分区的 USB 驱动器,如下图所示:

What impact does deleting a partition have on data in Linux?

系统中分配的设备是 /sdb,它有两个分区:sdb1 和 sdb2。现在你已经确定了哪个设备包含这些分区,你可以通过使用 fdisk 和设备的路径开始操作:

sudo fdisk /dev/sdb
Copy after login

这将在命令模式下启动 fdisk。你可以随时按 m 来查看选项列表。

接下来,输入 p,然后按回车查看分区信息,并确认你正在使用正确的设备。如果使用了错误的设备,你可以使用 q 命令退出 fdisk 并重新开始。

现在输入 d 来删除一个分区,它将立即询问分区编号,这与 “Device” 列中列出的编号相对应,在这个例子中是 1 和 2(在下面的截图中可以看到),但是可以也会根据当前的分区表而有所不同。

What impact does deleting a partition have on data in Linux?

让我们通过输入 2 并按下回车来删除第二个分区。你应该看到一条信息:“Partition 2 has been deleted”,但实际上,它还没有被删除。fdisk 还需要一个步骤来重写分区表并应用这些变化。你看,这就是完全网。

你需要输入 w,然后按回车来使这些改变成为永久性的。没有再要求确认。

在这之后,你应该看到下面这样的反馈:

What impact does deleting a partition have on data in Linux?

现在,使用

sudo fdisk --list /dev/sdb
Copy after login

查看该设备的当前分区表,你可以看到第二个分区已经完全消失。你已经完成了使用终端和 fdisk 命令来删除你的分区。成功了!

相关推荐:《Linux视频教程

The above is the detailed content of What impact does deleting a partition have on data in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!