Ubuntu in Hyper-V
July 3, 2017 | Hyper-V Windows 10 LinuxIn this post, I describe how I installed Ubuntu in Hyper-V, on my Dell XPS 15 9560 laptop running Windows 10 Pro Creators Update as of this writing.
Enable Hyper-V
First we need to make sure Hyper-V is enabled. In my case, Hyper-V was enabled automatically when I installed Docker for Windows. Otherwise, it is easy to enable Hyper-V.
The Hyper-V role cannot be installed on Windows 10 Home.
Download Ubuntu ISO
Here I downloaded the ISO for Ubuntu Desktop 16.04.2 LTS.
Create a Hyper-V Switch
When Docker for Windows was installed, it created an internal virtual switch named DockerNAT. However, it appears that DockerNAT was created for the exclusive use by the Docker virtual machine MobyLinuxVM and Docker containers. If I connect my own virtual machine to DockerNAT, I won't be able to get network connection in my virtual machine. So I had to create a new Hyper-V virtual switch. In this case, I opt to create another internal virtual switch, with network address translation (NAT).
- Open Hyper-V Manager;
- In Hyper-V Manager, click Virtual Switch Manager… in the right hand Actions menu;
- In Virtual Switch Manager, select Internal as the type of virtual switch to create, then click the button
Create Virtual Switch
; - Give the virtual switch a proper name—I used InternalNAT—then click the button
OK
.
The above steps created a new Hyper-V Virtual Ethernet Adapter (NIC) named vEthernet (InternalNAT) (see Control Panel > Network and Internet > Network Connections). Alternatively, one can create the internal virtual switch, in one single step, in a PowerShell console with elevated permission:
- Assign an IP address to the virtual NIC:
- Configure NAT on the virtual switch:
There is no native DHCP server on Windows 10—although one can install the freeware DHCP Server for Windows—so I’ll simply use static IP addresses on the Hyper-V virtual machines.
Create an Ubuntu Virtual Machine with Hyper-V
- Open Hyper-V Manager
- In Hyper-V Manager, click Quick Create… in the right hand Actions menu. Quick Create was introduced in Windows 10 Creators Update.
- In Create Virtual Machine, select InternalNAT for Network
The rest of the installation is pretty straightforward…
Assign a static IP address
Once the installation is completed and the VM is rebooted, modify /etc/network/interfaces
to assign 192.168.100.2/24 to eth0:
then bring up eth0:
Install OpenSSH server
Install the virtual HWE kernel
Virtual Hardware Enablement (HWE) kernel is a kernel suitable for use as a guest virtual machine. The virtual HWE kernel will load fewer drivers and may boot faster and have less memory overhead than a generic image (see Supported Ubuntu virtual machines on Hyper-V).
Install tools and daemons for use with VMs
Change the resolution
The resolution is set at 1152x864 (4:3), and can’t be changed in Settings > Displays. To change the resolution, we have to modify /etc/default/grub
.
Change the following line:
to:
Then in a terminal, run:
Reboot. The resolution will be changed to 1600x900 (16:9).