Skip to content

Instantly share code, notes, and snippets.

@Calvindd2f
Created October 13, 2024 05:01
Show Gist options
  • Select an option

  • Save Calvindd2f/ec921f1ede53280a8981c2b9c1c66996 to your computer and use it in GitHub Desktop.

Select an option

Save Calvindd2f/ec921f1ede53280a8981c2b9c1c66996 to your computer and use it in GitHub Desktop.
# From PwSh
# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
# $userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
# [System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Administrator\Ubuntu", "User")
# wsl --shutdown
# wsl --update
# winget install --interactive --exact dorssel.usbipd-win
# usbipd list
# usbipd bind --busid 4-4
# usbipd attach --wsl --busid <busid>
# lsusb
# usbipd detach --busid <busid>
# Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow
# New-NetFirewallHyperVRule -Name "MyWebServer" -DisplayName "My Web Server" -Direction Inbound -VMCreatorId '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -Protocol TCP -LocalPorts 80
# $Uri='https://github.com/dorssel/usbipd-win/releases/download/v4.3.0/usbipd-win_4.3.0.msi'
# Ensure systemd in wsl
echo '
[boot]
systemd=true
' >> /etc/wsl.conf
# ip route show | grep -i default | awk '{ print $3}'
# netsh interface portproxy add v4tov4 listenport=<yourPortToForward> listenaddress=0.0.0.0 connectport=<yourPortToConnectToInWSL> connectaddress=(wsl hostname -I)
# netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=192.168.101.100
#
#
#
#
#
# usbipd bind --busid 2-2
# usbipd.exe attach --wsl --busid 2-2
#
#
##########################
# Fork WSL2 Kernel
cd ~
git clone https://github.com/your-username/WSL2-Linux-Kernel.git
cd WSL2-Linux-Kernel
# Install build tools
sudo apt-get install build-essential flex bison libssl-dev libelf-dev
# Configure the kernel
make KCONFIG_CONFIG=Microsoft/config-wsl menuconfig
# In the kernel configuration menu, enable the following options:
echo '
Enable follwing in Kernel menu:
Networking support -> Wireless
Networking support -> Wireless -> cfg80211 - wireless configuration API
Networking support -> Wireless -> Generic IEEE 802.11 Networking Stack (mac80211)
Device Drivers -> Network device support -> Wireless LAN -> Atheros Wireless Cards -> Atheros 802.11n wireless cards support
Device Drivers -> Network device support -> Wireless LAN -> Atheros 802.11n wireless cards support -> Atheros ath9k rate control
Device Drivers -> Network device support -> Wireless LAN -> Atheros 802.11n wireless cards support -> Atheros ath9k PCI/PCIe bus support
Device Drivers -> Network device support -> Wireless LAN -> Atheros 802.11n wireless cards support -> Atheros ath9k AHB bus support
'
# Save the configuration and exit the menu.
#
#
# Build the kernel
make KCONFIG_CONFIG=Microsoft/config-wsl -j$(nproc)
# Copy the built kernel to your Windows system
cp arch/x86/boot/bzImage /mnt/c/Users/c/
# Update your WSL configuration to use the custom kernel
### IN POWERSHELl / WINDOWS ENV
# if (Test-Path 'C:\Users\c\.wslconfig'){ni c:\users\c\.wslconfig }
# echo @"
# [wsl2]
# kernel=C:\\Users\\c\\bzImage
# "@ >> .wslconfig
# Restart WSL:
# wsl --shutdown ; sleep 10 ; wsl
# Verify kernel version
uname -r
@Calvindd2f
Copy link
Author

sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev

make KCONFIG_CONFIG=Microsoft/config-wsl

In case forgot deps for kernel building

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment