Tag Archives: Hyper-V

Installing Ubuntu 14.04 LTS as a Generation 2 Hyper-V guest

Since Microsoft release Windows Server 2012 R2 Hyper-V have had two different generations of virtual machines. The old “Generation 1” and the new “Generation 2”. Microsoft added generation 2 to get rid of the old stuff that really doesn’t make sense in a virtual world. And also to add new stuff. Generation 2 virtual machines provide the following new functionality:

  • PXE boot by using a standard network adapter
  • Boot from a SCSI virtual hard disk
  • Boot from aSCSI virtual DVD
  • Secure Boot (on by default)
  • UEFI firmware support

As can be expected all of these features worked fine straight away with Windows 8 (64-bit) and Windows Server 2012 or later. But they did not work well with Linux. Until now.

The fresh Ubuntu 14.04 LTS release works fine with and can be installed into a generation 2 virtual machine in Hyper-V. There is only one thing you need to know – Secure Boot has to be disabled. Hyper-V enables secure boot by default so if you just click through the wizard to create a VM it will not work. You have to disable Secure Boot.

Here’s the PowerShell way to check if Secure Boot is enable for your VMs:

Get-VM | Get-VMFirmware

To disable Secure Boot for a specific VM (‘TrustyTahr’) use this:

Get-VM -Name 'TrustyTahr' | Set-VMFirmware -EnableSecureBoot Off

Now you can install Ubuntu in a generation 2 Hyper-V machine. It just works. And even though I have not done any valid tests the gen 2 Ubuntu machine feels a lot snappier than on old one.

Basic inventory of HyperV virtual machines using PowerShell

Working at large scale with thousands of servers customers often asks for a list of machines with various properties for each machine.

Most of the time the customer want this information in an simple format (read CSV, the World isn’t as advanced as you like!) so that they can use it internally. In this blogpost I will show how you can get the information about memory, CPU count etc for a set of Hyper-V machines from Virtual Machine Manager via PowerShell.

Start a PowerShell command line and load the PowerShell Snap-In for Virtual Machine Manager.

Add-PSSnapin -Name Microsoft.SystemCenter.VirtualMachineManager

Now we can work with the commands made available to us by the Snap-In, if you want to find all the commands that are available issue:

Get-Command -Module Microsoft.SystemCenter.VirtualMachineManager

So let’s begin by loading information about all our machines from the VMM host into a variable named $VMs

$VMs = Get-VM -VMMServer hyperv-vmm01.sth.basefarm.net

What the above command does is to load all of the VMs on the host HYPER-V-01.mydomain.com into the variable $VMs. This means we will only do one call to the server which avoid generating unnecessary load.

Now let’s check how many machines we have:


And now that we know we have machines to query, let’s find out what attributes exists (things we can get into our output)

$VMs | Get-Member -MemberType Property

For example, to find all macines that are powered off:

 $VMs | where { $_.Status -eq 'PowerOff' } | select VMHost, name , Memory, CPUCount , Status

The above example adds some complexity to the command, but it is to filter so we only see machines that have the status is ‘PowerOff’.

Now let’s get what we wanted from the beginning, a list of machines for a specific customer. The list should include name of the VM host, VM name, memory, number of CPUs and current status.

 $VMs | where { $_.Name -Match 'CUST*' } | select VMHost, name , Memory, CPUCount , Status

This will list all machines who’s name begins with ‘CUST’. So we now have found what we wanted!

But instead of copying & pasting this we want to write the result to a CSV file so we can send that to the customer. Let’s make that easier by getting the output of the above command into a variable named $result

 $result = $VMs | where { $_.Name -Match 'LFO*' } | select VMHost, name , Memory, CPUCount , Status

Now our ‘report’ is stored in the $result variable and we can use standard PowerShell to export it to a CSV file:

$result | Export-Csv -NoTypeInformation -Delimiter ';' .\report.csv

Now our report is available in a CSV file on the file ‘report.csv’ (in the current directory)

A very basic way of getting your Hyper-V inventory out!

Minimal CentOS 6.4 with Hyper-V

Now that CentOS includes the kernel drivers for Hyper-V it is very easy to setup a CentOS 6.4 based server in Hyper-V. Download the “minimal” ISO and create a new Hyper-V VM. Run through the installation and reboot.

What you will notice when logging in is that the eth0 NIC has not been started. This is normal and if you want to access the network with a DHCP assigned address simply start the interface:

ifup eth0

Now you should be able to access the network that your Hyper-V VM has access to.

Since you don’t wan’t to do this everytime you start your system you need to change a config file. The file to change is (provided your NIC is named eth0)


The contents of this file is something similar to this:


If you’re happy with getting your IP from the DHCP server, simply change the “ONBOOT=no” to “ONBOOT=yes”. Next time you reboot you will get your network straight away.