Wsl
Installation
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# OR
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Download a distribution
Build a distribution
Create rootfs from Docker image
sudo su -
mkdir rootfs && docker export $(docker create archlinux) | tar -C rootfs -xf -
cd rootfs && tar czf ../rootfs.tar.gz --hard-dereference * && cd ..
Create rootfs from ISO
sudo su -
unsquash -d rootfs /path/to/distro.sfs to extract file system
cd rootfs && tar czf ../rootfs.tar.gz --hard-dereference * && cd ..
Install distro
- Create distro folder
- Download
Launcher.exe
oricons.zip
from here - Extract
rootfs.tar.gz
into distro folder - Run
"distro.exe"
to install - Run
"distro.exe --help"
to configure distro
Import a distribution
- Find the distro of choice at https://jenkins.linuxcontainers.org/view/Images/
- Download the
rootfs.tar.xz
for that distro - Unpack it using tar or 7zip to get
rootfs.tar
- Import using
wsl --import <distro name> <distro folder> <path to rootfs.tar>
import --import Debian C:\Users\jdoe\WSL\debian C:\Debian\rootfs.tar
Compacting WSL ext4.vhdx
wsl --shutdown
diskpart
select vdisk file="C:\path\to\ext4.vhdx"
compact vdisk
Build kernel
- Install required packages
sudo apt install g++ make flex bison libssl-dev libelf-dev bc
- Download new kernel source from https://github.com/microsoft/WSL2-Linux-Kernel/releases
- Extract, change into folder, and run
make KCONFIG_CONFIG=Microsoft/config-wsl
- Copy built kernel in arch/x86/boot/bzImage to Windows folder, i.e.: /mnt/c/Users/jdoe/kernel
- Add line below to C:\Users\jdoe\.wslconfig under [wsl2] section
[wsl2] kernel=C:\\Users\\jdoe\\kernel
- Restart WSL using
"wsl --shutdown"
or restart LxssManager service - Check kernel using
"uname -r"
Systemd
Arch
# As root
pacman-key --init
pacman-key --populate archlinux
pacman-key --refresh-keys
pacman -S archlinux-keyring
pacman -Syu
pacman -S --noconfirm base-devel curl git go vi vim wget
user=ctran
useradd -d /home/$user $user
mkdir /home/$user
chown $user:$user /home/$user
passwd $user
su - $user
# As user with sudo
git clone https://aur.archlinux.org/yay.git
cd yay && makepkg -si
yay -S --noconfirm daemonize
wget https://github.com/arkane-systems/genie/releases/download/v1.42/genie-systemd-1.42-1-x86_64.pkg.tar.zst
sudo pacman -U --noconfirm ./genie-systemd-1.42-1-x86_64.pkg.tar.zst
# Shortcut
mintty.exe --WSL="Arch" --configdir="C:\Users\jdoe\AppData\Roaming\wsltty" -~ genie -s
CentOS 8
yum install -y curl git vi vim wget
wget https://github.com/arkane-systems/genie/releases/download/v1.42/genie-1.42-1.fc33.x86_64.rpm
yum -y install ./genie-1.42-1.fc33.x86_64.rpm
# Shortcut
mintty.exe --WSL="CentOS8" --configdir="C:\Users\jdoe\AppData\Roaming\wsltty" -~ genie -s
Ubuntu/Debian
apt install -y curl git vi vim wget
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
apt install -y ./packages-microsoft-prod.deb
apt update && apt install -y dotnet-runtime-5.0
wget https://github.com/arkane-systems/genie/releases/download/v1.42/systemd-genie_1.42_amd64.deb
apt install -y ./systemd-genie_1.42_amd64.deb
# wsltty shortcut
mintty.exe --WSL="Ubuntu-20.04" --configdir="C:\Users\jdoe\AppData\Roaming\wsltty" -~ genie -c zsh
“Waiting for systemd” hang fix
# Ubuntu
sudo mv /usr/lib/systemd/system/systemd-remount-fs.service /usr/lib/systemd/system/systemd-remount-fs.bak
sudo systemctl disable multipathd.socket
# CentOS 8
sudo mv /usr/lib/systemd/system/systemd-remount-fs.service /usr/lib/systemd/system/systemd-remount-fs.bak
sudo mv /usr/lib/systemd/system/systemd-modules-load.service /usr/lib/systemd/system/systemd-modules-load.bak
sudo systemctl disable auditd
# Use command below to list failed service and disable/remove them
sudo systemctl list-units --failed
Restart WSL with wsl --shutdown
DNS Resolution
Simple
- Create/edit
/etc/wsl.conf
with the following lines[network] generateResolvConf = false
- Remove
/etc/resolv.conf
if it’s a symlink - Create/edit
/etc/resolv.conf
with lines belowsearch domain1 domain1.com nameserver 10.10.10.50
- Restart WSL with
wsl --shutdown
in CMD
Better - Using dnsmasq
NOTES: Install systemd above first
- Create/edit
/etc/wsl.conf
with the following lines[network] generateResolvConf = false
- Install dnsmasq using apt, yum, or pacman
- Create/edit
/etc/dnsmasq.conf
listen-address=0.0.0.0,127.0.0.1 server=/domain1/domain1.com/domain2/domain2.com/10.10.10.50 server=/domain2/domain2.com/10.10.10.51 server=8.8.8.8 server=8.8.4.4
- Enable and start dnsmasq service
sudo systemctl enable dnsmasq sudo systemctl start dnsmasq
- Remove
/etc/resolv.conf
if it’s a symlink - Create/edit
/etc/resolv.conf
with lines belowsearch domain1 domain1.com nameserver 127.0.0.1
- Restart WSL with
wsl --shutdown
in CMD
Docker Fix
sudo vim /etc/docker/daemon.json
{ "iptables": false }
VPN Fix
- Run command below in Powershell as administrator
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
- Create a ps1 file,
vpnfix.ps1
for example, with content belowGet-NetAdapter | Where-Object {$_.InterfaceDescription -Match "AnyConnect"} | Set-NetIPInterface -InterfaceMetric 9000
- Create a shortcut for
powershell.exe
pointing to that ps1 fileC:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -f "C:\path\to\vpnfix.ps1"
- Change that shortcut to run as Administrator
- Right click -> Properties -> Shortcut tab -> Advanced -> Run as administrator
- Run this shortcut every time after connecting to VPN
NAT fix
# Required for Debian
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
cgroup fix
# Required for Debian and Ubuntu
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
Kali shell fix
sudo vim /usr/lib/win-kex/xstartup
export SHELL=/bin/zsh