Intalling Ubuntu In A Hyper-V Environment

Published October 6th, 2015 at 11:56 AM. by Joe Prochazka

The following is a walkthrough on how to install an optimized version of Ubuntu within a Hyper-V environment. The steps basically follow the techNet articles related to the installation of Ubuntu within Hyper as outlined by Microsoft. As well a needed change to the Grub configuration as of Ubuntu 15.04 is covered as well.

Before we create the virtual machine using the Hyper-V Manager we will want to create a new VHDX file which will be used as the operating systems main hard disk. We will use PowerShell in order to create the disk file mainly so we can set the BlockSizeBytes to 1MB instead of the default 32MB. This should drastically reduce the amount of disk space taken up by the VHDX file especially when the Linux file system is mostly empty.

PS> new-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\Ubuntu 15.04 Desktop.vhdx" -SizeBytes 127GB –Dynamic –BlockSizeBytes 1MB

Now it is time to fire up the Hyper-V Manager and add a new virtual machine. After starting the "New Virtual Machine Wizard" click next to enter the page titled "Specify Name and Location". Here supply a name for your new virtual machine. For the sake of this walkthrough I will be using the name "Ubuntu 15.04 Desktop". If you wish you may specify where to store the new virtual machine but you can leave the defaults if you like.

After clicking "Next" you will be asked to use either a Generation 1 or Generation 2 virtual machine. You can choose either but if you do choose to use a Generation 2 virtual machine you will need to disable Secure Boot which will be covered shortly.

After entering the "Assign Memory" page of the wizard you can specify the amount of memory to make available to your new virtual machine. Choosing to use dynamic memory for this virtual machine should not be a problem if this is the option you prefer.

You should already have a virtual switch created in order to allow the new virtual machine to connect to a network. This article does not explain the creation of virtual switches so if you have not and/or do not know how to create one you may need to do learn how to make one or do so before starting.

Now it is time to connect the virtual hard disk we created earlier. To use the existing VHDX file created when starting this walk through simply tick the "Use an existing virtual hard disk" radio button then browse to where you created it to. If you are following this walkthrough word for word you should find the hard disk in the directory C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\.

In the Installation Options section of the wizard you can go ahead and select to install an operating system from a bootable image file and supply the path to the image if that is how you are going to install the operating system on this new virtual machine. Once you have made your choice here go ahead and click Finish.

If you decided to make this a Generation 2 virtual machine do not start the virtual machine yet. As stated earlier you will need to disable Secure Boot in order to boot Ubuntu in this generation VM. Again open PowerShell and run the following command. If you named your virtual machine something other than Ubuntu 15.04 Desktop be sure to change the -VMName flag in the following line before executing it.

Set-VMFirmware –VMName "Ubuntu 15.04 Desktop" -EnableSecureBoot Off

Now it is time to start the newly created virtual machine. Start the virtual machine and select Install Ubuntu from the list of options presented by the Ubuntu installer when it is displayed. and follow the setup instructions as normal. When you reach the partition setion of the installation go ahead and partition the disk as you would normally or select the default "Erase Disk and Install Ubuntu". If you wish you can choose the option "Use LVM with the new Ubuntu Installation" as well. It is recommended that the ext4 file system be used instead of ext3 in order to more efficently use the space supplied when using a dynamic VHDX file. By default Ubuntu 15.04 uses the ext4 file system. After setting up your partions continue the installation as normal.

After installation you should have Ubuntu booted up and logged into the system.

When installing Ubuntu 15.04 I ran into issues when updating the kernel. During the update Grub would hang when trying to configure the new kernel. In order to get around this hang up the line GRUB_DISABLE_OS_PROBER=true needed to be added to the bottom of the file /etc/default/grub after which Grub needed to be updated for the change to take place. You really should do this right away before running any updates. More information on this issue can be found in this article.

sudo nano /etc/default/grub
sudo update-grub

At this time it would not be a bad idea to install updates if you did not choose to do so during the installation.

sudo apt-get update
sudo apt-get upgrade

You may wish to install the virtual-kernel package supplied by Ubuntu instead of the normal kernel installed by default. The virtual kernel contains only drivers needed to run in a virtual machine environment. This means less space is used by the kernel when ran within a virtual environment. If you choose to install the virtual machine optimized kernel run the following command.

sudo apt-get install linux-virtual

Next you will need to install a few daemons:

  • VSS Snapshot daemon – This daemon is required to create live Linux virtual machine backups.
  • KVP daemon – This daemon allows setting and querying intrinsic and extrinsic key value pairs.
  • fcopy daemon – This daemon implements a file copying service between the host and guest.

Depending on the version of Ubuntu you are installing and if you decided to install the virtual-kernel package you will need to choose the appropriate packages to install.

Ubuntu 14.04 w/ Virtual Kernel
sudo apt-get install hv-kvp-daemon-init linux-tools-virtual linux-cloud-tools-virtual

Ubuntu 14.04 w/ Stock Kernel
sudo apt-get install hv-kvp-daemon-init linux-tools linux-cloud-tools

Ubuntu 12.04, 14.10, or 15.04 w/ Virtual Kernel
sudo apt-get install linux-tools-virtual linux-cloud-tools-virtual

Ubuntu 12.04, 14.10, or 15.04 w/ Stock Kernel
sudo apt-get install linux-tools linux-cloud-tools

After completing these steps reboot your virtual machine and you should be good to go.


AdWords Ad