Using Hyper-V services to simplify the software development cycle

Hyper-V for software developers:

An efficient and well-defined development environment is required for a software engineer to be effective.  A major part of this environment is the testing/certification system (i.e. the Operating System available to install and test the software under development).  Microsoft’s Hyper-V is a service which runs on 64-bit versions of Microsoft Windows Server and Windows 8.1 Pro.  It is an excellent tool to enable a simple and effective test environment for software developers. Hyper-V virtualization services is a key part of my software development process.  Below, I share how I setup, configure, and utilize the service for my everyday development and testing needs.

Pros:

  • not necessary to purchase new hardware
  • easy to reconfigure the operating system to a “clean” or “well defined” state for testing
  • able to share images of operating systems easily with other developers
  • faster setup and re-configure times
  • easy to roll-back to a previous state to get a fresh look at a software bug

Cons:

  • A 64-bit version of Microsoft Server (or Windows 8.1 Pro) operating system is required to install the host Hyper-V service
  • An Intel or AMD microprocessor with hardware-assisted virtualization must be available and configured by you in the BIOS

Requirements:

  • Windows Server 2008 or later, Windows 8.1 (64-bit) Pro/Enterprise
  • A x64-based processor  (64-bit)
  • A BIOS with hardware-assisted virtualization. This is available in processors that include a virtualization option such as Intel Virtualization Technology (Intel VT) or AMD Virtualization (AMD-V)
  • A BIOS with hardware-enforced Data Execution Prevention (DEP) must be available and be enabled. Specifically, you must enable the Intel XD bit (execute disable bit) or AMD NX bit (no execute bit).

The first requirement to utilize Hyper-V is to install the host service on your Windows Server or Windows 8 Pro/Enterprise system.  This is a one-time setup as described below.

Enabling Intel VT or AMD-V in the BIOS:

Enabling the Intel Virtualization Technology (Intel VT) or AMD Virtualization (AMD-V) feature in your processor via the BIOS is required to run Hyper-V.  Unfortunately, not all processors have this feature.  If the processor in your host system does not have this feature then you can either purchase a new processor or use a different virtualization host such as Virtual Box which does not require hardware virtualization. To verify that your processor’s Virtualization Technology is enabled, restart your PC and enter the BIOS menu (note: there is no common PC BIOS or BIOS interface so you should refer to your motherboard/CPU documentation for detailed information about your specific system).  Enter the BIOS as your system is restarting (typically press the Delete, F1, ESC, or Alt-F4 keys).  Once you’re in the BIOS menu look for a setting title Intel Virtualization Technology or VT-x.  This could be under the Advanced CPU, Chipset, Advanced, or Other sub-menu.  Make sure the setting is Enabled and save the BIOS settings and restart your system. If you can’t locate the setting you can simple try installing Hyper-V.  If the virtualization feature is enabled (as it would be by default with most modern AMD processors) then Hyper-V will work fine.  If the feature is NOT installed then you will get a warning during installation and you will not be allowed to continue until the virtualization feature is enabled.

Installing Microsoft Hyper-V services on Windows Server:

From the Windows Start Menu, search for the Server Manager and launch it

launch the server manager
launch the server manager

In the Console Tree on the left-side, right-click Roles and select Add Roles.  .

select add roles
select add roles

The Add Role Wizard  will be displayed.  Click-though the wizard and select Hyper-V from the Select Server Roles page.  If Hyper-V is already installed then simply click the Cancel button and move along to the next section.  Otherwise, press the Install button and click-through the Confirmation and Progress pages to complete the installation

add role wizard
add role wizard

Installing Microsoft Hyper-V services on Windows 8.1:

In the Control Panel, click Programs, and then click Programs and Features.  Click Turn Windows features on or off.  Click Hyper-V, click OK, and then click Close.

Launching the Hyper-V Console:

From the Windows Start menu, search for the Hyper V Manager and launch it

launch hyper-v manager
launch hyper-v manager

When you launch the Hyper-V manager you will see a list of all current virtual machines (guest operating systems) that you have created.  Selecting a virtual machine from the top-center view will display a list of each of the snapshots you have created for that virtual machine.

hyper-v manager view
hyper-v manager view

Your view of virtual machines will be empty if this is the first time you have run the Hyper-V manager.

Creating a new virtual machine:

In the Actions pane located in the upper-right select New | Virtual Machine.  The New Virtual Machine wizard will be displayed.

hyper-v wizard - startup
hyper-v wizard – startup

Click Next and enter a description of your new Virtual Machine such as “Windows Server 2012 Essentials” or “Windows 8.”  Click Next to configure the amount of memory accessible to the virtual machine.

hyper-v wizard - VM name
hyper-v wizard – VM name

Enter the amount of memory you want the guest operating system in you new virtual machine to have access to.  Note this physical memory must exist in the host system running Hyper-V.  So you should make this value only as large as you actually need.  Make sure you take into account the actual amount of RAM required by the operating system you are going to install in the virtual machine (for example Windows Small Business Server 2011 requires a minimum of 1024 MB).  You can always change this value later so don’t be too concerned about absolute requirements or optimizations for your system at this time.  Click Next to configure your network.

hyper-v wizard - configure memory
hyper-v wizard – configure memory

Configure the network you want the guest operating system to have access to.   It’s best to select the LAN.  Doing so will allow the installed guest operating system to appear on your local network just like a normal physical system.  You will have access to  file sharing, internet access, and (most important to us developers) remote debugging features.  Click Next to configure the size and location of the virtual hard drive.

hyper-v wizard - configure network
hyper-v wizard – configure network

Enter a name for your new virtual machine.  It will always have the file extension vhd.  You should name it something relevant so you will be able to match the vhd file with the operating system you install within the virtual machine.  For example,  if I create a virtual machine named, “Windows 2012 Server Essentials” then I would name the virtual machine something like, “ws2012essentials.vhd” so I can immediately identify the vhd file when exploring the Windows file system. Enter the location of your new virtual machine.  I prefer to save all virtual machines on a secondary data drive away from the Windows operating system drive of the Hyper-V host not only for easier storage management but also a slight boost in efficiency by reducing the amount of hard drive seeks between both the Hyper-V host and the virtual machine.  But you can place the vhd files where ever you prefer as long as there is enough space on the hard drive. Enter the size in Gigabytes of the virtual hard drive.  The best size is dependent on the guest operating system you install in the virtual machine.  There’s quite a bit of trial and error to get this value just right for your needs.  I recommend leaving the default value of 127GB.  You can increase size of the virtual hard drive later if you need.  Press Next to configure the guest operating system and attached CD/DVD devices. hyper-v create 5

Finally, locate the iso file containing the operating system you want to install into your new virtual machine.  You can download iso files directly from Microsoft’s MSDN site.  This iso file will be mounted in the virtual machine as a CD/DVD device an allow you to install the operating system on the first boot of the virtual machine.  Press Next to view the final settings of the new virtual machine.

hyper-v wizard - configure guest operating system
hyper-v wizard – configure guest operating system

If all your virtual machine settings look okay then click Finish to finalize the process.  A new virtual hard disk will be created with the name you specified in the folder you specified.  Return to the Hyper-V manager and you will see the name of your new virtual machine in the Virtual Machines pane located in the top-center of the window.

hyper-v wizard - verify final settings
hyper-v wizard – verify final settings

Now your new virtual machine is setup and you can install the operating system into it.  Double-click the virtual machine within the Hyper-V manager to start it.   You will see the virtual machine starts in a disabled state.

hyper-v first launch
hyper-v first launch

From the virtual machine select Action | Start to launch the install process of the new virtual machine.

hyper-v install guest OS
hyper-v install guest OS

Now the install process will begin loading directly from the iso file you specified when creating the virtual machine.  Finish the install process just like you would on any machine any you are done.

hyper-v install OS
hyper-v install OS

Launching a virtual machine:

After you have created one of more virtual machines you can launch them directly from the Hyper-V Manager.  Double-click the virtual machine from the Virtual Machine pane located at top-center then click Action | Start.

Creating and utilizing snapshots:

Snapshots give you the ability to freeze an operating system at a point in time.  This is perfect for testing before-and-after issues and compatibility with other software. To create a new snapshot for a virtual machine select the virtual machine from the Virtual Machines pane, right-click and select Snapshot.

hyper-v snapshot
hyper-v snapshot

Managing virtual machine images:

It’s best to manage your virtual machines directly through the Hyper-V Manager.  You can create, edit, and delete directly through the manager’s user-interface.  With that, it’s good to know that all virtual machines,  virtual hard disks, and snap shots are stored on a local hard drive on the Hyper-V host system.  You can locate this folder via Windows Explorer.  Open an Explorer window to the folder you specified during the virtual machine creation wizard.  For example, in my case I save all virtual machine files on a data drive D:

hyper-v explore
hyper-v explore

Tips and tricks:

  • Backup your virtual machine image files.  Be aware of the folder containing the virtual machine, virtual hard drive, and snap shot files.  If you don’t run an image backup on your Hyper-V host machine then make sure you backup those specific folders.  Regenerating all your virtual machines would not be fun!
  • Create a snapshot immediately after installing a new operating system on your virtual machine.  The ability to rollback to a “clean” system will be helpful at some point trying to track-down a bug
  • Install the Hyper-V host on the most powerful and memory-filled system you have available.  Each virtual machine will gobble memory from the host so if you want to run multiple virtual machines simultaneously you’ll need more RAM.  Also, a multi-core CPU is much more friendly to running virtual machines.
  • Create a library of virtual machines with all the operating systems you develop for.   Have them available at a moments notice for quick efficient testing of your code.  If your product supports all the way back to Windows XP then so should your VM library.
  •  Share virtual machine images with other developers.  Unlike physical hardware which might not always be compatible, you can share some, or all, of your VM library with other developers in your company.  As long as they use Hyper-V it’s all good.  When creating a new library you can divvy up the work, save time, helping each other build a VM library.
  • Add multiple languages to your VM library.  We’ve all seen some bugs which are only reproducible in certain languages.  Add some Japanese, German, and other native VM’s to your library based on the target audience of your software.