Ubuntu 24.04.1 on Hyper-V
Amazingly enough, it turns out to be non-trival to get Ubuntu 24.04.1 running on a 4K high resolution display on Hyper-V. During the process I experienced crashes during installation, disk read errors, hangs, black screens during boot and login - and difficulties achieving a connection with full resolution on my 4K display.
Since our file encryption app Xecrets Ez is built for Linux in addition to Windows and macOS, we need an environment where we can test and develop it for Linux, and the choice fell on Ubuntu as it's touted as perhaps the most common desktop environment for normal users.
In some configurations, the high resolution was just not available, specifically this was where the linux-azure cloud package was installed. Apparently this only supports lower resolutions out of the box. I'm sure it's possible to tweak this, but as everything else Linux it's practically impossible to find useful documentation.
When I finally got an image working reasonably well, it turned out that the screen scaling was not saved between reboots. I have no idea why, but I did find a remedy.
What follows is a basic step-by-step action list that at least got things working for me with no hitches during the process. Your mileage may vary, but there should be some useful hints here.
Here goes.
Download a .iso image
Get the current image from https://ubuntu.com/download/desktop
"The latest LTS version of Ubuntu, for desktop PCs and laptops."
Download 24.04.1 LTS (At the time of writing this was current)
This downloads for example: ubuntu-24.04.1-desktop-amd64.iso
When downloaded, startup Hyper-V Manager, and under the Actions pane select:
Quick Create...
Select the ISO image:
Local Installation Source -> ubuntu-24.04.1-desktop-amd64.iso
Uncheck "This virtual machine will run on Windows (Enables Windows Secure Boot)"
Under More options:
Name: "Ubuntu 24.04 LTS" (...or whatever you want to name it)
Click: Create Virtual Machine
Edit settings: Uncheck Use Automatic Checkpoints (may be the cause of black screens and hangs), Integration services check "Guest services" ("Ensuring it then says All services offered")
In the window "Virtual machine created successfully", click "Connect", and then start the virtual machine.
"Try or Install Ubuntu", accept all default choices except language and keyboard according to your situation.
Reboot as instructed, complete installation
In Ubuntu: Software Updater - install all updates, "Restart now"
Open terminal:
# This was part of the hard-to-find secret sauce...
sudo apt update
sudo apt install linux-image-extra-virtual
sudo nano /etc/default/grub
Edit
# Use your native resolution....
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:3840x2160"
Save
sudo update-grub
Shutdown
In the Windows host, open powershell in administrator mode and using your VM name and your native resolution as above:
set-vmvideo -vmname "Ubuntu 24.04 LTS" -horizontalresolution:3840 -verticalresolution:2160 -resolutiontype single
Startup the Ubuntu virtual machine again and log in.
If scaling is needed, set scaling in settings to for example 200%, and also to make it "stick" after reboot
open terminal and do:
# This was also non-trivial to figure out...
gsettings set org.gnome.desktop.interface scaling-factor 2
Reboot and confirm that it all works as expected and no settings have reverted.
Create a checkpoint
Now is probably a good time to shutdown again and create a manual checkpoint.
Credits
A lot of the above is found in various parts in this thread: https://superuser.com/questions/1660150/change-screen-resolution-of-ubuntu-vm-in-hyper-v . But it's about various versions and distributions, and there are also some digressions. No mention of crashes and black screens, which did appear to be reduced (but still happen) once automatic checkpoints were disabled. (Dynamic memory may be another culprit here, still trying to verify this.) This post is specifically about Windows 11, Hyper-V and Ubuntu 24.04.1 .
Other notes
Slightly off-topic, but worth mentioning if the goal is to setup a development and/or test environment under Ubuntu 24.04 in a Hyper-V virtual machine:
- Don't install the snap version of VS Code. It messes up the environment for .NET framework apps when debugging, moving the location of special folders into the 'snap' folder etc. Download the binary and install it.
- Don't install the snap version of the .NET Framework. If you require higher bands than the .1xx band (which is the only supported by the Canonical repository), then download the binary and install it manually.
- If you want to enable enhanced mode when connecting to the VM, thus getting copy/paste to work as well as higher screen resolutions, you can actually forego most of the above, as you need to run xrdp (or equivalent) for this. There are quite a few how-to sites available, some with scripts. I've found that this script actually works fine for 24.04 also. It's referenced on this site. It turns out you may actually need to really set the transport type, even with Windows 11 and generation 2 VMs like this: Set-VM -VMName <Name-of-VM> -EnhancedSessionTransportType HvSocket in a PowerShell window as administrator.
No comments:
Post a Comment