...
Code Block |
---|
C:\Users\gilbert>winget list|wsl grep Git Git Git.Git 2.48.1 winget GitHub Desktop GitHub.GitHubDesktop 3.4.17 winget |
WSL creates a very special Linux Virtual Machine VM running the Microsoft version of the Linux Kernel. Unlike other VMs, the Windows system is tightly connected to this Linux VM. Windows programs can directly access the Linux files, Linux has access to the Windows disks, Linux and Windows programs can share the same network adapters, and you can combine Linux and Windows programs on the same command line.
If you want the full Linux Gnome Desktop experience, create a normal Linux VM with Hyper-V. WSL is command line only, but you can install individual Linux GUI programs into WSL and when you run them an application window pops up on the Windows desktop:
...
The Microsoft Linux Kernel runs a special non-Docker container system. You can install one or more Linux “distributions” (Ubuntu, Debian, SUSE, etc.) each into their own container under the Kernel. Unlike Docker, this special container system lets the distributions run systemd background services and shares resources like network adapters. Each distribution has its own isolated file system, processes, and libraries. That VM launches a special Container runtime. There are Windows commands to create a Container image based on a snapshot of a current Linux distribution such as Ubuntu 24.04 or Oracle Linux 9.1. By choosing the distribution, the user also chooses a set of pre-installed programs and libraries and a package manager that can download additional components. The container is owned exclusively by the Windows user who creates it. It cannot be shared with anyone else. During setup the Windows user selects a default administrative userid and password, which then becomes the default Linux userid under which the Linux programs run.
This solves the otherwise impossible problem of reconciling the entirely different security systems of Windows and Linux. Linux programs run in a container created by a Windows user who has full control and global permission over everything in the container he created. Nothing runs in the container except programs started by the owning user. The container cannot be shared, so no other Windows user has access to anything in it. They can build their own containers over which they will have their own exclusive control. Linux programs access Windows file as the Windows user that created the container in which they are running and that called them and therefore started them running.
WSL creates a tightly coupled communication pipe between the Windows login session and each WSL Container owned by the logged in Windows user. At each end of the pipe is a private network file server and a private sort of ssh command server. These servers are transparently integrated into the Windows 11 tools (like File Explorer) and the Microsoft Linux Kernel so that Windows sees the Linux file system as mounted Windows files, and Linux sees the Windows disk letters as mounted Linux files.
A particularly slick trick is the ability for the execution of a command to slide back and forth between the two systems whenever a Windows exec and a Linux program appear on each side of “|” (a pipe). The Windows and Linux command line execution allow the standard output of a Windows program to be piped to a WSL interface which transmits the byte streams to Linux where a new bash process is created, an environment is set up, and a program is run so that its standard input is the stream of Windows bytes adjusted for the difference in the way Windows and Linux handle line end characters.
A Linux program can pipe its standard output to a Windows program by WSL interface that does the same thing in the opposite direction.
It is a whole lot more complicated to explain how you can type a Windows command to run a Linux Gnome program and have the Linux user window pop up as a GUI application on the Windows desktop. Windows has a Wayland compositor so it can usually translate Linux application calls into a usable Windows app.
...
WSL tries to hide the fact that it runs Linux programs in a Container. Each Container is called a “distro”, short for “distribution”. On the one hand, a “distribution” can refer to a tar file of the file system of any of the common available Linux distribution (Ubuntu, Debian, Kali, etc.). In Container language, this would be called an Image. However, WSL also talks about starting up a distro and running a program in it. This corresponds to a “container”. WSL gets away with the ambiguity because in the very limited command set that the wsl.exe program provides, if you do a
wsl --install Ubuntu-24.04
This is both a command to download the Ubuntu-24.04 tar file Image from a Microsoft library source (dare we call it “WslHub”?) and also to start running it in a Container called Ubuntu-24.04. Unlike Docker or other container systems, WSL only allows you to create one container from any one named image. There is a way to get around this restriction, but Microsoft doesn’t make it easy and doesn’t tell ordinary end users how to do it.
When you use the distro name in the --install, you are talking about the Image. After that, references to the same distro name are about the Container built from the Image during the install.
Not a Docker Container
Docker is a specific system for building a specific type of container used to run applications. Each Docker container is running just one program. If you need more than one program, you group containers together and connect them with a virtual network. If you make any changes to a file in the container, the change is lost when the container stops running.
While WSL containers are also built from an image file, the image is typically one of an entire normal Linux operating system, except for the Kernel. Unlike Docker, it can have background services managed by “systemd”. You can install any Linux package. You can install snaps. You can even install the docker.io package and have a full Docker Engine running inside a WSL distro.
The default and probably best adapted distribution is Ubuntu (24.04 LTS). Ubuntu has supported WSL since the earliest version, installs with systemd and snap enabled, and provides the widest library of programs that you can install and run using the apt package manager.
...