Skip to content

Instantly share code, notes, and snippets.

@beastycoding
Forked from deoren/Ubuntu_on_Hyper-V.md
Created January 26, 2023 05:43
Show Gist options
  • Save beastycoding/61028d40601c3e0517ff366b2a942d2c to your computer and use it in GitHub Desktop.
Save beastycoding/61028d40601c3e0517ff366b2a942d2c to your computer and use it in GitHub Desktop.
Ubuntu on Hyper-V

Enabling full Hyper-V support for Ubuntu

Install packages

Short version: See docs.microsoft.com link below.

Ubuntu 17.04 and later

  1. sudo apt-get update
  2. sudo apt-get install linux-image-virtual linux-tools-virtual linux-cloud-tools-virtual

Ubuntu 16.04

  1. sudo apt-get update
  2. sudo apt-get install linux-virtual-lts-xenial linux-tools-virtual-lts-xenial linux-cloud-tools-virtual-lts-xenial

Common problems

Failure to copy files to the guest via Copy-VMFile

To confirm run systemctl status hv-fcopy-daemon.service and you will see output similar to this:

● hv-fcopy-daemon.service - Hyper-V File Copy Protocol Daemon
   Loaded: loaded (/lib/systemd/system/hv-fcopy-daemon.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2018-06-30 13:37:34 CDT; 11min ago
  Process: 718 ExecStart=/usr/sbin/hv_fcopy_daemon -n (code=exited, status=2)
 Main PID: 718 (code=exited, status=2)

Jun 30 13:37:34 ubuntu-1604-test hv_fcopy_daemon[718]: WARNING: hv_fcopy_daemon not found for kernel 4.13.0-45
Jun 30 13:37:34 ubuntu-1604-test hv_fcopy_daemon[718]:   You may need to install the following packages for this specific kernel:
Jun 30 13:37:34 ubuntu-1604-test hv_fcopy_daemon[718]:     linux-tools-4.13.0-45-generic
Jun 30 13:37:34 ubuntu-1604-test hv_fcopy_daemon[718]:     linux-cloud-tools-4.13.0-45-generic
Jun 30 13:37:34 ubuntu-1604-test hv_fcopy_daemon[718]:   You may also want to install one of the following packages to keep up to date:
Jun 30 13:37:34 ubuntu-1604-test hv_fcopy_daemon[718]:     linux-tools-generic
Jun 30 13:37:34 ubuntu-1604-test hv_fcopy_daemon[718]:     linux-cloud-tools-generic
Jun 30 13:37:34 ubuntu-1604-test systemd[1]: hv-fcopy-daemon.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Jun 30 13:37:34 ubuntu-1604-test systemd[1]: hv-fcopy-daemon.service: Unit entered failed state.
Jun 30 13:37:34 ubuntu-1604-test systemd[1]: hv-fcopy-daemon.service: Failed with result 'exit-code'.

Explanation:

When installing later releases of Ubuntu 16.04 (e.g., .3, .4, etc) a newer kernel is included. This kernel is set as the active kernel and will not work with the "tools" packages installed by following the earlier instructions.

To fix this, you have to either downgrade to the LTS kernel or install the "tools" packages for the active version of the kernel like so:

  1. sudo apt-get update
  2. export running_kernel=$(uname -r); sudo apt-get install linux-tools-${running_kernel} linux-cloud-tools-${running_kernel}
  3. sudo reboot

An alternative for step 2 is to run:

  1. sudo apt-get install -s linux-cloud-tools-generic-hwe-16.04 linux-tools-generic-hwe-16.04

Result:

ubuntu@ubuntu-1604-test:~$ dpkg -l | grep linux | grep -E "image|tools" | awk '{print $2, $3}' | sort

linux-base 4.5ubuntu1~16.04.1
linux-cloud-tools-4.13.0-45-generic 4.13.0-45.50~16.04.1
linux-cloud-tools-4.4.0-128 4.4.0-128.154
linux-cloud-tools-4.4.0-128-generic 4.4.0-128.154
linux-cloud-tools-common 4.4.0-128.154
linux-cloud-tools-generic 4.4.0.128.134
linux-cloud-tools-virtual 4.4.0.128.134
linux-cloud-tools-virtual-lts-xenial 4.4.0.128.134
linux-hwe-cloud-tools-4.13.0-45 4.13.0-45.50~16.04.1
linux-hwe-tools-4.13.0-45 4.13.0-45.50~16.04.1
linux-image-4.10.0-28-generic 4.10.0-28.32~16.04.2
linux-image-4.13.0-45-generic 4.13.0-45.50~16.04.1
linux-image-4.4.0-128-generic 4.4.0-128.154
linux-image-extra-4.10.0-28-generic 4.10.0-28.32~16.04.2
linux-image-extra-4.13.0-45-generic 4.13.0-45.50~16.04.1
linux-image-generic-hwe-16.04 4.13.0.45.64
linux-image-virtual 4.4.0.128.134
linux-signed-image-4.13.0-45-generic 4.13.0-45.50~16.04.1
linux-signed-image-generic-hwe-16.04 4.13.0.45.64
linux-tools-4.13.0-45-generic 4.13.0-45.50~16.04.1
linux-tools-4.4.0-128 4.4.0-128.154
linux-tools-4.4.0-128-generic 4.4.0-128.154
linux-tools-common 4.4.0-128.154
linux-tools-generic 4.4.0.128.134
linux-tools-virtual 4.4.0.128.134
linux-tools-virtual-lts-xenial 4.4.0.128.134

Set video resolution

By default the screen size is small ...

  1. Open Terminal
  2. Type: sudo nano /etc/default/grub
  3. Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT, and add video=hyperv_fb:DESIRED_RESOLUTION. The resolution I want is 1280x720. So my line ends up looking like this: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1280x720"
  4. Write the changes and quit nano.
  5. Run: sudo update-grub
  6. Reboot the virtual machine

The resolution should now be set as specified.

Enable NOOP scheduler for better I/O performance

  1. Open Terminal
  2. Type: sudo nano /etc/default/grub
  3. Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT, and add elevator=noop. My line ends up looking like this: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1280x720 elevator=noop"
  4. Write the changes and quit nano.
  5. Run: sudo update-grub
  6. Reboot the virtual machine

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment