Skip to main content

WSL Conf

cat /etc/wsl.conf.bak

[boot]
systemd=true

[user]
default = username

[automount]
enabled = true
#mountFsTab = true
root = /mnt/

Memory​

Get-Content "$HOME\.wslconfig"
  1. Run in PowerShell
@'
[wsl2]
memory=10GB
swap=16GB
'@ | Set-Content "$HOME\.wslconfig" -Encoding ascii

or

@'
[wsl2]
memory=6GB
swap=16GB

[experimental]
autoMemoryReclaim=dropcache
'@ | Set-Content "$HOME\.wslconfig" -Encoding ascii

WSL.conf issues​

If the WSL Distro fails to boot, it generally is due to WSL.conf issues.

  1. Locate the Linux VHD disk image in PowerShell
Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\* | 
Select-Object DistributionName, BasePath

output

DistributionName BasePath
---------------- --------
Kali D:\Linux\KaliLinux
docker-desktop \\?\D:\Docker\wsl\DockerDesktopWSL\main
Arch \\?\D:\Linux\ArchRescue
  1. Shutdown WSL and mount the linux VHD
wsl --shutdown
wsl --mount "D:\Linux\ArchRescue\ext4.vhdx" --vhd --bare
  1. Launch the working Linux distro
wsl -d Kali
  1. Inside the owrking distro, create a directory to mount the target VHD and mount it
sudo mkdir -p /mnt/arch_root
sudo mount /dev/sdd /mnt/arch_root
  1. Make the changes or the backup to the wsl.conf file.
sudo mv /mnt/arch_root/etc/wsl.conf /mnt/arch_root/etc/wsl.conf.bak
  1. Inside the working distro, umount the VHD and exit
sudo umount /mnt/arch_root
exit
  1. Back to Windows host powershell, umount the VHD on WSL
wsl --unmount "D:\Linux\ArchRescue\ext4.vhdx"
wsl --shutdown
  1. Try to enter the buggy WSL distro
wsl -d ArchRescue