Passa al contingut principal

Working like WSL2 (without having it)

TL;DR

Here is an approach to work with a non-WSL Linux guest (with VirtualBox or VmWare) and launching native Windows commands (f.e. MS Office Excel)

--

Hi all,

Some people have WSL2. Some people not, like me, and we are in the middle-of-nowhere with WSL1, as we are not able to do real stuff with Docker, Kubernetes, and so on, because WSL1 lacks the needed capabilities that a real Linux kernel has, so the only solution (see rants section below) is to stick with VirtualBox (or VmWare if you prefer) and work isolated from Windows apps.

But here's a way to overcome such limitations.

The idea is to run a small agent in the Windows side (the host) that will be capable of running whatever command you send from the Linux side (the guest).

In order to do that, you'll need:
  • Windows:
    • Java 11 (https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot)
    • Groovy (https://dl.bintray.com/groovy/maven/apache-groovy-binary-3.0.4.zip)
  • Linux:
    • Netcat

Once you have them installed, you'll have to do:

1. Create the agent in Groovy

Create a file (f.e. c:\GroovySocketServer1070.groovy) with the following content:

new groovy.ui.GroovySocketServer (new GroovyShell(), // false"println line.execute().text", // true1070);

That's all: A poor-man's telnet server written in three lines of Groovy, that will execute whatever command it receives at port 1070!
There's a caveat: If there's an error it will be lost, as STDERR is not captured.

You can run the agent  with a command like (the paths must reflect the exact locations of the Java and Groovy installations) this:

C:\>PATH=C:\p\groovy-3.0.4\bin;C:\p\jdk-11\bin;%PATH% C:\>groovy C:\GroovySocketServer1070.groovy


2. Launch the commands from Linux

From the Linux guest you can launch any Windows program like this:

$ echo "C:\\Windows\\System32\\cmd.exe /C dir" | nc -N 10.0.2.2 1070 $ echo "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE" | nc -N realhost 1070 &

Bonus point: The GroovySocketServer allows multiple concurrent executions (so you don't have to wait for the termination of other commands)!

Sweet and easy: You can execute any host program from the guest.

Hope you like it!

Rants

Comentaris

Entrades populars d'aquest blog

Minimal Ubuntu 18.04 on Aspire One Cloudbook

Hi, Here's a cookbook of tips to setup a Aspire One Cloudbook 14 with a minimal (but usable for your parents) Ubuntu. Setup the BIOS Press F2 when the Acer logo appears, and then change the EFI system to legacy. Reboot and then press F12 when the logo appears (to choose the installing media). Installation. I have selected a Lubuntu 18.04 installation but it's not a critical choice. More on this onwards. When prompted, specify the following options for the partitions: discard (as the Cloudbook 14 has a eMMC drive) and noatime . When prompted, install nothing but "OpenSSH Server" (as it won't be a standard desktop) After-install setup Update the dependencies with apt update && apt upgrade . In other linux machine, download and compile a recent kernel (currently 5.10.3): make clean menuconfig; make -j $(nproc); make bindeb-pkg # as we're going to scp the generated kernel to the aspire1 In the parent directory there'll be a " linux-image-5.10.3*....

My latest web bookmarks

  • https://possiblelossofprecision.net/?p=2255