WSL#
Resources#
Overview#
Linux Desktop#
-
Enable systemd in WSL2 and have the best Ubuntu GUI desktop experience!
- Using X410 with WSL2
- Fully Working KDE on Bash on Ubuntu 20.04
- WSL2 GUI Using VcXsrv: Complete Guide For Beginners
-
What's the easiest way to run GUI apps on Windows Subsystem for Linux?
-
LXQt
- Launch xfce4 or other desktop in Windows 11 WSLg Ubuntu distro
Nvidia/CUDA#
- https://ubuntu.com/tutorials/enabling-gpu-acceleration-on-ubuntu-on-wsl2-with-the-nvidia-cuda-platform#3-install-nvidia-cuda-on-ubuntu
- https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=WSL-Ubuntu&target_version=2.0&target_type=deb_local
Commands#
wsl --list --online |
list available Linux distributions |
wsl --list --verbose |
list installed Linux distributions |
wsl --unregister <distro> |
unregister and uninstall wsl distro |
`wsl --set-default-version [1 | 2]` |
wsl --update |
update WSL |
wsl --status |
check WSL status |
wsl hostname --all-ip-addresses |
get all Host IP address |
`grep -m1 nameserver /etc/resolv.conf | awk '{print $2}'` |
`ip route | grep default |
`ifconfig eth0 | grep inet` |
Config#
wsl.conf#
/etc/wsl.conf
: per-distribution settings for WSL
Bash[boot] systemd=true command=service docker start # Set a command to run when a new WSL instance launches. This example starts the Docker container service [automount] # Automatically mount Windows drive when the distribution is launched enabled=true # Set to true will automount fixed drives (C:/ or D:/) with DrvFs under the root directory set above. Set to false means drives won't be mounted automatically, but need to be mounted manually or with fstab. root=/ # Sets the directory where fixed drives will be automatically mounted. This example changes the mount location, so your C-drive would be /c, rather than the default /mnt/c. options="metadata,uid=1003,gid=1003,umask=077,fmask=11,case=off" # DrvFs-specific options can be specified. mountFsTab=true # Sets the `/etc/fstab` file to be processed when a WSL distribution is launched. [network] # Network host settings configure the DNS server used by WSL2 hostname=DemoHost # change hostname generateHosts=false # prevent WSL from the default behavior of auto-generating /etc/hosts generateResolvConf=false # prevent WSL from auto-generating /etc/resolv.conf so that you can create your own ie. nameserver 1.1.1.1 [interop] enabled=false # Set whether WSL supports interop process like launching Windows apps and adding path variables. Setting these to false will block the launch of Windows processes and block adding $PATH environment variables. appendWindowsPath=false [user] default=DemoUser # Set the user when launching a distribution with WSL
.wslconfig#
%USERPROFILE%/.wslconfig
: global settings for WSL2
[wsl2] section setting |
default | notes |
---|---|---|
kernel |
Microsoft built kernel provided inbox | absolute Windows path to a custom Linux kernel |
memory |
50% Windows total memory capped at 8GB | WSL2 VM memory allocation |
processors |
Windows logical processors count | WSL2 VM logical processors count |
localhostForwarding |
true |
allow Host access (via localhost:port ) to WSL2 VM wildcard /localhost ports |
kernelCommandLine |
blank | additional kernel command line arguments |
safeMode |
false |
disables many features, intended for distro recover recovery |
swap |
25% Windows memory size | WSL2 VM swap space size, 0 for no swap file |
swapFile |
%USERPROFILE%\AppData\Local\Temp\swap.vhdx |
absolute Windows path to the swap virtual hard disk |
pageReporting |
true |
enables Windows to reclaim unused allocated memory frin WSL2 VM |
guiApplications * |
true |
enable WSLg /GUI applications support |
debugConsole * |
false |
enable output console displaying dmesg contents of WSL2 VM |
nestedVirtualization * |
true |
enable other nested VMs to run inside WSL2 |
vmIdleTimeout * |
60000 |
WSL2 VM idle milliseconds before it is shut down |
path
values must be escaped Windows paths e.g:C:\\Temp\\myCustomKernel
size
values must be a size followed by a unit e.g.8GB
or512MB
*
only for Windows 11
.wslgconfig#
%USERPROFILE%/.wslgconfig
: global settings for WSLg- WSLg Configuration/Debug Options
X11#
Overview#
X11
: client-server system for managing GUI usingX protocol
(reference)
[!warning]
X Server
runs on physical/local user machine;X Client
runs on server/remote machine
X Server
: mediates access to displays/input devices e.g. monitors, mice, keyboardsX Client
: client program handles graphical dataX Display
: made up of at least one screen, keyboard, and pointer deviceX11 Forwarding
: useX11
overSSH
becauseX protocol
is plaintext-
$DISPLAY
: variable denotingX Display
connection forX Client
-
X Client
derivesunix
/tcp socket
connection to display through theX Server
X Server
accepts/rejects connection and then forwards the connection to the requested screenhostname:display_number.screen_number
: formatdisplay_number
: must always be explicitly sethostname
,screen_number
: defaults todevice_name/unix
and0
:0
: shorthand fordevice_name/unix:0.0
unix:0
: shorthand fordevice_name/unix:0
unix
/tcp socket
associated to display:hostname:n
->localhost:6000+n
hostname/unix:n
->/tmp/.X11-unix/Xn
X11 Startup files#
Bash Init Scripts and Loading/Execution Order
Linux Login Scripts
-
~/.xinitrc
: executed in text console mode login -
executed after logging in by
xinit
usually invoked viastartx
- first you log in on a text console
- then you start the GUI with startx
- purpose:_ start the GUI part of the session
- sets GUI-related settings e.g. key bindings (with
xmodmap
,xkbcomp
), X resources (withxrdb
), etc - launches session/window manager (possibly as part of a desktop environment)
- sets GUI-related settings e.g. key bindings (with
-
/etc/X11/Xsession
: analog to/etc/profile
used by login shells -
executed when
X Window System session
is started (regardless of using a display manager or startx from a virtual terminal) /etc/X11/Xsession.d/*
: ordered scripts that get sourced (analog to/etc/profile.d
)-
~/.xsession
: executed in graphical mode login -
purpose: starting the GUI session manager and possibly set login-time parameters (e.g. env vars)
- on termination => the
X session
will log out and returned to your display manager login screen -
Example:
Bash#!/bin/sh # typical .xsession . ~/.profile . ~/.xinitrc # Start our session manager of choice exec x-session-manager
-
~/.xsessionrc
: place to setX session
specific settings -
set env vars or run once-off utilities at launch (e.g
xrandr
/xmodmap
) - can also use this to source
/etc/profile
and~/.profile
- does not exist by default so you must create it
Created: 2023-09-01