WSL Manager

(github.com)

109 points | by gballan 17 hours ago

9 comments

  • wongarsu 16 hours ago
    The ability to run docker containers as wsl instances looks nifty. A bit more overhead since they now run as a VM instead of a container, but you get the ability to start a shell with Windows terminal or access files with Explorer (and thus every program running in Windows)
    • osigurdson 14 hours ago
      Perhaps I misunderstand your comment but when you run docker / podman in Windows, you are using WSL / HyperV.
      • ghosty141 2 hours ago
        Just FYI you can also run a windows docker natively in windows without using WSL or any linux component. But that's more of a niche usecase.
      • wongarsu 14 hours ago
        running docker on windows runs docker in wsl (which is a HyperV guest). The project offers running docker images as wsl instance (which is a HyperV guest), no docker involved
        • llm_nerd 13 hours ago
          You said - "A bit more overhead since they now run as a VM instead of a container"

          To which osigurdson seemed to be noting that WSL2 itself is a VM (meaning if you launch 1 or 100 WSL2 instances, a single Linux VM will be spun up), and when you run docker, it runs using exactly that same VM (optionally, though it's the default now to just use WSL2's backend).

          Can you clarify what you meant by "A bit more overhead"? Running a container via docker or directly via WSL2 will use the same underlying VM, and there will only be that one VM regardless of the number of WSL2 or docker instances.

          • wongarsu 13 hours ago
            For a single container the difference depends on your exact setup. I typically run docker in the same WSL instance as my other wsl stuff, so starting a single docker container adds 0 additional VMs, while starting the container as a wsl instance will add one VM. If you use the "docker for windows" package you may be adding a VM just for running docker, depending on your setup.

            Once you start the second container the difference becomes more obvious: running $N containers in docker uses one VM with one linux kernel, no matter how many containers you add. Running $N containers as separate WSL instances runs $N VMs and $N linux kernels. That's the "bit more overhead" I was referring to

            • llm_nerd 12 hours ago
              "Running $N containers as separate WSL instances runs $N VMs and $N linux kernels."

              But it doesn't, and this is what I'm disagreeing with.

              If you instantiate WSL2, it launches a Linux VM. A single Linux VM. If you then run Docker with WSL2 integration (the default and hugely recommended), it uses that Linux VM as its VM as well, so you're still at 1 VM.

              If you run 100 WSL2 instances, they will all use that single Linux VM, each doing namespacing for isolation with their own filesystems. If you run 100 Docker instances, they will all use that single Linux VM.

              If you run 100 WSL instances, and 100 Docker instances (assuming, again, WSL2 integration which is the default), they will all be using that single Linux VM.

              • Jenk 11 hours ago
                Every time you run `wsl --install <distro>` you are creating a new VM. Every time you run `wsl --unregister <instance id or name/>` your are removing a VM.

                It is these two operations at the heart of OP's app.

                • super256 6 hours ago
                  No, this is wrong.

                  WSL2 distributions share the same Linux kernel. They only get their own root filesystem with a Linux userland (/bin, /usr, /lib etc), and some WSL config meta data. This is then stored as a virtual disk image (which is probably where your belief comes from). But the kernel runs in a single utility VM. The distros share that kernel instance and they are separated via namespaces only.

                  This makes running multiple WSL2 distributions in parallel very performant btw, as there is no world switch.

                  • Jenk 1 hour ago
                    I stand corrected. It makes sense that it is a chroot/rootfs rather than fully independent VMs.

                    re: side-by-side running, I always get socket and/port port problems when doing that. Without having looked into it at all I figure it is NAT collisions.

                • mappu 6 hours ago
                  This is not true - it's actually all the same VM if you check hcsdiag.

                  WSL2 distros only use Linux namespaces, same as docker, and the WSL2 --system distro can see PIDs from all running WSL2 distros.

                • llm_nerd 10 hours ago
                  Okay, are you guys using wrong terminology? Are you talking about a filesystem image as a "VM", because that would not be correct. A "Virtual HD" (VHD) is not a VM. Do you think a WSL2 distro instance is a "VM" because it's persistent? Did you know Docker containers can be persistent as well, people just choose as a best practice not to use it like that? Does that make them magical VMs?

                  WSL2 has a single VM running as the process vmmem (or vmmemWSL in the newest versions). This is the single Linux kernel that will be shared by every WSL2 instance. It will also be the instance that hosts Docker containers as well. I mean, I'm just echoing myself and apologies for the repetition, but this is just easily confirmed, utter factual truth.

                  A rootfs is not a VM. WSL2 and containers have different nuances about their filesystem and isolation (WSL2 instances is aware of other instances, for instance, as a design aspect, and WSL2 persists rootfs changes while docker as a best practices does not), but they're more alike than different. And they share little in common with something like VirtualBox or vmware, which actually isolate every such system as VMs.

                  Again, sigh, if you install 10 WSL2 "distros", you will have 10 rootfs overlays on your drive, and 10 persistence VHD files. When you run these the VM they all run under in the shared vmmem instance, which is the single utility Linux VM.

                  • opello 10 hours ago
                    Is there a way to visualize this on a running system or some documentation that describes it? I'm not familiar with the plumbing here but did try to find some documentation.
                    • llm_nerd 10 hours ago
                      I've done a lot of in-depth WSL2 work, so I'm just aware of its particulars, but to cite some documentation-

                      https://learn.microsoft.com/en-us/windows/wsl/about

                      "WSL 2 uses virtualization technology to run a Linux kernel inside of a lightweight utility virtual machine (VM). Linux distributions run as isolated containers inside of the WSL 2 managed VM. Linux distributions running via WSL 2 will share the same network namespace, device tree (other than /dev/pts), CPU/Kernel/Memory/Swap, /init binary, but have their own PID namespace, Mount namespace, User namespace, Cgroup namespace, and init process."

                      (under "What is WSL2"?)

                      https://www.docker.com/blog/new-docker-desktop-wsl2-backend/

                      "WSL 2 runs all distros in the same utility VM, sharing the same Kernel."

                      If you run multiple distros take a look at the process manager and find the single vmmem or vmmemWSL (newer versions have the latter). That single instance is all of the instances, and all of the docker containers you might be running as well, each with namespace isolation (with WSL2 having intentional bridging between them for convenience). Visualise it by doing something intensive in any of them and seeing the single process react, because that's the single utility VM responsible for all of them. Further while starting up the first WSL2 instance or Docker container is expensive, requiring the initialisation of all of the resources for the utility VM and the memory to support it, subsequent iterations are much less expensive.

                      • opello 9 hours ago
                        Thanks, it wasn't out of doubt that I asked, but it seemed having a reference to point at would help resolve the contention. The Docker blog post covered a lot more detail, even about WSL2, which was really informative and I hadn't seen.

                        I wonder exactly how much work "container" is doing in that Microsoft blog post's description, because it doesn't seem like it's the same kind of environment as a runc or containerd container?

                        I also wasn't quite sure how much detail to infer from the behavior of vmmemWSL or vmcompute.exe, because my casual understanding is that there's some adaptation layer that handles mapping Linux calls to Windows calls. It seems reasonable to allow for process mapping or accounting shenanigans for any number of good reasons.

                        • llm_nerd 9 hours ago
                          >there's some adaptation layer that handles mapping Linux calls to Windows calls

                          This was how WSL1 functioned. It used a shim layer, and honestly it was pretty neat for a lot of the basic stuff. It fell apart if you were doing more complex/advanced stuff, however, as there were many missing cases and exceptions.

                          WSL2 instead uses that utility VM, with a couple of special Microsoft kernel drivers to interact with the host system.

      • smallerize 14 hours ago
        The linked project includes a very different way to launch docker containers.
    • Chris2048 14 hours ago
      How does this compare to running the containers in one of the WSL VMs? Can't you do all the same things via the host VM?
  • lukax 16 hours ago
    Looks nice but still a bit sad that Flutter is used instead of something native given that they don't need the app to be cross-platform.

    Well, even Microsoft uses React Native for a lot of Windows-only apps.

    • pjmlp 3 hours ago
      The React Native reason is called C++/WinRT, the teams that internally rioted against C++/CX and came up with C++/WinRT (now in maintenance, go figure), never cared one single second about the Visual Studio experience (using C++/CX was similar to the Delphi/VB like experience from C++ Builder), that everyone else was losing.

      Thus React Native is the only alternative left those teams had to have some kind of nice GUI design experience alongside C++/WinRT, when using WinAppSDK, think Qt with QML/C++.

      Agree on the Flutter comment.

    • Defenestresque 14 hours ago
      I'm glad I'm not alone in missing native apps. I get that it's easier to code a note-taking Electron app, but every time I look at a Linux terminal app written in JavaScript it makes me want to cry.

      I know I'm beating a dead HN horse here, but how the hell is it possible that megabytes of embedded JavaScript in websites, to the point that LinkedIn uses about half the RAM I had for my first computer loading 32 MB of JavaScript files. Jjira loads 50 (!) MB of javascript, enough to include the uncompressed version of War and Peace 16 times. That's the size of a full installation of the entire Windows 95 operating system. GitLab's static landing page is 13MB of JavaScript, larger than that of Twitter.

      What the hell are we doing here? Why can I spin up a 100 MHz, 8MB RAM VM with a hard drive size that's 1/16th of your entry level MacBook's RAM and have apps open immediately? I understand some backsliding as things get more high level, but a website loading 50 megabytes of JavaScript, to me, is like a bright neon sign that screams "something has gone wrong terribly here". Obviously programs, websites and operating systems have become incredibly more complex but your $200 A-series Samsung phone has about 8 cores at 2.2 GHz each. A $200 processor when Windows 95 was released had one core at 0.1GHz. making the processing power about 164x faster. Keep in mind this $200 includes a fully functioning computer in the palm of your hand. The actual CPU part for a midrange phone like the Samsung A15 5G is the Dimension 6100+, which costs all of $25 bucks.

      There must be some sort of balance between ease of prototyping, creating and deploying an application without bundling it with Electron or building websites that use tens of megabytes of a scripting language for seemingly nothing. Especially when we can see that a fast, usable website (see this very website or the blogs of many of the people who post here, compared to Reddit for your average medium or substack blog).

      How the hell do we fix this? The customers clearly don't want this bloat, companies clearly shouldn't want it either (see research that indicates users exposed to a 200 millisecond load delay on Google, performed 0.2-0.6% fewer searches, and effect that remained even when the artificial delay was removed. This was replicated by Microsoft, Amazon and others. It's frequently brought up that Amazon has said that every 100 milliseconds of page load time cost them 1% in sales, though it's hard to find definitive attribution to this), programmers should hopefully not want to create crappy websites just like mechanics should hopefully not want to install brake pads that squeal every time the user breaks.

      This got way longer than the two sentences I expected the post to be, so my apologies.

      [1] https://tonsky.me/blog/js-bloat/ [2] Velocity and the Bottom Line, Shurman and Brutlag

      • ai-psychopath 14 hours ago
        > The customers clearly don't want this bloat,

        citation needed. the customers clearly want it, for example most programmers chose VS Code over a native app

        • pjmlp 3 hours ago
          I did not chose VSCode, I only touch it, because there are SDKs whose programmers decided only to support VSCode as Electron fans.

          Thus I begrudgingly use VSCode when forced to do so, otherwise I use the IDEs of each OS vendor.

        • 306bobby 8 hours ago
          If there was a vs code native alternative that was parity, that might not be a case. That's apples and oranges
          • xd1936 18 minutes ago
            Zed?
          • krapht 7 hours ago
            Sublime Text? Sure, doesn't have the long tail of extensions, but surely most people don't need those. The biggest issue with ST being the fact that it costs money...
            • pjmlp 3 hours ago
              And we don't want to pay for tools, while expecting to be paid ourselves, rigth?
  • admiralrohan 6 hours ago
    My WSL Ubuntu instance always gets disconnected after I come out of sleep or hibernation mode. Anyone else faced this issue and any solutions? I have tried everything found online.
  • herf 9 hours ago
    I wish there were more ways to specify whether the Windows filesystem /mnt/c should be mounted in a WSL2 instance - it is kind of generally on or off. In cases where I want WSL2 to function as a "container" isolated from my desktop, I use a different Windows user just in case.
  • llm_nerd 13 hours ago
    Neat project. Merging the layers of a docker image and setting that as a WSL filesystem is a nice convenience.

    I recently realized that 100% of what I use Windows for was as a WSL2 foundation: It had been reduced to being an extremely overbearing and heavyweight host machine for a Linux VM. Nothing in my life was Windows-only anymore, and it was basically just inertia that I even still had it installed.

    I'd been a "Windows guy" for decades, had decades of Windows software dev under my belt, even got my MCSE, MCDBA, along with other Microsoft certs, and even wrote for MSDN Magazine. No longer did it have any leverage on my profession at all, which was shocking to me.

    The next day I purged Windows from my two main working machines, so now I'm pure Linux and macOS. A few weeks later and I can say it has been a marvelous transition, and cuts out the no longer relevant middleman.

    • martinald 7 hours ago
      It's interesting because I'm the same in so much that I use windows basically as a WSL2 host and not much else. I use a MacOS a lot.

      _However_, still find the Linux desktops that I've tried are too buggy. While the hardware support is incredible (compared to Windows out of the box), I constantly hit bugs with fractional scaling on multiple monitors. I'm hopeful that Ubuntu 26.04 may finally iron out the last problems with this. The latest version of Fedora I installed did fix all this but I'm far too used to Debian based OSes.

    • binkHN 8 hours ago
      Right there with you. When Microsoft started pushing Windows 11 over Windows 10, that's when I decided I had enough of my experience being dumbed down. I switched over to Linux, haven't looked back, and couldn't be happier. I still run a Windows virtual machine for those times that I need something native to that operating system, but I should have made the move years ago; Microsoft doesn't care about Windows anymore.
  • shmerl 14 hours ago
    Is there anything that can run a normal Linux VM guest with good quality graphics acceleration on Windows host (i.e. both full OpenGL and Vulkan support)? Not the gimped half VM over HiperV.

    VirtualBox has really broken graphics support, you can only run software rendering Linux DEs that way.

    • okanat 14 hours ago
      WSL2 already allows you to use your own GPU driver as a paravirtualized GPU over open source Mesa d3d12 driver. You get quite good OpenGL performance with that.

      There are projects like this https://github.com/jamesstringer90/Easy-GPU-PV that you can use to setup a Hyper-V machine to use the same paravirtualization.

      • shmerl 14 hours ago
        > Tere are projects like this https://github.com/jamesstringer90/Easy-GPU-PV that you can use to setup a Hyper-V machine to use the same paravirtualization.

        > Automatically Installs Windows to the VM

        This seems to be focused on Windows guests. I need this for Linux guests.

        May be when Hyper-V will make this usable out of the box for any guests, I'll take a look. And if it's something shareable, may be VirtualBox should pick that up.

    • eddythompson80 14 hours ago
      You can pass a GPU to the vm if you have more than one. GPU vendors have been gating GPU virtualization for data centers only. Or you can run X on windows like wslg does it.
      • shmerl 14 hours ago
        I need something similar to what qemu/kvm can do with virgl and venus, i.e. pass through graphics call to the same GPU that's used by the host, not pass whole GPU with SR-IOV or PCIe passthrough. So far I haven't found anything like that which actually works.

        I'm not using X, I need a normal KDE Wayland session.

  • skhameneh 14 hours ago
    This is great and all... Except I’ve long given up on WSL. I really tried to make WSL work for many things, only to find the entire experience (reliability, performance, and beyond) was simply better in every way without Windows.

    No matter what you do, there will always be some weird platform detection or line termination that pops up somewhere. And if it isn’t that, it’s degraded performance or kernel-level incompatibility.

    • Rapzid 13 hours ago
      I guess your YMMV. I switched from developing in Linux VMs to WSL about 3 years ago and have used it daily for development.

      I don't do much OS level engineering these days though and would probably fire up some VMs for that.

    • skhameneh 11 hours ago
      So there’s a good number of comments, I’ll try to address them:

      - Yes, these issues persist with WSL2.

      - WSL2 allows mounting between the system/subsystem, but there is considerable overhead.

      - Using WSL for remote workspaces from the host is very much a mixed bag.

      - Attempting to use WSL entirely with graphical applications has very limited/poor support.

      - If you wish for VM acceleration, you have to use Hyper-V, not all toolchains work with Hyper-V and this heavily restricts the host machine.

      - If you wish to do anything that crosses the subsystem and the host, line delimiters and platform detection are very error prone.

      - If you accidentally misconfigure WSL2 (which is quite easy to do) the WSL userspace can have substantial access to the host files, often beyond what may be initially apparent.

      - Of compatibility issues, non-standard socket implementations have caused a lot of incompatibilities with software for me.

    • eddythompson80 13 hours ago
      > (reliability, performance, and beyond)

      Considering it's just a headless linux vm with some integration with the host, I don't understand what reliability, performance or beyond it could possibly introduce beyond what any VM solution provides?

      There are few gotchas with WSL. I hate how by default it includes your Windows path in your default linux path out of the box. It's easy to turn off and my init scripts for any VM always do that anyway, but it's the main thing I have seen people who are new to WSL get tripped by. It's useful to be able to run windows programs from within WSL. Like all the cli tools that pop up a browser to make you login, but that's about where its usefulness ends for me.

      > No matter what you do, there will always be some weird platform detection

      In my experience, unless you're running a very mainstream distro (read Ubuntu) there will always be a weird "platform detection" issue. I run openSUSE on most of my devices, and used to scripts not working because "uhhh, this is not Ubuntu or Debian or Fedora". The only time I run into "platform detection" issues are scripts that assume `uname -r` of a very narrow format.

      > or line termination that pops up somewhere.

      That goes back to my original comment about running Windows programs from linux, or moving files to/from linux. I never run into this issue because, just like on a linux desktop, I only interact with linux through the commandline. Even on a full linux desktop, I have this mental separation between GUI apps and terminal apps.

      > it’s degraded performance or kernel-level incompatibility.

      The only "kernel-level incompatibility" I run into is that WSL kernel doesn't have /dev/kvm. Granted I don't do a lot of kernel module specific development, so I don't know how something like a USB device or a PCIe interface can be passed to the WSL instance. But again, I'm thinking of it, and treating it like a user-mode development VM, not a full host.

      • withinboredom 12 hours ago
        USB forwarding to WSL is built in to the WSL kernel, but you do need to install a thing on the windows side. After that, there are a number of GUIs to manage your usb devices or you can use the shell. Switching a usb devices from windows to WSL basically unplugs it from windows and plugs it into WSL.

        I need it to access ssh keys from my yubikey. It’s painless if you just set it up to automatically forward the device on startup.

    • omnibrain 14 hours ago
      Yes, I since embraced pwsh for terminal stuff on Windows. For everything else I switched back to proper VMs or remote hosts.
    • TZubiri 14 hours ago
      I've transitioned from linux back to windows for workstation usage, and it's one of the main features that allowed me to do so, I haven't had major problems, so I would be interested to know what issues you faced. Of course direct linux is better than WSL, but I found the product to be of very high quality and well integrated with windows.
      • nilkn 13 hours ago
        Same here. The initial version of WSL back in the day could certainly be rough, but modern WSL2 seems totally fine to me. It is the key ingredient that allows me to have one workstation that can do "everything".
    • righthand 14 hours ago
      100% agree. If anything WSL is a Linux onboarding experience at best.
    • tonymet 12 hours ago
      maybe it was WSL1 ? WSL2 IO is excellent as long as you stay within the FS. And with VS Code WSL support , all IO & commands are remoted into WSL so there are no Windows/Linux compatibility issues.
    • pjmlp 3 hours ago
      I already given up on dual booting around 2010.

      The only difference bettween 2010 and 2026, it that nowaday instead of having a mix of Virtual Box/VMWare Workstation depending on my work system, I have WSL 2.

      However my Windows develoepr experience goes back to Windows 3.1, thus I mix and match my needs, between Windows and Linux sides.

      WSL 2.0, and Virtualisation Framework are really the Year of Linux Desktop. /s

  • tonymet 12 hours ago
    this is great and I have a feature request: A "refresh VM" feature that exports your home dir + packages into a new VM instance.

    I've tried Optimize-VHD but renewing the VM this way frees up disk and speeds up the VM as well. None of the WSL settings for sparse disk / disk shrinking seem to work well.

    Here's what I usually do

       $ tar -czf /mnt/c/Temp/home-backup.tgz $HOME
       $ apt list --installed > /mnt/c/Temp/packages.txt
    
    delete the VM, create a new one, reverse the process.

       $ tar -cxf /mnt/c/Temp/home-backup.tgz -C $HOME
       $ apt update
       $ cat /mnt/c/Temp/packages.txt | xargs apt install
    • Quarrel 1 hour ago
      You operate a little cleaner than I do- there are invariably things that end up in /usr/local/bin..

      Still, thanks for the process you use.

      My wsl is pretty long lived now, through quite a few ubuntu upgrades and installations of stuff that I probably no longer need.

  • behnamoh 15 hours ago
    I wish it was a TUI. Windows is a plague I try to stay away from as much as possible, and it already gives me headaches to setup WSL and manage them over ssh. Some things you just can't do w/o remote desktop... And sometimes WSL crashes and there's literally no way to recover except to restart the whole machine.

    The only reason I use Windows is because Nvidia drivers are easier to setup. But once I'm inside my Fedora WSL, that feels like home, not the Windows host.

    • Juminuvi 15 hours ago
      I think the UI is pretty slick but agree having a TUI option as well would be awesome. Everything in wsl management (import, export, register, compact, etc) can be done with shell commands I believe so a tiny performant TUI might be a straight forward thing for op to add in the future though.
    • eddythompson80 14 hours ago
      Are you sshing into the wsl instances or he windows host? Pretty much all my interactions with wsl is using the wsl cli. Other than the very initial step of enabling wsl, mostly because I never memorized the powershell enable command.
      • behnamoh 14 hours ago
        I ssh directly into WSL but for setting it up (auto-start, recovery, etc.) I ssh into PowerShell (which I hate). A TUI would go a long way there because no one wants to learn PowerShell.
        • eddythompson80 14 hours ago
          You can use wsl.exe from powershell to manage wsl.
          • mmastrac 12 hours ago
            FWIW I started reverse engineering the WSL2 API -- it's not terribly complicated to do most tasks without the CLI (which is clunky IMO, as it had a number of times where it changed in backwards/forwards incompatible ways)

            https://crates.io/crates/wsl-api