Skip to content

Running VS Code server for WSL inside genie bottle

vincent163 edited this page Jun 7, 2021 · 5 revisions

When running code from WSL, the VS Code server is always launched outside the bottle even if the code command is called inside the bottle. This may be inconvenient in some cases, such as not being able to execute systemctl commands inside a VS Code console.

Here is a hack I currently use to run VS Code server inside the bottle. Go to %USERPROFILE%\.vscode\extensions\ (on Windows) and find the folder with name ms-vscode-remote.remote-wsl-* where * is usually a version number. Then navigate to scripts folder. There should be three files under the folder, called wslServer.sh, wslCode.sh and wslDownload.sh respectively. Prepend the following lines to wslServer.sh:

# Check if inside bottle
if ! genie -b; then
        # Rerun current script inside bottle
        exec genie -c "$0" "$@"
fi

Then execute wsl --shutdown and restart VS Code in case the VS Code server is already running inside WSL. Next time the VS Code server is launched, it will be inside the bottle and systemd will have PID 1.