3

Issue: Windows 10 clones to same disk/different SSD won't boot.

Why: I've got a M.2 NVMe with the following structure:

  • 300 MB Recovery Partition
  • 100 MB EFI System Partition
  • Windows 8.1
  • Unallocated Space
  • Windows 10 (clone source)

I want to extend the Windows 10 install to the left, and afaik it can be only done by cloning/reinstalling.

Attempts: I booted on a Linux pendrive and did a dd clone to a new partition in the unallocated space in the same drive. Then I used the Windows Recovery mode to create an entry for the new partition.

It won't boot, it black screens. Trying to bootrec, bcdboot copy, delete and rebuild everything doesn't work. I've tried to remove the entry pointing to the source Windows 10 and rename its Windows folder so only the clone remains in the boot but it didn't help either.

I then tried to clone the source to a different SSD with a new EFI Partition pointing only to that new Windows 10 clone, also deleting the EFI partition from the NVMe so there's only one possible EFI System Partition to boot from, but it still doesn't work, getting me a blue screen this time around.

I know I should have removed the NVMe at this point but it'd require to take the entire computer apart, as it's at the bottom of the mobo in a very tight mini-itx case.

The saving grace is that undoing the bcd changes is pretty straightforward, so the original 8.1 and 10 installs boot fine.

Questions: I suspect this is one of the cases in which Windows sprawls everywhere and gets confused, preventing itself from repairing whatever issues or creating correct entries until it loses access to the installations it shouldn't be touching in first place.

Is there a way to make the source Windows 10 install invisible to the Recovery Mode/cloned install without physically removing the disk or deleting the partition? I'd like to delete the source only once I'm sure the clone works.

Update 1

Turns out the issue with the cloned Windows 10 isn't about the bcd, or not about it alone. Trying to boot into it in safe mode gets me as far as to the login screen (!!!). Then things get weird.

  • Trying to login gets me an "Unknown hard error" by Sihost.exe. The cursor won't stop blinking and spinning. Ctrl+Shift+Esc brings up the Task Manager, and from there I can open the cmd, explorer, etc.

  • Taking a look at the Event Viewer log reveals an endless list of "DCOM got error "1084" attempting to start the service ShellHWDetection with arguments "Unavailable" in order to run the server" errors, which I suspect are the reason behind the blinking cursor.

  • Sfc and dism /online find no errors to repair. Nor does chkdsk.

  • Doing a normal boot on the other hand results in a screen that won't even show the login screen, is unresponsive to all shortcuts tried (Crtl+Shift+Esc, Win+P, Win+L, Win+Ctrl+Shift+B, Crtl+Alt+Del), won't display a context menu upon right clicks and generally eats the cursor (it's not visible until moved and disappears after a second idle, no spinning icon at all).

P.s.: Before the gparted thing I also tried to do a fresh install in a new partition then clone the source Win 10 over it. Didn't work and tipped me off about it not being about the BCD.

0

1 Answer 1

9

The clone wouldn't boot properly because its Registry Keys pointed to the old partition.

It's been years since I last cloned a Windows (to a different drive), but if I recall it correctly a cloned Windows is able to correct itself on its first boot. This doesn't happen when you clone a system to another partition on the same drive because it can still see the old partition, with the original letter and everything, so the clone has no reason to think it can't access those files until it can't and gets stuck in an error loop.

Understanding what's going on makes this a very fixable problem!

To get a working Windows clone on the same drive you'll need:

  • A USB drive with Ubuntu
  • A working Recovery Environment (RE) partition or a USB drive with a Windows image created with the Windows Media Creation Tool (preferred)

There are plenty guides on the internet on how prepare these USBs if you need.

This guide covers a GPT/EFI boot, and the example case has one Windows 8.1 installation, and a Windows 10 installation which will be cloned. I've never seen any guide about cloning to the same drive (they all tell you to remove the drive with the source) thus this solution has been tested by exactly one (01) person so far, hello there _o/, so proceed with caution.

The exact solution to the issue in the question is at the end of this answer.


How to clone Windows 10 to another partition on the same disk, in a dual boot EFI system

Preparations for cloning the system

  1. (Optional, but not a bad idea) Update your Windows and creating a system restore point before proceeding.

  2. (Optional safety measure) Check your registry keys backup at \Windows\System32\config\RegBack. This folder should contain 5 files: DEFAULT, SAM, SECURITY, SOFTWARE and SYSTEM, but starting in Windows 10, version 1803, this is no longer done automatically. Check this article for details.

    If it's empty or has files with zero bytes you'll need to run a Windows task or backup them manually by copying them using the command prompt in RE or when logged in a different system. I simply took the opportunity to copy them when logged in another system.

  3. Turn off hibernation. You want to be sure your Windows 10 clone source is completely off when copying it.

  4. Make sure all your operating systems are booting without issues.

    (Optional safety measure) Backup the BCD files before starting, because your boot is likely to get wrecked in the process. You'll probably rebuild them instead of using the backups, but it doesn't hurt to have them. Each Windows installation will have their own boot files at \Windows\System32\Boot.

    There are also actual the boot files found in the hidden EFI partition on your disk. It's usually 100 MB and will be identified as "EFI System Partition". You'll need to use and elevated command prompt from RE/a different system that isn't using the same boot to do so.

First you'll assign a letter using disk part. There's an explanation on how to further this in guide. Then you'll use xcopy:

xcopy S:\ D:\EFI_Boot_BK /s /e

Where S:\ is the EFI partition and D:\EFI_Boot_BK is the backup destination.

xcopy usage


Cloning the Windows 10 system

Cloning in Ubuntu

  1. Boot from the Ubuntu USB drive and select "Try Ubuntu".
  2. Open Gparted. Navigate to the drive containing the clone source, format the new partition where the clone will be placed if you didn't already and take note of the name of the partitions containing the clone source and target.
  3. Open a Terminal.

Type the following command to clone the Windows 10 to the new partition:

sudo dd if=/dev/SOURCE of=/dev/TARGET status=progress bs=64K

bs is the block size (64k is a good value), status=progress will display a message with the cloning progress.

SOURCE is the partition of the Windows you're copying and TARGET is where you'll put it. DOUBLE CHECK THE PARTITION NAMES BEFORE CLONING. This process can't be undone; cloning to the wrong target partition will overwrite its data.

Example from my system:

Windows 10 cloning in Ubuntu (ignore the partition mess and the Fresh Win 10, they were made to test what turned out to be bad advice)

Once finished, the clone will have the same label of the source system. You can use Gparted to rename them to something else. In this case I renamed the source to "Win 10 (BK)". Apply the changes.

A more detailed explanation of using dd:

Using the RE cmd to fix the boot using DISKPART and boot commands

  1. Reboot either into one of the original windows and open an elevated command prompt, into the RE or the Windows 10 USB install drive. I prefer the later to avoid accidentally triggering Automatic Repairs, which at this point can mess up the boot to your previously working Windows installs.

    If using the USB tool, choose Next then Repair your computer to access the recovery screen, then Troubleshoot > Command Prompt. In RE it'll be something like Troubleshoot > Advanced options > Command Prompt.

  2. Use DISKPART to assign a letter to the EFI partition. Use the opportunity to take note of the letters assigned to your Windows partitions.

In my case the commands used were:

> diskpart
> list disk
(figure out which disk contains your installations from their details)
> sel disk 2
(my windows disk)
> detail disk
(get details to find out installation letters and find boot partition)
>sel vol 9
(my boot partition's volume number)
> assign letter=S
(you can assign whatever free letter you want)
> exit

Using DISKPART to assign letter to EFI boot

  1. Correct the master boot code of the cloned partition.

Type:

bootsect /nt60 C: /force

C: is the letter assigned to the cloned partition here. Replace with whatever letter yours have.

  1. (optional safety measure). Type bcdedit and take photos of all entries to fully recreate the flags later. Windows does a very good job of rebuilding entries but might assign the wrong locale or leave some of the original flags out, which isn't an issue but isn't ideal.

  2. Recreate the BCD entry for the cloned partition. This procedure is similar to bootrec /rebuildbcd, with the advantage of recreating the entry even in the cases /rebuildbcd fails with the "cannot find specified path".

Type:

bcdboot C:\Windows /s S: /f UEFI

C:\Windows is the source used to rebuild this entry; in this case the cloned partition. S: is the destination, the EFI boot partition. This procedure should rebuild only the clone entry. /f UEFI should be used in this case, for a GTP, EFI disk.

  1. (possibly optional) Now, nearly every guide I've came across to fixing BCD issues recommends using the following commands. Yet, they seem to apply to MBR boots, not EFI. They won't harm an EFI boot system, but might be as useful as throwing salt over your shoulder. Do for good luck!

Type:

> bootrec /fixmbr
> bootrec /fixboot
(don't worry if it says "Access is denied")
> bootrec /rebuildbcd
(It'll probably return 0 installations found ¯\_(ツ)_/¯ )
  1. Type bcdedit to confirm all Windows installations have a Windows Boot Loader entry. You can use bcdedit /set {identifer} flag flagvalue to adjust or add flags to entries. This is a good opportunity to change the description of the source and cloned windows so you can easily tell them apart when booting.

    The cloned windows will likely be the default OS now. I like to change it to a safe, bootable windows just in case. This can be done in the OS selection screen when booting, or now, by using bcdedit /default {identifier}. You can use shutdown -r to restart when done.

    To copy an entry identifier (or any other value) highlight it by clicking and dragging the cursor and right-clicking. You can paste by right-clicking again. It'll look like this:

Copy and paste in CMD

TIP: There's a chance you accidentally triggered an automatic repair by now and one of your original Windows partitions isn't booting, you can't use your keyboard to select an OS or some other weirdness. You can use bootsect /nt60 all /force to fix all partitions sectors, followed by the bcdboot procedure to copy the BCD from the affected installation to the boot partition.

Misc useful boot and BCD resources:


Fixing the Cloned Windows 10 black screen / sihost.exe Unknown Hard Error

This is the step I was stuck on when I posted the question.

By now you're not supposed to try to log into the cloned Windows yet. If you do, you won't be able to reach the login page. You'll see a black screen with a cursor that keeps disappearing when you stop moving it. Windows won't react to any shortcuts you use. I don't advise to try it, it's easier to confirm and fix the issue straight away by doing the following:

  1. You can use bcdedit /set {identifier} safebootalternateshell Yes to set the clone to safe mode or boot into one of your original Windows installations and use Win+R to bring the Run box up, typing msconfig to change settings from there.

Msconfig

Select the clone and check Safe boot. If you're on the source Windows 10 install, you'll be able to see the letter the clone assumed when you're using the clone installation itself besides the letter assigned to the source Windows. Take note of them.

You can also use that screen to set a different Windows installation as default if you didn't already.

  1. Boot into the cloned Windows 10. You should be able to reach the login screen without issues. Once you log in you'll see something like this (apologies for the terrible photo!):

Hard Error at log in

Wait for the screen to turn black. You cursor should be blinking and loading like crazy, the error box will remain there.

  1. Press "Ok" on the box. Use Ctrl+Shit+Esc to open the Task Manager. Go to File > Run new task and type cmd, checking "Create this task with administrative privileges" if given the option.

    You'll have to type quickly because the error state in which Windows is causes all inputs to keep losing focus. Minimize the task manager, that will mitigate the issue of losing focus when typing on the prompt at least.

  2. (optional) You can further confirm your issue is exactly like mine by checking the Event Viewer and Disk Management.

    To check the events type eventvwr and go to Windows Logs > System. You should see multiple DistributedCOM 10005 errors popping at every second, saying things like "DCOM got error "1084" attempting to start the service ShellHWDetection with arguments "Unavailable" in order to run the server".

    To confirm the clone is accessing the source windows partition type diskmgmt in the cmd. You'll see Page File and possibly other flags that shouldn't be there on the source partition. The clone will be the boot system but will lack a page file.

    That means the clone knows it's in a different partition with a letter other than the one of the source system, it's the current booted system, its registry is being used, but those keys still point to the source system. It's presumably denying access, causing the black screen and all those errors.

    To fix it you'll need change the letter of the old system, and assign its original letter to the clone, while being logged into the clone. DO NOT DO IT THROUGH DISK MANAGEMENT. It'd try to correct the registry (which will be already correct if the letters are switched) and break everything. You'd have to reclone the system.

    In this example the original source Windows 10, in the partition Win 10 (BK) has the letter C:. The clone has the letter F:. You want the source to have any other letter and the clone to be C:.

  3. To correct the letters minimize everything, return to the cmd and type regedit to open the Registry Editor. Go to HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices. You should see something like this:

Registry partition letters

Return to the cmd and type \DosDevices\(ANY LETTER NOT IN USE):. Example: \DosDevices\X:. Highlight it then right click to copy. Don't press Enter. The reason you're doing it is because the prompt loses focus fewer times that any other windows. Trying to type that directly in the registry key is hell, but pasting is easy!

  1. Return to the Registry window, right click the entry with the letter of the source Windows 10 install partition. In my case that's C:. Select Rename and paste the the string you just prepared in cmd.

  2. Repeat the cmd trick, now typing the letter you want the cloned partition to be, which should be the one the original system had and you just freed up. In my case that's \DosDevices\C:. Copy, right-click and rename the key pointing to the cloned system (\DosDevices\F:), paste the new value.

  3. Congratulations, you did it! You can open msconfig, disable safe boot and reboot into the cloned system. It should be running without any issues now.

MS article on changing boot drive letters through regedit:

1
  • How on earth does this answer only have 9 upvotes. It has surely saved actual lives. Mar 6 at 0:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .