WSL: Mixed topics


Starting and shutting down of WSL

Starting

To start the WSL just start the Ubuntu app from your windows system:

Shutting down

To shut down the WSL service execute the following command in a Windows console:

wsl --shutdown

Exchanging files between Windows host and WSL system

Accessing Host’s Windows files from inside WSL

Change to mnt folder and enter dir:

> cd /mnt

> dir

This will show the drives of Windows Host system. For example an output like this:

c  e  g   wsl  wslg

All this drives are accessible from WSL.

So knowing the devices available you can copy form Windows file system as follows: cp /mnt/c/somefile.txt /home/yourusername/

Configuration

Limit used memory

Sometimes WSL 2 might be pretty memory consuming. After having ubuntu consoles running for a while you might often notice that 6, 7, 8 or more GBytes of your memory gone to WSL. The process involved here is called vmmem. So if you see in your task manager the process vmmem eating up most of your memory you know WSL might be behind it!

To check how your current WSL memory usage is, open your ubuntu console and run the following command in your console:

free -h --giga

If the memory usage shown by this command looks more than what you would expect it to be, your can limit that by creating a WSL config file. To do that you can open your ubunutu console and run the following command (where username would be your user name:

editor "$(wslpath "C:\Users\username\.wslconfig")"

This will open the Gnu nano editor on WSL Ubunutu. You can enter the following content into the editor (for the memory limit you can chose whatever is propriate in your case):

[wsl2]
memory=4GB

Once you have entered that content you can save your changes by pressing [Ctrl] followed by [x]

Then you have to shutdown the WSL:

wsl --shutdown

Once you open a new ubunutu console the WSL is started again and then you can check whether your configuration was recognized by WSL by running the same command you used at the beginning:

free -h --giga


total used free shared buff/cache available
Mem: 3.9G 436M 2.4G 1.0M 1.1G 3.3G
Swap: 1.0G 0B 1.0G

As you can see the WSL has recognized the memory limit we set before.

Troubleshooting

unable to find an interpreter for …

Problem

Trying to open VS Code from WSL as follows

$ code .

Leads to the following error being issued:

run-detectors: unable to find an interpreter for /mnt/c/Users/***/AppData/Local/Programs/Microsoft VS Code/Code.exe

Resolution

Execute the following command in a PowerShell on Windows host:

wsl --shutdown

Then opens a new wsl command prompt and try to open VS code again:

$ code .

This time it should work.