Configure WSL#
Enable Windows Subsystem for Linux#
In Control Panel
- Programs
- Turn Windows features on or off
, check Windows Subsystem for Linux
and Virtual Machine Platform
(required for WSL2).
Alternatively, you can execute the following commands in an elevated command prompt:
# Windows Subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Afterwards, restart your computer.
Set the default WSL version#
Execute the following command in an elevated command prompt:
wsl --set-default-version 2
This will make future Linux installations default to WSL2.
Existing WSL virtual machines can also be converted using the following commands:
# Get information about existing WSL versions
wsl --list --verbose
# Convert an existing distribution to a specific version
wsl --set-version <distribution name> <versionNumber>
Upgrade to WSL2.
Move installation location (optional)#
Currently, WSL does not support setting the installation path. After some time, the size of the installation can grow to 10GB+. You can use the open-source tool LxRunOffline to install Linux to any location or move an existing Linux subsystem to any location.
Install LxRunOffline#
Scoop is a Windows command-line package manager that provides a similar experience to apt/yum.
To install LxRunOffline using Scoop, follow these steps:
# Execute in PowerShell
set-executionpolicy remotesigned -scope currentuser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
scoop bucket add extras
scoop install lxrunoffline
Alternatively, you can directly download the binary file and then run regsvr32 LxRunOfflineShellExt.dll
to complete the installation.
Move#
# Execute in PowerShell
# View all installed distributions
lxrunoffline gd
# Move an existing distribution, the path format is similar to D:\wsl\Ubuntu-18.04
LxRunOffline m -n <distribution name> -d <path>
# Wait for a while to complete the move, then check the current location of the distribution
LxRunOffline di -n <distribution name>
Install Linux system#
Choose and install a WSL system using the command line.
Alternatively, open Microsoft Store and search for WSL to get available Linux distributions.
Or download the official image and install using LxRunOffline.
Command line installation#
-
View available distributions
wsl --list --online or wsl -l -o
-
Install a distribution
wsl --install -d distribution
After installation, you may encounter the error "WslRegisterDistribution failed with error: 0x800701bc".
Download Arch Linux#
Download link: https://mirrors.tuna.tsinghua.edu.cn/archlinux/iso/latest/
Find archlinux-bootstrap-2023.04.01-x86_64.tar.gz
, note that it is a tar.gz file.
Install Arch Linux to WSL#
LxRunOffline i -n <custom name> -f <Arch image location> -d <installation location> -r root.x86_64
For example:
LxRunOffline i -n ArchLinux -f C:\Users\user\Downloads\archlinux-bootstrap-2023.04.01-x86_64.tar.gz -d C:\Users\user\Linux -r root.x86_64
After executing the command, you may encounter the following error:
[ERROR] Couldn't get the value "DistributionName" of the registry key "Software\Microsoft\Windows\CurrentVersion\Lxss\TryStoreWSL". Reason: The system cannot find the file specified.
To resolve this issue, open the Registry Editor, find the key "Software\Microsoft\Windows\CurrentVersion\Lxss\TryStoreWSL", and delete it.
After installation, uncomment the mirror address in /etc/pacman.d/mirrorlist
.
Then run the following commands:
pacman-key --init
pacman-key --populate archlinux
Using WSL#
File system#
In WSL1, the file directory is located at:
- Ubuntu:
%localappdata%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs
- Ubuntu18.04:
%localappdata%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs
In WSL2, you can directly access the WSL virtual machine on the network using \\wsl$
. For example, Ubuntu is \\wsl$\Ubuntu
.
Alternatively, you can open the current directory in WSL2 by calling explorer.exe .
in the terminal, which is very cool~
Windows disks are represented as /mnt/c|d|e...
in WSL. You can access them, but it is recommended to copy files to the WSL directory as there is a significant performance loss.