Hyper-V

Ubuntu in Hyper-V

Whilst running Ubuntu 20.04 in a Windows 10 Hyper-V VM, I found that I could not change the screen resolution. I am not sure what the root cause of the issue was but the following fixed it!

Setup

I can't remember why I needed this but the following is helpful:
sudo apt-get install linux-image-extra-virtual

Change Screen Resolution

It defaulted to 1024x768, but 1440x900 works better as some dialogs are no longer cropped and it uses more of my monitor, to make the change, do the following:

  • Start VM and login
  • Open a terminal session
  • Execute: sudoedit /etc/default/grub
    this prompts for password, to sudo, so enter it
  • Use the arrow keys to navigate to the line that says:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    and change it to
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1440x900"
  • Press Ctrl+X to exit, press Y to save and press Enter to accept the odd-looking filename
  • Execute: sudo update-grub
  • Execute: sudo reboot
  • Done!

Nested Virtualization

The way to enable this is with PowerShell from the host machine. You need to execute the following command in PowerShell 5.x or 7+:
Set-VMProcessor -VMName -ExposeVirtualizationExtensions $true
It is worth noting that the Set-VMProcessor command is in the "hyper-v" module. This module might not be installed, if it is not then you need to add it via the "Add/Remove Windows Features" option in Windows Settings, which is most likely where you installed Hyper-V from in the first place.

Please note that you need to shutdown/power off the VM before using the Set-VMProcessor command, but once you have subsequently started the VM things like Windows Sandbox should work fine inside the VM. See Run Hyper-V in a Virtual Machine with Nested Virtualization | Microsoft Learn and Set-VMProcessor (Hyper-V) | Microsoft Learn for more information.