Creatively using a VHD file for development
Image Usage
In a previous post I discussed the creation of a fully configured Windows based virtual machine for various Windows development work. Now let's use it.
This post assumes the availability of a fully configured VHD file as outlined in the previous post “Setup a Windows Development Environment in a Virtual Machine and Beyond”. While the content and configuration of the image is not perfect, it will give anyone using it a good head start. It will require less work on the development infrastructure and free up time to work on projects.
The content of the provided virtual machine file can be used in different ways. See the diagram below for suggestions. Please note that your system might not support one or the other suggested scenario.
You can always install missing software via chocolaty or webpicmd or any other method.
Please remember, software like Visual Studio 2013 and others require you to purchase a proper license before using it in production.
As always, all information is provided as-is. I cannot guarantee it will work in your environment, nor can I be held liable for any issues caused by following the steps or using the resulting image. Simply put, YMMV.
Usage Diagram
Use as Virtual Machine
The VHD file from the previous post can be used in different ways. The easiest way is using as a virtual machine. There are a few limitation when using the VHD as a virtual machine in a virtualized environment. Refer to the sections below to find out about the limitations.
Hyper-V
The virtual machine in the VHD file has been built using Hyper-V. Using it with Hyper-V on a Windows 8 or Windows 8.1 client or Windows Server 2012 (R2) is the preferred way. There is however one limitation. If you intend to develop Windows Phone software you will not be able to use the emulator due to restrictions in the Microsoft Hypervisor (no support for nested virtualization).
Steps to run the virtual machine (VM) in Hyper-V on Windows 8(.1)
Make sure you have enabled Hyper-V on your system via Control Panel\Programs\Turn Windows features on or off/Hyper-V. To enable this feature your system must be enabled to support virtualization via BIOS settings. Refer to your specific BIOS for details.
- Copy the VHD file to a local directory
- Start Hyper-V Manager and create a new virtual machine and attach the newly copied VHD file as the disk
- Memory: 2GB minimum
- 2 processors (or more)
- Do NOT connect a network yet
- Point it to the previously copied VHD file as the target disk
- Start the virtual machine and follow the steps to create a local user account.
YOU WILL NOT BE USING THIS USER ACCOUNT AT ALL. A FULLY CONFIGURED ACCOUNT HAS BEEN CREATED FOR YOU. IT IS STRONGLY RECOMMENDED THAT YOU USE THIS ACCOUNT. Feel free to rename the account to your liking at a later time as suggested in Next Steps further down. - Follow the steps in Next steps towards the end of the post
VirtualBox 4.2 and above
The provided VHD file can be used directly w/o any conversion by the latest builds or VirtualBox. If you are unfamiliar with creating a virtual machine in VirtualBox refer to this documentation. Make sure to select “Use existing hard disk” or similar to attached the copied VHD file to the newly created VM. A copy of the latest version of VirtualBox can be downloaded from project’s website. Below steps have been performed using VirtualBox 4.2.
Other settings:
- Memory: 2GB minimum
- 2 processors (or more)
- OS: Windows 8, 64-bit (or similar, 64-bit Windows is important!)
- Make sure VT-x/AMD-V, Nested Paging is enabled
Once the installation of the virtual machine has finished, launch the VM and go through the setup process.
- Start the virtual machine and follow the steps to create a local user.
YOU WILL NOT BE USING THIS USER ACCOUNT AT ALL. A FULLY CONFIGURED ACCOUNT HAS BEEN CREATED FOR YOU. IT IS STRONGLY RECOMMENDED THAT YOU USE THIS ACCOUNT. Feel free to rename the account to your liking. - After a reboot, install the virtual machine Guest Additions as described here.
- Follow the steps in Next steps down at the end of the post.
Parallels 9
The provided VHD file can easily be converted using OOB tools shipping with Parallels. Assuming you have installed Parallels Desktop 9 for Mac, follow the steps below to get a working Parallels VM working in Mac OS
- Copy the provided VHD file to a local directory on your Mac or make a copy available via an external drive (ideally via USB 3).
- On your Mac open a terminal window
- Run the following command to convert the VHD file into a Parallels VM format:
/Applications/Parallels/Desktop.App/Contents/MacOS/prl_convert <path to the provided VHD including full file name>
- After the script completed successfully you will find a virtual machine file of the same file name as the original file in your documents folder. The file will have a .pvm extension.
- Use the “Add Existing Virtual Machine” option in Parallels Desktop 9 for Mac to add the virtual machine to Parallels.
- Parallels will start the virtual machine. Follow the steps to create a local user.
YOU WILL NOT BE USING THIS USER ACCOUNT AT ALL. A FULLY CONFIGURED ACCOUNT HAS BEEN CREATED FOR YOU. IT IS STRONGLY RECOMMENDED THAT YOU USE THIS ACCOUNT. Feel free to rename the account to your liking. - Shutdown and configure the virtual machine with the following settings:
- At least 2GB of RAM
- 2 processors (or more)
- After a reboot you will have a fully configured running virtual machine.
- Follow the steps in Next steps down at the end of the post.
Fusion 6
VMware Fusion 6 is capable of importing the provided VHD and run Windows on Mac OS
- Create a local copy of the provided VHD file
- In Fusion select “Import” to import the local copy of the VHD file
You have two options to import the VHD file. Either “Windows 8 64-bit” or “Hyper-V (unsupported)”. Hyper-V, even though unsupported by VMware, is the only option if you intend to use the virtual machine to develop Windows Phone apps and want to use the phone emulator that ships with Visual Studio.
- Once imported you should choose “Customize Settings” to adjust the virtual machine’s memory and other configurations. Suggestion is to use at least 2 GB of RAM and 2 processors or more.
- Fusion has created a copy of the provided VHD file. You can now delete the original copy of the VHD file from your hard disk.
- Before starting the newly created virtual machine (VM), make sure to disconnect the VM from the network
- Start the VM and follow the setup to create a local user account.
YOU WILL NOT BE USING THIS USER ACCOUNT AT ALL. A FULLY CONFIGURED ACCOUNT HAS BEEN CREATED FOR YOU. IT IS STRONGLY RECOMMENDED THAT YOU USE THIS ACCOUNT. Feel free to rename the account to your liking. - After a reboot you will have a fully configured running virtual machine.
- Follow the steps in Next steps down at the end of the post.
Native Boot
Boot-To-VHD
Note: “Bitlockered” volumes are not compatible with Boot-To-VHD. A non bitlockered volume on the local system is required if you want to use this option. Either add a second hard drive to your system or shrink the existing bitlockered volume to make room for another not protected volume.
- Create a new top level folder called \images in order to hold the provided VHD. This example uses a second volume of D:\
You can change the drive letter and path for your VHD if needed - Copy the provided VHD file under <name of VHD file> (pick one or leave the existing) into the \images directory
- Open an elevated command prompt and run the following command
bcdedit /copy {current} /d "My New VHD Image"
- Copy the long {CLSID} number given in the output, and use it in the following commands
- Note that {curly braces} are required
- The square brackets on the drive letter in below commands are required
- Run the following commands
bcdedit /set {CLSID} device vhd=[D:]\images\<name of VHD file>
bcdedit /set {CLSID} osdevice vhd=[D:]\images\<name of VHD file>
bcdedit /set {CLSID} detecthal on
- Reboot. You will have the option to boot the " My New VHD Image " as if it were a local installation
- Select “My New VHD Image” and follow the setup to create a local user account
YOU WILL NOT BE USING THIS USER ACCOUNT AT ALL. A FULLY CONFIGURED ACCOUNT HAS BEEN CREATED FOR YOU. IT IS STRONGLY RECOMMENDED THAT YOU USE THIS ACCOUNT. Feel free to rename the account to your liking at a later time - Follow the steps in Next steps down at the end of the post.
Windows-To-Go
Using this method requires the availability of a Windows To Go approved USB stick. Microsoft employees can purchase Windows To Go approved USB sticks via MSMarket (navigate to the hardware marketplace and search for “Windows To Go”). You find a list of approved Windows To Go devices on the Microsoft website . The minimum RAM size should be no less than 50GB.
To build your own Windows To Go USB stick from a provided VHD refer to the previous post .
This option will allow you to use a provided USB device with your system. The system must be able to boot from an external USB device. No changes to the existing software environment is required.
- Make sure your PC supports booting from an external device like a USB stick
- Turn off your system
- Insert the provided USB device with a Windows To Go image in an available USB slot. Ideally USB 3.
- Turn on your PC and boot from the newly inserted USB device using the appropriate settings/key sequences for your device
- Using a MacBook requires you to select the proper boot volume at startup. Press and hold the option key at system start and select the “Windows” partition for startup
- Follow the setup to create a local user account.
YOU WILL NOT BE USING THIS USER ACCOUNT AT ALL. A FULLY CONFIGURED ACCOUNT HAS BEEN CREATED FOR YOU. IT IS STRONGLY RECOMMENDED THAT YOU USE THIS ACCOUNT. Feel free to rename the account to your liking at a later time. - After a reboot you will have a fully configured running virtual machine.
- Attention: Using this USB device with a MacBook requires the installation of the Boot Camp device drivers to function properly. Please refer to Apple’s Boot Camp Get Started pages for details on how to obtain drivers. You may have to run the bootcamp.msi in the bootcamp\drivers\apple subdirectory of the boot camp download to get your devices installed. Make sure to run it from an elevated command prompt.
- Follow the steps in Next steps
- Log on using the following user credentials:
Next steps
- Log on using the following user:
hal9000
- <no password has been set>
- Feel free to rename the account and set a proper password via
Control Panel\User Accounts and Family Safety\User Accounts - Make sure you use the virtual machine manager of your system to check your network settings and to enable networking
- Check and see if there are any updates on Windows Update and install
You're now good to go. Please remember, software like Visual Studio 2013 and others require you to purchase a proper license before using it in production.