How to install Windows to a VHD

Goal of this tutorial

This tutorial tells you how to install Windows to a Virtual Hard Disk file and successfully boot it. This is useful if you want to test another OS without creating partitions or formatting.

Create and setup the Virtual Hard Disk

For this purpose, reach Disk Management by running diskmgmt.msc.

Click on Action -> Create VHD File.

Select the path where to save the VHD to. Make sure to select a good size (for example 50 GB), use the format "VHD" (NOT VHDX!), and make sure to check Dynamic Expansion.

Once done, the VHD will appear as an uninitialized disk. Right click the Disk and select "Initialize Disk". Choose MBR or GPT, it doesn't matter and click OK. Now right click the unallocated space and click "Create new simple volume". Leave the default size and click Next, assign it to a letter (for example F), use default format settings (NTFS) and choose a label (for example AtlasOS) and click Next. Click End to finish.

Congratulations! Your VHD is now set-up and ready for use!

Install Windows to the VHD

Now that you have the Virtual Hard Drive mounted to a drive letter, you can proceed installing Windows to it. For this purpose, mount the ISO file by double clicking it or by using a tool like PowerISO or Daemon Tools. Go and look for a file named install.esd or install.wim, inside the sources directory. Use the dism command to get information of the file, for example:

dism /get-imageinfo /imagefile:E:\sources\install.esd

Choose the Windows version you want to install by its index, in my case it will be the index "1", and expand it to the VHD using dism. In my case, F is the drive letter for the VHD and E is the drive letter for the ISO:

dism /apply-image /imagefile:E:\sources\install.esd /index:1 /applydir:F:\

Congratulations! Once this is done the OS is expanded, now proceed copying setup scripts to the VHD. Look for a folder named $OEM$ inside sources, in the ISO, and:

-> Copy the content of the $$ directory to F:\Windows

-> Copy the content of the $1 directory to F:\

Look for an autounattend.xml file in the root of the ISO and copy it to the root of the VHD. Some of these files might not be there depending on the OS, in that case just skip.

All I can see is several install.swm files (install.swm, install2.swm, etc.), what do I do?

In that case the two commands will be different:

dism /get-imageinfo /imagefile:E:\sources\install.swm

dism /apply-Image /imagefile:E:\sources\install.swm /SWMFile:E:\sources\install*.swm /index:1 /applydir:F:\

Create boot files

Now that we've set-up our VHD we're ready to create boot files so that Windows will add a boot entry for it.

Change the name of your current Windows 10 installation so you can remember it:

bcdedit /set description "Regular Windows 10"

And then create boot files for your new OS:

bcdboot /d /addlast F:\Windows

Where F:\ is the drive letter of the VHD. It should say "Boot files created".

Boot to your new OS!

Now you should be able to reboot and select the new OS just fine. Pro tip: to change the description of the OS you can use bcdedit /set description "The name you want" to change the description for the currently booted OS.

Delete the OS

Want to delete the OS? Proceed booting into your regular OS and then run msconfig, head to the Boot section and delete the Operating System. Once done, you can freely delete the VHD file.