Enable Enhanced Session Mode for Arch Linux guests in Hyper-V
Using Linux virtual machines in Hyper-V out of the box is somewhat less comfortable than with guest Windows machines. The reason for this is that Hyper-V was not originally intended for desktop use; you can't just go ahead and install the guest additions package and get workable graphics acceleration, clipboard, shared directories and other joys of life, as it happens in VirtualBox.
Hyper-V itself provides multiple integration services - so, guests can use the shadow copy service (VSS) of the host, guests can send a shutdown signal, guests can synchronize the system time with the virtualization host, files can be exchanged with the virtual machine from the host (Copy-VMFile in PowerShell). For some guest operating systems, including, of course, Windows, in the Virtual Machine Connection application (vmconnect.exe) Enhanced Session Mode is available, which works via the RDP protocol and allows you to forward disk devices and printers to the virtual machine, as well as use the shared clipboard.
Enhanced Session Mode works out of the box on Windows in Hyper-V right after installation. With guests on Linux, you need to install an RDP server that supports vsock (a special virtual network address space in Linux designed to communicate with the hypervisor). If for Ubuntu, the VMCreate application that comes with Hyper-V on desktop editions of Windows has a special prepared virtual machine template in which an RDP server running with vsock XRDP already pre-installed, then with other distributions it is less and less clear - for example, the author this post it turned out to enable ESM in Fedora. Here we also enable Enhanced Session Mode for the Arch Linux virtual machine.
Installing integration services
Everything is more or less simple here, we just need to install the package hyperv from community repository:
% for i in {vss,fcopy,kvp}; do sudo systemctl enable hv_${i}_daemon.service; done
XRDP Installation
Repository linux-vm-tools on GitHub provides scripts that automate the process of installing and configuring XRDP for Arch Linux and Ubuntu. Install Git, if it is not already installed, along with the compiler and other software for manual builds, and then clone the repository:
At the time of this writing, the most recent release of XRDP, which is installed by the script makepkg.shproposed in the repository is 0.9.11, in which parsing is brokenvsock://-addresses, so you have to install XRDP from Git and the Xorg driver for it from AUR manually. The patch for XRDP offered in the AUR is also slightly outdated, so you will have to edit the PKGBUILD and the patch manually.
We clone the repositories with PKGBUILDs from the AUR (usually this procedure, along with the assembly, is automated by programs like yay, but the author did this whole procedure on a clean system):
In a patch arch-config.diff, which edits units and XRDP startup scripts under the paths to files used in Arch Linux, contains, among other things, a patch to the script instfiles/xrdp.sh, which at the time of writing was removed from the XRDP distribution, so the patch will have to be edited manually:
Build and install the package with the command % makepkg --skipchecksums -si (key --skipchecksums is needed to disable checksum verification of source files, since we edited them manually).
Let's go to the directory xorgxrdp-devel-git, after which we simply build the package with the command % makepkg -si.
Let's go to the directory linux-vm-tools/arch and run the script install-config.sh, which sets XRDP, PolicyKit and PAM settings:
% sudo ./install-config.sh
Script installs legacy setting use_vsock, which is ignored since version 0.9.11, so let's edit the configuration file /etc/xrdp/xrdp.ini manually:
; port=vsock://<cid>:<port>
-port=3389
+port=vsock://-1:3389
; 'port' above should be connected to with vsock instead of tcp
; use this only with number alone in port above
; prefer use vsock://<cid>:<port> above
-use_vsock=true
+;use_vsock=true
; regulate if the listening socket use socket option tcp_nodelay
Add to file ~/.xinitrc launching your preferred window manager/desktop environment, which will be executed when the X server is started:
% echo "exec i3" > ~/.xinitrc
Let's turn off the virtual machine. Enable the vsock transport for the VM by running the following command in PowerShell as an administrator:
As soon as the XRDP service starts after the system starts, the vmconnect application will determine this and the menu item will become available. View -> Enhanced session. When you select this item, we will be prompted to set the screen resolution, and on the tab local resources in the dialog that opens, you can select the devices forwarded inside the RDP session.
Let's connect. We will see the XRDP login window:
Enter your username and password.
Using
The profit from these manipulations is noticeable: the RDP session works much more responsive than when working with a virtual display without Enhanced Session. The disks forwarded inside the VM via RDP are available in the directory ${HOME}/shared-drives:
The clipboard is working fine. You cannot throw printers inside, this is not only not supported, but also breaks disk forwarding. The sound also does not work, but the author did not need it. In order to capture keyboard shortcuts like Alt + Tab, you need to expand vmconnect to full screen.
If for some reason there is a desire to use the RDP client built into Windows instead of the vmconnect application or, for example, connect to this machine from another machine, then you will need to change the file /etc/xrdp/xrdp.iniport on tcp://:3389. If the virtual machine is connected to the Default Switch and receives network settings via DHCP, then you can connect to it from the host at Π½Π°Π·Π²Π°Π½ΠΈΠ΅_ΠΌΠ°ΡΠΈΠ½Ρ.mshome.net. You can only log in to TTY from the vmconnect application by turning off Enhanced Mode.