Mercenarys' note

WSL setting note

Install

Run Windows CMD as administrator:

wsl -l -o                            // list available Linux options 
wsl --install -d <Linux name>        // install the specified Linux 

Reference:

Enable GUI

The first method allows basic GUI usage. The second method ensure a long-term GUI operation.

Method-1

M1.1. Settings in Linux terminal

Install GUI related package such as:

sudo apt install ubuntu-desktop
sudo apt install nautilus
export DISPLAY=<WINDOWS LOCALHOST IP>:0.0 

You can find your Windows localhost IP by “ipconfig” in Windows CMD.
There might be difference in wsl 1 or 2. Check your version with these tips: https://linuxhint.com/check-wsl-version/

Reference:

M1.2. Settings in Windows

Method-2

Method allows basic GUI usage. Method-2 uses an additional utility to ensure X server continue working after host sleeps or alter network setting.

M2.1. Settings in Linux terminal

Similar to method-1 we install required package. But we set port to

export DISPLAY=:0

Next, download and run wsld

M2.2. Setting in Windows

Similar to method-1. In addition, download and run wsldhost.ext –daemon with admin privilege.

All these can be done on system boot with shell or batch script.

Use GPU and CUDA

Host requirement

Linux setting

Migrate: import & export

In windows CMD

wsl --export Ubuntu-20.04 tmp.tar
wsl --unregister Ubuntu-20.04 
wsl --import Ubuntu-20.04 <PATH_TO_STORE_VM> tmp.tar 

WSL config

Manually set DNS in /etc/resolv.conf

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf                                    # prevent overwrite

Mount Physical Disk

Run PowerShell as administrator:

 GET-CimInstance -query "SELECT * from Win32_DiskDrive"    # now the device path 
 wsl --mount \\.\PHYSICALDRIVE2 --bare                     # mount
 wsl --unmount \\.\PHYSICALDRIVE2                          # unmount 

In WSL:

lsblk                                                      # see mounted disk 
mount /dev/sdc1/ /mnt/wsldisk2                             # mount sdc's sdc1 to '/mnt/wsldisk2' folder

In case formatting is needed

sudo mkfs.ntfs -f /dev/sdc1/

32-bit i386 manually setting

Ubuntu 20 running in WSL seems weakly supports i386 packages.

  1. search needed packages from https://packages.ubuntu.com/search?keywords=search
  2. download .deb from i386 category
  3. extract by
    dpkg -x <DEB_FILE_NAME> <DESTINATION_DIRECTORY>
    
  4. add /lib/i386-linux-gnu/ too LD_LIBRARY_PATH. \*.deb may have different organization under DESTINATION_DIRECTORY, add them to LD_LIBRARY_PATH accordingly

Play audio

A few highlight

resize VHDX

mount vhdx

 wsl --mount --vhd E:\wsldisk2.vhdx  # in powershell 

In case access denied, repeat following

In case system hang during using large software, or installing large software, simplify your PATH by removing unessential 9p filesystem paths.