×

Creating “Reverse WSL” For Running Windows Application On Linux Host

Creating “Reverse WSL” For Running Windows Application On Linux Host


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 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, in Malaysia, 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.

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. 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.

Reverse WSL With QEMU, Libvirt & VirtIO

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 the 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 will also need Windows 10 Pro or Windows 11 Pro as RDP would be a key component for this, which 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.

$ dnf install virt-manager libvirt-daemon-kvm -y

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

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="3,5">2</vcpu>
  <cputune>
    <vcpupin vcpu="0" cpuset="3"/>
    <vcpupin vcpu="1" cpuset="5"/>
  </cputune>

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

  1. Change default disk to VirtIO bus

f2d14462bca721f419b98ea5723d5bf7.png

  1. Set VirtIO Video

5cb8577f26f7d63169a2988eb556c867.png

Disable 3D accelleration for now. You can enable it later after drivers are loaded and RDP is operational.

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

9e6f389d39dca4bd249aa6f634033d73.png

  1. 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

  1. Configure HyperV optimization.

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>
  1. Enable shared memory (this is needed later for filesystem sharing)

24f3f26420939629495918bfd2e02a92.png

  1. Add filesystem sharing to your Home directory

5fd1a365bcbb39fd0b427b3477bf9e82.png

  1. Then click Begin Installation to start installation.

Make sure you select Windows 10/11 Pro during 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

  1. Install VirtIO guest tools

420e6f638b94174fcce664b1a27e74ca.png

  1. 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

  1. Then, enable remote desktop

f4958f01ca425b8326bc7b15b43d36d1.png

  1. 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

  1. Now you can start the VM back up.

Connecting to RDP

To connect to RDP, you will need to install Remmina RDP client

Afterwards, setup the connection with following settings

  • 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 to make things appear as if it is not a VM.

The VM is now ready to be used to install Microsoft Office.

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.

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.

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

  • https://linuxhint.com/install_virtio_drivers_kvm_qemu_windows_vm/
  • https://leduccc.medium.com/improving-the-performance-of-a-windows-10-guest-on-qemu-a5b3f54d9cf5



Source link