
Using virtual machines on Linux in Hyper-V out of the box is a somewhat less comfortable task than with guest Windows machines. The reason for this is that Hyper-V was not initially intended for desktop use; you cannot simply install the guest additions package and achieve functional graphics acceleration, clipboard sharing, shared directories, and other perks of life, as is the case with VirtualBox.
Hyper-V itself provides — for instance, guests can utilize the host's Volume Shadow Copy Service (VSS), signals can be sent to shut down guests, guests can synchronize their system time with the virtualization host, and file sharing with the virtual machine is possible from the host (Copy-VMFile in PowerShell). For certain guest operating systems, including Windows of course, Enhanced Session Mode is available in the Virtual Machine Connection application (vmconnect.exe) which works over the RDP protocol and allows for the passthrough of disk devices and printers to the virtual machine, as well as sharing the clipboard.
Enhanced Session Mode works out of the box in Windows in Hyper-V immediately after installation. For Linux guests, you need to set up an RDP server that supports vsock (a special virtual network address space in Linux designed for communication with the hypervisor). If for Ubuntu there is a specially prepared virtual machine template in the VMCreate application that comes with Hyper-V on desktop editions of Windows, where an RDP server functioning with vsock, is already pre-installed, with other distributions it is less straightforward — for example, the author of managed to enable ESM in Fedora. Here, we will activate Enhanced Session Mode for a virtual machine running Arch Linux.
Installing integration services
Here, everything is more or less simple; we just need to install the hyperv package from the community repository:
% sudo pacman -S hypervWe will enable the VSS, metadata % for i in {vss,fcopy,kvp}; do sudo systemctl enable hv_${i}_daemon.service; done
Installing XRDPlinux-vm-tools
Repository % sudo pacman -S git base-devel % git clone https://github.com/microsoft/linux-vm-tools.git % cd linux-vm-tools/arch
% sudo pacman -S git base-devel
% git clone https://github.com/microsoft/linux-vm-tools.git
% cd linux-vm-tools/archAt the time of writing this article, the latest version of XRDP that can be installed using the script makepkg.sh, available in the repository, is 0.9.11, vsock://-addresses, so you will need to install XRDP from Git and the Xorg driver from AUR manually. The patch for XRDP provided in AUR is also slightly outdated, so you'll need to manually edit the PKGBUILD and the patch.
Let's clone the repositories with the PKGBUILD files from AUR (usually this process is automated with programs like , but the author performed the entire process on a clean system):
% git clone https://aur.archlinux.org/xrdp-devel-git.git
% git clone https://aur.archlinux.org/xorgxrdp-devel-git.gitFirst, we'll install XRDP itself. We'll open the file PKGBUILD with any text editor.
Let's edit the build parameters. The PKGBUILD for building XRDP from Git does not include support for vsock during the build, so we will enable it ourselves:
build() {
cd $pkgname
./configure --prefix=/usr
--sysconfdir=/etc
--localstatedir=/var
--sbindir=/usr/bin
--with-systemdsystemdunitdir=/usr/lib/systemd/system
--enable-jpeg
--enable-tjpeg
--enable-fuse
--enable-opus
--enable-rfxcodec
--enable-mp3lame
- --enable-pixman
+ --enable-pixman
+ --enable-vsock
make V=0
}In the patch arch-config.diff, which modifies the units and startup scripts of XRDP to the paths used in Arch Linux, there is also a patch for the script instfiles/xrdp.sh, which, at the time of writing this article, from the XRDP package, so the patch will need to be edited manually:
[Install]
WantedBy=multi-user.target
-diff -up src/xrdp-devel-git/instfiles/xrdp.sh.orig src/xrdp-devel-git/instfiles/xrdp.sh
---- src/xrdp-devel-git/instfiles/xrdp.sh.orig 2017-08-30 00:27:28.000000000 -0600
-+++ src/xrdp-devel-git/instfiles/xrdp.sh 2017-08-30 00:28:00.000000000 -0600
-@@ -17,7 +17,7 @@
- # Description: starts xrdp
- ### END INIT INFO
-
--SBINDIR=/usr/local/sbin
-+SBINDIR=/usr/bin
- LOG=/dev/null
- CFGDIR=/etc/xrdp
-
diff -up src/xrdp-devel-git/sesman/startwm.sh.orig src/xrdp-devel-git/sesman/startwm.sh
--- src/xrdp-devel-git/sesman/startwm.sh.orig 2017-08-30 00:27:30.000000000 -0600We will build and install the package by running the command % makepkg --skipchecksums -si (the key --skipchecksums is needed to disable checksum verification of the source files since we edited them manually).
Let's navigate to the directory xorgxrdp-devel-git, and then simply build the package with the command % makepkg -si.
Let's navigate to the directory linux-vm-tools/arch and run the script install-config.sh, which installs the settings for XRDP, PolicyKit, and PAM:
% sudo ./install-config.shThe script installs the outdated setting use_vsock, which is ignored from version 0.9.11, so we will need to manually edit the configuration file: /etc/xrdp/xrdp.ini manually:
; port=vsock://:
-port=3389
+port=vsock://-1:3389
; 'port' above should be connected with vsock instead of tcp
; use this only with number alone in port above
; prefer use vsock://: above
-use_vsock=true
+;use_vsock=true
; regulate if the listening socket uses the socket option tcp_nodelayLet's add to the file ~/ .xinitrc launch your preferred window manager / desktop environment that will run when the X server starts:
% echo "exec i3" > ~/ .xinitrcShut down the virtual machine. Activate the vsock transport for the virtual machine by executing the following command in PowerShell as an administrator:
PS Admin > Set-VM -VMName MACHINE_NAME -EnhancedSessionTransportType HvSocketLet's start the virtual machine again.
Connection
As soon as the XRDP service starts after the system boots, the vmconnect application will detect it and an item will become available in the menu View -> Enhanced Session. When selecting this item, we will be prompted to set the screen resolution, and in the tab Local Resources of the opened dialog, we can select the devices passed into the RDP session.


Let's connect. We will see the XRDP login window:

Let's enter our username and password.
Using
The profit from these manipulations is noticeable: the RDP session works much more responsively than when using a virtual display without Enhanced Session. The drives passed into the VM via RDP are available in the directory ${HOME}/shared-drives:

The clipboard works fine. It's not possible to pass printers in, not only is this not supported, but it also . Sound does not work either, but the author did not require it. To capture key combinations like Alt+Tab, you need to expand vmconnect to full screen.
If for any reason there is a desire to use the built-in Windows RDP client instead of the vmconnect application, or, for example, to connect to this machine from another machine, then it will be necessary to change to the file /etc/xrdp/xrdp.ini port to tcp://:3389. If the virtual machine is connected to the Default Switch and receives its network settings via DHCP, then you can connect to it from the host at the address machine_name.mshome.net. You can only access TTY from the vmconnect application, disabling Enhanced Mode.
References used:
- Bug reports on GitHub: ,
Source: habr.com
