| 1 | # mini_init |
| 2 | |
| 3 | mini_init is the first executable that's launched when the WSL2 virtual machine starts. See [WSL2 boot process](boot-process.md) for more details. |
| 4 | |
| 5 | ## Virtual machine setup |
| 6 | |
| 7 | mini_init is started when the kernel is done booting, and calls `/init`, which is `mini_init`. Like other standard linux `init` executables, `mini_init` starts by mounting `/proc`, `/sys`, `/dev` and other standard mountpoints. |
| 8 | |
| 9 | `mini_init` then performs various configuration such as enabling crash dump collection, configuring logging via `/dev/console` and tty configuration. |
| 10 | |
| 11 | Once everything is ready, `mini_init` connects two hvsockets to [wslservice](wslservice.exe.md). |
| 12 | |
| 13 | One of them, called the "mini_init" channel is used for messages sent by `wslservice.exe`. See `src/shared/inc/lxinitshared.h` for a list of messages and responses. Common messages are: |
| 14 | |
| 15 | - `LxMiniInitMessageLaunchInit`: Mount a virtual disk and start a new distribution. See [`init`](init.md) for more details |
| 16 | - `LxMiniInitMessageMount`: Mount a disk in `/mnt/wsl` (used for wsl --mount) |
| 17 | - `EJECT_VHD_MESSAGE`: Eject a disk |
| 18 | - `LxMiniInitMessageImport`: Import a distribution |
| 19 | - `LxMiniInitMessageExport`: Export a distribution |
| 20 | |
| 21 | The other hvsocket channel is used to send notifications to [wslservice.exe](wslservice.exe.md). This is used mainly to report when linux processes exit (which wslservice uses to know when distributions are terminated). |
| 22 | |
| 23 | ## Networking configuration |
| 24 | |
| 25 | As part of the boot process, `mini_init` also launches the [gns binary](gns.md) which manages networking configuration |
| 26 | |
| 27 | ## Other tasks |
| 28 | |
| 29 | `mini_init` performs various other maintenance tasks such as: |
| 30 | |
| 31 | - Reclaiming unused memory |
| 32 | - Launching the debug shell tty |
| 33 | - Synchronizing IO when the virtual machine terminates |
| 34 | - Resizing filesystem (for wsl --manage <distro> --resize) |
| 35 | - Formatting disks (used when installing new distributions) |
| 36 |