Skip to content

Instantly share code, notes, and snippets.

@bre7
Last active March 22, 2024 23:07
Show Gist options
  • Save bre7/0be8dafe4fb5f78318db8cf33799b30f to your computer and use it in GitHub Desktop.
Save bre7/0be8dafe4fb5f78318db8cf33799b30f to your computer and use it in GitHub Desktop.
VirtualBox - Creating virtual machine from physical machine (Windows 10)

Creating virtual machine from physical hard drive partition

  1. Use Disk2Vhd and create a VHD for the partition you want to convert. (If using VirtualBox, disable Vhdx option)

  2. Open Windows 10's native Disk Management tool (Run > diskmgmt.msc). Attach VHD (Action > Attach VHD).

  3. Convert to MBR Disk using AOMEI Partition Assistant Demo (if there's another way please post a comment)

  4. Detach VHD

  5. Once done, create a new VM in VirtualBox and select the newly created VHD

  6. Attach a Windows 10 ISO (use the Media Creation Tool to create it) to the VM

  7. Turn on VM and boot ISO

  8. Select Repair your computer and then Command Prompt

  9. Run the following commands:

diskpart
list disk
select disk 0
list partition
select partition 1
active
exit

In my case there was only 1 disk and partition.

  1. Run the following commands:

bootrec /fixmbr (this command will fix MBR)

bootrec /fixboot (this command will fix boot sector)

bootrec /scanos (this will scan for Windows installations to add)

If fixboot replied with the error Access denied, then run the following command:

bcdboot C:\windows
  1. Reboot and enjoy your fixed VM !

PRs welcome for fixes & improvements !!!1!


SEO:

  • Create virtual machine from installed Windows 10
  • Fix "Fatal: INT18: Boot failure"
  • Fix fixboot access denied

Sources:

  1. https://www.veeam.com/blog/how-to-convert-physical-machine-hyper-v-virtual-machine-disk2vhd.html
  2. https://www.diskpart.com/articles/convert-vhdx-gpt-to-mbr-4125.html
  3. https://superuser.com/a/1303238/940718
  4. https://social.technet.microsoft.com/Forums/en-US/7262c702-ce37-4853-9a12-5cafcf10342e/disk2vhd-efi-vhdx-vm-fails-to-boot-solved?forum=winserverhyperv
  5. https://forums.virtualbox.org/viewtopic.php?f=2&t=86038#p409915
@jsteave
Copy link

jsteave commented Jun 25, 2021

amazing work. keep it up.

@mickael28
Copy link

mickael28 commented Oct 9, 2021

Hey @bre7, I was following the steps but when I enter active on my selected partition, I get this error.

The ACTIVE command can only be used on fixed MBR disks.

I've seen some articles for converting a GPT disk to an MBR disk, but in that case, they use a clean command which will delete all partitions :S

Do you know how I could bypass that problem by any chance?

Thank you!


Forgot to mention that before trying with the GPT partition, I tried converting the VHDX file from GPT to MBR, but then that file was failing to be added in Virtual box with:

'F:\CLONED-WIN10-DESKTOP.VHDX'
(VERR_NOT_SUPPORTED)
Result Code: | E_FAIL (0x80004005)

Component: | MediumWrap
Interface: | IMedium {ad47ad09-787b-44ab-b343-a082a3f2dfb1}
Callee: | IVirtualBox {d0a0163f-e254-4e5b-a1f2-011cf991c38d}
Callee RC: | VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)

Another issue I've been facing is that when creating to convert from GPT to MBR is that when I Attach the VHD file, which was created from a single partition, not sure why but disk manager loads the complete original disk (which that partition and with another RAW partition there).

Not sure how all this interacts but when I then try with Acronis to change from GPT to MBR on that disk, it says that it needs to reboot my system rather than just changing that type while I am inside windows.
The problem with this has been that then, on the reboot, the VHD was not mounted (as I was expecting) so the tool has messed up all my other hard drives, changing random ones from GPT to MBR (even where C: windows was installed) but the VHD is still in GPT format.

This whole process is still so complex and messed up in some scenarios. Wondering how's not much easier by now.

I'll see if I eventually have it working trying things.


Final update for today. Trying in a different desktop PC with a different hard drive, I managed to at least convert the VHD GPT to MBR and tried the steps above.

Finally, I managed to activate the partition that had the VM, but... now that's just booting to a Black screen :S

@bre7
Copy link
Author

bre7 commented Oct 9, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment