Switching a Windows 8 Consumer Preview from a VHD to Hyper-V
Now that Windows 8 Consumer Preview (CP) is out the doors, I'll start publishing a series of articles about Windows 8 development in various areas, but primarily focused on development.
I'll start today with some tips and tricks that allow to run Windows 8 natively from a VHD, but also run that same VHD from Hyper-V, within Windows 8 Consumer Preview.
The common scenario is simple, you want to try out stuff that worked in the Developer Preview (DP) inside Win8 CP, or run a two instances of the Win8 CP for testing purposes. Chances are you installed the DP on a VHD, from the excellent blog post from Scott Hanselman.
A few things about Hyper-V
Hyper-V’s been here for a while on the Server side, but chances are you never looked at it. Hyper-V will most likely completely replace Virtual PC, as it now supports 64 Bits virtual machines and the very useful dynamic memory feature. Dynamic memory basically add or removes physical memory assigned to the virtual machines depending on the actual demand. This allows to have higher virtual machine density on servers, but on client machines this is also pretty useful because you may not have 32GB of ram, and still want to use it for your primary OS.
This is why this tutorial suggests to have a machine starting with 512MB of RAM, so that it can grow to the appropriate amount, and not arbitrarily reserve 2 or 4GB of ram, just in case.
Running the VHD from Hyper-V
So now that Hyper-V is now included natively in Windows 8, and even though the final SKU in which it will be included is unknown, we can use it from the CP.
If you’re like me, you may have installed the CP directly on a SSD to make it pretty darn fast. Now, here’s how you install Hyper-V :
- Open the start menu, type “Feature” and open “Turn Windows Features on and off”
- Select “Hyper-V” and OK. Reboot. (If the Hyper-V infrastructure is off, then either your CPU does not support hardware virtualization, or it is disabled in your bios)
- Launch the “Hyper-V Manager”
- In the right hand side panel, select “Virtual Switch Manager”
- Click on “Create a Virtual Switch”
- Set a relevant network or network adapter name
- Select your network card, could be either a wireless or wired network card, then OK.
- In the right hand side panel, select “New” and “Virtual Machine”
- Give it 512MB of RAM and check the “Dynamic Memory” box, then next
- Select the virtual network switch you previously created
- Select “Use an existing Virtual Hard Disk” and select the Windows 8 DP VHD or VHDX file
- Click next twice.
- Now in the list of machines in the Hyper-V Manager, right click on your machine and start.
Chances are that your machine will not boot and ask you to replace the disk with a bootable one.
Here’s how to fix that :
- Double click on the virtual machine line to open a Display Console
- In the Media menu, select “Insert Disk” and select the Windows 8 CP iso file
- Reboot the virtual machine using the reset button in the toolbar
- Once on the Windows 8 install welcome screen, type Shift+F10, this will show a command line window
- Run Diskpart
- Type “list volume”
- Type “select volume 1”
- Type “list partition” and find the “System Boot” partition or the primary partition
- Type “select partition 1” (replace the 1 with the partition listed at the previous step)
- Type “active”
- Then type “exit”
- Back at the command line, you should be on the X: drive
- Type the following “bcdboot c:\windows /s c:” (you may need to replace the second “c:” with the drive that is the System Boot, when installing on a physical machine)
- Once done, close the installer window to exit the installation and reboot
- You’re done !
Note that this section can be used to register pre-installed Windows 7 or 8 VHD to an existing Windows 7 or 8 physical machine. But in this case, you may need to find the actual hidden boot partition that the Windows Installation creates automatically. You’ll find that partition with the “list partition” command.
Happy Windows 8 CP’ing !