Misc help on using WSL:
- get WSL Version
- reboot / restart wsl
- Install Docker
- Install Brew
- Dealing with VPN
- Shrink WSL Disk
- Install Oracle Client
- Move WSL to New computer
- Other misc
If like me you maintain your original WSL 1 version, and instead of upgrading you installed a new WSL 2 distribution then you may want to define a default version.
wsl -l -v
outputs something like this:
C:\WINDOWS\system32>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu Running 1
docker-desktop Running 2
Ubuntu-20.04 Running 2
docker-desktop-data Running 2
The '*' next to Ubuntu indicates that it is the default version, and also if you look at the version column you can see that it is running under WSL version 1. You will also see that I have a version called 'Ubuntu-20.04' That's the version I want to set as the default version.
wsl -s Ubuntu-20.04
and now verify that the default version has been set:
C:\WINDOWS\system32>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
docker-desktop Running 2
Ubuntu Running 1
docker-desktop-data Running 2
wsl --shutdown
This is almost a complete cut and paste of instructions found (here)[https://blog.avenuecode.com/running-docker-engine-on-wsl-2]:
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt update && sudo apt upgrade -y
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release -y
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo usermod -aG docker $USER
sudo curl -L \
"https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# start engine
sudo service docker start
docker run hello-world
Add the following line to the .bashrc file
...
wsl.exe -u root service docker status || wsl.exe -u root service docker startFollowing these guidelines
sudo apt-get install build-essential curl file git
Then install linux brew...
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Finally add the homebrew path to the your .profile
echo 'export PATH=/home/linuxbrew/.linuxbrew/bin:$PATH' >>~/.bash_profile
- helm
- act
brew install helm act
As show above specific distros can be listed using:
wsl -l
Then to run one, just type its name, example:
Microsoft Windows [Version 10.0.666.666]
KJNETHER@SILLYWINDOWS C:\tools\Cmder
$ wsl -l
Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)
docker-desktop
Ubuntu
docker-desktop-data
KJNETHER@SILLYWINDOWS C:\tools\Cmder
$ Ubuntu
kjnether@SILLYWINDOWS:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
kjnether@SILLYWINDOWS:~$
- jq
Powersmell cli to get the dns ips for the vpn:
(Get-NetAdapter | Where-Object InterfaceDescription -like "Cisco AnyConnect*" | Get-DnsClientServerAddress).ServerAddresses
Add those to the WSL file: /etc/resolv.conf
example:
...
nameserver <ip goes here>
nameserver <ip goes here>
...
Attempt to ping the host
Firewall Rules - Not sure if this is required, think it may have been with new machine so I can ping the hosts
netsh advfirewall firewall add rule name="ICMPv4 Allow Ping Requests" protocol=icmpv4:8,any dir=in action=allow
Enable-NetFirewallRule -DisplayName 'Virtual Machine Monitoring (Echo Request - ICMPv6-In)'
OLD STUFF...
This link provided these powershell commands that can be run after VPN is connected to give WSL higher level priority.
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
(Get-NetAdapter | Where-Object InterfaceDescription -like "Cisco AnyConnect*" | Get-DnsClientServerAddress).ServerAddresses
other options:
For whatever reason you may fill up your WSL hard drive. If your drive is configured to grow based on demand, you may eventually find yourself in the situation where your disk has used up all the space on your machine. In my experience this has happened when running various data pipelines that pull / prep / and push data, but do not necessarily clean up after themselves.
- find the path to your WSL ext4.vhdx file, if you are running ubuntu under wsl look for a folder in C:\Users\kjnether\AppData\Local\Packages\ that has the word ubuntu in it... mine is: CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
- open a cmd with admin permissions
- shutdown wsl
wsl --shutdown - open diskpart
diskpart - select the disk, for me this is the command
select vdisk file="C:\Users\kjnether\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx" - select disk for readonly
attach vdisk readonly - compact the disk
compact vdisk - detach the disk
detach vdisk - yer now done!
exit
I'm going to install in /opt/oracle, you can install anywhere you see fit.
sudo apt install libaio1t64
# you also will need this symbolic link
sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1
Create the directory:
sudo mkdir /opt/oracle
cd /opt/oracle
Get the software:
sudo wget https://download.oracle.com/otn_software/linux/instantclient/1924000/instantclient-basic-linux.x64-19.24.0.0.0dbru.zip
sudo wget https://download.oracle.com/otn_software/linux/instantclient/1924000/instantclient-sqlplus-linux.x64-19.24.0.0.0dbru.zip
Unpack the software
sudo unzip instantclient-basic-linux.x64-19.24.0.0.0dbru.zip
sudo unzip instantclient-sqlplus-linux.x64-19.24.0.0.0dbru.zip
Modify environment, by opening .bashrc and adding the following lines to the file:
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_24:$LD_LIBRARY_PATH
export PATH=/opt/oracle/instantclient_19_24:$PATH
Summarized from here
For most the name will be Ubuntu
wsl --list
The following isn't used, but is rather a backup in case things go sideways
wsl --export Ubuntu D:\wsl_backup\ubuntu.tar
Now export your current wsl image file
wsl --export --vhd <Distribution Name> <FileName>
Where "FileName" is the image that was exported in previous steps.
wsl --import-in-place <Distribution Name> <FileName>
Started running into issues where vscode wasn't able to authenticate to github for my copilot subscription. Not sure if this going to work, but to try to facilitate the network communication betweek copilot and the auth process adding the github ip to the network configuration:
Open up /etc/network/interfaces, then add the following line to the file:
140.82.121.6 api.github.com