如何恢复在分区内创建分区表

如何恢复在分区内创建分区表

我错误地想添加一个分区/dev/sda,我用 fdisk 启动/dev/sda2它并将其视为磁盘。我该如何恢复它?

ghostrider@dev1:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   800G  0 disk 
├─sda1   8:1    0   953M  0 part /boot
└─sda2   8:2    0 399.1G  0 part /

ghostrider@dev1:~$ sudo fdisk /dev/sda2

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

The old ext4 signature will be removed by a write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x1d9559e3.

Command (m for help): p
Disk /dev/sda2: 399.7 GiB, 428495339520 bytes, 836904960 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
Disklabel type: dos
Disk identifier: 0x1d9559e3

Command (m for help): F
Unpartitioned space /dev/sda2: 399.7 GiB, 428494290944 bytes, 836902912 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

Start       End   Sectors   Size
 2048 836904959 836902912 399.1G

Command (m for help): n  
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-836904959, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-836904959, default 836904959): 

Created a new partition 1 of type 'Linux' and of size 399.1 GiB.

Command (m for help): w
The partition table has been altered.
Failed to add partition 1 to system: Invalid argument

The kernel still uses the old partitions. The new table will be used at the next reboot. 
Syncing disks.

ghostrider@dev1:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   800G  0 disk 
├─sda1   8:1    0   953M  0 part /boot
└─sda2   8:2    0 399.1G  0 part /

编辑: 稍后服务器重启后,服务器卡在 initramfs 中并显示错误消息

Gave up waiting for root 
ALERT! UUID=xx-xx-xx-xx-xx doesn't exist dropping to shell

答案1

看起来什么都没发生,因为fdisk无法覆盖文件系统。尝试覆盖时,它显示错误:

Failed to add partition 1 to system: Invalid argument

不过,这是确保您的备份是最新且可恢复的好时机。无论如何,可能确实出了问题。


请注意,在您执行任何操作之前,它fdisk确实会尝试警告您有关该问题。它警告:

The old ext4 signature will be removed by a write command.
 
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x1d9559e3.

即使你对工具打印的消息非常熟悉,也最好通读一遍,因为有一天可能会出现意想不到的事情。如果你注意到了这一点,你可能会在造成任何损害之前意识到出了问题。

相关内容