如何修复分区表排序?

Koo*_*inn 5 filesystems gparted partitioning

我打算安装一个全新的 Linux 发行版 (Mageia),我认为这是一个重新组织我的分区的机会。我希望在开始时使用所有非 Linux(Windows、还原等)分区,在最后使用 Linux 分区,这样如果我想测试更多发行版,我可以更轻松地创建新的 Linux 分区。

我使用 GParted 删除了现有的 Linux 分区(我备份了想要保留的数据)并将剩余的移到前面。我稍后会在 Mageia 安装程序中创建 Linux 分区。

花了一些时间,但最终 GParted 没有问题地完成了。Mageia 也顺利安装。

启动到 Mageia 时,我遇到了一些(无关?)ATI Radeon 视频卡(仍未解决)的问题,这让我只剩下控制台,而在重新启动时,我看到了Error: Can't have overlapping partitions压缩。

没问题,我想,我会再次启动 GParted 并修复它。唉,GParted 将整个磁盘显示为未分配。好的,回到 Linux。从命令行开始分手给了我

[root@localhost ~]# parted
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: Can't have overlapping partitions.
Run Code Online (Sandbox Code Playgroud)

fdisk 应该给我更多信息,它确实做到了:

[root@localhost ~]# fdisk -l -u /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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 identifier: 0x2bd2c32a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400    7  HPFS/NTFS
/dev/sda2          208845  1953520064   976655610    5  Extended
/dev/sda3       950740992  1013655551    31457280    7  HPFS/NTFS
/dev/sda4      1013655552  1015754751     1049600   12  Compaq diagnostics
/dev/sda5          208896   409808895   204800000    7  HPFS/NTFS
/dev/sda6       409810944   950740991   270465024    7  HPFS/NTFS
/dev/sda7      1015757883  1034184374     9213246   82  Linux swap / Solaris
/dev/sda8      1034184438  1953520064   459667813+  83  Linux
Run Code Online (Sandbox Code Playgroud)

如果我排序分区启动似乎/dev/sda5/dev/sda6应该叫/dev/sda3/dev/sda4,反之亦然。

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400    7  HPFS/NTFS
/dev/sda2          208845  1953520064   976655610    5  Extended
/dev/sda5          208896   409808895   204800000    7  HPFS/NTFS
/dev/sda6       409810944   950740991   270465024    7  HPFS/NTFS
/dev/sda3       950740992  1013655551    31457280    7  HPFS/NTFS
/dev/sda4      1013655552  1015754751     1049600   12  Compaq diagnostics
/dev/sda7      1015757883  1034184374     9213246   82  Linux swap / Solaris
/dev/sda8      1034184438  1953520064   459667813+  83  Linux
Run Code Online (Sandbox Code Playgroud)

从谷歌搜索我发现testdisk可以解决这个问题。

  1. 我如何使用testdisk?界面相当混乱。
  2. 我可以从 Linux/Windows 运行它还是应该启动实时版本?

提前致谢,

缺口


我按照以下答案中的说明进行操作,但它不起作用。

我必须重新创建这些分区:

/dev/sda3       950740992  1013655551    31457280    7  HPFS/NTFS
/dev/sda4      1013655552  1015754751     1049600   12  Compaq diagnostics
Run Code Online (Sandbox Code Playgroud)

这是发生的事情:

[root@localhost ~]# fdisk /dev/sda

Command (m for help): d
Partition number (1-8): 3

Command (m for help): d
Partition number (1-8): 4

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First sector (950743040-1953520064, default 950743040): 950740992
Value out of range.
First sector (950743040-1953520064, default 950743040):
Run Code Online (Sandbox Code Playgroud)

第一个分区需要从 95074 0992开始,但新分区可能只从 95074 3040开始。

我该如何进行?

小智 8

我找到的修复分区顺序的最佳解决方案:

Enter into the disk partition place: 
fdisk /dev/sda

Command (m for help):   m  
Command action
  ...
   l   list known partition types
   m   print this menu
   p   print the partition table
   q   quit without saving changes
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):   x

Expert command (m for help):   m
Command action
...
   f   fix partition order
   m   print this menu
   p   print the partition table
   q   quit without saving changes
   r   return to main menu
   v   verify the partition table
   w   write table to disk and exit

Expert command (m for help):   f
Done.

Expert command (m for help):   w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
Run Code Online (Sandbox Code Playgroud)

完毕!


syn*_*-dj 2

重叠分区问题的出现部分是由于 PC 分区的奇怪之处。

分区表的空间正好可以容纳 4 个“主分区”条目。如果您需要有超过 4 个分区,则有一种称为“扩展”分区的机制 - 它实际上创建一个大分区(在您的情况下是分区#2),而该分区又具有一个自己的子分区表,允许添加称为“扩展”分区的附加条目“逻辑”分区。

您所做的是创建一个从扇区 208845 到 1953520064 的扩展分区,同时还创建了与为“扩展”分区保留的磁盘空间重叠的附加主分区 3 和 4。

解决问题的最简单方法如下:

  • 使用 Linux fdisk 删除分区 3 和 4
  • 使用与之前相同的扇区开始/结束值将它们重新创建(再次使用 fdisk)作为扩展分区内的逻辑分区

如果您希望逻辑分区顺序反映它们在磁盘上的“物理”位置,fdisk也可以提供帮助。只需按“x”即可激活扩展功能并使用修复 分区顺序功能。之后您可能需要针对 Linux 系统调整fstabs - Windows 具有基于 GUID 的分区识别,并且不应该关心顺序。