Installation and Upgrades
Installed version
$lsb_release -a
https://learn.microsoft.com/en-us/windows/wsl/disk-space
Available Disk space
wsl.exe –system -d <distribution-name> df -h /mnt/wslg/distro
Compact vdisk:
PS>diskpart
DISKPART>select vdisk file=”path\to\ext4.vhdx”
DISKPART>compact vdisk
DISKPART>detail vdisk
DISKPART>expand vdisk maximum=<sizeInMegaBytes>
DISKPART>exit
Expanding
$sudo mount -t devtmpfs none /dev
mount | grep ext4
$sudo resize2fs /dev/sdX <sizeInMegabytes>M
$sudo apt install resize2fs
$resize2fs 1.44.1 (24-Mar-2021)
Filesystem at /dev/sdb is mounted on /; on-line resizing required
old_desc_blocks = 32, new_desc_blocks = 38
The filesystem on /dev/sdb is now 78643200 (4k) blocks long.
Export / Import
PS>wsl -l #list images
PS>wsl –export <image> <file.tar> <<– use Ubuntu as template image
PS>wsl –import <new-image> <target directory> <file-name.tar>
Folder Structure : <WSL-path>/<project-name>/<image-name> ex. E:/VMs/WSL/EDUDATE.ACADEMY/edudate-ops
ON LEOPARD:
Images archived on: C:\Users\timys\OneDrive\VMs\WSL\backup <- synced on OneDrive
WSL disks stored locally on: C:\Ops\VMs\WSL\<project-name>
Add user
# adduser <new-user>
Change default uid
Login as root PS> wsl -d <image> -u root
((If taken from starfish-snapshot backups))
#./change-wsl-owner <new-user>
change-wsl-owner is script that automate below manual ops
Else – Manual
#vi /etc/wsl.conf
[user]
default=<new-user>
#groupmod -n <new-group> <old-group>
#usermod -l <new-user> -d /home/<new-user> <old-user>
- #usermod -l edudateops -d /home/edudateops ubuntu
#mv /home/<old-user> /home/<new-user>
#exit
PS>wsl –shutdown
PS>wsl -d <new-wsl-distribution>
$echo “cd ~” >> .bashrc
$sudo apt update
$sudo apt upgrade -y
$git config –global user.name “Edudater”
$git config –global user.email “[email protected]”
Advanced settings configuration in WSL | Microsoft Learn
Windows File Explorer
WSL2 Problems:
- Networking through NAT is unreliable, Issues still reported from Microsoft
- Can’t install php8.2 from binaries, need to compile
- use dockers ok
Remove MySQL:
sudo apt remove –purge ‘*mysql*’
Enable/Disable service
$sudo systemctl disable nginx
List packages: dpkg -l|grep php |teepackages.txt
force remove packages: sudo dpkg –remove –force-remove-reinstreq awsvpnclient
Install MySQL on WSL : https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database
Use sudo service mysql start|stop|status (systemctl won’t enable)
Install MySQL On WSL2 Ubuntu
https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-database
$sudo apt update
$sudo apt upgrade -y
$sudo apt install mysql-server
$sudo usermod -aG mysql edudate <<exit -relogin>>
$sudo usermod -d /home/mysql , sudo mkdir /home/mysql; sudo chown mysql:mysql /home/mysql
$sudo /etc/init.d/mysql start OR sudo service mysql [start|stop|restart…]
$sudo service mysql restart //<– to avoid the socket problem chmod g+rwx /var/run/mysqld/socket.lock
$mysql –version
$sudo mysql <<-Grant root access from any host >>
mysql>CREATE USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘Gray$cal3’;
mysql>ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password by ‘Gray$cal3’;
mysql> FLUSH PRIVILEGES;
mysql>quit;
$sudo mysql_secure_installation <–follow instruction to secure root user
$sudo service mysql restart
$sudo chmod g+rwx /var/run/mysqld
$mysql -u root -p //<– should login ok with password 🙂
Then setting up port binding:
$sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
Change all bind-address=0.0.0.0 or comment #
Otherwise you get “reading initial communication packet” error
$sudo service mysql restart
user = mysql
# pid-file = /var/run/mysqld/mysqld.pid
# socket = /var/run/mysqld/mysqld.sock <- change to writable otherwise get socket errors
# port = 3306
# datadir = /var/lib/mysql
Windows firewall open port 3306
Use Skywalk , MYSQL Workbench to load the schema edudate to the server.
Networking:
- From your WSL distribution (ie Ubuntu), run the command: ip addr
- Find and copy the address under the inet value of the eth0 interface.
- If you have the grep tool installed, find this more easily by filtering the output with the command: ip addr | grep eth0
- Connect to your Linux server using this IP address.
Set Execution Policy
Set-ExecutionPolicy -ExecutionPolicy ByPass -Scope CurrentUser
Network port forwarding:
Execute the following script from PS:
>VMs\WSL\scripts\network.ps1
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”)) {
$arguments = “& ‘” + $myinvocation.mycommand.definition + “‘”
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$remoteport = wsl get-ip-addr
$found = $remoteport -match ‘\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}’;
if ($found) {
$remoteport = $matches[0];
}
else {
Write-Output “IP address could not be found”;
exit;
}
$ports = @(5001, 19000, 19001);
for ($i = 0; $i -lt $ports.length; $i++) {
$port = $ports[$i];
Invoke-Expression “netsh interface portproxy delete v4tov4 listenport=$port”;
Invoke-Expression “netsh advfirewall firewall delete rule name=$port”;
Invoke-Expression “netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteport”;
Invoke-Expression “netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$port”;
}
Invoke-Expression “netsh interface portproxy show v4tov4”;
Fix Signing
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Upgrade 20.04 to 22.04
sudo apt update && sudo apt full-upgrade
# restart Ubuntu
$sudo do-release-upgrade
$cat /etc/os-release
Advanced Settings : wsl.conf & .wslconfig
https://docs.microsoft.com/en-us/windows/wsl/wsl-config
/usr/bin/get-ip-addr
ip addr | grep ‘global eth0’
$sudo chmod +x /usr/bin/get-ip-addr
Automatic WSL services startup
Find Disk volume
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue(“DistributionName”) -eq ‘<distribution-name>’ }).GetValue(“BasePath”) + “\ext4.vhdx”
Steps to display GUI apps on Windows:
https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-11-with-gui-support#1-overview
VcXsrv Windows X Server
On Windows 10:
Install X10 Server on Windows :https://sourceforge.net/projects/vcxsrv/
Note:
During setup is important to disable the access control to avoid the permission denied error when trying to run a GUI application. And save the configuration into config.xlaunch
Enable VcXsrv on windows firewall.
On WSL2:
Set DISPLAY to one of the following: in /etc/bash.bashrc or ~/.bashrc
Note: use Windows LAN WIFI adapter or Ethernet Adapter, the default get IP from Hyper-V adapter which is wrong.
Edit file /etc/wsl.conf to disable auto generation of this file
[network]
generateResolvConf = false | true
wsl –shutdown
export DISPLAY=”`grep nameserver /etc/resolv.conf | sed’s/nameserver //’`:0.0″
export DISPLAY=”`sed-n ‘s/nameserver //p’/etc/resolv.conf`:0.0″
export DISPLAY=$(iproute|awk’/^default/{print $3}’):0.0
export DISPLAY=<hard-code-windows-wifi/ethernet IP address> ex. Export DISPLAY=192.168.1.72:0.0
Display number format n[0..] ex 0.0,1.0,2.0..etc default 0 = 0.0
Create xsession
echo xfce4-session >~/.xsession
Install Chromium
sudo add-apt-repository ppa:saiarcot895/chromium-dev
sudo apt-get update
sudo apt-get install chromium-browser
chromium-browser
Install gedit:
sudo apt install gedit
gedit
Install X11 apps:
https://packages.debian.org/stretch/x11-apps
sudo apt install x11-apps
xeyes
xcalc
Google Drive & OneDrive and the others
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.