1

I have a PC laptop with Windows 10, it has two hard drives, one for windows that is separated with UEFI, windows and data partition, and another hard drive that has some more apps installed on it.

I am trying to duplicate that system to be able to run it on virt-manager under Gentoo Linux.

So first I duplicated the hard drives using disk2hd (https://docs.microsoft.com/en-us/sysinternals/downloads/disk2vhd), it created two separated VHDX files for each hard drive.

Then I converted these images to qcow2, a format that virt-manager is familiar with using qemu-img with these flags:

qemu-img convert -p -f vhdx -O qcow2

I mounted the qcow2 and verified that the files are presented and that the images are correct.

then I ran virt-manager, enabled UEFI and configured it to boot from the main hard drive. windows fails to boot. when I tried to run windows recovery it could not fix the startup failure.

I googled and I found that the only real way to fix windows boot is to download windows, and run an upgrade on the current windows system.so I did that, I downloaded the ISO, booted it on virt-manager but I could not upgrade, it failed to detect a previous windows installation on the drive.

Then I thought about reinstalling Windows on that partition, and then overwriting the new Windows files with the old ones by deleting the ProgramData, Users, Program Files and Windows directory and replacing it with the old backup.

The failure that I had with that is that the current drive is divided to UEFI, Windows and data partitions and it gave me an error that it could not install Windows on the partition that the previous Windows installation existed it, then I mounted the qcow2 image of the main drive, deleted all the partition table, reinstalled Windows on that drive while allowing the Windows installation to re-partition the drive automatically and then to replace the files, but after replacing the files Windows did not boot again and showed exactly the same symptoms.

virt-manager could run Windows properly because when I installed a new version of Windows, it executed properly and I had no problems, but I am trying to run the same installation of Windows from that other computer.

So for now I have no idea what else I can do to resolve this problem so any information would be greatly appreciated.

update 1

I am trying to preserve some accounting app that I don't have an upgrade license for that uses MS SQL that I don't have the username and password for. and in general I think it would be fun to know how to preserve a Windows computer on a VM.

So regarding error messages.. When Windows issuing startup repair the only error that I see is

Startup Repair couldn't repair your PC

When I start Windows installation and try to upgrade current Windows I get:

The upgrade option isn't available if you start your computer using Windows installation media.

When I try to install Windows on the same partition that the Windows was already installed to try and the move windows.old directory to Windows I get

Windows cannot be installed on this disk. The selected disk is of the GPT partition style.

update 2

Credit to all the wonderful answers, I prefer to be able to resolve working with VHDX then using a different backup software and play with that.

My hard drive literally crashed OS I backed up the VHDX files again and try on a different Gentoo machine that I have.

So from the beginning, I noticed that the laptop has Windows 10 Home Edition 64 bit Hebrew edition and that it uses UEFI.

So I created a new Windows 10 VM with Q35 Chipset and Firmware UEFI x86_64: /usr/share/qemu/edk2-x86_64-code.fd created 2 SATA drives and pointed them to the original VHDX files instead of converting it to qcow2 first, and allowed to boot from all drives and set the CDROM to boot from first.

First I booted with Linux Gentoo mini CD just to confirm that the drives are readable from the VHDX files and they are not, so I re-created the qcow2 files, booted from Gentoo Linux and the drives where readable. (For some reason I thought that QEMU supports VHDX out of the box).

So booted Gentoo Linux ISO again and checked the drives and now I see partitions.

In /dev/sda I have one NTFS partition at /dev/sda1 labeled Microsoft Basic Data. this is for all the other programs that I installed that laptop.

and on /dev/sdb I have the following:

/dev/sdb1 vfat 260M EFI System
/dev/sdb2 GUID:63 16M Microsoft reserved
/dev/sdb3 ntfs 118.1G Microsoft basic data
/dev/sdb4 ntfs 865M Windows recovery environment

So Windows is installed on the 2nd drive on /dev/sdb3, I mounted and verified. Since sdb has the EFI partition I assume that the boot should be fixed in that drive and I can remove /dev/sda from the bootable drives in the VM. so I did that and boot Windows installation ISO.

Tried executing Startup Repair again, it showed Diagnosing your PC and then Attempting Repair and then it rebooted and now it actually works. I don't know if it's because of my failed drive, because I didn't see any related errors, but you guys made my understand how important it is to check that the original laptop uses UEFI and to keep using the original drive's partitions and hard drives exact order. You helped me not to spread out and try stuff that will mess things up like repartition the drive and waste a lot of time for nothing.

I actually wrote the responses here live while re-trying everything and I'm so glad it works.

Dave M
  • 13,138
  • 25
  • 36
  • 47
ufk
  • 901
  • 6
  • 23
  • 38
  • why not doing you a fresh install ? what things you trying to preserve ? include more detail about the errors – Madhubala Jun 13 '21 at 18:12
  • @Madhubala - updated main post – ufk Jun 14 '21 at 19:58
  • 1
    Windows cannot be installed on this disk. The selected disk is of the GPT partition style. - this is simply a partition table error - turn-off uefi mode in kvm and retry – Madhubala Jun 17 '21 at 02:22
  • @Madhubala - I changed UEFI mode to BIOS and unfortunately the results are the same. – ufk Jun 17 '21 at 18:54
  • @ufk What did you do within WinRE? Repair it via a command terminal in WinRE, following Step 5 in the last section of [this](https://superuser.com/a/1581804/529800) answer ["_How do I configure system partitions on a new drive for applying an image?_"], as the issue is likely that the BCD store no longer points to the correct volumes. As to GPT, in order for Windows to be installed on a GPT partition table, the install USB must be configured for UEFI boot and UEFI must be configured w/ CSM [legacy] mode disabled - AFAIK, those are the only two reasons why that error would be displayed. – JW0914 Jun 18 '21 at 11:20
  • @JW0914 - thank you for the info, I tried repairing the boot using the command line and it always failed. Forgot to add that info to my question – ufk Jun 18 '21 at 11:20
  • @JW0914 - I tried using fixmbr and fix boot options while being on uefi. I’m not home now, I have backup of my images, I will try again and provide exact feedback. – ufk Jun 18 '21 at 11:26
  • @ufk Please boot to WinRE and perform Step 5 to resolve the issue _(`/FixBoot` requires extra steps with EFI boot and it will not run without first changing to `EFI\Microsoft\Boot`)_. CSM [Legacy] mode in UEFI should never be enabled, as its sole purpose was to support distros that didn't yet support EFI boot circa <2017; AFAIK, all distros support EFI boot and Windows has supported it since at least Win 7. _(CSM Mode emulates BIOS' 16bit architecture within a 32bit environment & doing so will cause performance degradation - boot times increase by 400%+, GPT cannot be used in Windows, etc.)_ – JW0914 Jun 18 '21 at 11:30
  • @JW0914 thank you so much, I will test and let ya know as soon as I get home – ufk Jun 18 '21 at 11:34
  • @DanielB - if i recall correctly i tried Virtio and AHCI and on both cases the results where the same – ufk Jun 20 '21 at 08:17
  • @ufk "_Tried executing Startup Repair again, it showed Diagnosing your PC and then Attempting Repair and then it rebooted and now it actually works. I don't know if it's because of my failed drive, because I didn't see any related errors..._" **The issue has always been the BCD Store**, as once Windows is applied/moved to a different partition, the BCD Store no longer has the correct info. All that's ever needed to be done for the boot issue was `BootRec /FixMBR && BootRec /RebuildBCD`. _(Even when natively applying a previously captured WIM, `BootRec` must still be run for the same reasons.)_ – JW0914 Jun 24 '21 at 13:05

1 Answers1

2

One, or both, of these two factors are likely at play, with #2 being the boot issue:

  1. Windows is not intended to be imaged on one system and used on a different system, VM or otherwise, without first running SysPrep on the cloned OS partition prior to it booting on the new system
  2. A BCD Store [UEFI] issue, as device volume paths and GUIDs are no longer accurate within the BCD Store [Boot\BCD || EFI\Microsoft\Boot\BCD] when Windows is moved/applied to a new partition:
    • Inaccuracies within the BCD Store will cause boot failure during boot Phase 2:
      Boot loader phase → Windows Boot Manager
      Boot Sequence
    • BCD Store volume path and GUID example:
      # Full volume paths:
        # \\?\GLOBALROOT\Device\Harddisk#\HarddiskVolume#
        # \\?\GLOBALROOT\Device\Harddisk#\Partition#
      
      PS $  BcdEdit /Enum
      
        Windows Boot Manager
        --------------------
        identifier              {bootmgr}
        device                  partition=\Device\HarddiskVolume8
        path                    \EFI\Microsoft\Boot\bootmgfw.efi
        description             Windows Boot Manager
        locale                  en-US
        inherit                 {globalsettings}
        default                 {current}
        resumeobject            {e335a64a-37dc-11eb-bd2a-85edee9cbf64}
        displayorder            {current}
        toolsdisplayorder       {memdiag}
        timeout                 30
      
        Windows Boot Loader
        -------------------
        identifier              {current}
        device                  partition=C:
        path                    \Windows\system32\winload.efi
        description             Windows 10
        locale                  en-US
        inherit                 {bootloadersettings}
        recoverysequence        {55541c35-9fa7-11eb-9281-8086f283f968}
        displaymessageoverride  CommandPrompt
        recoveryenabled         Yes
        isolatedcontext         Yes
        allowedinmemorysettings 0x15000075
        osdevice                partition=C:
        systemroot              \Windows
        resumeobject            {e335a64a-37dc-11eb-bd2a-85edee9cbf64}
        nx                      OptIn
        bootmenupolicy          Standard
        hypervisorlaunchtype    Auto
      

To resolve:

Perform the BCD store fix [#3] first, but the VHDX should be SysPrep'd, as that is the correct way to clone the OS to a different machine [physical or virtual]:
(I've listed the steps in their correct chronological order)

  1. SysPrep the VHDX:
    1. Boot the cloned VHDX on the same system it was cloned from and log in
    2. WinKey+R → Open: %WinDir%\System32\Sysprep\sysprep.exe → OK
      1. System Cleanup Action: Enter System Out-of-Box-Experience (OOBE)
      2. Shutdown Options: Shutdown
      3. OK
    3. After SysPrep finishes, boot back to the original Windows install and re-create the VM image from the SysPrep'd VHDX

  2. Firmware settings [BIOS || UEFI] in the VM must match:
    If Windows was installed on a UEFI PC, the VM must be UEFI with CSM [Legacy] Mode disabled
    • CSM Mode should never be enabled, as its sole purpose was to support distros that didn't yet support EFI boot circa <2017; it emulates BIOS' 16bit architecture within a 32bit environment and doing so will cause performance degradation (boot times increase by 400%+, GPT cannot be used in Windows, etc.)

  3. Boot to WinRE: Command Prompt and execute Methods 2 & 3:
    If WinRE fails to boot, boot an Install ISO/USB [WinPE] and open a terminal via Ctrl+Shift+F10
    [BootRec | BcdBoot]
    • BIOS:
      BootRec /FixMBR && BootRec /FixBoot && BootRec /RebuildBCD
      
    • UEFI:
      BootRec /FixMBR && BootRec /RebuildBCD
      
      If needed, fixing the boot directory requires extra steps for EFI boot:
      ::# Mount EFI partition at Y:
          Diskpart
      
            Lis Vol
            Sel Vol #
            Assign Letter=Y
            Exit
      
      ::# Enter EFI directory and repair EFI boot structure:
          Cd /d "Y:\EFI\Microsoft\Boot"
          BootRec /FixBoot
      
          ::# If Access Denied error occurs (C: is OS partition, refer to Lis Vol):
              BcdBoot C:\Windows /s C: /f UEFI
      
      ::# Resolve any other boot issues:
          BootRec /FixMBR && BootRec /RebuildBCD
      
      ::# Remove EFI mountpoint and reboot:
          DiskPart
      
            Sel Vol Y
            Remove
            Exit
      
          Exit
      


While Startup Repair could be used, there's no guarantee it will fix a BCD Store that isn't corrupted, often returning it didn't find, or couldn't fix, an issue:
(I've never found a man page on what Startup Repair does on the backend - please comment if knowing)

  • It's well-known the BCD Store is almost always the cause of boot issues after moving/applying the OS to a new partition (#2 at answer's top), so it's simply more efficient to run BootRec directly, taking ~2m from start to finish, versus much longer for Startup Repair to run and the user to determine if it fixed the issue
  • Startup Repair doesn't list what it does afterward, instead logging to:
    X:\Windows\System32\LogFiles\Srt\Srttrail.txt
    
    To determine what was/wasn't done, it requires accessing WinRE's Command Prompt and opening the log within NotePad; should this not be done, the log is lost upon rebooting since X: is a RAM drive

All of this takes exponentially longer [less-efficient] than simply running BootRec directly to fix the most likely problem, an issue with the BCD Store (work smarter, not harder).

JW0914
  • 7,052
  • 7
  • 27
  • 48
  • For virtualization, BootRec is only helpful in cases where this wasn't done in an exact manner. Windows and the firmware use paths to disks and partitions that are based on their number, as in "disk 0, partition 1". In the case that the system disk was at ordinal `0` and it's so also in the VM (which is a very large majority of the cases), BootRec will not help. Startup Repair is more useful, in that it also resets some software components that may not be adapted to new configuration. – harrymc Jun 19 '21 at 14:58
  • @JW0914 Thanks for posting this. Extremely useful – William Martens Jun 19 '21 at 15:22
  • 1
    @harrymc AFAIK, the way Windows boot loader and manager [boots](https://i.stack.imgur.com/cQurP.png) doesn't change within a VM; please provide documentation links and I will update my answer accordingly ([Windows Boot Loader Settings](https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/bcd-system-store-settings-for-uefi#windows-boot-loader-settings)). I did miss a glaring detail in the OP's question [no `SysPrep`] and did add that to my answer, but if doc links are provided, I will modify my answer accordingly. – JW0914 Jun 19 '21 at 16:06
  • Several of your statements go against my experience. I have virtualized Windows systems before without SysPrep or BootRec, so I really think that your answer is wrong. – harrymc Jun 21 '21 at 08:14
  • @harrymc My answer is compiled directly from Microsoft Docs, so again, if you have doc/man page links, please provide them and I will modify my answer accordingly. – JW0914 Jun 21 '21 at 12:09
  • Then you misunderstood the documentation. SysPrep is a tool for preparing an image for distribution and multiple installations, so it deletes data that some would prefer to keep and is absolutely not the tool for vitualization. BootRec is not required since a truly virtualized computer is identical to the VM. The poster's problem is with his tools, but you're just heaping up lots of irrelevant information. – harrymc Jun 21 '21 at 13:22
  • @harrymc I'm not going to argue with you as I've provided information compiled directly from the developer and I'll take the developer's documentation over your opinion, so please either provide documentation/man page links so I can update the answer accordingly or please move on. – JW0914 Jun 21 '21 at 13:27
  • The links you already have, you just need to read them again, and understand. And let me quote yourself: "I'll comment where I please - have a great day. (*if you don't want comments, don't post an answer, it's that simple*)". – harrymc Jun 21 '21 at 13:36
  • @harrymc This is a recurring theme with you, as you either disregard Microsoft Docs entirely in favor of your opinions or choose to interpret specific wording as to only be in support of your opinion. The purpose of SysPrep is laid out clearly in its man page - if needing further elaboration on it, please reach out to the doc authors for clarity via a GitHub issue. It's not my job to argue with you over your hubris and opinions, so if you take issue with what the man pages state, please reach out to the authors, commenting back w/ a link; short of that, I consider this conversation concluded. – JW0914 Jun 21 '21 at 13:43
  • I also considered our conversation on my answer as finished several times, it's you that didn't agree. I don't disagree with Microsoft documentation, just with the use that you're doing with utilities that don't pertain here. Normally I don't comment on answers by others, you should perhaps do the same. – harrymc Jun 21 '21 at 14:03
  • updated main post, you helped me to know what not play and mess with and things are working now, you provided so much valuable information and I really appreciate all your help. – ufk Jun 23 '21 at 20:28