Windows sub-system Linux 101
unpublished draft
WSLDocker
Overview
Windows sub-system Linux (aka wsl) is a set of services that provide environment for installing many Linux distributions on top of windows. As of Windows 10 and above, WSL should be available at default and can be turn on or off with Windows Features.
Common installation
- Enable windows feature first
- Download and install wsl2 update
wsl --set-default-version 2
wsl --update
Useful to know
Installation#
Before install WSL2, make sure those features was on:
- Containers
- Hyper-V
- Virtual Machine Platform
- Windows Sub-system for Linux
- Install and set default wsl to wsl2
- WSL config
- Create VHDX drive - optional
- If we want to be able running background service within WSL, enable systemd. This is easy way.
Mounting attention
Virtual hard disk frive always get un-mount for every restart, shutdown, so create a auto-mount a VHD/VHDX file at Startup as workaround, tutorial here.
Goal command to setup: powershell.exe Mount-VHD -Path "C:\Users\[SpecificUser]\wslvhdx\swap.vhdx"
Approach by global style (.wslconfig) file, should be locate at `%USERPROFILE%` (for all distributions)
[wsl2]
memory=8GB # Limits VM 8 GB memory in WSL
processors=2 # Makes the WSL 2 VM use two virtual processors
swap=32GB # Limits VM 32 GB storage in WSL - optional
swapFile=%USERPROFILE%\AppData\wslvhdx\swap.vhdx # Specify the actual swap file location - optional
Some useful command#
On window environment#
- Check list of installed wsl:
wsl -l -v
- Upate wsl kernel:
wsl --update
- Run a command to a specific Distribution:
wsl -d <DistributionName> <command>
|free -m
- get to see current consuming resouces. - Stop a wsl:
wsl --shutdown <DistributionName>
| Stop all wsl:wsl --shutdown
- Start a wsl:
wsl -d <DistributionName>
- Set default distro:
wsl --set-default <DistributionName>
- Delete a distro:
wsl --unregister <DistributionName>
- Restart LxssManager:
Restart-Service LxssManager
On WSL environment#
- Get current absolute path corresponding to Window:
wslpath -w .
Docker related
Move docker data to another volume#
- Docker default saving image path windows:
C:\Users\<userName>\AppData\Local\Docker\wsl\data
- Change it via tutorial
wsl --export docker-desktop-data E:\docker-desktop\docker-desktop-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data E:\docker-desktop\data E:\docker-desktop\docker-desktop-data.tar --version 2
Docker specific#
- WSL: normally locate at
%USERPROFILE%\AppData\Local\Docker\wsl
(to see where%USERPROFILE%
store. usecd ~
command). docker-desktop
- The distro that actually ran all the container, distro folderdocker-desktop-data
- The distro that would store docker image, data folder- Changing docker image location