Hyper-V is a native hardware-assisted virtualization platform provided in Windows 8 Pro and Windows Server 2008 R2 and above. In essence, a Virtual Machine is a PC emulation running on your PC. You install VM software on your physical host machine, then boot up and install any number of guest OSs. Popular VM software includes VMware, VirtualBox and Microsoft Virtual PC (which was used to power XP Mode in Windows 7).

VMs are essential for web developers:

  1. They allow you to test alternative browsers such as historical versions of IE or Linux installations.
  2. You can set up development servers such as Linux with Apache, PHP and MySQL on a Windows development PC.

VMs are hard disk images so they can be backed-up, cloned and moved far easier than a real PC. In addition, most VM software allows you to make snapshots so you can test software or configurations and revert back in the event of catastrophic failure.

Hyper-V has a number of benefits including speed, multi-core processor support and booting to VMs (users can use a guest VM as their daily OS so they can’t trash the host). But the main advantage is that VMs operate in the background. There’s no need to start the software; it’s always running and controlling your booted guest OSs. Similarly, there’s no need to open or connect to the guest OS desktop — if you’re running a development server, you can simply transfer files like you would to any other device on your network.

So let’s look at the basics of using Hyper-V. I’m using Windows 8 but Windows Server is similar.

1. Enable Hyper-V

From the Windows Control Panel, select Programs and Features followed by Turn Windows features on or off. Check Hyper-V and all platform and tools sub-components. It’ll take a few minutes to install.

2. Configure Hyper-V Defaults

From the Start screen (or Win+Q), run the Hyper-V Manager. You can change the default settings in Action > Hyper-V Settings.

Hyper-V settings

3. Create a New Virtual Machine

To create a new VM, select Action > New > Virtual Machine…. Enter a name for your VM and select a different file location if necessary:

Hyper-V create VM wizard

Now enter the amount of memory you want the VM to use — keep it as dynamic unless you want to specify a maximum:

Hyper-V create VM wizard

You can now create or use an existing hard disk image and specify a maximum size (it will grow as the VM requires more space):

Hyper-V create VM wizard

Finally, you can choose to install an operating system from a physical drive or ISO image:

Hyper-V create VM wizard

Hit Finish to complete the wizard. You can now boot your VM (click Start in the Actions pane) and install a guest OS. Remember this occurs in the background; to view the desktop, click Connect… in the Actions pane.

Hyper-V boot guest OS

Note that the VM will not be able to connect to a network yet — you may wish to configure that first so updates can be downloaded.

4. Connecting to Your Network

Connecting to the network is slightly unusual compared to other VM software. Hyper-V creates a virtual switch device which is subsequently used for all host and guest connectivity. Under the right-hand Actions pane, click Virtual Switch Manager…. Select External and hit Create Virtual Switch.

Hyper-V virtual switch

Assign a name (Virtual Switch is as good as any), select the real network adapter used for networking on your host OS, and hit Apply. The dialog can then be closed.

Now, right-click your VM and choose Settings… (or click Settings… under your VM in the Action pane). Select the Network Adapter tab and ensure Virtual Switch (or whatever you named it) is selected.

Hyper-V virtual switch

Reboot your VM and, with luck, you should have network connectivity.

Network Troubles?
Many people experience networking problems with Hyper-V guests — I did. A separate hardware NIC adapter is recommended, but this is impractical for most desktop and laptop PCs. If you can’t connect or connectivity randomly drops, try the following remedies:

  1. Configure the guest OS to use a fixed IP address.
  2. If it continues to fail, disable TCP Checksum Offload and UDP Checksum Offload in your physical NIC adapter settings (they may have slightly different names).

5. Connect to Your VM

As mentioned, you can click Connect… in the VM’s Action pane to view the desktop. Alternatively, you can use Microsoft’s Remote Desktop Connection tool much like you would with any networked Windows device.

Hyper-V offers some great features which will benefit web developers. Do you have any interesting uses for the platform?

Craig Buckler
Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler

  • http://blog.wasimshaikh.com Wasim

    Very good article , will try soon.
    Thanks

  • http://paulwp.com Paul

    lovely! I’m going to try and install a LAMP stack and use it for development. I’d like to get xdebug to work, so I can use Phpstorm on the host and connect to xdebug on the virtual machine

    • http://www.optimalworks.net/ Craig Buckler

      It should be possible and, one thing I forgot to mention, is that Hyper-V is resource efficient. The XP VM shown above rarely exceeds 3% processor use and a lightweight Linux stack should be less.

      Let me know how you get on and whether you have any distro recommendations.

  • http://www.hostking.co.za Tasneem

    Just a brilliant article! I’ve just done this on a test box and it’s actually quite easy to do.

    • http://www.optimalworks.net/ Craig Buckler

      It is relatively straight-forward, although the networking may catch you out. I struggled for a couple of hours!

  • Aboladebaba

    Thanks for your clear and unambiguous presentation!

    I was trying to create virtual machines on my laptop and I got stuck with the virtual switch creation on Windows Server 2008 R2. With this article I could see what I didn’t do right, I will go back and implement what have learnt here and if I run into troubles again I will surely come back :)

    Aboladebaba.

  • John King

    I had major problems with my internet connection after I installed Hyper-V. I used the ‘Network Adapter/Virtual Switch’ setting you used above and it created a new default internet connection which stopped me being able to access the internet on Win8. It took me a whole day to sort out, grrr!

    When I actually had a spare day I treid again but this time (and maybe this is for virtual WinXP only) I just used the ‘LEGACY Network Adapter’ option. This worked perfectly.

    • http://www.optimalworks.net/ Craig Buckler

      Sorry if this article led to problems. Did you select your in-use network adapter when creating the virtual switch? If you’re using ethernet and have an unconfigured wireless card, selecting that card would result in connection failures.

      If you do have problems, you should be able to remove the virtual switch and everything will go back to the original configuration.

      Incidentally, where did you see “Legacy Network Adapter”? Was that one of your external network types?

      • John King

        Hi Craig, your article didn’t cause the problems but it used the same setup as an article I’d read a few months ago so I thought I’d highlight the issue I had. Yes, I did use my in-use network adapter, but at the time I had no idea how to fix the connectivity issue I was having. Which led to much frustration.

        I think I added the Legacy Network Adapter using the ‘Add Hardware’ setting after I’d created the virtual machine. My settings look the same as your in the final diagram above but I have:

        Legacy Network Adapter
        – Virtual Switch

        above the Network Adapter item.

  • http://www.greenleaf-net-solutions.com/ Colin Crawford

    Hi
    I’ve used Hyper-V before with Server 2008 R2 and managed to sort the networking out. But I didn’t know Windows 8 Pro had it built in, I would change from Windows 7 but don’t like some of the aspects in Windows 8. I’m lost without the Start button and the other ways of navigating around.

    Great write up but need to reconsider Windows 8 to have the use of Hyper-V.

    Colin

Related books & courses
Available now on SitePoint Premium

Preview for $1