Entropic Thoughts

Enhanced Session with Fedora 40 in Hyper-V

Enhanced Session with Fedora 40 in Hyper-V

My new laptop1 Actually, it’s not new – I bought it refurbished from a dealer with good reputation. I have long rejected buying electronics anything but new, but I am reconsidering. This is a test! is a ThinkPad P52, with one of those dual gpu deals. I’m irrationally scared of running Linux with dual gpu​s, so I decided to try running Linux inside a Hyper-V vm in Windows. Assuming the vm itself can capture keyboard, mouse, monitor, camera, etc., it should be a fairly transparent experience.2 Spoiler alert: it does not seem to be capable of capturing the built-in webcam. More on that later.

My main concern with using Windows as a hypervisor is that it constantly reboots itself. This turns out not to be a problem! Apparently the vm is restored to its previous state when Windows has rebooted. This makes Linux-under-Windows an even better experience over native Linux from a reboot perspective.

Getting sound working

But there are some problems. Sound, for example. The default Hyper-V connection mechanism does not support sound at all. If one wants sound to pass between hardware and vm, one needs what Hyper-V calls Enhanced Session Mode, which, from my understanding, uses regular rdp to connect to the virtual machine.

SELinux denial of xrdp

There is rdp support in Fedora 40, available through the packages xrdp and xorgxrdp-glamor. I started by roughly following the instructions by HarmfulBreeze on GitHub, along with the comment by nreith. Though when I tried connecting with enhanced session mode enabled it said something about being unable to start the X session.

I had a hunch, and indeed grepping journalctl -b for AVC showed that it was an SELinux denial getting in the way. The sealert tool suggested using audit2allow to create a policy that allows whatever was denied, but the RedHat SELinux Troubleshooting documentation says audit2allow should be a last resort, so I hesitated. I eventually found an article on installing xrdp on Fedora which looks every bit like blogspam, but it did suggest

$ sudo chcon --type=bin_t /usr/sbin/xrdp
$ sudo chcon --type=bin_t /usr/sbin/xrdp-sesman

This seems to have solved the problem of avc denials when setting up a new X session.

Getting XMonad to start

That problem out of the way, the connection attempt still failed, although now it was far less obvious why. The visible symptom was that it disconnected immediately upon connection. By grepping for xrdp in journalctl -b I found a helpful warning:

[WARN ] Window manager (pid 1838, display 10) exited quickly (0 secs). This could indicate a window manager config problem

Further up in the logs, it also informed me that it tried to launch the window manager through /usr/libexec/xrdp/startwm-bash.sh. I sprinkled various debug prints3 Something mature like echo "GETTING HERE" > /tmp/aaahah. in that script and the ones it called, to figure out where it crashed. It seemed to get all the way to my .Xclients, so I set up a known location for XMonad to log to, by changing the .Xclients script to say

#!/bin/sh
exec xmonad > "$HOME/.xmonad/logs/xmonad-$(date +%Y-%m-%dT%H:%M:%S).txt" 2>&1

It turns out XMonad was the thing that crashed, with the unhelpful error message

xmonad-x86_64-linux: user error (openDisplay)

I still don’t know what that means, but as part of my debugging I changed my .Xclients script to

#!/bin/sh

if [ -n "$XRDP_SESSION" ]; then
    echo "$DISPLAY" > /tmp/wuhuh
    exec xmonad > "$HOME/.xmonad/logs/xmonad-$(date +%Y-%m-%dT%H:%M:%S).txt" 2>&1
else
    exec xmonad > "$HOME/.xmonad/logs/xmonad-$(date +%Y-%m-%dT%H:%M:%S).txt" 2>&1
fi

And for some weird reason, that seems to have made it work. Can you spot the difference? The only thing it does different under rdp is dumping the $DISPLAY variable into a file before starting XMonad. I have no idea why that works, but I’m also not really in a mood to start poking at it, now that it’s running.

Passing through sound devices

At this point, it was surprisingly painless to get sound going. I expected it to be further trouble because Fedora 40 uses PipeWire rather than PulseAudio4 Is that how that sentence is shaped? I know too little about these things. so I was close to postponing solving that problem further.5 I don’t really use sound in my work other than for video conferencing and music, and my phone can do those things in a pinch.

I followed the instructions in the readme of pipewire-module-xrdp to install the module, and then re-connected to the vm, opting to transfer remote sound to and from my physical machine. Although the Windows volume mixer indicated that sound was playing at that point, I didn’t get any sound either through headphones or built-in speakers. I also didn’t get any sound from Windows, so I tried solving the problem as one solves problems with Windows: I rebooted the computer.

Lo and behold! That produced sound on the built-in speakers. When I connected my headphones, sound still … worked, but there was an odd crackling and uneven volume. This problem seems to go away with a reboot, but then it comes back. I don’t yet know how to fix it.6 I am currently circumventing this problem by through a high-quality bluetooth dac instead.

There were a lot of false starts and red herrings to chase along the way. The whole ordeal from Linux vm without sound (through the native connection method) to one with sound (through rdp) took about three hours. The points listed above above are, I think, the main obstacles that held me back.

Other potential issues

Multiple monitors just works

I was a bit concerned about running this setup with an external monitor. I love the way XMonad handles multiple monitors on native Linux – that is one of the primary reasons I use XMonad – and it is not obvious that rdp will do the right thing and connect each physical monitor as a separate X montor.

But it does! Rejoice. This one worked right out of the box.

Webcam just does not work

As mentioned in an earlier sidenote, the webcam cannot be captured by the vm. I have experimented a little with streaming it from Windows over udp using ffmpeg, but not achieved anything satisfying yet7 It is finicky and comes with a hefty delay., so for the time being, I’m setting up my phone on a stand for video conferencing.

Game Bar is annoying as all crap

Oh, dear $deity! This started just today with the most recent Windows update. Now the vm is considered by Windows to be a video game and thus it is no longer allowed to capture the Super+G key combination, because that launches an abomination called Game Bar which sits on top of the vm. To continue using the vm, the Game Bar first needs to be closed.

This wouldn’t be a problem, were it not for the fact that

  • G is the physical key which corresponds to D under Colemak,
  • I use an external Apple keyboard on which I have swapped Meta and Super, and
  • I frequently delete word forward with Meta-D in Emacs and readline.

Under this unlucky combination of circumstances, Meta-D in Emacs gets interpreted as Super-G in Windows, which launches Game Bar. I can’t delete words forward anymore! And I haven’t found a way to turn this off. I have found guides for how to do it, but the toggle they reference is not visible in my Windows settings. Please send help.

Summary

So there are some quirks:

  • Sound is bad, but I think this is a Windows thing and not a Linux-under-Windows thing.
  • The webcam cannot easily be used from Linux when it runs under Windows. Annoying but I can live with that.
  • Game Bar came as a really nasty surprise and I hope it goes away soon or I have to do something more drastic.

But some things also work really well:

  • Reboots don’t kill the state of my Linux machine! It just gets restored when the computer starts back up.
  • Dual-monitor works just as well as I would have expected it to under native Linux.
  • The dual gpu​s work. I don’t know if I can access the discrete gpu from Linux, but that is far into the future anyway.

For the time being, the benefits outweigh the drawbacks, and I will keep this setup and re-evaluate later.

Oh, and the thing I tried before with running a more vanilla Fedora? Not worth it. I get so much more joy out of a computer configured to align with my brain.