Windows WSL

Highlights

chevron-rightSetup after laptop reboothashtag
# enable ssh
$ sudo /etc/init.d/ssh restart
# restart docker
sudo service docker start
# re-register ssh keys with ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_gabepublic
chevron-rightResynch wsl clock when out-of-synchhashtag
$ sudo hwclock -s
# if it does work, do the following
# From cmd prompt
wsl --shutdown
# then restart
wsl

Summary

Setup

Source: Install WSL commandarrow-up-right

  • Use winver to find the Windows version

    Windows 10 Version 20H2 (OS Build 19042.2006)

  • The original wsl status; Note: this will change after wsl install.

chevron-rightwsl --statushashtag

  • Turn-on Hyper-V, then Reboot Source: [REF-4]

Required features for WSL
  • Check system info

chevron-rightsysteminfohashtag

  • Install Ubuntu and Reboot

  • After reboot, a linux ubuntu terminal open to complete the ubuntu OS installation

circle-info

Ubuntu virtual hard disk

They are stored in %USERPROFILE%\AppData\Local\Packages<distribution package name>\LocalState\ext4.vhdx For Ubuntu, the distribution package name is CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc

  • List all available distributions from Powershell:

  • Install ssh

  • Generate host keys for ssh; otherwise, the following error may occur during ssh restart: sshd: no hostkeys available -- exiting.

  • Restart the ssh server

  • In addition to linux installation, the wsl was also updated; now we can issue the following:

Troubleshooting

circle-exclamation
circle-info

After running wsl --install -d Ubuntu command, even though it fails, the "Ubuntu" icon will show up on the start menu.

  • To solve the "virtual hard disk uncompressed and unencrypted" issue, do the following:

    • This is recommended by Ref-3, and it worked

    • Open up File Explorer and navigate to C:\Users\YOUR_USER\AppData\Local\Packages\CanonicalGroupLimited...

    • Right click on LocalState, then select Properties, then Advanced

    • Ensure Compress contents to save disk space and Encrypt contents to secure data are both deselected

    • Click OK, then Apply, to Apply changes to this folder only

    • From the start menu, find and click "Ubuntu". A terminal window will open and start installing Ubuntu, as follow:

Update

Connect Windows to Linux

  • Open File Explorer, and type \\wsl$

  • File explorer will show the Linux instance and the folder structures

Windows File Explorer shows Ubuntu folders

Connect Linux to Windows folders

  • From the Linux terminal

Use Termius or putty to connect to linux

For the host address, enter localhost.

VS Code Connect Remotely to WSL

  • Install extension "Remote WSL" if not already. Not sure if need to restart VS code after installation.

  • Once installed, a button should appear on the bottom left hand corner (><) that can be used to "Open a Remote Window". This will open a new VS code

  • To open a Linux terminal within the already running VS code, click the (+) dropdown located on the top right hand side of the terminal tab, and select the distro "Ubuntu (WSL)"

  • Also see this articlearrow-up-right

    • From VS code connect to WSL

    • Then open folder and choose WSL folder

Start WSL after Windows reboot

circle-info

After rebooting Windows, the File Explorer cannot connect the Linux folder (see Connect Windows to Linux) until WSL is started.

  • To start WSL, for example after rebooting Windows, open PowerShell in the administrator mode, and issue the following command:

  • The PowerShell terminal now becomes the WSL Ubuntu terminal.

    • Note: to open another Ubuntu terminal, from the Windows "Start" menu, find & click "Ubuntu for Windows", that will open the Ubuntu console

    • [Alternative] PowerShell is limited in functionality and lacks features such as: multiple tabs, panes, etc. Try install the "Windows Terminalarrow-up-right". Using the windows terminal, to open "Panes"arrow-up-right within the same tab, [alt-click-dropdown-selectType] to open a new pane of the selected terminal type; [ctrl-shift-w] to close the focused pane; [alt-arrowKey] to move between pane; [alt-shift-arrowKey] to resize pane.

  • From the Ubuntu terminal, start the SSH service so that we can connect to wsl Ubuntu from the SSH terminal (such as: putty or termius)

Repair or Reset WSL Linux instance

Best Practice - Set up a WSL development environment

[REF-5] Microsoft: Set up a WSL development environmentarrow-up-right]

Install GUI desktop in WSL2 Ubuntu

Source: - [Referenced here] WSL2 Ubuntu GUIarrow-up-right - Install GUI Desktop in WSL2 Ubuntu 20.04 LTS in Windows 10arrow-up-right

  • From the ubuntu terminal, setup Xfce. Note: after completion of the installation, we will be able to RDP (Windows remote desktop) into the Ubuntu GUI desktop

  • Update the Distro installation and remove previous install of xrdp

  • Install Xrdp

  • Install Xfce , select lightdm or gdm3 as per your preference when asked; optional to add xfce4-goodies.

  • Open the start script, /etc/xrdp/startwm.sh, and comment the last 2 lines, and add one new entry, as shown below

  • Modify the port to 3390 in the xrdp config

  • Start the dbus and xrdp

  • Open RDP and connect to localhost:3390

How-to

chevron-rightwsl not found after windows updatehashtag
chevron-rightcannot ssh into wsl after windows updatehashtag

windows update changes the wsl ssh config causing ssh from windows using (putty, termius, etc.) to fail. SSH should be possible with localhost:22, and the linux userid/password.

To fix the issue, do the following:

  • From the start menu, find Ubuntu and open

  • Go to /etc/ssh folder, and modify sshd_config to the following:

  • Restart the ssh server

Source: https://stackoverflow.com/questions/65196276/sshing-from-windows-10-into-wsl2-ubuntuarrow-up-right

chevron-rightwsl2 clock out of sync (Temporary solution)hashtag
chevron-rightError due to WSL time out of sync or not updatedhashtag

An error occurred (SignatureDoesNotMatch) when calling the GetCallerIdentity operation: Signature expired: 20230804T145316Z is now earlier than 20230805T044911Z (20230805T050411Z - 15 min.)

Run the following command; issue should have been fixed by wsl; see https://stackoverflow.com/questions/65086856/wsl2-clock-is-out-of-sync-with-windowsarrow-up-right

chevron-rightSetup second instance of WSL Linuxhashtag

References

Last updated