From 1be6e5cbfe977aab9766b8a3b67adab4e08359db Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 22 Dec 2022 15:10:14 +0000 Subject: [PATCH] Revised all WSL documentaiton --- handbook/computing/bulkupdatelaptop.html | 31 ++- handbook/computing/winlaptop.html | 249 +++++++++-------------- handbook/computing/wsllaptop.html | 98 ++++++++- handbook/survey/getin.htm | 11 +- 4 files changed, 213 insertions(+), 176 deletions(-) diff --git a/handbook/computing/bulkupdatelaptop.html b/handbook/computing/bulkupdatelaptop.html index e83720bef..d42c9c72f 100644 --- a/handbook/computing/bulkupdatelaptop.html +++ b/handbook/computing/bulkupdatelaptop.html @@ -8,7 +8,7 @@

CUCC Expedition Handbook - Bulk Update laptop

-

Cave data - Bulk Updates

+

Cave data - Bulk Update Laptop

You will already have explored what your laptop can do in the basic Expo laptop guide, @@ -62,11 +62,7 @@ raw survey notes (surveyscans), scanned cave centre-line plots and everything el

You need to register a key with the expo server to get upload (i.e. read/write) access. Do this first, Without it none of git, scp, ftp or rsync will work. You can do this entirely on your own if you have access to the expo laptop to upload and install the public key generated by your laptop.

-

QMs and scripts

-

You may not need a full troggle software development machine if you are only fixing a small script. If you are, you need -

+

Your own Bulk Update laptop

@@ -99,6 +95,29 @@ You can do this entirely on your own if you have access to the expo laptopRead the Detailed Windows Configuration Instructions for foconfiguring a Windows Bulk Update machine. +

QMs and scripts

+

You may not need a full troggle software development machine if you are only fixing a small script. If you are, you need +

+ +

The Expo Laptop(s)

+

[These notes are to remind nerds when configuring or updating a replacement expo laptop.] +

The expo laptop is configured as a "Bulk Update" laptop (including al the "Survey laptop" tools), but has a few extras. +

Configuring git

On a new machine you need to configure your git identity: diff --git a/handbook/computing/winlaptop.html b/handbook/computing/winlaptop.html index 3d7a446bc..696e39b3a 100644 --- a/handbook/computing/winlaptop.html +++ b/handbook/computing/winlaptop.html @@ -14,47 +14,55 @@
Setting up a basic Expo laptop
-Setting up a machine for Expo survey processing +Setting up a 'survey laptop' for Expo survey processing

+

Unlike a Linux machine, on Windows there are two distinct levels of 'bulk update laptop' capability: +

    +
  1. Keys and key management, simple file transfer, scp, ftp +
  2. Synchronisation of entire file heirarchies: installation and use of rsync +
+

Level 1 - Windows Bulk Update

+ -
  • Possibly an even easier way to do it
    -- using OpenSSH for Windows

    Software

    -

    The above gets the command-line PuTTY tools (ssd, sftp, pscp) running, but doesn't get rsync working. You might like to try this (untested).

    +

    The above gets the command-line puTTY tools (ssd, sftp, pscp) running. -

    When using Windows please, please be excessively careful when naming files and survex names and be exceptionally careful when using rsync. +

    Most Windows software that we recommend "just works" if you have set up puTTY and have done the key-pair setup and are running a local ssh agent (pagent) automatically at boot up on your laptop. +

    Some software (such as Filezilla) defaults to using pageant and it "just works". -

    Things that already work well

    -

    Anything where the file upload and download is done via the verson control client software works really well. +

    When using Windows please, please be excessively careful when naming files and survex names. + +

    Configuring Filezilla or equivalents

    + +

    Filezilla defaults to using pageant and it "just works" if you used PuTTy. + + + +

    Configuring git

    +

    Idiots guide to setting up git for expo + - PDF - Brendan's guide. Uses puTTY and GitKraken on WIndows. Read this, but most people will need to use VS Code instead of Git Kraken. -

    Key management using PuTTy

    -

    Most Windows software that we recommend "just works" if you have set up PuTTy and have done the key-pair setup and are running a local ssh agent (pagent) automatically at boot up on your laptop.

    Some software, such as the commercial (but free) GitKraken, requires that you click a checkbox to say that you are "using local SSH agent" rather than specifying ssh private keys explicitly (File->Preferences->Authentication in GitKraken). -

    Some software (such as Filezilla) defaults to using the local agent and it "just works". -

    Brendan wrote a guide to using putty and git for expo on a Windows machine. It's worth reading and it has lots of screenshots: Idiots guide to accessing expo git.pdf. -

    Read the online instructions about using OpenSSH in Windows as an alternative. (Then write them up and edit this handbook to be more useful.)

    Things that cause problems

    Filenames

    Linux allows characters in filenames which Windows doesn't. There are also apparently normal filenames which Windows rejects (such as "CON") for historical reasons. Linux filenames are case-senstitive and Windows filenames aren't: beware. -

    Symbolic links and sFTP

    +

    Symbolic links and file-transfer

    Linux people like to use links. This is where there is really only one file, but it is referred to by different names. This is particularly useful when a file is moved, but you want people who have got the old location to still be able to find it. This happens quite a lot when updating handbooks.

    The links you are most likely to come across are that what looks like @@ -128,7 +145,7 @@ is a link to the file seem to have any hard links anywhere. -

    What really makes things unpleasant is that sFTP software won't tell you when it comes across a link and will just do something stupid. Our recommended sFTP software - Filezilla - is guilty of this,as it pftp (PuTTy) working in eith sFTP or scp mode.. So what happens is that when you download a load of files onto your laptop using Filezilla it will simply turn every link it finds into a complete copy of the file. Then when you upload those files to the server, the copied file overwrites the link. So the server now has two files with the same content - which is a maintenance nightmare. This is painfully stupid because if it is a symbolic link there is no reason why Filezilla couldn't just create a Windows Shortcut which would do exactly the same thing. But it doesn't. +

    What really makes things unpleasant is that sFTP software won't tell you when it comes across a link and will just do something stupid. Our recommended sFTP software - Filezilla - is guilty of this,as it pftp (puTTY) working in eith sFTP or scp mode.. So what happens is that when you download a load of files onto your laptop using Filezilla it will simply turn every link it finds into a complete copy of the file. Then when you upload those files to the server, the copied file overwrites the link. So the server now has two files with the same content - which is a maintenance nightmare. This is painfully stupid because if it is a symbolic link there is no reason why Filezilla couldn't just create a Windows Shortcut which would do exactly the same thing. But it doesn't.

    So the ordinary user won't notice any problems, but the nerds behind the scenes start to cuss and shout and generally carry-on in an expletive-heavy manner. @@ -139,10 +156,10 @@ There are two types of linux links: hard links and symbolic links. Symbolic link

  • When using the git version control systems the download of a link works fine. But be careful not to edit the link file downloaded (it is just a text file holding the path of the file holding the actual contents) because then the version control client would upload it to the server and overwrite the link on the server with something that isn't a link. It also won't work as a Windows shortcut, but at least the default behaviour isn't actively dangerous.
  • When using sFTP, manually check whether any files you are copying from the server are links - look at the symbol in Filezilla.
  • Be careful not to copy any links using sFTP and instead recreate them manually on the Windows filesystem using right-click "Create shortcut". -
  • You will have to find out what to make the shortcut link to by logging in to the server (using a PuTTy ssh logon) and doing "ls -l" in the folder where the link is. +
  • You will have to find out what to make the shortcut link to by logging in to the server (using a puTTY ssh logon) and doing "ls -l" in the folder where the link is.
  • But later, when re-uploading edited files from Windows to the server, Filezilla will see the Windows shortcut as a ".lnk" file which it will upload, but which will mean nothing to the linux server receiving it. So you would have to manually recreate the symbolic link by logging into the server using ssh and using the "ln -s" command. Yuk.
    -
  • Even if you use scp instead of sFTP, it does the same stupid thing when copying from a linux filesystem to a Windows filesystem. The PuTTy package includes pscp.exe but even if you force it to use the scp protocol like this: +
  • Even if you use scp instead of sFTP, it does the same stupid thing when copying from a linux filesystem to a Windows filesystem. The puTTY package includes pscp.exe but even if you force it to use the scp protocol like this: pscp -scp expo@expo.survex.com:expoweb/essentials.gpx . @@ -150,137 +167,55 @@ it downloads a copy of the contents of essentials.gpx and not a link.
  • A possible fix in the future might be to keep all your expo files in a separate partition of your hard disc which is formatted with a linux filesystem (such as ext4) and run the ext2ntfs driver to mount this fielsystem read-write from Windows. Probably not a good idea as the driver is a bit flaky in read-write mode and you could lose everything. - -

    Things that are really quite involved

    -

    The core problem is integrating the PuTTy key management software (pagent.exe) with a terminal window. We need a terminal window to run rsync as -none of the packaged software (Filezilla, PuTTy) includes an rsync client. -

    [Well, strickly speaking we need a Windows rsync executable, and this does exist, and a command-line ssh, which the 'OpenSSH in Windows' system -provides. But we haven't properly explored this set of mechanisms yet.] -

    The solution we have now for rsync is to use WSL and to create another key, distinct from the PuTTy one, and to upload that key to the expo -server. Because this is treating WSL as if it were a different machine requiring its own key quite separate from the Windows key. (This works the -same way in WSL1 and WSL2 - but see "Do you feel lucky, punk" below...) -

    [We are not the only people to find this nasty and irritating. Other -hacks are to use the obsolescent cygwin rsync or the rsync packaged within bash within more recent versions of 'Git for Windows' (which is built on MYSYS2. -If you are already familiar with any of these, then use them and not WSL.] - -

    WSL - Windows Subsystem for Linux

    -

    [On 23 November 2022 a new way of installing and using WSL was announced, see -Windows Subsystem for Linux now packaged as a Microsoft Store app so all documentation on this expo site needs to be revised.] -

    So on a machine with WSL enabled, create an ordinary cmd window and get into the WSL environment using the wsl command:
    - -D:\CUCC-Expo\expoweb\ wsl - -
    -which puts you into the WSL environment with a new command prompt, e.g.
    - - -philip@Muscogee:/mnt/c/Users/Philip$ - -

    and now you can setup keys in the same way as you would on a Linux machine using ssh-keygen: -

    -$ ssh-keygen -C "philip@muscogee-wsl"
    -Generating public/private rsa key pair.
    -Enter file in which to save the key (/home/philip/.ssh/id_rsa): id_rsa_wsl
    -Enter passphrase (empty for no passphrase):
    -Enter same passphrase again:
    -Your identification has been saved in id_rsa_wsl.
    -Your public key has been saved in id_rsa_wsl.pub.
    -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]-----+
    -$
    -
    -
    -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). -

    Now you have to complete the key-pair setup 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 "Second Machine". -

    -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: -

    -rsync -nazv --delete-after --prune-empty-dirs expo@expo.survex.com:expofiles/ expofiles
    -

    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. -Under WSL2 /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 sate that we want to be user expo@ ?). Ghastly anyway. See next section, where the -same problem appears on WSL1. -

    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. - -

    Permissions, permissions..

    -

    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 mounted on a plugged-in SD card. The problem of permissions that seemed to be a WSL2 issue reappeared with -a vengence on WSL1. -

    The recommended WSL procedure (Jan.2018) said to mount the drive using -a new 'metadata' setting: -

    sudo umount /mnt/d
    -sudo mount -t drvfs D: /mnt/d -o metadata,uid=1000,gid=1000,umask=22,fmask=111
    -

    This is probably why there is a difference between automatically-mounted drives (e.g. C:, /mnt/c) and plug-in drives: -"By default, WSL will set the uid and gid to the default user with drives that are auto-mounted during instance start. If you mount manually, you will -have to set these explicitly (the default user that gets created when WSL is first installed has a uid=1000 and gid=1000)." -

    And of course you will need to arrange that this happens automatically whenever you start WSL, so you will need to set -/etc/fstab, so ensure that the relevant line says: -

    D:           /mnt/d         drvfs   metadata,uid=1000,gid=1000,umask=22,fmask=11     0    0
    - -

    See also File Permissions for WSL (Dec. 2021). +

    Level 2 - Windows Bulk Synchronisation with rsync

    -

    "Are you feeling lucky, punk"

    -

    So here is the current wild frontier. Currently these are the ways to get a terminal window which you might expect to work: + +

    When using Windows please, please

    +

    rsync is a Linux command-line application, so we need a terminal window to run it and a Windows client executable. +None of the packaged software (Filezilla, puTTY) includes a Windows rsync client. +

    Windows comes with a terminal window (cmd.exe) so we 'just' need a native Windows rsync executable rsync.exe. +

    +disadvantage that you may not have easy access to the files from Windows. + + +

    If you just want rsync, then please try the Cygwin method first. +If you struggle with Cygwin, then you are unlikely to get any of the other methods to work either. So use Filezilla or WinScp. + +

    If you don't like Cygwin, and want to use a bash terminal environment instead of Windows cmd.exe, then try the MINGW32 method. + +

    Only install WSL if you are pretty sure that you want to use WSL for things other than rsync. +


    Go back to: Basic laptop
    Go back to: Survey laptop
    - +Go on to: Windows WSL laptop

    diff --git a/handbook/computing/wsllaptop.html b/handbook/computing/wsllaptop.html index cb109c5d4..d16c0a30d 100644 --- a/handbook/computing/wsllaptop.html +++ b/handbook/computing/wsllaptop.html @@ -20,7 +20,8 @@
    Setting up a Windows machine for expo bulk data rearrangements

    - +On 23 November 2022 a new way of installing and using WSL was announced, see +Windows Subsystem for Linux now packaged as a Microsoft Store app so some of the documentation on this expo site needs to be revised. WSL2 is now noticeably even slower for NTFS files.

    WSL1 and WSL2

    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 is 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 has @@ -33,13 +34,13 @@ the Linux bash terminal window. However, if all you want to use it for is rsync,

    On some Windows 10 laptops WSL1 fails to install properly and you have to use WSL2.

    When running a full troggle development laptop (see separate troggle documentation) you will want to use python venv. This barfs untidily if you have the code on NTFS, e.g. if mounted on /mnt/c/. You almost -certainly have to move all your code to the internal network share e.g. \\wsl$\Ubuntu-20.04\home\expo\troggle\ which +certainly have to move all your code to the internal network share e.g. \\wsl$\Ubuntu\home\expo\troggle\ which is how it looks when you are browing from Windows. (No, don't try to be cute and keep it on /mnt/c/ and just put a soft link in /home/expo/. That doesn't work either.) This means that the code is actually living on a Linux ext4 filesystem hidden away on your disc where you can only see it using the -'network' method \\wsl$\Ubuntu-20.04\home\expo\troggle\. This means that file access is somewhat faster too but you probably won't notice. +'network' method \\wsl$\Ubuntu-20.04\home\expo\troggle\. This means that file access is somewhat faster too but you probably won't notice. You will need to make sure that your backup/archive methods access this filesystem though. -

    rsync doesn't work with NTFS partitions the way that WSL1 does. See Windows laptop for a bit of detail. [Work in progress.] +

    rsync doesn't work with NTFS partitions the way that WSL1 does.

    Read WSL & Visual Studio Code and go back and read the bits about VS Code running remotely in the ※Windows data maintenance laptop page. @@ -54,9 +55,89 @@ href="https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/"> in the \\wsl$\ ext4 filesystem (WSL2 only, not WSL1).

    If you are disturbed by the instructions to produce an entirely different 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 this October 2019 article. (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. +

    WSL - Creating another ssh key

    + +

    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. So on a machine with WSL enabled, create an ordinary cmd window and get into the WSL environment using the wsl command:
    + +D:\CUCC-Expo\expoweb\ wsl + +
    +which puts you into the WSL environment with a new command prompt, e.g.
    + + +philip@Muscogee:/mnt/c/Users/Philip$ + +

    and now you can setup keys in the same way as you would on a Linux machine using ssh-keygen: +

    +$ ssh-keygen -C "philip@muscogee-wsl"
    +Generating public/private rsa key pair.
    +Enter file in which to save the key (/home/philip/.ssh/id_rsa): id_rsa_wsl
    +Enter passphrase (empty for no passphrase):
    +Enter same passphrase again:
    +Your identification has been saved in id_rsa_wsl.
    +Your public key has been saved in id_rsa_wsl.pub.
    +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]-----+
    +$
    +
    +
    +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). +

    Now you have to complete the key-pair setup 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 "Second Machine". +

    +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: +

    +rsync -nazv --delete-after --prune-empty-dirs expo@expo.survex.com:expofiles/ expofiles
    +

    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. +

    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. + +

    Permissions, permissions..

    +

    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 +a vengence on WSL1. +

    The recommended WSL procedure (Jan.2021) said to mount the drive using +a new 'metadata' setting: +

    sudo umount /mnt/d
    +sudo mount -t drvfs D: /mnt/d -o metadata,uid=1000,gid=1000,umask=22,fmask=111
    +

    This is probably why there is a difference between automatically-mounted drives (e.g. C:, /mnt/c) and plug-in drives: +"By default, WSL will set the uid and gid to the default user with drives that are auto-mounted during instance start. If you mount manually, you will +have to set these explicitly (the default user that gets created when WSL is first installed has a uid=1000 and gid=1000)." +

    And of course you will need to arrange that this happens automatically whenever you start WSL, so you will need to set +/etc/fstab, so ensure that the relevant line says: +

    D:           /mnt/d         drvfs   metadata,uid=1000,gid=1000,umask=22,fmask=11     0    0
    + +

    See also File Permissions for WSL (Dec. 2021). + + +

    "Are you feeling lucky, punk"

    + + -

    Links to useful articles to help you work this out for yourself: