This is the WSL2-Linux-Kernel that has been modified to enable loadable modules support and be able to use wireless adapters
Amazing tutorial by TheConsciousCat on this whole process
https://www.youtube.com/watch?v=l7VQQJdePlk
Make a directory named src
mkdir ~/src
Clone the kernel
git clone https://github.com/EDLLT/WSL2-Linux-Kernel.git
Put your driver inside
drivers/net/wireless/realtek
-
Edit the Kconfig file inside
drivers/net/wireless/realtek/Kconfig
and make it point to your driver just like this commit below https://github.com/EDLLT/WSL2-Linux-Kernel/commit/e23de6383dcc5af1c2a50115029a9d318a63a997 -
Also edit the Makefile in
drivers/net/wireless/realtek/Makefile
and add the obj pointing to your driver just like below https://github.com/EDLLT/WSL2-Linux-Kernel/commit/2b0edd829739af7b6f601a54ba815c67b1d564ef -
Get into menuconfig
make -j $(expr $(nproc) - 1) KCONFIG_CONFIG=Microsoft/config-wsl menuconfig
-
Inside menuconfig goto
Device Drivers
(Hit Arrow down 15 times)Network device support
(Hit arrow down 23 times)Wireless LAN
(Hit arrow down 45 times) -
Now that you are in Wirelass LAN go down up until you find
Realtek devices
(~55 downs) & Find the driver you want to enable, in my case the driver I want to enable is called Realtek 8822B USB WiFi PressM
to enable it, (MAKE SURE IT SAYSM
NOT*
FOR THE DRIVER YOU WANT OTHERWISE IT MIGHT ERROR) -
Save the configuration file as
Microsoft/config-wsl
Now once you've done everything proceed to the below New Build Instructions
-
Install the build dependencies:
sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev
-
Load modules
make -j $(expr $(nproc) - 1) KCONFIG_CONFIG=Microsoft/config-wsl modules
-
modules_install
make -j $(expr $(nproc) - 1) KCONFIG_CONFIG=Microsoft/config-wsl modules_install
-
Build the kernel
make -j $(expr $(nproc) - 1) KCONFIG_CONFIG=Microsoft/config-wsl
Assuming that there were no errors you're safe to proceed
-
A file called bzImage file will be created in
~/src/WSL2-Linux-Kernel/arch/x86/boot
copy the bzImage to /mnt/Users/YOUR_USER Note: ReplaceYOURUSER
with your actual usercp ~/src/WSL2-Linux-Kernel/arch/x86/boot/bzImage /mnt/c/Users/YOURUSER
-
Create a file called .wslconfig inside
/mnt/c/Users/YOURUSER
and edit it nano /mnt/c/Users/YOURUSER/.wslconfig -
Paste this in(Don't forget to replace YOURUSER with your actual user) then CTRL+X to save the file and hit enter
[wsl2] kernel=C:\\Users\\USERNAME\\bzImageMODULESLOADED
-
goto windows command prompt and shutdown wsl(then wait for 10 seconds)
wsl --shutdown
Now try typing wsl, give it a second or two and it should work, (If it doesn't and you want to revert then delete the .wslconfig inside C:\Users\YOURUSER)
Goto your kernel directory
cd /lib/modules/$(uname -r)/kernel/drivers/net/wireless/realtek
Use ls to list out the folders available
ls
My result
rtl88x2bu rtl8xxxu
Once found cd into the folder containing the module you want to load in here I want to load rtl88x2bu
cd rtl88x2bu
Use ls again and find the file name then type modprobe NAME without .ko
ls
Result
88x2bu.ko
sudo modprobe 88x2bu
If everything works fine no error should pop up
use lsmod to list the loaded modules
lsmod
Result
Module Size Used by
88x2bu 4104192 0
cfg80211 1093632 1 88x2bu
And that's it, now attach your usb using usbipd(https://docs.microsoft.com/en-us/windows/wsl/connect-usb#attach-a-usb-device)
after that running iwconfig gives me
iwconfig
Result
lo no wireless extensions.
bond0 no wireless extensions.
dummy0 no wireless extensions.
eth0 no wireless extensions.
tunl0 no wireless extensions.
sit0 no wireless extensions.
wlan0 unassociated Nickname:"WIFI@RTL88X2BU"
Mode:Managed Frequency=2.412 GHz Access Point: Not-Associated
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
And that's it, you can do whatever you want with it as if you were in a normal linux environment!
If you didn't understand something then feel free to make an issue and i'll try to help whenever I can
The rest of the things below is from https://github.com/microsoft/WSL2-Linux-Kernel, didn't remove it just in case someone wanted it for some reason
The WSL2-Linux-Kernel repo contains the kernel source code and configuration files for the WSL2 kernel.
If you discover an issue relating to WSL or the WSL2 kernel, please report it on the WSL GitHub project. It is not possible to report issues on the WSL2-Linux-Kernel project.
If you're able to determine that the bug is present in the upstream Linux kernel, you may want to work directly with the upstream developers. Please note that there are separate processes for reporting a normal bug and a security bug.
Is there a missing feature that you'd like to see? Please request it on the WSL GitHub project.
If you're able and interested in contributing kernel code for your feature request, we encourage you to submit the change upstream.
Instructions for building an x86_64 WSL2 kernel with an Ubuntu distribution are as follows:
- Install the build dependencies:
$ sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev
- Build the kernel using the WSL2 kernel configuration:
$ make KCONFIG_CONFIG=Microsoft/config-wsl
Please see the documentation on the .wslconfig configuration file for information on using a custom built kernel.