https://learn.microsoft.com/en-us/windows/wsl/basic-commands
https://learn.microsoft.com/en-us/windows/wsl/install
https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
Note: Most wsl commands must be executed as a regular user (not Administrator); otherwise you'll get an "Access denied" message.
If you are local administrator, activate UAC (it's enough any level over 'Never notify') to be able to open terminals without Administrator privileges.
Choose the proper download: AL2022.zip
https://github.com/yosukes-dev/AmazonWSL
Choose the proper download: Amazon2.zip
https://github.com/yosukes-dev/AmazonWSL/tree/2
wsl -l -v
wsl --unregister <distroName>
wsl --update
wsl -v
WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.22631.4112
Let's 1st install a distro that will later use for exporting and importing it
wsl.exe --install -d Debian
It's possible to see where the distro has been installed (BasePath), eg:
PS> Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse
Name Property
---- --------
{8d5b10d4-3c52-4bf5-93ab-3ce6e State : 1
28ea406} DistributionName : Ubuntu
Version : 2
BasePath : C:\Users\mysername\AppData\Local\Packages\CanonicalGroupLimited.Ubuntuon
Windows_79rhkp1fndgsc\LocalState
Flags : 15
DefaultUid : 1000
PackageFamilyName : CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
KernelCommandLine : BOOT_IMAGE=/kernel init=/init
DefaultEnvironment : {HOSTTYPE=x86_64, LANG=en_US.UTF-8,
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/...
{bdb8fc95-5e65-4efd-aca2-565d0 State : 1
076f1fd} DistributionName : Debian
Version : 2
BasePath : C:\Users\myusername\AppData\Local\Packages\TheDebianProject.DebianGNULinux
_76v4gfsz19hv4\LocalState
Flags : 15
DefaultUid : 1000
PackageFamilyName : TheDebianProject.DebianGNULinux_76v4gfsz19hv4
Export the distribution as a .tar file
wsl --export Debian wsl-debian-20230916.tar
or (UNTESTED)
wsl --export --vhd Debian wsl-debian-20230916.vhdx
Unregister the distribution, so that we can import it later
wsl --unregister Debian
Import the .tar into the same BasePath where it was before
wsl --import Debian C:\Users\myusername\AppData\Local\Packages\TheDebianProject.DebianGNULinux_76v4gfsz19hv4\LocalState .\wsl-debian-20230916.tar
Import the .tar intro a new BasePath
md D:\wslDistroStorage
md D:\wslDistroStorage\MyDebian
wsl --import Debian D:\WSL_DISTROS\MyDebian .\wsl-debian-20230916.tar
Alternatively, copy the ext4.vhdx file in the BasePath directory and import it inplace (UNTESTED):
wsl --import-in-place Debian ext4.vhdx
At time of writing, WSLg is supported in Windows 11 and there aren't plans to support it in windows 10.
Install X servers for Windows and start it before entering the WSL environment:
VcXsrv - https://sourceforge.net/projects/vcxsrv/
Click desktop icon "XLaunch", click Next, click Next and in the "Extra setting" toggle on "Disable access control"
Windows 11 uses WSLg out of the box (the following configuration, if it exists, must be removed).
Windows 10 needs a running X server. If graphical applications can't connect automatically, paste the following commands to the terminal before starting the applications or set them on every login by adding them to ~/.bashrc:
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 # WSL 2
export LIBGL_ALWAYS_INDIRECT=1
The Windows Terminal is a modern, fast, efficient, powerful, and productive terminal application for users of command-line tools and shells like Command Prompt, PowerShell, and WSL. Its main features include multiple tabs, panes, Unicode and UTF-8 character support, a GPU accelerated text rendering engine, and custom themes, styles, and configurations.
Install from Microsoft Store:
https://aka.ms/terminal
Virtual disk file, eg:
C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx
7 Simple Ways to Free Up Space on Ubuntu and Linux Mint
https://itsfoss.com/free-up-space-ubuntu-linux/
WSL – Reclaiming Storage Space
https://tkacz.pro/wsl-reclaiming-storage-space/
# .local/bin
export PATH="$HOME/.local/bin:$PATH"
# INI WSL
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 # WSL 2
export LIBGL_ALWAYS_INDIRECT=1
# END WSL
#JDK 11
export JDK_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 && export JAVA_HOME=$JDK_HOME
#JDK 8
#export JDK_HOME=/usr/lib/jvm/java-8-oracle && export JAVA_HOME=$JDK_HOME
Ubuntu under WSL uses, by default, SysVinit instead of systemd. Systemd equivalent sysvinit commands:
https://linuxhandbook.com/system-has-not-been-booted-with-systemd/
For enabling systemd:
https://ubuntu.com/blog/ubuntu-wsl-enable-systemd
See page 'Eclipse IDE'
https://sites.google.com/site/pawneecity/eclipse-ide
Install the Visual Studio Code extension:
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl
And start it from WSL with:
code .
Podman (drop-in replacement for docker)
https://sites.google.com/site/pawneecity/docker/podman-docker
Docker Desktop WSL 2 backend
Note: It requires paid subscription for enterprises with 250 employees or $10 million in annual revenue
https://docs.docker.com/docker-for-windows/wsl/
The idea is having the DBMS in WSL and the UI tools in Windows (eg: DBeaver), as stated at:
https://harshityadav95.medium.com/postgresql-in-windows-subsystem-for-linux-wsl-6dc751ac1ff3
To set the password for postgres, type:
sudo passwd postgres
Close and reopen the terminal.
To start the service, type:
sudo service postgresql start
To connect to postgres, type:
sudo -u postgres psql
If unable to access ports in wsdl from windows, shutting down and restarting wsl might fix it.
jdoe@BC27IB:~$ wsl.exe --shutdown
[process exited with code 1]
If unable to start WSL on Windows 11 because of error "process exited with code 4294967295" then run on a cmd console as administrator (reboot computer afterwards):
netsh winsock reset
Output of command:
Sucessfully reset the Winsock Catalog.
You must restart the computer in order to complete the reset.
Reference (and other alternative solutions):
https://github.com/microsoft/WSL/issues/5092
Temporary solution is to set systemd=false in /etc/wsl.conf and the run wsl.exe --shutdown
the run sudo apt update or whatever
then enable systemd again
Solution is:
sudo nano /usr/lib/binfmt.d/WSLInterop.conf
with content:
:WSLInterop:M::MZ::/init:PF
and execute from a 'cmd' console:
wsl --shutdown
Appeared on Windows 11 w/ WSL2 after upgrading Ubuntu 22.04 to 24.04 when executing, eg, google-chrome.
Workaround is to add the following lines to the file .bashrc (and source it, or restart WSL):
# FIX for "Failed to connect to the bus: Failed to connect to socket /run/user/1000/bus: No such file or directory" (Windows 11 w/ WSL2)
dbus_service_name="dbus"
if systemctl is-active --quiet "$dbus_service_name.service" ; then
# Note: 1st time only rises error "Failed to connect to bus: No such file or directory"
echo "$dbus_service_name service is running"
else
echo "Restarting service $dbus_service_name..."
sudo service $dbus_service_name restart
fi
dbus-daemon --session --address=$DBUS_SESSION_BUS_ADDRESS --nofork --nopidfile --syslog-only &