Is there an way to make WSL2 mount its folders on another drive outside Windows Preview Build 20211? - windows-subsystem-for-linux

I've this SSD drive that I bought only for work so I would like WSL2 to write on it. Found this article which I was following thru, to find out wsl --mount is working on Windows Preview Build 20211, not on my build (Win 10 1909 18363.1110).
Is there an way to do this?
Thanks!

Found out later, with a little change of terms on my research, that it could be done as in this tut here: https://www.sitepoint.com/wsl2/
To make it quick for anyone searching around here, you have to export your Linux image, unregister it from wsl and then import it again on the other drive. How it's done:
List your distros
In a Windows Powershell terminal, enter wsl --list. It should return what distros you have installed and if they're running.
Export your distro
In the same Powershell, enter mkdir D:\backup to make a dir for your backup then export it using wsl --export <distro> D:\backup\<distro>.tar. In my case, wsl --export Ubuntu D:\backup\ubuntu.tar.
Unregister the distro
You have to remove it from the C: drive with wsl --unregister Ubuntu and to make sure it worked, after the process is done list all distros again with wsl --list.
Import the distro on another drive
The syntax for this will be wsl --import <distroName> <target\directory> <origin\image>. So if you'd like to make an directory for your WSL in your new drive, just do mkdir D:\wsl or name it anyway you want. I already have a folder for that, so I went with wsl --import Ubuntu D:\wsl-dev D:\backup\ubuntu.tar.
You can verify if it's done by using the very same wsl --list.

And if you want to change your default user from root, follow below steps.
For Ubuntu 18.04, the command to change default user is
ubuntu1804 config --default-user <username>
Took me a while to figure out. Finally found it thanks to this link

Related

How to access a WSL instance from another?

I am upgrading my WSL2 instance from Debian 10 to Ubuntu 20.04 LTS, because I need some newer packages.
How do I copy files and directories from Debian to Ubuntu, preserving the permissions and owner? (uid and gid are the same in the two Linuxes.)
Copying to windows first changes the permissions and owner of files.
explorer.exe also changes permissions and owner.
Preferably, I'd also like to avoid having to create a shared disk image file that I could mount from Debian and Ubuntu in turn.
I'd like something simpler, like accessing the second WSL instance directly from the first, e.g.,
$ cp -a <Debian>/myfiles/ <Ubuntu>/myfiles
Is this possible?
See also my similar question: How to access \wsl$\othercontainer\some\file from within a WSL container? where the short answer is:
sudo mkdir /mnt/othercontainer
sudo mount -t drvfs '\\wsl$\othercontainer' /mnt/othercontainer
ls -l /mnt/othercontainer/some/file
NOTE: It looks like symbolic links aren't supported.
Use tar. It will preserve all the file metadata.
In <Debian>, create myfiles.tar.gz:
tar zcvf myfiles.tar.gz myfiles
Copy myfiles.tar.gz to your windows drive e.g. with explorer.exe or with /mnt/c, and then copy myfiles.tar.gz to <Ubuntu>. In <Ubuntu>, untar it:
tar zxvf myfiles.tar.gz myfiles

Unison fails with "ill-formed message" error, same remote & local versions

I'm trying to get unison working after upgrading to Mac OS X Catalina. Unfortunately, macports installs a more recent version of ocaml (4.08.1), which means that the unison 2.51.2 release won't compile.
Well, that's no problem, I just update to git master on unison, and recompile. Unfortunately, this fails at sync time because the version of ocaml used to compile on the mac (4.08.1) is different from the one used to compile on the other machine (4.07.1). Sigh. Okay, use opam magic to install 4.07.1 on my machine. Everything should be fine, right? No!
Here's the error:
Connected [//zzzmyhost//home/clements/unison-home -> //zzzmyotherhost//Users/clements/clements]
Looking for changes
Uncaught exception Failure("input_value: ill-formed message")
Raised at file "/private/tmp/unison/src/lwt/lwt.ml", line 126, characters 16-23
Called from file "/private/tmp/unison/src/lwt/generic/lwt_unix_impl.ml", line 102, characters 8-23
Called from file "/private/tmp/unison/src/update.ml" (inlined), line 2105, characters 2-69
Called from file "/private/tmp/unison/src/uitext.ml", line 978, characters 16-56
Called from file "/private/tmp/unison/src/uitext.ml", line 1066, characters 6-90
Called from file "/private/tmp/unison/src/uitext.ml", line 1088, characters 19-66
Called from file "/private/tmp/unison/src/uitext.ml", line 1144, characters 21-43
What's going on?
Sigh... the problem here (very non-obvious) is actually with a corrupted/wrong-format syncronization file, created when doing the failed sync in the earlier test.
The solution is just to go into ~/Library/Application Support/Unison (on a UNIX machine this path would presumably live in ~/.unison and delete the archive file that's causing the problem (probably the most recent one). In a pinch, just delete all of the archive files and start over.
I've got the same problem between Windows and Ubuntu 20.04 after upgrading from Ubuntu 18.04. I tried the binary from Ubuntu 18.04 in 20.04, which still fails, so the incompatibility is likely inside one of the dependencies.
As a workaround I created a Docker image based on Ubuntu 18.04:
FROM ubuntu:18.04
RUN apt-get update && apt-get dist-upgrade -y
RUN apt-get install unison -y
RUN useradd martin --home /home/martin
WORKDIR /home/martin
USER martin
Building it with docker build -t unison:18.04 .
And then I added a wrapper to ~/bin/unison-2.48.4-docker:
#!/bin/bash
docker run --rm -i \
-v /home/martin/dirtosync:/home/martin/dirtosync \
-v /home/martin/.unison:/home/martin/.unison \
--hostname $(hostname) \
unison:18.04 unison "$#"
Setting the --hostname is important, since the hostname is part of the archive file.
Inside the profile on my Windows machine I configured:
servercmd = ~/bin/unison-2.48.4-docker
In my setup with two windows clients and one Ubuntu 18.04 server, connected by ssh, the problem startet with a second server running on Ubuntu 20.04. Neither the old server nor the windows clients could sync with the new machine.
My solution: Copying the binary from Ubuntu 18.04 to a new directory in the Ubuntu 20.04 machine. This new file is referenced in the "authorized_keys" file of ssh on the new machine.
So far, everything works great with unison 2.48.4.

Installing fzf fuzzy finder offline

I'm behind a firewall and I have the fzf.tar.gz package which has the content of the git repo. How can I install fzf offline?
The install command ~/.fzf/install is reaching out to github.com. I'm on Redhat with no internet connection.
https://github.com/junegunn/fzf
This is just what I observed, I can't guarantee I didn't miss anything:
First, clone fzf to FZF_DIR on an online PC, then,
I'd suggest you to execute 'install' on an online PC to get necessary files
~/.fzf/bin/fzf this one is downloaded by install script
~/.fzf.bash this one is generated by install script
cp ~/.fzf/bin/fzf $FZF_DIR/bin
copy $FZF_DIR (with fzf binary in it) and .fzf.bash into your offline PC
ln -s $FZF_DIR ~/.fzf
source .fzf.bash in your .bashrc
Entire FZF_DIR is needed because it includes some other useful scripts sourced by .fzf.bash.

windows subsystem for linux preserve file attributes in git repo

When sharing a git repo between wsl on windows10 and any linux, all files added/changed from wsl get the rw-rw-rw attributes, even if I explicitly do a chmod ug+x file.py before adding. If You do a ls -l in wsl all files are listed with rwxrwxrwx no matter what.
On linux I have to do a find . -name "*.py" -exec chmod ug+x {} \; on every pull/clone
What is the best way to fix this? Are there some settings in WSL? git hooks?
I assume your git repo is somewhere in the windows file system, i.e. in /mnt/c/path/to/git. In this case WSL sets all permissions in order
to best reflect the Windows permissions. (FAQ)
There is currently no way in the stable build to change this behavior. But with
the insider build 17063 the WSL team face this by implementing DrvFs support, which
allows setting the owner and mode of files using chmod/chown, and also
the creation of special files such as fifos, unix sockets and device
files. (Release Notes)

NFS client under WSL - mount.nfs: No such device

I am getting the following error trying to mount a nfs export.
sudo mount 192.168.1.175:/mnt/nas /mnt/c/nas
mount.nfs: No such device
Any ideas on how to fix this?
As of October 2020: You can mount nfs with wsl2, but wsl2 itself requires a hardware virtualization available. See here: https://github.com/microsoft/WSL/issues/5838
If like me you are stuck on WSL1 you can work around this issue by mapping the drive in windows. Use the Map Network Drive feature and create a drive letter for your nfs mount e.g. G:
Now in WSL you can mount that drive letter:
sudo mkdir /mnt/g
sudo mount -t drvfs G: /mnt/g
from: How to Mount Windows Network Drives in WSL
I have not tested the access speed to a drive mapped through to WSL like this but I would expect it to be slow!
The error indicates the nfs kernel modules are not loaded correctly and
also verify the exported path "/mnt/nas" exists on sever "192.168.1.175" or not.
first of all,we understand nfs is one of tctp/ip protocol, so one client and one server are needed, So our purpose is sharing a dir on windows or wsl to a another linux, that means the windows or wsl is a server, all you guys are right about wsl nfs, it doesnt work if we use the wsl nfs inside, we can make a another nfs server on windows instead of wsl, and configure the share dirs right which we can find the dirs on wsl, e.g. /mnt/d/WORK/tftpserverDir, after that we can mount successfully. those are tips of me:
make a nfs server on windows
I dowwnload from this:
https://www.hanewin.net/nfs-e.htm
configure the shared dir in exports file
D:\WORK\tftpserverDir -name:nfsroot -umask:000 -public -mapall:0
mount the share dirs on your dst linux
mount -t nfs -o nolock -o tcp -o rsize=32768,wsize=32768 172.10.10.80:/nfsroot /sdcard/mnt