WSL Programming


 As I type this out, I'm currently waiting for a new laptop to arrive from System76, on which I plan to do most of my development. However, in the interim, I'm trying to move my personal projects away from my "normal" workstations (work-provided, corp-ified devices) and onto devices which are entirely owned by me.

At the moment, this means I'm running on a Windows 10 device, which has WSL 2.0 up and running with an Ubuntu image. Once I'm up and running with a tmux session, it does feel pretty naturally like Linux, but there are some quirks, which I'll dive into within this post.

Host Filesystem Access

Right off the bat, as I tried downloading some files for usage within WSL, accessing the "Downloads" directory of my host computer became a blocker.

To get ourselves unstuck, lets take a look at the /mnt directory within a WSL shell:

~ $ ls /mnt/
a  c  d  e  f  g  wsl

As we can see here, all our drives are visible. Querying further:

~ $ df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sdd       ext4      251G  3.8G  235G   2% /
tmpfs          tmpfs      13G  274M   13G   3% /mnt/wsl
...
tools          9p        931G  357G  574G  39% /init
none           devtmpfs   13G     0   13G   0% /dev
none           tmpfs      13G   20K   13G   1% /run
none           tmpfs      13G     0   13G   0% /run/lock
none           tmpfs      13G     0   13G   0% /run/shm
none           tmpfs      13G     0   13G   0% /run/user
tmpfs          tmpfs      13G     0   13G   0% /sys/fs/cgroup
A:\            9p        233G  205G   29G  88% /mnt/a
C:\            9p        931G  357G  574G  39% /mnt/c
D:\            9p        100M   47M   54M  47% /mnt/d
E:\            9p        437G  109G  329G  25% /mnt/e
F:\            9p        495G  172G  324G  35% /mnt/f
G:\            9p        112G   85G   27G  77% /mnt/g

As we can see here,  all the drives are mounted under this /mnt path. If we look closer, they're also using a "9P filesystem", which actually means that the implementation of this subsystem uses a networked filesystem technology to treat the WSL instance as a "client", and the native Windows filesystem as a "server", emulating a natural Linux filesystem by translating requests through this protocol. Windows devs have written about this technology choice, connecting client and host over AF_UNIX sockets.

I was surprised to see remnants of Plan 9 here, but hey, seems like a pretty cool technology choice. If it works right away, it beats building a new proprietary protocol format.

Comments