|
| 1 | +--- |
| 2 | +title: Fedora i3 VM setup on Windows 11 using Hyper-V |
| 3 | +date: 2025-09-17 |
| 4 | +--- |
| 5 | + |
| 6 | +Recently a thought came to my mind. We live in the year 2025, virtualization has come |
| 7 | +very far thanks to the cloud and WSL2 works pretty good now. |
| 8 | +Surely it must have become easy and reasonably performant to create a Linux VM on |
| 9 | +Windows and use that for development work. Let's even try to use Hyper-V since |
| 10 | +that is something the Microsoft Azure Platform is build on. |
| 11 | + |
| 12 | +<!--more--> |
| 13 | + |
| 14 | +## Creating a VM in Hyper-V |
| 15 | + |
| 16 | +This step is actually pretty easy. [Microsoft has a very minimal and good documentation |
| 17 | +on how to do it](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/get-started/create-a-virtual-machine-in-hyper-v). |
| 18 | +You just need to follow the steps in the Hyper-V VM creation wizard. |
| 19 | + |
| 20 | +After that is done, open the VM settings, search for "Integration Services" and |
| 21 | +then make sure to check the "Guest services" checkbox. |
| 22 | + |
| 23 | +## Intializing the Linux VM |
| 24 | + |
| 25 | +After you install the guest OS with the ISO, make sure to not forget to |
| 26 | +eject the ISO drive or else Hyper-V will load it again. |
| 27 | + |
| 28 | +If you only want to run a Linux VM that has 0 contact with the host OS, |
| 29 | +then you done. You don't need to read further. |
| 30 | +However, usually you want to share files, devices and other resources with the host OS. |
| 31 | +And that is exactly why I made this blog post. |
| 32 | +It is not really straight forward to share these resources on a newly created VM. |
| 33 | +I am not sure why though since Hyper-V is a rather advanced Hypervisor. |
| 34 | +Well, it is Windows in the end so lets just dive into what we need, |
| 35 | +to make sure we have a somewhat pleasant desktop VM experience. |
| 36 | + |
| 37 | +From what I could gather Hyper-V does not provide a native way to share the resources. |
| 38 | +Hyper-V has something called "enhanced session mode". |
| 39 | +This mode enables the VM to use / share some host OS resources like network connections, |
| 40 | +drives and audio devices. But where is the catch? Well, for all these features we |
| 41 | +are required to use the RDP protocol. Yes, you read it correctly. |
| 42 | +For some reason Microsoft did not think it would be good to provide these features |
| 43 | +out-of-the-box but rely on the RDP protocol. At least for me, that is a very weird decision. |
| 44 | + |
| 45 | +This brings us to the next step. To be able to even activate the "enhanced session mode" |
| 46 | +for a VM, you need to install and configure a RDP server on your Linux VM. |
| 47 | +Otherwise it will simply not work. |
| 48 | + |
| 49 | +### RDP and Xorg |
| 50 | + |
| 51 | +This blog post is about setting up the [i3 window manager](https://i3wm.org/) in a VM on Windows. |
| 52 | +i3 is built on top of Xorg but Xorg itself does not implement the RDP protocol |
| 53 | +nor does it understand it. So we need to install something called [xrdp](https://www.xrdp.org/). |
| 54 | +You don't need to know much about it except it enables Xorg to understand the RDP protocol. |
| 55 | +Or to be more precise, xrdp acts as a frontend and Xorg will act as the backend. |
| 56 | + |
| 57 | +### Actual setup |
| 58 | + |
| 59 | +1. The first thing to do after the first boot is to install the following packages: |
| 60 | + |
| 61 | +```bash |
| 62 | +sudo dnf install xrdp xrdp-selinux xorgxrdp hyperv-daemons |
| 63 | +``` |
| 64 | + |
| 65 | +This will install the required services needed to run a RDP server with Xorg as the backend. |
| 66 | +The `hyperv-daemons` package is something very essential here. It installs a couple |
| 67 | +of daemons that enable clipboard integration and other important features. |
| 68 | + |
| 69 | +2. Before starting the xrdp server, you need to optimize some of its configuration. |
| 70 | +The following `sed` commands will handle the optimizations for you: |
| 71 | + |
| 72 | +```bash |
| 73 | +sudo sed -i_orig 's/port=3389/port=vsock:\/\/-1:3389/g' /etc/xrdp/xrdp.ini |
| 74 | +sudo sed -i_orig 's/security_layer=negotiate/security_layer=rdp/g' /etc/xrdp/xrdp.ini |
| 75 | +sudo sed -i_orig 's/crypt_level=high/crypt_level=none/g' /etc/xrdp/xrdp.ini |
| 76 | +sudo sed -i_orig 's/bitmap_compression=true/bitmap_compression=false/g' /etc/xrdp/xrdp.ini |
| 77 | +``` |
| 78 | + |
| 79 | +3. One of they daemons installed by `hyperv-daemons` will automatically mount |
| 80 | +all drives that are shared with the VM into your home directory. The default name |
| 81 | +for the mount directory is not very *nice*. The next `sed` command renames it |
| 82 | +to `shared-drives`. |
| 83 | + |
| 84 | +```bash |
| 85 | +sudo sed -i 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' /etc/xrdp/sesman.ini |
| 86 | +``` |
| 87 | + |
| 88 | +4. Allow everyone to create X server sessions (required because of RDP): |
| 89 | + |
| 90 | +```bash |
| 91 | +sudo tee /etc/X11/Xwrapper.config >/dev/null <<EOL |
| 92 | +needs_root_rights=no |
| 93 | +allowed_users=anybody |
| 94 | +EOL |
| 95 | +``` |
| 96 | + |
| 97 | +5. Make sure the Hyper-V specific kernel module is enabled: |
| 98 | + |
| 99 | +```bash |
| 100 | +echo "hv_sock" | sudo tee /etc/modules-load.d/hv_sock.conf |
| 101 | +# Make sure VMware kernel module is blacklisted |
| 102 | +echo "blacklist vmw_vsock_vmci_transport" | sudo tee /etc/modprobe.d/blacklist-vmw_vsock_vmci_transport.conf |
| 103 | +``` |
| 104 | + |
| 105 | +6. Enable the xrdp service and shutdown the VM: |
| 106 | + |
| 107 | +```bash |
| 108 | +sudo systemctl enable xrdp |
| 109 | +sudo systemctl enable xrdp-sesman |
| 110 | +poweroff |
| 111 | +``` |
| 112 | + |
| 113 | +7. Enable enhanced session mode for the VM (run this as Administrator in powershell): |
| 114 | + |
| 115 | +```powershell |
| 116 | +Set-VM "VM NAME" -EnhancedSessionTransportType HVSocket |
| 117 | +``` |
| 118 | + |
| 119 | +Now you can start the VM again. |
| 120 | +A new dialog should now pop up asking you about resolution. Congrats! You are done! |
| 121 | +Now you should be able to run the VM in enhanced session mode and share OS resources |
| 122 | +with your VM. |
| 123 | + |
| 124 | +There is one remaining issue which I could not solve yet. |
| 125 | +When using Xorg as the backend for xrdp, the screen is blurry and pixilated on heavy load. |
| 126 | +This is very weird especially because a friend of mine, who uses Arch Linux, can't reproduce this behaviour. |
| 127 | +I will update this blog once I find a solution to this issue or if I understand why this even happens. |
0 commit comments