Build system setup of WSL2

This method is NOT OFFICIALLY supported. A native GNU/Linux environment is recommended.

It's not supported, like the tagline says above, but it does work. The performance will only be about 5% slower than native Linux.

As administrator, run wsl --install -d Debian from a Windows shell. Then run wsl (or debian, it does the same thing) as a regular user, and set your username and password.

After you have your Debian (or other) Distribution installed:

sudo apt update
sudo apt dist-upgrade

To be able to build an OpenWrt image, you must not have spaces in PATH or in the work folders on the drive and you should not be building as the 'root' user. But by default, in a WSL environment, the windows PATH folders are included, and those have spaces:

echo ${PATH} gives, e.g.:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/GnuPG/bin:/mnt/c/Program Files (x86)/dotnet/:/mnt/c/Program Files/WireGuard/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files (x86)/AOMEI/AOMEI Backupper/6.5.1:/mnt/c/Program Files (x86)/Bitvise SSH Client:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Users/Bas Mevissen/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Bas Mevissen/.dotnet/tools 

Your /etc/wsl.config should look like this to get rid of the mixing of Windows paths with your linux environment:

[boot]
systemd=true
[interop]
appendWindowsPath=false
[automount]
enabled=false
[user]
default=yourwslusernamehere

Shutdown WSL to apply changes:

From a windows shell:

wsl --shutdown

wsl

Verify whether no Windows path elements appear in the PATH environment variable, by the following command in WSL:

echo ${PATH} now gives:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib

See also: Configure global options with .wslconfig

It is possible to limit WSL2's use of RAM/CPU resources by creating/editing %USERPROFILE%\.wslconfig.

You'll have to choose how much memory as a fraction of what your build system has: If your computer has 32GB, and an 8 core processor:

[wsl2]
networkingMode=mirrored # allows your WSL2 to share the same address as your windows host.
memory=8GB # Limits VM memory in WSL 2 to 8 GB
processors=4 # Makes the WSL 2 VM use four virtual processors
swap=10GB # Important if you have less than 8GB above for memory
swapFile=C:\\swap.vhdx # or other drive where you want the swap file
nestedVirtualization=true
guiApplications=false # You are not running graphical applications to build openwrt, so it is unneeded.
kernelCommandLine=mitigations=off
[experimental]
sparseVhd=true
autoMemoryReclaim=Gradual

Restart WSL to apply changes:

wsl --shutdown

wsl

sudo apt install openssh-server

sudo nano /etc/ssh/sshd_config

Ensure the following settings are uncommented and set:

Port 22 # use a different port if your Windows is running SSH
ListenAddress 0.0.0.0
PasswordAuthentication yes

sudo service ssh restart

Now use SCP, e.g. WinSCP and connect to localhost with SCP. You will have a panel on the left which is your local native windows drive, and one on the right which is your WSL2 environment. You may still have to use utilities like dos2unix if you are creating new files in the Windows environment, but if you first create them on the WSL2 environment, it's internal editor and many third-party editors (Notepad++) will honor the unix format.

WSL2 / Debian has to be running in order to access the files. If you exit out of your last WSL2 window, the WinSCP client will tell you it's been disconnected, as normally WSL shuts-down within 60 seconds.

SSH access from across your network: if you create an Incoming firewall rule in Windows Firewall, for port 22, you can connect from other computers to your running wsl, as long as a wsl shell is open. There are means to keep WSL2 running even if the last shell is closed, but it is not within the scope of this brief how-to wiki.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2026/05/10 02:21
  • by s2s2