moved WSL1 to bottom - online edit of handbook/computing/wsllaptop.html [PosixPath('/home/philip/expo/expoweb/handbook/computing/wsllaptop.html')]

This commit is contained in:
Philip Sargent 2024-12-14 23:48:07 +00:00
parent 3159669839
commit a0a0864141

View File

@ -21,8 +21,81 @@
<br>
<a href="winlaptop.html">Setting up a Windows machine for expo bulk data rearrangements</a>
</p>
In late 2022 a new way of <a href="https://www.theregister.com/2022/11/23/wsl_microsoft_store_default_version/">
installing and using WSL</a> was announced and this page has been revised to match. <a href="https://learn.microsoft.com/en-us/windows/wsl/compare-versions?source=recommendations">WSL2 is now noticeably even slower</a> for NTFS files, so now it is only really useable if you move all the troggle code into your Linux filespace on <var>\\wsl.localhost\Ubuntu-22.04\home</var> which means that those files will only be accesible from Linux. Buggeration. If you have to use NTFS for those files for some other reason, you would need to revert to using WSL1.
This is how to <a href="https://www.theregister.com/2022/11/23/wsl_microsoft_store_default_version/">
install and use WSL</a> and by default we use Ubuntu24.04. We assume that you have a relatively recent machine. If not, see the bottom of this page about WSL1, which is different and old.
<p>You will be doing all your work in the
<var>\\wsl.localhost\Ubuntu\home\username\expo\</var>filesystem, not in <var>C:/Users/username/expo</var> not even if you have mounted it as <var>/mnt/c/username/expo</var>. If you try that you will hit file permissions problems and it will also be quite slow (but see WSL1 below).
<h4>WSL - Creating another ssh key</h4>
<p>If you have PuTTY installed and working, but you now want to use WSL rsync, you need to set up a key again within the WSL environment.
<p>[ Now that Microsoft allows installation of OpenSSL using <a href="">standard Windows tools</a> on Windows 10 and 11, we need someone to revise all the Windows/troggle documentation for a PuTty-free route. Volunteers? ]
<p> So on a machine with WSL enabled, click on "Ubuntu" in the start menu system under "Apps"
<br />
which puts you into the WSL environment with a new command prompt, e.g.<br />
<span style="font-family:monospace; size=x-small; background-color: lightgray">
<span style="color: green">
username@machinename</span><span style="color: yellow">:~</span>$
</span>
where 'username' is your logged-in user name.
<p>and now you can setup keys in the same way as you would on a Linux machine using ssh-keygen:
<pre>
<tt>$ <b>ssh-keygen -C "username@machinename-wsl"</b>
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): <b>id_rsa_wsl</b>
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in <em>id_rsa_wsl</em>.
Your public key has been saved in <em>id_rsa_wsl.pub</em>.
The key fingerprint is:
SHA256:ySs0YD5IG2ZD50+riUDHWosNq+WJdqpkDlINXh709r0 philip@muscogee-wsl
The key's randomart image is:
+---[RSA 2048]----+
| . o |
| ..+ . |
| oB+* + |
|.=O%.* + o |
|.+*o= = S . |
|.* o = . . . |
|=++.o . . E |
|B o . |
|oo |
+----[SHA256]-----+
$
</tt>
</pre>
The generated key is in the current directory and you need to move them to ~/.ssh/ as is standard on Linux (which is not at all the same place that puTTY uses to keep keys on Windows).
<p>Now you have to complete the <a href="keyexchange.html">key-pair setup</a> with the new key "id_ras_wsl.pub". But you don't need anyone else's help this time as you can use puTTY to ssh into the server and copy your key to the right place yourself: it is a <a href="keyexchange.html#secondmachine">"Second Machine"</a>.
<p>
Now finally you can use all the usual command line tools at your wsl command line to communicate with the server with ssh, scp, rsync, such as:
<pre>
<tt>rsync -nazv --delete-after --prune-empty-dirs expo@expo.survex.com:expofiles/ expofiles</tt></pre>
<p>If you are disturbed by the instructions to produce an entirely different SSL key for WSL to use when your PC already has a perfectly good PuTTy key installed on the server, then you are right. It is inelegant. But it works, the instructions are shorter and there are fewer things that go wrong. If you are terribly offended by that then you can set your PC up to use one key shared between WSL and normal-Windows as described in <a href="https://devblogs.microsoft.com/commandline/sharing-ssh-keys-between-windows-and-wsl-2/">this October 2019 article</a>. (Don't set up a password on the key because then you don't need to install keychain.) But beware, this sort of thing goes out of date quite rapidly.
<h3 id="pain">Python on WSL</h3>
<p>WSL installs python by default, but it may be a rather old python (depending on the history of your laptop, phase of moon etc.) and if you want development speed you want python3.13. [NB check what version of python is running on the server. It was 3.11.2 in December 2024.].
<p>We used to have lengthy instructions fo installing python using "deadsnakes" but since December 2024 we just use the <var>uv</var> utility for everything.
<p>To install python3.11 and pip follow <a href="https://www.linuxcapable.com/how-to-install-python-3-11-on-ubuntu-linux/">these instructions</a> to the letter. But that's not enough, you need to configure pip to work properly with python3.11 (this is because it's a bit bleeding edge as yet), so you ALSO then need to re-install the latest with:
</p>
<code><pre>
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
and test the result using:
python3.11 -m pip --version
</pre></code>
<p>The error you are trying to get rid of when attempting to use pip looks like this:<br />
<var>ImportError: cannot import name 'html5lib' from ...</var>
<h3>WSL1 Historic problems</h3>
<a href="https://learn.microsoft.com/en-us/windows/wsl/compare-versions?source=recommendations">WSL2 is now noticeably even slower</a> for NTFS files mounted as /mnt/c or /mnt/d, so now it is only really useable if you move all the troggle code into your Linux filespace on <var>\\wsl.localhost\Ubuntu-22.04\home</var> which means that those files will only be accesible from Linux. Buggeration.
<h3>WSL1 and WSL2</h3>
<p>WSL now installs as WSL2 by default, but older machines (mostly laptops) may not have the Hyper-V Virtualization hardware and may have to run WSL1.
This may be fine: the behaviour is nearly identical so far as an expo laptop is concerned, where you just want to use rsync and scp. An old 2011-era PC had
@ -58,62 +131,8 @@ permissions that are fundamentally different things and are never in sync in any
href="https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/">All sorts of fun</a> results. The alternative is to store all your data
in the \\wsl$\ ext4 filesystem (WSL2 only, not WSL1).
<p>If you are disturbed by the instructions to produce an entirely different SSL key for WSL to use when your PC already has a perfectly good PuTTy key installed on the server, then you are right. It is inelegant. But it works, the instructions are shorter and there are fewer things that go wrong. If you are terribly offended by that then you can set your PC up to use one key shared between WSL and normal-Windows as described in <a href="https://devblogs.microsoft.com/commandline/sharing-ssh-keys-between-windows-and-wsl-2/">this October 2019 article</a>. (Don't set up a password on the key because then you don't need to install keychain.) But beware, this sort of thing goes out of date quite rapidly.
<h4>WSL - Creating another ssh key</h4>
<p>If you have PuTTY installed and working, but you now want to use WSL rsync, you need to set up a key again within the WSL environment.
<p>[ Now that Microsoft allows installation of OpenSSL using <a href="">standard Windows tools</a> on Windows 10 and 11, we need someone to revise all the Windows/troggle documentation for a PuTty-free route. Volunteers? ]
<p> So on a machine with WSL enabled, create an ordinary cmd window and get into the WSL environment using the wsl command:<br />
<span style="font-family:monospace; size=x-small; background-color: lightgray">
D:\CUCC-Expo\expoweb\ <font color=red>wsl</font>
</span>
<br />
which puts you into the WSL environment with a new command prompt, e.g.<br />
<span style="font-family:monospace; size=x-small; background-color: lightgray">
<span style="color: green">
philip@Muscogee</span><span style="color: yellow">:/mnt/c/Users/Philip</span>$
</span>
<p>and now you can setup keys in the same way as you would on a Linux machine using ssh-keygen:
<pre>
<tt>$ <b>ssh-keygen -C "philip@muscogee-wsl"</b>
Generating public/private rsa key pair.
Enter file in which to save the key (/home/philip/.ssh/id_rsa): <b>id_rsa_wsl</b>
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in <em>id_rsa_wsl</em>.
Your public key has been saved in <em>id_rsa_wsl.pub</em>.
The key fingerprint is:
SHA256:ySs0YD5IG2ZD50+riUDHWosNq+WJdqpkDlINXh709r0 philip@muscogee-wsl
The key's randomart image is:
+---[RSA 2048]----+
| . o |
| ..+ . |
| oB+* + |
|.=O%.* + o |
|.+*o= = S . |
|.* o = . . . |
|=++.o . . E |
|B o . |
|oo |
+----[SHA256]-----+
$
</tt>
</pre>
The generated key is in the current directory and you need to move them to ~/.ssh/ as is standard on Linux (which is not at all the same place that puTTY uses to keep keys on Windows).
<p>Now you have to complete the <a href="keyexchange.html">key-pair setup</a> with the new key "id_ras_wsl.pub". But you don't need anyone else's help this time as you can use puTTY to ssh into the server and copy your key to the right place yourself: it is a <a href="keyexchange.html#secondmachine">"Second Machine"</a>.
<p>
Now finally you can use all the usual command line tools at yor wsl command line to communicate with the server with ssh, scp, rsync, such as:
<pre>
<tt>rsync -nazv --delete-after --prune-empty-dirs expo@expo.survex.com:expofiles/ expofiles</tt></pre>
<p>But this only works with WSL1 not WSL2 ! Under WSL1 it doesn't matter if your /expofiles/ is mounted on the Linux filesystem,
typically under /home/expo/expofiles, or whether it it in the NTFS filesystem mount for Linux as,
e.g. /mnt/d/expofiles.
but under WSL2 rsync to /mnt/d/expofiles fails, either with a permissions problem or, if you try sudo rsync.. ,
with a ssh authentication failure (why? Given that we explicitly state that we want to be user expo@ ?). Ghastly anyway. See next section, where the
same problem appears on WSL1.
<p>All of which is really a bit ridiculous if all you want to do is to use rsync on a Windows machine to sort out some photos.
<h3 id="permissions">Permissions, permissions..</h3>
<p>Having happily used WSL1 in this manner for a couple of years, it was a rude awakening to try this with a new laptop with a small
hard-drive, so all the expo code was re-mounted on a plugged-in SD card. The problem of permissions that seemed to be a WSL2 issue reappeared with
@ -162,22 +181,11 @@ and <a href="https://www.windowscentral.com/how-install-wsl2-windows-10">here</a
<tt><a href="https://www.scivision.dev/mount-usb-drives-windows-subsystem-for-linux/">mount-usb-drives-windows-subsystem-for-linux</a></tt>
<tt><a href="https://man.openbsd.org/ssh">ssh command line</a></tt>
<h3 id="pain">The pain continues: Python on WSL2 </h3>
<p>WSL2 installs python by default, but it may be a rather old python (depending on the history of your laptop, phase of moon etc.) and if you want development speed you want python3.11. [NB check what version of python is running on the server. It was 3.11.2 in April 2024.]
<p>To install python3.11 and pip follow <a href="https://www.linuxcapable.com/how-to-install-python-3-11-on-ubuntu-linux/">these instructions</a> to the letter. But that's not enough, you need to configure pip to work properly with python3.11 (this is because it's a bit bleeding edge as yet), so you ALSO then need to re-install the latest with:
</p>
<code><pre>
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
and test the result using:
python3.11 -m pip --version
</pre></code>
<p>The error you are trying to get rid of when attempting to use pip looks like this:<br />
<var>ImportError: cannot import name 'html5lib' from ...</var>
<hr />
Go back to: &#8251;<a href="basiclaptop.html">Basic laptop</a><br />
Go back to: &#8258;<a href="surveylaptop.html">Survey laptop</a><br />
Go back to: &#9775;<a href="winlaptop.html">Windows Bulk Update laptop</a><br />
Go back to: &#8251; <a href="basiclaptop.html">Basic laptop</a><br />
Go back to: &#8258; <a href="surveylaptop.html">Survey laptop</a><br />
Go back to: &#9775; <a href="winlaptop.html">Windows Bulk Update laptop</a><br />
Go back to: &#9874; <a href="troglaptop.html">Troggle development laptop</a><br />
<hr /></body>
</html>