So, after the (very) impressive demo by @richturn_ms during the Windows Developer Day – Creators Update, for the ones following WSL since some time now (if not from the beginning), there was this part that must have triggered the “wow” effect.
Now, I’m by no means what you can call a developer. Matter fact, I’m not a SysAdmin neither, just a simple hobbyist who likes to come with “special” ideas.
Back to our topic, after the “wow” effect faded away, I scratched my head a little bit as Rich was showing something that was normally forbidden!
Or was he? the way he performed the demo, was actually the “correct” way: from one OS to another using a standard protocol (SSH).
After some research, I found also a way for the ones of us that do not code in C++, however would like to modify files, directly from the WSL filesystem in the “correct” way also with VSCode (however, I guess other editors will also be able to apply this method).
So for the ones of you, who would like to open/create/update files with VSCode, just follow this small steps:
- Install Remote VSCode extension
- Edit your “User Settings” to enable the server to start automatically
- Bypass all the “SSH Tunneling” part, it will not be needed in our case
- Install Rmate for Bash (just perform the Quick Install commands)
- From WSL, run
$ rmate -H localhost mytextfile.txt
- Save your changes, and confirm that the change has been correctly applied:
$ ll mytextfile.txt
$ cat mytextfile.txt
And that’s all, this should allow you to edit single files when following howtos in Internet (think Go, Nodejs, etc..).
>>> Nunix out <<<
So, I have this shiny Surface Pro 4 with a nice 64Go SDCard and, as you may know if you’re reading this blog, WSL does not (yet) mount SDCards or USB sticks.
I tried two “normal” ways, with CIFS and SSHFS, however when trying to mount the filesystem I got the not so nice errors.
ref: https://www.swiftbyte.com/articles/linux/mounting-a-wicd bashhare-in-ubuntu-on-boot
Then, while playing with Docker and the WSL, I could actually mount my SDCard to a docker (normal) and then access it from the “normal/linux” docker client:
Ok, until now, everything is working as expected. A quick inspect show us the configuration of the Mount:
At this moment, as my *nix skills are a bit rusty, I searched for an alternative to NFS as my direct memories are not so good, so don’t blame me but my Masta instead.
Also the high risk of not being able to mount it (once again) didn’t motivate me too much (still, I will try it in another blog if no one else tries it).
“Et la lumière fut!”. I already went to the extent of implementing an SSH server into a container (by the way, no need for that to access it) so I could try to RSYNC and … IT WORKED.
So here is the setup needed:
- Have Docker for Windows installed
- Pull the Ubuntu image (I choose this one for “standardization” purpose)
- Create a new container from Powershell! with the following options and follow the configuration stated in Docker own Dockerfile for the SSH service:
PS> docker run -it -p 2222:22 -v d:/:/mnt ubuntu bash
- The reason is simple: Powershell “sees” your external drive
- This command will expose the SSH port to your local port 2222 and mount your external drive to “/mnt”
- Install RSYNC in the container
$ apt-get install rsync
- You can exit your session without killing your container by using “CTRL+P” and then type “CTRL+Q”
- Open a WSL Bash console
- You can already connect with your WSL Docker client and see your drive mounted in “/mnt”
- Install RSYNC (if not already done) in WSL
$ apt-get install rsync
- Try to sync a file from WSL to your External drive
/usr/sbin/rsync -avh --progress -e "ssh -p2222" bigfile.txt firstname.lastname@example.org:/mnt/
- Please note that you need your “local IP” as we did map the port 2222 to the ssh port of the Container
- For this first test, I created a 1Go file and synched it
And here you have, now you can have your files synched to your external drives.
I will do a follow-up blog post with another synch tool: Unison (both ways sync for the win).
>>> Nunix out <<<