-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsl.html
executable file
·273 lines (261 loc) · 20.5 KB
/
wsl.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<html>
<head>
<link rel="stylesheet" href="stylesheet.css">
<title>WSL</title>
</head>
<body>
<div class="main">
<h1>WSL <span class="italic">(Windoze Subsystem for Linux)</span></h1>
<h4>Work in progress</h4>
<p><span class="italic">This page is a <span style="italic">work in progress</span>. Check back later for updates!</span></p>
<h2>Introduction</h2>
<p>I think I tried WSL a few years ago and wasn't especially impressed.</p>
<p>At work, I have a Windoze laptop and would do a lot of <span class="italic">real work</span> 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.</p>
<p>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.</p>
<h3>Why Windoze???</h3>
<p>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.</p>
<p>At home, my main machine is true Linux but I have a laptop with Windoze.</p>
<hr/>
<h2>Links</h2>
<p>Here are some links to help you get started
<h3>General Information about WSL</h3>
Check out <a href="https://learn.microsoft.com/en-us/windows/wsl/about"><span class="italic">What is the Windows Subsystem for Linux?</span></a><p>
<h3>Instructions for installing WSL and installing a Linux Distro</h3>
<p>Check out <a href="https://learn.microsoft.com/en-us/windows/wsl/install"><span class="italic">How to install Linux on Windows with WSL</span></a>.</p>
<h4>Enable virtualization!</h4>
<p>Be aware that <span class="italic">Virtualization</span> must be enabled on the Windoze machine. When I first wanted to install WSL, vitualization was not enabled:</p>
<pre class="indent smaller-text">
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>
</pre>
<p>I had to enable virtualization from my laptop's BIOS:</p>
<div class="indent">
<img src="images/virtualization.png" width="690" height="518"/>
</div>
<p>I even had to look up tips from the Internet to bring up the BIOS menu so your mileage may vary!</p>
<h3><span class="monospaced">wsl</span> man page</h3>
<p>I couldn't find a decent <span class="italic">man page</span> of the <span class="monospaced">wsl</span> command so I captured the online help and saved in <a href="https://gist.githubusercontent.com/pfuntner/7055ea04c84199fed503c1a2798b4378/raw/5eba5215296595e54bf526b27850424e47304e03/wsl-man.txt">a Gist file</a>.</p>
<hr/>
<h2>Likes</h2>
<p>There are some things I like about WSL.
<h3>Great command line interface!</h3>
<p>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.</p>
<p>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 <span class="italic">real</span> Linux machine</p>
<p>So Windoze did something good!</p>
<h3>Access to Windoze files</h3>
<p>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 <span class="monospaced">/mnt/c/</span>.</p>
<p>For instance, you can run the Windoze Notepad app via <span class="monospaced">/mnt/c/WINDOWS/system32/notepad.exe</span>. <span class="bold">However</span>, because WSL has a different file space so although you can <span class="italic">start</span> Notepad, you can't use it to <span class="italic">edit</span> a file in the WSL file space! Still, there's a huge benefit to access to Windoze files.</p>
<h4>Symbolic links</h4>
<p>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 <a href="https://www.cygwin.com/">Cygwin</a> instead of a Windoze command prompt and have some Github repos in Windows - some directories are present in my <span class="monospaced">PATH</span>! Rather than duplicate the repos, I use symlinks:
</p>
<pre class="indent smaller-text">
ln -sv /mnt/c/cygwin64/home/mrbruno/repos ~/repos
</pre>
<p>I host most of my Github repos in Windows, set up one or more symlinks, and edit them in WSL with <span class="monospaced">vi</span>. I can also edit the repos with VSCode and it's all very seamless.
</p>
<hr/>
<h2>Dislikes</h2>
<p>There are some things I <span class="bold">do not like</span> about WSL.
<h3>Networking</h3>
<p>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 <span class="italic">silver bullet</span>. I eventually got it working but I basically had to use <span class="monospaced">/etc/resolv.conf</span> from a colleague at work who got WSL working.</p>
<h3>Network performance</h3>
<p>I'm used to using Linux on an Openstack machine hosted by the company for whom I work. I would <span class="monospaced">ssh</span> 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!</p>
<h4>Side-by-side comparison</h4>
I want to compare performance of a large file on WSL compared to Openstack. I am choosing to use <a href="https://mirror.vtti.vt.edu/almalinux/9.3/isos/x86_64/AlmaLinux-9-latest-x86_64-dvd.iso">AlmaLinux-9-latest-x86_64-dvd.iso</a> (10,916,724,736 bytes, 11GB, md5sum: <span class="monospaced">c78e2b04410f98fa1a29f2b0b8e60077</span>) because it's quite large. I'm also using <a href="https://www.speedtest.net/apps/cli">speedtest-cli</a> to measure the speed.
<h5>WSL example</h5>
<pre class="indent smaller-text">
$ 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
$
</pre>
<!-- Result URL: https://www.speedtest.net/result/c/d893803d-e808-4a44-bf8a-bd13f8108ca2 -->
<h5>Openstack example</h5>
<pre class="indent smaller-text">
$ /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
$
</pre>
<p>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:</p>
<pre class="indent smaller-text">
$ 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)
$
</pre>
<p>
But you can see that there's a serious difference in time.
</p>
<h3>Lack of a <span class="italic">real</span> <span class="monospaced">cron</span> service</h3>
<p>Sure, WSL has commands like <span class="monospaced">crontab</span> and even a <span class="monospaced">cron</span> service but what good is it when you shut your laptop down?? I miss a real <span class="monospaced">cron</span> 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.</p>
<hr/>
<h3>Limited Linux distributions</h3>
<p>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:</p>
<pre class="indent smaller-text">
$ 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
$
</pre>
<p>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.</p>
<p>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.</p>
<p>I installed Ubuntu 22 in WSL on my laptops... I'm used to Ubuntu and <a href="https://ubuntu.com/about/release-cycle">Ubuntu 22 is supported for a while</a>. In contrast, Ubuntu 18 ended standard support in 2023!</p>
<h2>Tips</h2>
<p>I learned some other tips you might find useful with WSL.
<h3>Avoid the <span class="monospaced">shutdown</span> command!</h3>
<p>Lately I've found <span class="monospaced">shutdown -r 1</span> 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.</p>
<p>The first time I experimented with <span class="monospaced">shutdown</span> on WSL, I had trouble starting it back up again!</p>
<pre class="indent smaller-text">
<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
$
</pre>
<p>I thought it might not recover until I rebooted... possibly, some intervention had to take place! But eventually <span class="italic">(after at least 15 minutes, I think!)</span> it worked fine. In contrast, a <span class="italic">simple</span> reboot on a <span class="italic">real</span> Linux machine only takes a minute or two.</p>
<p>See <a href="#wsl_shutdown"><span class="italic">WSL Shutdown</span></a> for a better way to restart WSL.</p>
<h3 id="wsl_shutdown">WSL Shutdown</h3>
<p>From <a href="https://stackoverflow.com/questions/62314789/no-internet-connection-on-wsl-ubuntu-windows-subsystem-for-linux"><span class="italic">No internet connection on WSL Ubuntu (Windows Subsystem for Linux)</span></a>, I learned this is a good command to restart WSL (if necessary):</p>
<pre class="indent smaller-text">
wsl --shutdown
</pre>
<h3>Running Windoze commands from inside WSL</h3>
<p>I've seen this in various posts including <a href="https://stackoverflow.com/questions/62314789/no-internet-connection-on-wsl-ubuntu-windows-subsystem-for-linux"><span class="italic">No internet connection on WSL Ubuntu (Windows Subsystem for Linux)</span></a>:</p>
<pre class="indent smaller-text">
$ /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command 'Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList'
foo.com
$
</pre>
<p>I think this is useful enough to set up an alias:</p>
<pre class="indent smaller-text">
$ grep windows .bashrc
alias windows='/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe'
$ windows -Command 'Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList'
foo.com
$
</pre>
<p>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.</p>
<h3>Running WSL commands from Windoze</h3>
<p>You can run a Linux command directly from a Windoze command prompt:</p>
<pre class="indent smaller-text">
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>
</pre>
<p>I think I learned this from <a href="https://learn.microsoft.com/en-us/windows/wsl/networking"><span class="italic">Accessing a WSL 2 distribution from your local area network (LAN)</span></a>. This could be a good way of having something in the Windoze space accessing a file in the WSL space:</p>
<pre class="indent smaller-text">
$ wsl cat /etc/os-release | awk -F \" '/PRETTY_NAME=/ { print $2 }'
Ubuntu 22.04.3 LTS
$
</pre>
<p>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.</p>
<h3>Deleting a distro</h3>
<p>So I was chugging along with my WSL distro and was quite happy with it. I had a need to create a <span class="italic">small</span> 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:</p>
<pre class="indent smaller-text">
wsl --uninstall Ubuntu-20.04
</pre>
<p>I'm pretty sure I used <span class="monospaced">wsl --install Ubuntu-20.04</span> to install the second distro but, suffice to say, <span class="monospaced">wsl --uninstall</span> wasn't the command I wanted! Because shortly thereafter, my regular distro stopped working and I couldn't get back in! When I ran <span class="monospace">wsl</span>, it would just give me the help text and I was kind of baffled. It appeared that my regular distro was <span class="italic">gone</span>! I rebooted and hoped it would just pop back but no!</p>
<p>I believe the <span class="monospaced">--uninstall</span> 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!</p>
<p>And to be complete, it looks like the command I wanted to remove the second distro was:</p>
<pre class="indent smaller-text">
wsl --unregister Ubuntu-20.04
</pre>
<p>It was <span class="italic">amazingly quick</span> but it seemed to do what I wanted. I checked and it had not just put a file in the trash can.</p>
<p>I wasn't sure to call this a <span class="italic">tip</span> or <span class="italic">dislike/gripe</span> but I settled on a tip!</p>
<hr/>
</div>
<div class="footer">
<p>Learn more about github.io at <a href="https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages">Working with GitHub Pages</a>.</p>
</div>
</body>
</html>