sta*_*fry 9 windows boot clone gparted
我不幸需要克隆一个双引导的 Windows XP/7 机器来用一个更小的硬盘替换它的硬盘。我在启动它时遇到了很大的麻烦,我想了解发生了什么,以及我是否可以做得更好。
背景:机器有一个 750Gb 的驱动器,上面有 3 个分区:
原始安装的方式是没有单独的 Windows 7 恢复分区。我希望这个事实可以稍微简化事情。
我正在用 80Gb 驱动器替换它。分区已经从 Windows 7 中缩小,以便它们适合较小的磁盘。
我使用GParted(来自PartedMagicLinux LiveCD)来复制分区。我将 Windows XP 分区标记为活动分区(与原始磁盘上的相同)。
CloneZilla由于从较大的磁盘过渡到较小的磁盘,我无法使用或复制整个磁盘。
复制分区后,我手动复制引导加载程序(注意不要复制分区表):
$ dd if=/dev/sda of=/dev/sdb bs=446 count=1
Run Code Online (Sandbox Code Playgroud)
我移除了原始磁盘,设置了新磁盘,使其物理连接与原始磁盘(IDE 通道 1 主)相同,并尝试启动。这成功地显示了启动菜单,但在选择任一选项时失败(有两个:一个用于 XP,一个用于 Win7)。
我做了一些研究,这让我意识到 Windows 7 启动配置数据并不包含它应该包含的所有内容。我比较了原始磁盘和新磁盘的 BCD 输出,并注意到后者上的设备条目是unknown. 所以我手动将它们更改为与原始匹配 - 如下所示:
$ bcdedit /set {ntldr} device partition=C:
$ bcdedit /set {default} device partition=D:
$ bcdedit /set {default} osdevice partition=D:
Run Code Online (Sandbox Code Playgroud)
并重新启动。这次我可以同时启动XP和Win7。我需要做更多的测试,因为两个 BCD 之间似乎还有其他差异,但进行上述更改至少允许启动。
所以我的问题实际上是问为什么克隆分区上的 BCD 看起来与原始分区不同,并且足以阻止启动?
对此的后续行动是问我是否应该以另一种方式这样做?
sta*_*fry 13
After cloning partitions containing Windows operating systems, it is necessary to fix up the boot configuration data if the cloned partitions are not in exactly the same position on the cloned disc as they are on the original.
The Windows boot mechanism, since Windows Vista, stores its configuration as "Boot Configuration Data" (BCD) and this refers to partitions, not by partition numbers but by a disk signature and sector offset. The disk signature is a 32-bit value embedded in the Master Boot Record. Copying the first 446 bytes of sector 0 will copy the disk signature.
If cloning activities result in the cloned disk partitions having different starting sector addresses then the original ones (highly likely unless a whole-disk clone was used) then the clone will most likely fail to boot until these remedies are applied.
Basically, the sector offsets need to be updated and, for this, you'll need to use a recovery console (this is available on a Windows 7 install DVD). Ensure only the cloned drive is attached and boot from a Windows 7 install DVD. At the first screen make language selections and hit "next". At the next screen (where "install now" is displayed) press SHIFT+F10 to get a command prompt.
First, confirm the drive letters that are in place and the partitions to which they relate:
diskpart
list volume
exit
Run Code Online (Sandbox Code Playgroud)
Also, if you need to, re-confirm the active partition:
diskpart
select disk 0
select part 1
detail part
select part 2
detail part
... and so-on
exit
Run Code Online (Sandbox Code Playgroud)
On a BIOS system, the BCD is stored in a file at X:\Boot\BCD where X is the drive letter
of the active partition (for UEFI it's in the EFI System Partition). Normally hidden, it can
be seen with
dir /AH X:\Boot
Run Code Online (Sandbox Code Playgroud)
It can be backed up like this:
bcdedit /export X:\path\to\bcd\backup
Run Code Online (Sandbox Code Playgroud)
and restored
bcdedit /import X:\path\to\bcd\backup
Run Code Online (Sandbox Code Playgroud)
If a disk has multiple operating systems on it, there may be multiple BCDs. The active BCD is the one in at \Boot\BCD on the partition that is marked as active - the active partition. To list its contents (in increasing order of verbosity:)
bcdedit
bcdedit /enum
bcdedit /enum ALL
bcdedit /enum ALL /v
Run Code Online (Sandbox Code Playgroud)
To fix up the active BCD, establish the drive letters for the correct partitions and do:
bcdedit /set {default} osdevice partition=X:
bcdedit /set {default} device partition=X:
bcdedit /set {bootmgr} device partition=X:
bcdedit /set {memdiag} device partition=X:
bcdedit /set {ntldr} device partition=X:
Run Code Online (Sandbox Code Playgroud)
or, to fix up another BCD (at "X:\boot\bcd" in these examples):
bcdedit /store X:\boot\bcd /set {default} osdevice partition=X:
bcdedit /store X:\boot\bcd /set {default} device partition=X:
bcdedit /store X:\boot\bcd /set {bootmgr} device partition=X:
bcdedit /store X:\boot\bcd /set {memdiag} device partition=X:
bcdedit /store X:\boot\bcd /set {ntldr} device partition=X:
Run Code Online (Sandbox Code Playgroud)
For example, my system which has XP and 7 and they show XP as being on C: and 7 being on D: and the active partition is C:. then the active BCD will be at c:\boot\BCD. The boot manager will be found at C:\bootmgr and the memory diagnostic will be at C:\boot\memtest.exe, The required commands would be:
bcdedit /set {ntldr} device partition=C:
bcdedit /set {memdiag} device partition=C:
bcdedit /set {bootmgr} device partition=C:
bcdedit /set {default} device partition=D:
bcdedit /set {default} osdevice partition=D:
Run Code Online (Sandbox Code Playgroud)
With those changes, rebooting the computer (Pressing Alt-F4 will achieve this) and removing the DVD allowed the system to boot successfully.
Further Reading:
(a whole-disk clone should not suffer these issues because the partition layout on the copy should be exactly the same as the original)
根据这个关于 BCD internals 的非官方文档,BCD 存储中的分区实际上是通过磁盘签名和分区偏移量来标识的。您复制了磁盘签名(MBR 字节 440–443),但很可能在将分区放在较小磁盘上时更改了分区偏移量,因此 BOOTMGR 不再能够找到这些分区。
| 归档时间: |
|
| 查看次数: |
6961 次 |
| 最近记录: |