-
Enable virtualization in BIOS; the setting may be called VT-x, AMD-V, SVM, or Vanderpool.
Enable Intel VT-d or AMD IOMMU if the options are available. -
Search for "Turn Windows features on or off", open it and in the Windows Featues window tick the box in front of Hyper-V to activate it.
-
Enable Virtual Machine Platform in the Windows Features window (Turn Windows features on or off).
-
Enable Windows Subsystem for Linux in the Windows Features window (Turn Windows features on or off).
-
Search for Windows Updates and install any new WSL updates.
-
After completion of above tasks, you may want to set a specific WSL version to avoid having to migrate later (see Setting WSL versions)
-
Install an Ubuntu version from the Microsoft Store (eg. Ubuntu 22.04.1 LTS)
-
Run the distro and follow the setup.
-
Open a new CMD shell and navigate to your desired disk (eg.
F:/
).cd F: mkdir wsl cd wsl
-
Run
wsl -l
to list your registered distros. -
Run
wsl --export <distro> <target-file>
to export your distro to an archive.wsl --export Ubuntu-22.04 ubuntu-22.04.tar
-
Run
wsl --unregister <distro>
to unregister the MSStore installation.wsl --unregister Ubuntu-22.04
Note: You can now uninstall the MStore distribution like you would any other Windows application under Apps & Features.
-
Run
wsl --import <distro> <folder> <target-file>
wsl --import Ubuntu-22.04 ubuntu-22-04 ubuntu-22.04.tar
-
The newly imported instance will not inherit your previously created default user and instead use root by default. To fix, find the following key in the registry
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss
where
DistributionName == <distro>
and set itsDefaultUid
to decimal1000
(or hex3e8
). -
Try WSL with
wsl -d <distro>
wsl -d Ubuntu-22.04
Ref. https://blog.iany.me/2020/06/move-wsl-to-another-drive/
-
Install scoop by running the following command from a non-admin PowerShell
iwr -useb get.scoop.sh | iex
-
Install LxRunOffline by running
scoop bucket add extras scoop install lxrunoffline
-
Download a Linux Distro archive (see LxRunOffline/wiki for alternative downloads).
# Ubuntu 18.04 https://cloud-images.ubuntu.com/releases/bionic/release/ubuntu-18.04-server-cloudimg-amd64-wsl.rootfs.tar.gz # Ubuntu 20.04 https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64-wsl.rootfs.tar.gz # Ubuntu 22.04 https://cloud-images.ubuntu.com/releases/jammy/release/ubuntu-22.04-server-cloudimg-amd64-wsl.rootfs.tar.gz
-
Install the Linux distro under WSL with
# Change according to your preference LxRunOffline i -n ubuntu22 -d "C:\wsl\ubuntu22" -f "full\path\to\.tar.gz"
-
Login to the distro (Eg: ubuntu22)
wsl -d ubuntu22
-
Once logged in, create a new user (Eg: harry)
adduser harry
-
Give the user (harry) sudo access
usermod -aG sudo harry
-
To set harry as default user instead of root, run the following command from the Command Prompt (CMD)
LxRunOffline su -n ubuntu22 -v 1000
Ref. https://harry.plus/blog/manage-wsl-like-a-boss-with-lxrunoffline/
- (Global) Set the default WSL version for future distro installations:
wsl --set-default-version <version>
- (Individual) Convert already installed distros to a different version:
wsl --set-version <distro_name> <version>
where version is usually 1 or 2.
You will need to create/edit the wsl.conf file to ensure systemd starts up on boot.
- Open the
wsl.conf
file with sudo by runningsudo nano /etc/wsl.conf
- Add the following lines to the file
[boot] systemd=true
- Close out of the nano editor using CTRL+O to save and CTRL+X to exit.
- Close your WSL distro Windows and run
wsl.exe --shutdown
from PowerShell to restart your WSL instances. - Relaunch your WSL distro and check that systemd is running with the following command
which should show your services’ status.systemctl list-unit-files --type=service
Ref. https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/