WSL (Windoze Subsystem for Linux)
Work in progress
This page is a work in progress. Check back later!
Introduction
I think I tried WSL a few years ago and wasn't especially impressed. At work, I have a Windoze laptop and would do a lot of real work on an Openstack Linux machine.
I made a lot of use of VSCode's Remote SSH plugin to edit files on the Linux machine from the laptop but would occasionally have trouble with it working for me. In 2024, VSCode was causing me grief because the server code was taking over the remote CPU and it became so intolerable that I stopped using VSCode for a while. I asked colleagues with whom I worked if they had better solutions on Windoze laptops and someone said they used WSL. I asked him some more questions and it sounded very encouraging so I checked it out.
Now I'm basically doing all of my work on the WSL machine. I even went ahead and installed WSL on my home Windoze laptop as well.
Why Windoze???
At my current job, employees are given the choice of Mac or Windoze laptops. I'm a contractor and I don't even think they gave me a choice when I first started a couple of years ago - I just got Windoze. I've heard that contractors aren't even allowed to request Macs for some reason - I think there was another contractor on my team who was assigned a Mac but eventually had to return it for Windoze for some stupid reason. I don't even have that much experience with Macs and don't know if I would like it or not.
Links
Here are some links to help you get started
General Information about WSL
Check out What is the Windows Subsystem for Linux?
Instructions for installing WSL and installing a Linux Distro
Check out How to install Linux on Windows with WSL.
Enable virtualization!
Be aware that Virtualization must be enabled on the Windoze machine. When I first wanted to install WSL, vitualization was not enabled:
PS C:\Windows\system32> wsl --install Ubuntu-22.04 Ubuntu 22.04 LTS is already installed. Launching Ubuntu 22.04 LTS... Installing, this may take a few minutes... WslRegisterDistribution failed with error: 0x80370102 Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS. For information please visit https://aka.ms/enablevirtualization Press any key to continue... The operation completed successfully. PS C:\Windows\system32> systeminfo.exe Host Name: JCP-20230922 OS Name: Microsoft Windows 11 Enterprise OS Version: 10.0.22631 N/A Build 22631 . . . [01]: 10.24.98.199 [02]: fe80::e0c6:9638:4c6c:93e3 [03]: 2001:420:c0c8:1004::23 Hyper-V Requirements: VM Monitor Mode Extensions: Yes Virtualization Enabled In Firmware: No Second Level Address Translation: Yes Data Execution Prevention Available: Yes PS C:\Windows\system32>
I had to enable virtualization from my laptop's BIOS:
I even had to look up tips from the Internet to bring up the BIOS menu so your mileage may vary!
wsl man page
I couldn't find a decent man page of the wsl command so I captured the online help and saved in a Gist file.
Likes
There are some things I like about WSL.
Great command line interface!
In my job, I'm super comfortable in the Linux command line and don't need don't require a Linux GUI... I'm fine using Windoze for my web browser and other graphical apps.
WSL is an excellent replacement for the Linux command line! All the commands I except are there, they work like I expect, and if there are commands that weren't installed, I can install them just like any Linux system! I sometimes forget that I haven't ssh'ed into a real Linux machine
So Windoze did something good!
Access to Windoze files
The WSL machine has a different filespace but one of the most attractive things about WSL was the fact that I could easily get to any file in the Windows space. You just have to start the path with /mnt/c/.
For instance, you can run the Windoze Notepad app via /mnt/c/WINDOWS/system32/notepad.exe. However, because WSL has a different file space so although you can start Notepad, you can't use it to edit a file in the WSL file space! Still, there's a huge benefit to access to Windoze files.
Symbolic links
I've actually set up symbolic links to some important files and directories which actually live in the Window space. For example, for years, I've used Cygwin instead of a Windoze command prompt and have some Github repos in Windows - some directories are present in my PATH! Rather than duplicate the repos, I use symlinks:
ln -sv /mnt/c/cygwin64/home/mrbruno/repos ~/repos
I host most of my Github repos in Windows, set up one or more symlinks, and edit them in WSL with vi. I can also edit the repos with VSCode and it's all very seamless.
Dislikes
There are some things I do not like about WSL.
Networking
My biggest complaint has to be VPN. I'm mostly using WSL on my work laptop and I have to be on VPN to get to my company's network. It doesn't appear as though the WSL team put any thought at all into working with VPN and I'm not the only person who has had trouble. You'll find all sorts of posts and tips about what to do and I didn't find a single silver bullet. I eventually got it working but I basically had to use /etc/resolv.conf from a colleague at work who got WSL working.
Network performance
I'm used to using Linux on an Openstack machine hosted by the company for whom I work. I would ssh in and the command prompt is all I need. Compared to WSL, network-intensive operations (for instance, pulling a Docker image or downloading a large tarball) can take much longer. Not only do operations depend more on your ISP but there's your home network (possibly WiFi). The point is these devices likely don't process traffic at the same speed as commercial equipment. When I was using Openstack, the data never had to reach my laptop!
Side-by-side comparison
I want to compare performance of a large file on WSL compared to Openstack. I am choosing to use AlmaLinux-9-latest-x86_64-dvd.iso (10,916,724,736 bytes, 11GB, md5sum: c78e2b04410f98fa1a29f2b0b8e60077) because it's quite large. I'm also using speedtest-cli to measure the speed.WSL example
$ speedtest Speedtest by Ookla Server: Wavefly - Raleigh, NC (id: 51030) ISP: noyb Idle Latency: 39.35 ms (jitter: 1.69ms, low: 39.13ms, high: 42.53ms) Download: 259.49 Mbps (data used: 434.9 MB) 556.94 ms (jitter: 82.65ms, low: 38.45ms, high: 2325.42ms) Upload: 169.79 Mbps (data used: 227.9 MB) 149.73 ms (jitter: 47.05ms, low: 38.98ms, high: 237.16ms) Packet Loss: Not available. Result URL: noyb $ /usr/bin/time wget https://mirror.vtti.vt.edu/almalinux/9.3/isos/x86_64/AlmaLinux-9-latest-x86_64-dvd.iso --2024-04-14 09:12:47-- https://mirror.vtti.vt.edu/almalinux/9.3/isos/x86_64/AlmaLinux-9-latest-x86_64-dvd.iso Resolving mirror.vtti.vt.edu (mirror.vtti.vt.edu)... 198.82.152.116, 2001:468:c80:2133:0:b0e2:0:9874 Connecting to mirror.vtti.vt.edu (mirror.vtti.vt.edu)|198.82.152.116|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 10916724736 (10G) [application/octet-stream] Saving to: ‘AlmaLinux-9-latest-x86_64-dvd.iso.1’ AlmaLinux-9-latest-x86_64-dv 100%[===========================================>] 10.17G 20.2MB/s in 9m 41s 2024-04-14 09:22:29 (17.9 MB/s) - ‘AlmaLinux-9-latest-x86_64-dvd.iso.1’ saved [10916724736/10916724736] 18.41user 48.91system 9:41.49elapsed 11%CPU (0avgtext+0avgdata 9024maxresident)k 0inputs+21321888outputs (0major+661minor)pagefaults 0swaps $
Openstack example
$ /usr/bin/time wget https://mirror.vtti.vt.edu/almalinux/9.3/isos/x86_64/AlmaLinux-9-latest-x86_64-dvd.iso --2024-04-14 09:06:57-- https://mirror.vtti.vt.edu/almalinux/9.3/isos/x86_64/AlmaLinux-9-latest-x86_64-dvd.iso Resolving mirror.vtti.vt.edu (mirror.vtti.vt.edu)... 198.82.152.116, 2001:468:c80:2133:0:b0e2:0:9874 Connecting to mirror.vtti.vt.edu (mirror.vtti.vt.edu)|198.82.152.116|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 10916724736 (10G) [application/octet-stream] Saving to: ‘AlmaLinux-9-latest-x86_64-dvd.iso.1’ AlmaLinux-9-latest-x86_64-dv 100%[===========================================>] 10.17G 55.8MB/s in 2m 52s 2024-04-14 09:09:50 (60.5 MB/s) - ‘AlmaLinux-9-latest-x86_64-dvd.iso.1’ saved [10916724736/10916724736] 12.48user 52.31system 2:52.38elapsed 37%CPU (0avgtext+0avgdata 6568maxresident)k 4784inputs+21321768outputs (34major+410minor)pagefaults 0swaps $
You may have noticed that I didn't include the speedtest result. That's because it didn't work. I figure there are firewall rules set up at my work Openstack host so speedtest can't reach its servers:
$ speedtest Speedtest by Ookla [error] Error: [101] Network unreachable [error] Error: [0] Timeout occurred in connect. [error] Error: [0] Timeout occurred in connect. [error] Error: [101] Network unreachable [error] Error: [101] Network unreachable [error] Error: [0] Timeout occurred in connect. [error] Error: [0] Timeout occurred in connect. [error] Error: [0] Timeout occurred in connect. [error] Error: [101] Network unreachable [error] Error: [0] Timeout occurred in connect. [error] Server Selection - Failed to find a working test server. (NoServers) $
But you can see that there's a serious difference in time.
Lack of a real cron service
Sure, WSL has commands like crontab and even a cron service but what good is it when you shut your laptop down?? I miss a real cron service on my Openstack machine... although I didn't have a lot of cronjobs and recently lost the need to have those... it's a long story but I've shifted from using persistent cloud credentials to credentials that are only good for eight hours... the cronjobs depended on the credentials so I've already disabled the cronjobs.
Limited Linux distributions
I'm not impressed with the distributions WSL supports. Sure there are options but I don't think any of them are from the Redhat family including CentOS or Alma:
$ wsl --list --online The following is a list of valid distributions that can be installed. Install using 'wsl.exe --install <Distro>'. NAME FRIENDLY NAME Ubuntu Ubuntu Debian Debian GNU/Linux kali-linux Kali Linux Rolling Ubuntu-18.04 Ubuntu 18.04 LTS Ubuntu-20.04 Ubuntu 20.04 LTS Ubuntu-22.04 Ubuntu 22.04 LTS Ubuntu-24.04 Ubuntu 24.04 LTS OracleLinux_7_9 Oracle Linux 7.9 OracleLinux_8_7 Oracle Linux 8.7 OracleLinux_9_1 Oracle Linux 9.1 openSUSE-Leap-15.5 openSUSE Leap 15.5 SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4 SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5 openSUSE-Tumbleweed openSUSE Tumbleweed $
At my job, I deal with a variety of Linux systems but only Redhat and Debian families (along with Alpine in containers). I'm impressed that they have Ubuntu 24 but a little confused that they don't have a variety of Debian releases.
I don't think I've ever used Oracle or kali and it's been years since I've touched SUSE. I don't see them at work much either.
I installed Ubuntu 22 in WSL on my laptops... I'm used to Ubuntu and Ubuntu 22 is supported for a while. In contrast, Ubuntu 18 ended standard support in 2023!
Tips
I learned some other tips you might find useful with WSL.
Avoid the shutdown command!
Lately I've found shutdown -r 1 to be the easiest way to do a reboot a Linux machine and recover control of your shell before the reboot but you should avoid the command in WSL.
The first time I experimented with shutdown on WSL, I had trouble starting it back up again!
<3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_2.1.5.0_x64__8wekyb3d8bbwe <3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Common Files\Oracle\Java\javapath <3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\system32 <3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows <3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\System32\Wbem <3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\System32\WindowsPowerShell\v1.0\ <3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Windows\System32\OpenSSH\ <3>WSL (705) ERROR: UtilTranslatePathList:2866: Failed to translate C:\Program Files\Microsoft VS Code\bin $
I thought it might not recover until I rebooted... possibly, some intervention had to take place! But eventually (after at least 15 minutes, I think!) it worked fine. In contrast, a simple reboot on a real Linux machine only takes a minute or two.
See WSL Shutdown for a better way to restart WSL.
WSL Shutdown
From No internet connection on WSL Ubuntu (Windows Subsystem for Linux), I learned this is a good command to restart WSL (if necessary):
wsl --shutdown
Running Windoze commands from inside WSL
I’ve seen this in various posts including No internet connection on WSL Ubuntu (Windows Subsystem for Linux):
$ /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command 'Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList' foo.com $
I think this is useful enough to set up an alias:
$ grep windows .bashrc alias windows='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe' $ windows -Command 'Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList' foo.com $
Look at that! I didn’t even use my regular nickname for Windoze! I’m not sure if this is only for PowerShell or what. Frankly, at this point, I still don’t understand the difference between PowerShell and the regular Wiundoze command prompt - and I don't really care enough to learn the difference. I don't have a need to know the difference and there's a lot of other stuff I would rather learn. The example is pretty contrived too and I don't expect to issue it or remember it but the point is that it's possible.
Running WSL commands from Windoze
You can run a Linux command directly from a Windoze command prompt:
PS C:\Users\jpfuntne> wsl cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.3 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.3 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy PS C:\Users\jpfuntne>
I think I learned this from Accessing a WSL 2 distribution from your local area network (LAN). This could be a good way of having something in the Windoze space accessing a file in the WSL space:
$ wsl cat /etc/os-release | awk -F \" '/PRETTY_NAME=/ { print $2 }' Ubuntu 22.04.3 LTS $
As I previously said, I usually a Cygwin prompt instead of a regular Windoze prompt so this is a Linux command but it's running in the Windoze space and doesn't have direct access to the WSL file space.
Deleting a distro
So I was chugging along with my WSL distro and was quite happy with it. I had a need to create a small distro to test something so I installed another one for Ubuntu 20 at work. I don't think it had even finished before I thought better because I had nightmares of all the trouble I had with VPN. So I wanted to remove it immediately. I think I did a command like:
wsl --uninstall Ubuntu-20.04
I'm pretty sure I used wsl --install Ubuntu-20.04 to install the second distro but, suffice to say, wsl --uninstall wasn't the command I wanted! Because shortly thereafter, my regular distro stopped working and I couldn't get back in! When I ran wsl, it would just give me the help text and I was kind of baffled. It appeared that my regular distro was gone! I rebooted and hoped it would just pop back but no!
I believe the --uninstall actually uninstalled the WSL engine on my laptop! I hoped that I could just reinstall WSL so I did that and rebooted again and my distro hadn't been removed! I was very relieved that my distro was safe!
And to be complete, it looks like the command I wanted to remove the second distro was:
wsl --unregister Ubuntu-20.04
It was amazingly quick but it seemed to do what I wanted. I checked and it had not just put a file in the trash can.
I wasn't sure to call this a tip or dislike/gripe but I settled on a tip!