I’m expanding my 2-day Learn Azure workshop to support non-Microsoft developers and I needed to test the labs on Linux. Since my main OS is Windows 10, I needed to create a Linux VM using Hyper-V. It might be a simple process but there are many steps that can be overlooked (ask me how I know that!) so I thought I’d document how I did it. BTW, comments on how to improve this are welcome!
In Part-1, I’ll explain how to set Ubuntu running in Windows 10 using Hyper-V and in Part-2, how to install the required software on Ubuntu.
You can easily download an ISO file from the Ubuntu Website, create a new virtual machine using Hyper-V, boot and install Ubuntu from the ISO. Doing so gives you a clean installation with some annoying drawbacks. You can’t easily set the screen resolution, you can’t copy/paste between the host and the VM, mouse capture is so so and there are no automatic shared-drives.
Screen resolution can’t be modified unless you edit the boot loader file and reboot the VM. If you want to do so, here are the steps:
- Open Terminal
- sudo vi /etc/default/grub
- Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT
- Add video=hyperv_fb:[the resolution you want]. Ex: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1280x720"
- Write the changes and quit vi by typing: Esc + wq.
- sudo update-grub
- Reboot the virtual machine
This is fine but when you present, you may have to change your laptop's output resolution and you may also need to change Ubuntu's screen resolution. You will wish for a dynamic way to do that and yes, there's a way.
It's possible to run a Ubuntu VM in Hyper-V Enhanced Mode by installing xRDP and some config using a script provided by Microsoft. This gives you better integration and a much better user experience. You can enable Enhanced Mode using xRDP by following these steps:
- sudo curl -O https://raw.githubusercontent.com/Microsoft/linux-vm-tools/master/ubuntu/18.04/install.sh
- sudo chmod +x install.sh
- sudo ./install.sh
- Important: Shut down the VM and start it back (don’t just reboot it).
- Run this Powershell command: Set-VM -VMName <your_vm_name> -EnhancedSessionTransportType HvSocket
The Easy way!
But wait, there’s an easy way to run Ubuntu in Enhanced Mode with Hyper-V. Starting with Windows 10 1809, Microsoft provides an Ubuntu 18.04.1 LTS ISO with everything pre-configured!
Launch Hyper-V, click on Quick Create, select Ubuntu as your OS and click on the Create Virtual Machine button.
Click on Edit Settings to edit the default settings.
The VM is pre-configured to use 2GB of RAM. You may want to increase this to something more useful.
The default hard drive size is set to 11GB. This is not enough to install all our dev stuff so you will want to increase this. Select the Hard Drive and click on the Edit button.
Type a new size. Note that the disk is dynamic and will not take the full size right away. It will expand up to the size you'll set.
Save the settings.
You may want to move the VM to a disk with more space. To do this, right-click on the VM's name and select Move.
Connect to the VM and click on Start.
When configuring Ubuntu, make sure to select Require my password to log in as the other way will not work with Enhanced Mode.
Once installed, stop and restart the VM. This time you will be prompted with a dialog when you'll be able to select the screen resolution. Click More Options to display more features.
Note: If you select Save my settings for future connections, the dialog box will not show up again. I haven't found a way to edit or bring back that dialog so if you know how to to that, please leave a comment.
You can select the drives you want to share from the host. This way, you can easily share files from and to your host.
When launching the VM you'll notice that the connection is made using xRDP. Simply type the user name and password you configured in Ubuntu.
Ubuntu will report that the size of the hard drive is 11GB. Bummer!
We need to resize the disk partition by installing GParted.
- Open Terminal and type:
- sudo apt-get install gparted
- sudo gparted
It will report that not all the space is used. Click on the Fix button.
Right-click on the partition and select Resize/Move.
Using the handle on the right of the partition, select a new size by dragging it to the desired size.
Save the change by clicking on the checkbox icon and the Apply button.
You need to reboot the VM to see the change.
At this point, you may want to edit the Ubuntu settings and tweak the dock position and the screen lock time. Also, Ubuntu will prompt to install some updates.
That's it! The VM and the OS are now set. In Part-2, we'll see how to install the dev stuff.