7 ms·
Isn't WSL2 just a VM?
- mindcrash 11mo agoWSL 2 runs on a subset of Hyper-V, and on a hypervisor, so basically yes. However, there's some interesting things going on in WSL 2 versus a "normal" Hyper-V virtual machine. For example, a Linux distro running on WSL can (and will) use GPU partitioning (aka PCI/GPU passthrough) and a special implementation of DirectX enabling the installed video card to accelerate graphics within X and/or Wayland. Although this feature can be enabled with a lot of hacking in both the Linux guest and vanilla Hyper-V on the host (the latter through Powershell) it is officially unsupported on Windows 10 and Windows 11, and is only supported on Windows Server.
- sedatk 11mo agoOh, I thought GPU passthrough was enabled on vanilla Windows 11, but I didn't delve into that feature enough. It's still extremely impressive of course. Perhaps I should write another article about graphical features.
- DiabloD3 11mo agoNo, PCI-E passthrough is not enabled on non-Server, and you arguably wouldn't do this on a Windows hypervisor. anyways, you'd do it with a Linux+KVM hypervisor for either Linux or Windows guests. Using GPU passthrough, however, is allowed. WSL2 does this by using the existing Mesa/DRI/DRM open source stack, but instead of a GPU-specific DRM driver, it is one that speaks WDDM (the DRM equivalent in the Windows driver stack), and only requires a GPU-specific ennoblement package (provided by the vendor, and matches the Windows driver it is talking to; AMD, Nvidia, and Intel all ship one inside of WSL2).
- sedatk 11mo agoThanks!
- toast0 11mo ago> No, PCI-E passthrough is not enabled on non-Server, and you arguably wouldn't do this on a Windows hypervisor. anyways, you'd do it with a Linux+KVM hypervisor for either Linux or Windows guests. If it was enabled on Pro, I would use PCI passthrough. I use hyper-v for a Linux dev environment on a windows workstation. My NIC supports virtual functions, so if I could passthrough one to the dev VM, I wouldn't need software bridging and that might be nice. (OTOH, I don't know if my motherboard has reasonable passthrough groups and all the other stuff that makes passthrough never work for me)
- Zardoz84 11mo agoAnd why you not run Linux dev env on bare metal and avoid the pain of using W11 ?
- Spivak 11mo agoI think part of the answer is that if you're going to use both it's nicer to use Windows with Linux as the guest than the reverse. MS clearly put a lot of effort to make the integration nice and it shows. Like how Parallels on macOS makes Windows a very nice guest. If there was software that made Windows as seamless on Linux I bet it would get a lot of use.
- toast0 11mo agoI don't want two computers for work, and I'm not getting paid enough to fight with Linux GUI. I can do all the work without Linux GUI and have a working desktop (still W10 for now). I just need a VM to get a close enough match to prod VM.
- pjmlp 11mo agoAzure runs on top of Windows hypervisors. https://techcommunity.microsoft.com/blog/windowsosplatform/azure-host-os-%e2%80%93-cloud-host/3709528 https://techcommunity.microsoft.com/blog/windowsosplatform/a...
- my123 11mo agoRegular Hyper-V VMs can use it too but it's not well documented. The keyword to search for: "GPU-P" https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/gpu-partitioning https://learn.microsoft.com/en-us/windows-server/virtualizat...
- evanjrowley 11mo agohttps://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/gpu-partitioning#supported-gpus https://learn.microsoft.com/en-us/windows-server/virtualizat... It relies upon SR-IOV and only several server-specific Nvidia GPUs are listed as supported. Intel's Flex dGPUs and Arc iGPUs have supported SR-IOV for years now, but they aren't listed there. It would be super awesome if Microsoft could add it for Intel Arc iGPUs, desktop versions of Windows, and WSL2! Intel's GPU SR-IOV already works with KVM on Linux!
- rusk 11mo agoThus far I have found the native WSL2 graphics integration to be pretty disappointing in comparison to what I used to get with X-server setup. Unfortunately the legacy X implementation doesn’t have the modern API and application developers are tapering their interest in it. Hopefully the groundswell of WSL2 support will improve this in time …
- danjl 11mo agoAgreed. No way to really test WebGPU, for instance. You can't really test GPU drivers under Linux or using the native Windows browsers. Lots of incomplete attempts to make this work, none of which are reliable or easy to use.
- user34283 11mo agoSame here, but maybe for different reasons. As an end user, the out of the box experience of getting a blurry window with the wrong content size isn't very useful. And I've never tried to actually configure it properly. I wonder if it's a decent experience even when configured properly. In that case, why do all the IDEs come with remote development / WSL integrations that involve running the client on the Windows side?
- nine_k 11mo agoDon't WSL2 and the WinNT kernel both run on top of Hyper-V, on (very approximately) equal footing? The NT kernel, of course, has all the hardware access, not necessarily granted to other VMs, such as WSL2.
- p_ing 11mo agoSee https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/architecture https://learn.microsoft.com/en-us/windows-server/virtualizat....
- bogwog 11mo ago> and is only supported on Windows Server. Imagine licensing and installing Windows Server to run Linux software through WSL
- someguy101010 11mo agoclearly you have never worked in enterprise
- lukeschlather 11mo agoThere are a variety of applications that it's not really possible to run natively on Linux, for example Widevine L1. I don't think there are any applications that can't run through WSL.
- pjmlp 11mo agoIt is actually a product people pay for, https://learn.microsoft.com/en-us/azure/iot-edge/tutorial-develop-for-linux-on-windows?pivots=iotedge-dev-cli https://learn.microsoft.com/en-us/azure/iot-edge/tutorial-de...
- CoolCold 11mo agoI'm 99% sure ive seen such questions/requests on Reddit for Windows server.
- arghwhat 11mo ago> For example, a Linux distro running on WSL can (and will) use GPU partitioning (aka PCI/GPU passthrough) and a special implementation of DirectX That is still just a normal VM, but it's nice that it's automated. > enabling the installed video card to accelerate graphics within X and/or Wayland. nit: X and/or Wayland is not involved in application rendering at all - its applications themselves that use the GPU and its acceleration directly. Wayland and/or X is only involved when the apps are all done rendering[0], and the display servers own rendering is the comparatively simple task of stitching windows together[1], and sometimes not even that. 0: You can send buffers early over Wayland if you also send a sync fence, but this is just forwarded as a render dependency that the GPU scheduler will patiently wait for. 1: well also dealing with stuff like color transforms which can be complex to understand, but are computationally cheap and for fullscreen content possibly entirely free.
- kiddico 11mo agoHow did you learn about the things in [0]? Idk where to even start.
- arghwhat 11mo agoContributing to display servers and following kernel KMS/drm stuff, but #wayland on OFTC or #sway on libera chat are both very helpful. Also https://wayland.app https://wayland.app to see the current Wayland protocols (the Wayland core protocol is mainly some common primitives, most stuff is across the other protocols). For example, the sync object stuff is in https://wayland.app/protocols/linux-drm-syncobj-v1 https://wayland.app/protocols/linux-drm-syncobj-v1 (in many cases handled by your toolkit or WSI of choice).
- deleted 11mo ago[deleted]
- andix 11mo agoYes, it's "just" a VM. WSL2 is a bit like Firecracker for Linux. It's a lightweight VM, with a lot of optimizations here and there. For faster startup, lower memory footprint and so on. PS: which means you need a lot of memory, if you use WSL2 extensively (multiple Docker containers for example). 8-16 GB on top of your usual workloads is a good starting point. Docker on WSL2 is not a lot of fun with less than 20 GB system memory.
- nu11ptr 11mo ago> For faster startup, lower memory footprint and so on Any idea how they do this? My WSL2 starts insanely fast, like about 1-2 seconds. I've never seen a linux distro natively boot that fast. Assuming they suppress any sort of BIOS startup screen for starters, but what else?
- andix 11mo agoActually I don't know it either. But WSL2 doesn't really start a lot of processes, like a desktop/server Linux distribution. It starts up only a minimal set of processes, and a shell. dmesg looks like the kernel is booting up normally, so I guess they don't use some memory snapshots magic. I guess they just tweaked the kernel and the hypervisor to start up fast. There is also no BIOS/UEFI delay.
- sedatk 11mo agoIt’s a very trimmed down kernel with minimal set of drivers and modules. It doesn’t even support SD cards out of the box. That’s probably the main reason as no hardware probing/initialization delays are incurred.
- em500 11mo agoAt high level, WSL2 provides a single optimized VM and Microsoft-compiled Linux kernel. Optimized here means that the VM only provides a small set of devices to the Linux kernel, and the kernel operates with exact known hardware, which is much smaller and simpler compared to a full blown kernel (which detects a large variety of hardware) and fuller featured VMs (c.f. qemu emulated devices: https://kashyapc.fedorapeople.org/virt/qemu/qemu-list-of-emulated-devices.txt https://kashyapc.fedorapeople.org/virt/qemu/qemu-list-of-emu...). And when you run multiple "distributions" or instances, they all share the same running VM and kernel. So after a one-time startup of the VM+kernel, opening more distributions/instances is like starting new system containers (similar to lxc/lxd or systemd-nspawn, which are also very quick to spawn on Linux) rather than new VMs. The architecture is quite similar to Linux-on-ChromeOS (Crostini).
- pak9rabid 11mo agoYes, a VM with extremely tight integration with the Windows environment to make things that would otherwise require lots of time to setup a breeze. I use it as my daily driver for dev work (at work, since we're required to use Windows :( ) and to be honest it's quite pleasant most of the time.
- scuff3d 11mo agoI usually work in a VM hosted by my company. But the performance is really starting to irritate me. Been considering switching to WSL2, but last time I checked all they supported was Debian based distros, and we do all our work on RHEL8. I don't think it would matter much but it's still annoying working on an entirely different setup from the rest of the team. How is the graphical app support these days?
- spockz 11mo agoYou can create your own images: https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro https://learn.microsoft.com/en-us/windows/wsl/build-custom-d... Or more step by step: https://gist.github.com/artman41/858450e2c29b239d8692213b684ada25 https://gist.github.com/artman41/858450e2c29b239d8692213b684...
- pod_krad 11mo agoThey support Oracle Linux. It is almost the same as RHEL.
- stackedinserter 11mo agoHow is it "tight" when even `ps` or `top` show VM processes instead of OS ones? Could you give an example of functionality that can't be done with `docker run -it ubuntu`? I used it for a little bit (got Windows laptop, thought maybe I'll switch but no), and just hated that split brain workspace.
- baq 11mo agoyou can access the internal VM disk via \\wsl$ UNC and you should be able to easily subst a drive letter for the dumb software from eons ago that doesn't support UNC paths.
- bobse 11mo ago[dead]
- Thaxll 11mo agoI always found wsl to be a hack and not a true Linux distro, fake pid 1 not really starting or shutting down ect... Even the docker integration is really odd. I know it was fixed with wsl2 but wsl1 had terrible i/o performance.
- bangaladore 11mo agoImo, WSL2 is almost indistinguishable from a true Ubuntu VM. If you haven't tried it since WSL1, I'd give it a shot. Of course this comes down to whether you care or not about the integrations with Windows.
- firesteelrain 11mo agoWe use it work to do things on WSL2 in Azure Desktop that don’t require a Linux VM and using Windows versions of tools that feel clunky like helm, kubectl, etc. We can easily interface with ACR and AKS this way.
- creata 11mo ago> Linux and Win32 filesystem APIs were too different, and translating them made some apps and some workflows seriously suffer. Is the reverse also true? Does Wine face any similar performance problems?
- andix 11mo agoI guess the main issue is, that Windows filesystem APIs are slow. Windows does a lot of things when opening/closing file handles (acls, virus scanning, and many more). Unix style applications with a lot of small files just perform really poorly. That's also why npm install takes ages on Windows. They made it much better with Dev Drives, that use ReFS instead of NTFS and disables most of the filters in the filesystem stack.
- Gabrys1 11mo agoThe file operations on macOS are rather slow too. I needed to invest in some rsync-based syncing for an in-docker application build as accessing the mounted volume from a Docker container was around 20 times slower than on Linux :O
- andix 11mo agoThat’s another issue. The access from macOS/windows to the Linux filesystem (docker volume) is over the loopback network. Also the other way around docker bind mounts to windows/macos filesystem.
- perching_aix 11mo agoEvery FS I've ever had the misfortune of using chokes on lots of small files, especially if they're stored in a flat manner.
- andix 11mo agoEverything except FAT/NTFS is fine for small files. Refs works fine on windows too. Listing large directories is slow. But it is what it is.
- add-sub-mul-div 11mo agoCan you create multiple instances each with their own IP address like you can with Virtualbox? Networking was the reason I didn't stick with WSL2 when I tried it but that was a long time ago and it's probably improved.
- Rucadi 11mo agoyes just use brige networking instead of nat
- smw 11mo agoStrangely, if you create multiple 'instances', they're actually all running as "containers" in the same vm with the same kernel. You can see this by running `wsl --system` and noticing that ps will show you processes from all running wsl distros.
- ZhiqiangWang 11mo agoThe issue I have is VHDX keeps expanding, and you need to manually compact it to claim disk back to host.
- andix 11mo agoI think there is an auto shrink feature, but it might cause more trouble than good.
- Rucadi 11mo agocpu 100% and shitty integration.
- okanat 11mo agoYou need to enable sparse VHD! However it doesn't alwyas trigger. I have moderate success with enabling TRIM systemd service on the distro. Here is the tracking issue: https://github.com/microsoft/WSL/issues/12103 https://github.com/microsoft/WSL/issues/12103 And if nothing works you can still manually optimize. https://superuser.com/questions/1827953/reclaim-wsl2-disk-space-after-setting-it-to-sparse#1834374 https://superuser.com/questions/1827953/reclaim-wsl2-disk-sp...
- 9cb14c1ec0 11mo agoTip for all you hackers out there. WSL bypasses windows firewall rules by default. Not sure why Microsoft ever thought that was a good idea.
- Demiurge 11mo agoIs this, indeed, a fact? I've always had trouble getting ssh to work under WSL.
- 9cb14c1ec0 11mo agohttps://github.com/microsoft/WSL/discussions/10579 https://github.com/microsoft/WSL/discussions/10579
- pjmlp 11mo agoMissed the background info that WSL 1 was a pico process, based on Drawbridge research, and not the same as previous subsystems. "The Linux Kernel Hidden Inside Windows 10" https://youtu.be/_p3RtkwstNk?si=V9vhvrdDOLu2Durr https://youtu.be/_p3RtkwstNk?si=V9vhvrdDOLu2Durr WSL Pico Process Overview https://learn.microsoft.com/de-de/archive/blogs/wsl/pico-process-overview https://learn.microsoft.com/de-de/archive/blogs/wsl/pico-pro... The same Drawbridge technology is used to run SQL Server on Linux. https://arstechnica.com/information-technology/2016/12/how-an-old-drawbridge-helped-microsoft-bring-sql-server-to-linux/ https://arstechnica.com/information-technology/2016/12/how-a...
- zokier 11mo agoThe article mentions dynamic memory sizing as one of the benefits of WSL2 over traditional VMs, but afaik Hyper-V supports that on normal Linux VMs too. WSLg is genuinely pretty nifty, but for command-line stuff WSL2 imho doesn't really bring that many advantages.
- asaws 11mo ago[dead]
- finaard 11mo agoWhile I understand _why_ they did WSL2 it's pretty sad that they at the same time they just dropped any WSL1 development. We're using a lot of WSL in CI - we're mostly Linux based, but for some stuff toolchains came up which didn't work nicely with wine (like MSVC). So for us we want a Linux system that seamlessly can execute Windows stuff in a Linux based build process. WSL1 can do that, WSL2 can be kicked into working somewhat, but needs quite a few ugly workaround as they're not sharing a process namespace or file descriptors. While the faster IO would be nice that's pretty much the only thing we'd care about - and wouldn't work here, as we need shared access to the files. And while we could access the WSL2 files from Windows side that's even slower than just using WSL1.
- awestroke 11mo agoWindows files are still available via /mnt/c on WSL2
- finaard 11mo agoAs WSL1 runs on the same kernel I have stuff like named pipes available. I can fully mix processes from both worlds in one workflow. _Some_ of that works with WSL2 as well, but as it's processes on two different kernels requires hidden workarounds to make that work - and not everything is working (and may be even possible).
- hnlmorg 11mo agoWhy would you want to mix Windows and Linux processes into one workflow on the same host? I’m sure you’ve encountered a very niche problem that requires it, but I cannot think of any scenario where that kind of behaviour would be desirable vs splitting those workflows up. Are you not able to have separate Windows and Linux hosts (eg VMs or containers) that are instigated to run in parallel as part of the same pipeline, but don’t rely on the same processes running in the same host? Or at the very worst, use a TCP/IP based RPC to share state between the different hosts?
- 11mo ago
- jesuslop 11mo agoCould one mount a real coexisting ext4 partition to reduce some of the perf penalty of having to simulate a block device on top of those ugly big image files?
- CivBase 11mo agoWSL1 felt like a useful compatibility layer for running some Linux applications in Windows. It had plenty of warts, but it quickly became my preferred command shell for Windows. WSL2 is more capable, but it's not Windows anymore. I might as well run a proper Linux VM or dual boot. Better yet, I'd rather run a Windows VM in a bare metal Linux OS. Why even bother with WSL2? What's the value add?
- EgoIncarnate 11mo agoVs WSL1: GPU access. Actual graphics use is so so, but essential for doing CUDA/AI stuff Faster file system access on the Linux side (for Linux compiles etc). Ironically, accessing Windows filesystem is slower than WSL1. Better Linux compatibility. Vs a Linux VM: GPU access! Easier testing for localhost stuff, Linux ports get autoforwarded to Windows (if your test http server is running in WSL2 at port 8080, you can browse to http://localhost:8080 in your Windows browser) Easy Windows filesystem interaction. Windows local drives show up in /mnt automatically. Mix Windows commands with Linux commands. I use this for example to pipe strings.exe, which is UTF-16 aware, with Linux text utils. I think WSL2 tends to be better at sharing memory (releasing unused memory) with the rest of the system than a dedicated VM. You can mimic some of this stuff to a degree with a VM, but the built in convenience facetor can't be overlooked, and if you are doing CUDA stuff there isn't a good alternative that I am aware of. You could do PCI passthrough using datacenter class GPUs and Windows Server, but $$$.
- FergusArgyll 11mo agoFull access to the windows filesystem You can call windows programs from linux (e.g. explorer.exe .)
- dboreham 11mo ago> I might as well run a proper Linux VM or dual boot. Obviously you don't do the thing you're writing about. A "proper" Linux VM would incur more work for you and would be less useful. Dual boot would remove your ability to use the computer for activities that need a Windows OS. Running a Windows VM on Linux would take you down a rabbit hole of pain and annoyances, unless your use case for Windows is extremely limited.
- Pannoniae 11mo ago"1.6GB on a 32GB system. [...] I think that's pretty much okay. What'a a gigabyte to spare in these days anyway? Just assume that you're running your clock app under Electron." LOL, this made my day :P
- morshu9001 11mo agoMy limited and nontechnical experience with WSL2 is that it quacks like a subsystem. Great article though.
- DeathArrow 11mo agoWho remembers Cooperative Linux or coLinux? http://www.colinux.org/ http://www.colinux.org/
- rzzzt 11mo agoHN remembers: https://news.ycombinator.com/item?id=42989923 https://news.ycombinator.com/item?id=42989923
- cachius 11mo agoAlso one of LBW, LINE or LOW? LBW is a Linux system call translator for Windows. It allows you to run unmodified Linux applications on top of Windows. It is not virtualisation; only one operating system is running, which is Windows. It is not emulation; Linux applications run directly on the processor, resulting in (theoretically) full native performance. Consider it as being like WINE, but in reverse. https://cowlark.com/lbw/index.html https://cowlark.com/lbw/index.html https://github.com/davidgiven/LBW https://github.com/davidgiven/LBW LINE Is Not an Emulator. LINE executes unmodified Linux applications on Windows 98/2000 by intercepting Linux system calls. The Linux applications themselves are not emulated. They run directly on the CPU like all other Windows applications. LINE runs best on Windows 2000 https://web.archive.org/web/20010803130404/http://line.sourceforge.net/readme.php https://web.archive.org/web/20010803130404/http://line.sourc... Call me crazy, but I've wanted to run a linux binary natively under windows for a while now; kinda like wine, but in reverse. Well, the other day I was browsing through the MSDN docs (as you do) and discovered that it is possible to install a "vectored" exception handler. A quick bit of test code later, and I discovered that I can trap "int 0x80" instructions using this technique--those are used by linux binaries to initiate syscalls https://web.archive.org/web/20100409222341/http://netevil.org:80/blog/2004/jan/linux-on-windows/comments https://web.archive.org/web/20100409222341/http://netevil.or...
- kevinmgranger 11mo agoI keep reading that WSL2 uses 9p, but that's not _exposed_ anywhere, right?
- shmerl 11mo agoWhat's a good way to have Linux VM with graphics acceleration on Windows host? WSL doesn't cut it and VirtualBox has really broken graphics support.
- tuetuopay 11mo agoI’ve found VMware to work well, though it’s degrading quickly. X11 is sorta broken, and not all Wayland compositors run. As an example, I can run KiCAD just fine under X11 with the modesetting driver, including the 3D board view.
- shmerl 11mo agoI need something that can run KDE Wayland session properly, including clipboard sync. VirtualBox has a broken clipboard (supposedly they plan to fix it), and it's only software rendering. How does VMware implement OpenGL and Vulkan acceleration in the VM?
- tuetuopay 11mo agoMy guess would be something akin to VirGL where they forward opengl/vulkan commands to the host. I've never dug into the nitty gritty, but VMware workstation is recognized as a GPU accelerated app, and exposes a virtual GPU in the VM. On the linux side, the vmwgfx kernel driver and DRM drivers are used. For X11 you use modesetting, and for Wayland whatever it auto-selects. I don't use KDE but I can confirm Debian's Gnome works out-of-the-box with the default Wayland backend (to be fair, the only other compositor I tried was Sway, which is known for being picky about the GPU used). Copy/paste works properly, as do general acceleration. I use those VMs daily, fullscreen on a 1440p monitor, so acceleration is not optional :)
- shmerl 11mo agoNice, I'll look into it, thanks!
- okanat 11mo ago
- Const-me 11mo agoI find WSL 1 incredibly useful. C++ and .NET compiler toolchains, ssh and scp clients, and many other command-line Linux tools are working flawlessly for me despite the fake emulated kernel lacking some of the APIs. When I develop anything related to Linux be it embedded or servers, I use WSL1 a lot. I find WSL2 pretty much useless. When I want Linux inside a VM I use VMware which is just better. VMware has tree of snapshots to rollback disk state, hardware accelerated 3D graphics (limited though, I think only GL is there no Vulkan, but it’s better than nothing), can attach complete USB devices to the guest OS, can setup proper virtual networks with multiple VMs, and the GUI to do all that is decent, no command line required.
- mshroyer 11mo agoSome distros have better WSL support than others—some will only work with systemd disabled, others have issues with X11. Ubuntu is well supported of course, but on the RHEL-ish side I've found that AlmaLinux 10 works especially well.