blog,

Creating "Reverse WSL" For Running Windows Application On Linux Host

Izhar Firdaus Izhar Firdaus Follow Support Sep 11, 2023 · 11 mins read
Creating
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

State of the linux desktop in 2023

Linux today have matured to the point where majority of activities commonly done by computer users can be achieved easily, especially considering most people are primarily using the computer to access internet applications. Even when it comes to gaming, thanks to Steam’s effort in Proton and Steam Deck, Linux is now a pretty viable platform for those who who are not playing competitive games.

People I know also have experimented with making purely non-technical people to use Linux without them knowing, with good success rate, while I myself have experimented with forcing my department staff to use Linux as their primary operating system with good success, to the point of the staff noticed that Windows is a pretty difficult platform to work with for modern day developers.

Libreoffice also is fully capable to do all common office tasks without issues, and with some training to leverage the features available in Libreoffice, the team also discovered how frustrating it can be when working with Microsoft Office especially when trying to structurally automate formatting. A simple tool you know how to use well is a magnitude better than a fancy tool that you only know how to use its basic feature. Libreoffice also opens Microsoft Office documents well with minimal issues, except for the usual missing fonts messing with documents a bit, which easily fixed by installing the fonts.

However, Microsoft Office dominance can be an annoying problem when working with clients that primarily uses Microsoft’s stack and refuses to accept or work with PDF. Microsoft Office also almost always open ODF poorly with regular corruption, while DOCX files saved by Libreoffice seems to almost always opened poorly by Microsoft Office.

Wine, while becoming a great platform to run games thanks to Proton initiative, is still quite flaky to run Office due to less community investment is put on the matter. The Wine AppDB page for Office generally reported garbage rating for Office 2016 and newer.

Windows Subsystem For Linux (WSL)

The frustration regularly faced by developers when working on Windows, and the dominance of Open Source in software development ecosystem to a degree threathened Windows, where developers preferring MacOS for their preferred desktop because of its Unix heritage and MacPorts.

In response to that , for a few years now, Windows introduced the ability to run Linux commandline seamlessly on Windows through their WSL feature which essentially runs a Linux VM on top of Windows, with seamless filesystem integration to allow access of files in the host by the guest VM. This to a degree allows developers to have access to their Linux tooling on Windows, alongside access to Microsoft Office.

WSL also shows that, with some clever virtualization tricks to integrate the host and guest, the experience of using VM can be pretty seamless to the user if done well.

Reverse WSL With QEMU, Libvirt, VirtIO & SPICE/RDP

For those who primarily use Linux as their daily driver and dealing with clients who are locked into Microsoft ecosystem (even rejecting Google Docs), the lack of Microsoft Office on Linux sometimes forces people to switch to Windows in order to get work done, which usually means a troublesome dual computer operation.

However little is known to most that Linux virtualization have also improved significantly over the past several years, where it is now possible to create a “Reverse WSL” that allows you access to Microsoft Office on your Linux desktop, complete with clipboard sharing and filesystem sharing, with near-native performance using QEMU KVM virtualization. Effectively allowing you to keep using Linux as your primary operating system, while still getting access to Microsoft Office without having to dual-boot or lugging two computers around.

This guide will help you set up your computer with a highly fine tuned VM of Windows 11, alongside customizations needed to make integration seamless between the two operating systems, so that you can get benefits of both worlds on a single unified dual operating system experience.

System Requirements

This guide assumes that you have at least 4c/8t CPU with 16GB of RAM, and you are using Fedora as the primary operating system. Any other Linux distro should work too, but this guide focuses on Fedora.

You may want to use Windows 10 Pro or Windows 11 Pro as I found RDP local cursor give a better experience compared to SPICE. RDP is only available on the Pro edition of Windows.

Setting Up The VM

You will need to install and use QEMU and Libvirt for your virtualization, as VirtIO comes with it.

$ sudo dnf install virt-manager libvirt-daemon-kvm -y
$ sudo systemctl enable --now libvirtd.service

For near-native performance, we will be using VritIO to improve both disks, network and graphics I/O, which means, the VM creation process would be slightly different.

The first step is to start up Virt Manager, and before starting with installation, you will need to enable XML editing at Edit > Preferences

Screenshot from 2023-09-10 12-04-11.png

Then, create a new VM with at least 2 cores, and 8GB of RAM (you can enable ballooning later). Make sure that you check “Customize configuration before install” option at the final step of VM creation.

Screenshot from 2023-09-10 11-58-00.png

Screenshot from 2023-09-10 12-08-43.png

Screenshot from 2023-09-10 11-58-21.png

Screenshot from 2023-09-10 11-59-07.png

At the customization page, you will need to configure the following:

  1. CPU Pinning

    Screenshot from 2023-09-10 12-09-46.png

    Replace <vcpu>2<vcpu> with:

      <vcpu placement="static" cpuset="2,3">2</vcpu>
      <cputune>
        <vcpupin vcpu="0" cpuset="2"/>
        <vcpupin vcpu="1" cpuset="3"/>
      </cputune>
    

    This will pin the 2 CPU to physical core 2 (third core) and core 3 (fourth core) of the base host, minimizing competition with the main operating system running at core 0 (first core) and core 1 (second core)

    You can view which core tied to which cpuset by running cat /proc/cpuinfo |egrep -i 'processor|core id'. From the output, processor is the cpuset id, while core id is the physical core id.

  2. Set SPICE port. Note that we keep video to QXL as VirtIO video is only supported on Linux guests.

    801899947084c122e9a703b84096614a.png

  3. Change default disk to VirtIO bus

    f2d14462bca721f419b98ea5723d5bf7.png

  4. (Optional) If you will only have 1 windows VM, you may want to use TPM passthrough.

    9e6f389d39dca4bd249aa6f634033d73.png

  5. Add VirtIO driver ISO image as another SATA CDROM. You will need it to load VirtIO driver

    3f239e940b4d6d2511a023335243b7f9.png

    You can get VirtIO driver ISO image from Fedora here: https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso

  6. Configure HyperV enlightenment.

    6ed357ee7d3192bb75be953cc34aea1b.png

    Set the configuration to:

        <hyperv mode="custom">
          <relaxed state="on"/>
          <vapic state="on"/>
          <spinlocks state="on" retries="8191"/>
          <vpindex state="on"/>
          <synic state="on"/>
          <stimer state="on"/>
          <reset state="on"/>
        </hyperv>
    
  7. Enable shared memory (this is needed later for filesystem sharing)

    24f3f26420939629495918bfd2e02a92.png

  8. Add filesystem sharing to your Home directory

5fd1a365bcbb39fd0b427b3477bf9e82.png

  1. Then click Begin Installation to start installation.

When at the disk selection you will see that there are no disk to select. This is because Windows does not carry VirtIO disk drivers by default. You will need to load the driver from the secondary CD drive.

d8e04293c14c805a42661a89dc42d1e0.png

29d87b13b54d48ad069ac9d4f7224575.png

a8ebffcfeccb3c030fe47a6c9dbb09d1.png

Then proceed the installation as you would normally

c2d6c93cb0d5b566922b9b2fb2ce6113.png

On first boot , to improve performance, disable all telemetry monitoring

1d0399064cb6020ed67cadfe5aa1db4c.png

Setting up Windows

After successful installation, you will need to then install the rest of VirtIO drivers, VirtIO guest tools, and WinFSP to further improve host-guest integration and improve user experience.

  1. Install VirtIO drivers

    40f17b3274c9463d29682d0cef383ac8.png

  2. Install VirtIO guest tools

    420e6f638b94174fcce664b1a27e74ca.png

  3. Install WinFSP & Enable VirtIO FS

    WinFSP (https://github.com/winfsp/winfsp) provide capabilities similar to FUSE on Windows, which allows mounting of userspace filesystems. It is required in order to mount VirtIO shared filesystem as a drive in Windows. Download and install it, then enable VirtIO FS by enabling the following service in the Services app.

    Screenshot from 2023-09-10 21-53-18.png

    Screenshot from 2023-09-10 21-53-41.png

    If enabled correctly, you will see that a new drive Z:\ appeared that links to the Linux host storage

    Screenshot from 2023-09-10 21-54-14.png

  4. (Optional) Then, enable RDP

    f4958f01ca425b8326bc7b15b43d36d1.png

  5. Afterwards, shutdown the VM, as we now need to switch the network to VirtIO. Open the VM properties and ensure that NIC is switch to VirtIO

    11b06bfa96cf2da6ca416feb3e132a88.png

  6. Now you can start the VM back up.

Connecting to VM

To connect to the VM, I recommend to use Remmina

$ sudo dnf install remmina remmina-plugins-spice -y

Launch Remmina, then you may want to disable the fullscreen toolbar in Remmina preferences for added seamlessness

617cece718677af769e1b922937d65e0.png

Using SPICE

SPICE is the default remote connection protocol for QEMU and is generally recommended if you just need basic capabilities.

You make sure you use QXL driver. If you are using SPICE with Virtio video driver, you may experience mouse lag on slower computers.

On Wayland on my F37, SPICE also behave weirdly after Alt+Tab when put in full screen mode, where it behave as if Alt/Ctrl is always pressed until you leave full screen.

If you face above issues, then use RDP.

To connect to SPICE, use following settings

  • Protocol: SPICE
  • Basic tab:
    • Server: localhost:5900
  • Advanced tab:
    • Preferred video codec: VP8
    • Preferred image compression: LZ4
    • Enable audio channel

ac19822843405d04f683eeff7aa173a9.png

Click Save and connect., and you now have connected to the VM and can use it.

Switch to full screen view for seamless display. You will need to set resolution to match your monitor resolution.

Optionally, for better display performance with this method of connection, launch Performance app and configure it for best performance.

e33461d312451dc99354652afe56b1b6.png

Using RDP

I recommend using RDP because it uses local cursor and suffer less mouse lag compared to SPICE. You also have better control on display peformance tweaks on the client side, however, it might not perform that well for videos.

To connect to RDP, use following settings

  • Protocol: RDP
  • Basic tab:
    • Server: IP Address of the VM
    • Username: Windows login username
    • Password: Windows login password
    • Resolution: Use client resolution
    • Network connection type: LAN
  • Advanced tab:
    • Quality: Medium/Good
    • Gateway transport type: RPC
    • FreeRDP log level: ERROR
    • Audio output mode: Local

f6a8f2992a211f8e0ce8a54c788ed975.png

Click Save and connect., and you now have connected to the VM and can use it.

Switch to full screen view for seamless display.

Optimization & Tuning

For less CPU and RAM usage, you may want to also do the following:

  • Uninstall Microsoft 365
  • Uninstall Microsoft Teams
  • Uninstall OneDrive
  • Uninstall ClipChamp
  • Uninstall Microsoft Todo
  • Uninstall Microsoft News
  • Uninstall Xbox related packages

If you are on GNOME and is used to use top right hot corner for window switching, you may also want to install Winxcorners, and set top left corner to open Task View.

I recommend setting the VM wallpaper to match your main desktop wallpaper.

Conclusion

Windows-on-Linux virtualization have improved significantly today that it is possible to run Windows VM with minimal impact on performance. Open Source RDP clients also have catched up quite well in bringing smooth integration of audio and clipboard with remote Windows connection that it become pretty seamless to use Windows applications through RDP, especially for work related applications such as Microsoft office. VirtIO FS in the other hand makes disk integration experience almost as if you are using Wine.

Using this method, one more barrier of adoption of Linux as primary operating system is solved as it is relatively seamless to work with documents in the VM, that it barely feel like Microsoft Office is running in a VM.

References

Written by Izhar Firdaus Follow Support
I'm a system architect, data engineer and developer advocate with passion in Free / Open Source software, entrepreneurship, community building, education and martial art. I take enjoyment in bridging and bringing together different FOSS technologies to help businesses and organizations utilize IT infrastructure to aid and optimize their business and organizational process.

Switching to use Ruby 2.7 (or older) in Fedora 34 using DNF Modules

Fedora 34 now ships with Ruby 3.0 by default, which might be great news for Ruby developers. However, for those who might still be re...

In blog, May 18, 2021

« Previous Post

Allowing keyboard capture for Remmina, Virt Manager and other software in GNOME Wayland

One capability seems missing in Wayland compared to X11 is the ability to fully capture keyboard events, for example when using remot...

In blog, Sep 23, 2023

Next Post »