In this talk, we'll dive into WSL (Windows SubSystem For Linux). We'll look at the internals, tooling, tips/tricks/gotchas & upcoming roadmap for WSL2.
Author: Mithun Shanbhag
WSL is mainly for development scenarios. NOT for production scenarios.
Major adv is Windows <-> Linux interop
1. WSL2 requires windows insider build 18917 or higher.
2. You can install multiple linux distros (only one will be default).
2. Can be installed in one of the following ways:
Download & install from Microsoft store.
Download & install APPX.
2. Installation on Win Server has additional steps (unzip appx file & run installer).
7. Run “ls -l /usr/bin/wsl*“ to see list of wsl utilities
wslsys
wslfetch –splash (takes a bit of time)
wslvar –getsys
8. Run “sudo /etc/init.d/docker start” to start docker
Docker ps
Docker images
Docker run –it alpine /bin/sh
1. WSL2 requires windows insider build 18917 or higher.
2. You can install multiple linux distros (only one will be default).
2. Can be installed in one of the following ways:
Download & install from Microsoft store.
Download & install APPX.
2. Installation on Win Server has additional steps (unzip appx file & run installer).
@todo: Show examples with “--set-version” and “--unregister”.
1. The \\WSL$ is facilitated by 9P server (running inside /init)
5.1. To clarify:
- If linux command prompt is under /mnt/xyz, then the windows command gets the same as its current directory.
- If linux command prompt is elsewhere, then the windows command gets %WINDIR% as its current directory.
- /etc/fstab is processed on WSL start. /etc/fstab is a file where you can declare other filesystems, like an SMB share. Thus, you can mount these filesystems automatically in WSL on start up.
- /etc/hosts file, contains hostname <-> ip mapping
- /etc/resolv.conf file, contains list of DNS resolution servers
1.2. Not really a limitation. More like a blessing.
3.1. We’ll explore more in detail in WSL2 architecture.
@todo: wslpath
NTDLL, PEB, TEB etc are the standard interfaces between user-mode processes and the NT kernel.
3. Pico processes do not interact with NT Kernel directly.
3. When NT Kernel detect a process without PEB/TEB/NTDLL, it asks LXSS/LXCore to interact with it instead.
3. @todo: The pico providers (LXSS/LXCore) provide POSIX compliance for NT Kernel?
1. VFS abstracts all file system operations.
1. Various ile systems are mounted on different directories in the VFS namespace.
1. VFS utilizes a number of data structures
- inodes
- directory entries
- file objects
- file descriptors,
- special files (device files, FIFOs, sockets, symbolic links).
2. The first time an NT process requests launching a Linux binary an instance is created. Once the last NT client closes, the Linux instance is terminated.
Notes on /init:
/init is a multi-purpose binary that was written by Microsoft and is shipped as a binary resource contained in LxssManager.dll.
When /init is launched, it first checks its PID.
If the PID is 1, /init will run in "daemon mode" where it essentially the Lxss Manger service’s endpoint inside a WSL instance.
If the PID is not 1, /init runs as "binfmt_misc interpreter mode" which allows launching NT binaries.
Advantages of WSL2 over WSL
- Faster file access
- Full kernel implementation
7. Key thing to remember is that linux is running side-by-side with windows (and not inside it).
4. The EXT4 VHD is mapped in. Then the /init process is run.
Important to note that:
In WSL1, both Windows & Linux were running on same machine.
In WSL2, they are running in “separate” machines.
The P9 server facilitates Windows <-> Linux file sharing.
- In the scenario above, P9 allows Linux VM access to windows file share
9P facilitates \\WSL$ share
P9 here facilitates mounting of windows file share