Ubuntu VM with Enhanced Session Hyper-V with Sound

Last Modified: Wed, 24 Jan 2024 15:56:52 +0000 ; Created: Wed, 29 Nov 2023 03:23:22 +0000

I looked at multiple blogs, websites, and git repos with methods to enable enhanced session support for Ubuntu VM desktop support. I wanted the nice copy+paste and sound features. Many sites had quite the long solutions or methods, but I did find a simpler one that worked by combining information from multiple. Xrdp gives you the copy+paste and enhanced session support, but not sound without extra work.

Some of the sites I used to piece together a solution

  • https://gist.github.com/ANRCorleone/39322bd9514607b072adaa36d080d96c - The initial script for xrdp was great, but the extra steps to compile all of pulseaudio was not necessary for Ubuntu 22.04
  • https://github.com/Hinara/linux-vm-tools/tree/ubuntu20-04/ubuntu
    • Works great in 22.04 for getting enhanced session base to work with xrdp
    • It is not the sound part
    • More secure configuration as it does not enable port 3389 but only uses a loopback listening port for Hyper-V
  • https://c-nergy.be/blog/?p=17734 - There is an all-in-one "product" utility script offered here as well, but it did not work for me on Nov 2023 with Ubuntu 22.04 in Hyper-V. This blog post had just the audio parts assuming you got your xrdp + Hyper-V setup from above already working
  • Microsoft's Hyper-V Quick Create for Ubuntu 22.04 did not work out-of-the-box. In fact some important software was missing until I forced an OS apt-get update. Would recommend installing from vanilla OEM (Cananocial) ISO instead of using "Quick Create"
  • https://ubuntuforums.org/showthread.php?t=2481545&p=14132611#post14132611 - The later comment held the easier solution with minimal pulseaudio compile steps

My Consolidated Steps

Assuming you installed using the vanialla OEM (Canoncial) Ubuntu Desktop ISO and are now in a basic session.

On your Hyper-V host open a Windows PowerShell prompt as administrator

Set-VM -VMName "The_VM_Name" -EnhancedSessionTransportType HvSocket

Make sure your VM settings have all the "Integration Services" checked for enable.

Inside your Ubuntu guest VM

sudo apt update

sudo apt install -y xrdp

cd ~/
# Adjust URL for your Ubuntu version (HWE is the difference)
wget https://raw.githubusercontent.com/Hinara/linux-vm-tools/5a9e2654c3afa0c58aff139cbba6eff90e088e75/ubuntu/22.04/install.sh
chmod +x ./install.sh

# May require a reboot then rerun of the command again
sudo ./install.sh

# Once completed you may need another reboot for everything in the enhanced session to work correctly
sudo /sbin/reboot

# For enabling audio

sudo apt install -y pulseaudio pavucontrol
sudo apt install -y build-essential dpkg-dev libpulse-dev git autoconf libtool

git clone https://github.com/neutrinolabs/pulseaudio-module-xrdp.git

cd ~/pulseaudio-module-xrdp


./bootstrap && ./configure PULSE_DIR=~/pulseaudio.src


sudo make install

Finally perform another reboot, and you should have enhanced session support with audio