Installing Windows within Windows

May 30, 2023

  • notes
  • windows

Back in the days for high schools when I had way more time, I was toying around with my computer and with a couple of VMs and tools like EasyBCD and found the Windows bootloader is capable of booting from hard drives images.

A screenshot of EasyBCD

I’ve later found Microsoft’s OEM documentation on how to do this properly.

Microsoft’s guide is tailored to OEMs setting this up from Windows PE and isn’t necessarily tailored for the power user. So I thought I’d write things my own way to make this more accessible.

This is how I’m getting my streaming setup to work, so let’s begin.

Let’s Get Into It

Creating a virtual hard drive

Open a terminal as an administrator (Win XTerminal (Admin)) and run diskpart.

In diskpart, run the following to create a VHDX file.

create vdisk file="C:\Multiboot\Stream.vhdx" type=expandable maximum=180000

We then need to format the disk.

attach vdisk
create partition primary
format fs=ntfs label="Stream" quick
assign letter=v

You can now exit from diskpart.

Installing Windows

Next up grab a Windows 11 ISO (or any other ISO) and mount it on your system. Once the image is mounted, you can now apply the image to the virtual hard drive.

First check which edition you’d like to install with the following command and take note of the index numbers:

dism /get-wiminfo /wimfile:"X:\sources\install.wim"

Then apply said image onto the virtual hard drive.

dism /apply-image /imagefile:"X:\sources\install.wim" /index:4 /applydir:V:\

Adding it to the boot menu

Next up, we need to add Windows to the boot menu.

bcdboot V:\Windows

And that’s it! This sets it default OS and it will now get picked up next time you reboot.

Renaming the new installation

You can also change the name of the new installation.

List out the boot entries with bcdedit /v and copy the identifier of the entry referring to the VHDX file.

Windows Boot Manager
--------------------
identifier              {9dea862c-5cdd-4e70-acc1-f32b344d4795}
device                  partition=\Device\HarddiskVolume1
path                    \EFI\Microsoft\Boot\bootmgfw.efi
description             Windows Boot Manager
locale                  en-us
inherit                 {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}
default                 {cc33f9c6-fe8b-11ed-a1cd-683e26c558cc}
resumeobject            {cc33f9c5-fe8b-11ed-a1cd-683e26c558cc}
displayorder            {cc33f9c6-fe8b-11ed-a1cd-683e26c558cc}
                        {4ae36b77-a304-11ed-beaa-d8a5cf26f6ec}
toolsdisplayorder       {b2721d73-1db4-4c62-bf78-c548a880142d}
timeout                 30

Windows Boot Loader
-------------------
identifier              {cc33f9c6-fe8b-11ed-a1cd-683e26c558cc}
device                  vhd=[C:]\Multiboot\Stream.vhdx,locate=custom:12000002
path                    \windows\system32\winload.efi
description             Windows 11
locale                  en-us
inherit                 {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                vhd=[C:]\Multiboot\Stream.vhdx,locate=custom:22000002
systemroot              \windows
resumeobject            {cc33f9c5-fe8b-11ed-a1cd-683e26c558cc}
nx                      OptIn
bootmenupolicy          Standard

Windows Boot Loader
-------------------
identifier              {4ae36b77-a304-11ed-beaa-d8a5cf26f6ec}
device                  partition=C:
path                    \WINDOWS\system32\winload.efi
description             Windows 11
locale                  en-GB
inherit                 {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence        {b1f12712-39b5-11ed-ba7e-e992dd4a9090}
displaymessageoverride  Recovery
recoveryenabled         Yes
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=C:
systemroot              \WINDOWS
resumeobject            {4ae36b76-a304-11ed-beaa-d8a5cf26f6ec}
nx                      OptIn
bootmenupolicy          Standard
hypervisorlaunchtype    Auto

And use that to change the name:

bcdedit /set "{cc33f9c6-fe8b-11ed-a1cd-683e26c558cc}" description "Stream"

Restoring the default installation

You can also restore the default installation to the one you’re currently booted into by running:

bcdedit /default "{current}"

Finish

At this point, you should restart your computer to make sure it still works. If everything goes to plan, you should see this screen.