| 1 | # Init |
| 2 | |
| 3 | Init is top level process of a WSL distribution. For WSL1 distributions, it is launched by [wslservice](wslservice.exe.md) (see `src/windows/service/LxssInstance.cpp`) and for WSL2 distributions, it is launched by [mini_init](mini_init.md). |
| 4 | |
| 5 | ## WSL2 specific distributions startup |
| 6 | |
| 7 | Each WSL2 distributions runs in a separate mount, pid and UTS namespace. This allows distributions to run in parallel, without "seeing" each other. |
| 8 | |
| 9 | When a WSL2 distribution starts, [mini_init](mini_init.md): |
| 10 | |
| 11 | - Mounts the distribution VHD |
| 12 | - Clones into a child namespace |
| 13 | - Chroots in the VHD mountpoint |
| 14 | - Executes init (see the `LxMiniInitMessageLaunchInit` message). |
| 15 | |
| 16 | While each distribution runs in its own mount namespace, the `/mnt/wsl` mountpoint is shared between all distributions. |
| 17 | |
| 18 | ## Distribution initialization |
| 19 | |
| 20 | Once started, the `init` process performs various initialization tasks such as: |
| 21 | |
| 22 | - Mounting `/proc`, `/sys` and `/dev` |
| 23 | - Configuring cgroups |
| 24 | - Registering the binfmt interpreter (see [interop](interop.md)) |
| 25 | - Parsing [/etc/wsl.conf](https://learn.microsoft.com/windows/wsl/wsl-config) |
| 26 | - Starting systemd (see [systemd](systemd.md)) |
| 27 | - Mounting `drvfs` drives (See [drvfs](drvfs.md)) |
| 28 | - Configuring `wslg` (see [wslg](https://github.com/microsoft/wslg)) |
| 29 | |
| 30 | ## Running the distribution |
| 31 | |
| 32 | Once ready, `init` establishes either an `lxbus` (WSL1) or an `hvsocket` (WSL2) connection to [wslservice](wslservice.exe.md). This channel is used to transmit various commands to `init` (see `src/shared/inc/lxinitshared.h`), such as: |
| 33 | |
| 34 | - `LxInitMessageInitialize`: Configure the distribution |
| 35 | - `LxInitMessageCreateSession`: Create a new session leader. See [session leader](session-leader.md) |
| 36 | - `LxInitMessageTerminateInstance`: Terminate the distribution |