Skip to content

WSL#

Resources#

Overview#

Linux Desktop#

Nvidia/CUDA#

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 or 512MB
  • * only for Windows 11

.wslgconfig#

X11#

Overview#

  • X11: client-server system for managing GUI using X 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, keyboards
  • X Client: client program handles graphical data
  • X Display: made up of at least one screen, keyboard, and pointer device
  • X11 Forwarding: use X11 over SSH because X protocol is plaintext
  • $DISPLAY: variable denoting X Display connection for X Client

  • X Client derives unix/tcp socket connection to display through the X Server

  • X Server accepts/rejects connection and then forwards the connection to the requested screen
  • hostname:display_number.screen_number: format
    • display_number: must always be explicitly set
    • hostname,screen_number: defaults to device_name/unix and 0
    • :0: shorthand for device_name/unix:0.0
    • unix:0: shorthand for device_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 via startx

    • 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 (with xrdb), etc
    • launches session/window manager (possibly as part of a desktop environment)
  • /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 set X 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

Last update: 2023-09-01
Created: 2023-09-01