Skip to content

Instantly share code, notes, and snippets.

@fOmey
Last active September 4, 2024 13:23
Show Gist options
  • Save fOmey/33b0e8b2b492bacd1a0839e929ecffea to your computer and use it in GitHub Desktop.
Save fOmey/33b0e8b2b492bacd1a0839e929ecffea to your computer and use it in GitHub Desktop.
WSL : nl80211 not found fix & 8814au drivers

WSL : nl80211 not found fix & 8814au drivers

Quick facts

  • Do not save kernel source to a /mnt/c path, compile from the linux user home directory. Windows is case-insensitive, will cause random "file not found" compilation errors.
  • I'm using the Kali Windows store installation to do all these steps, this is especially important if you plan on using 8814au drivers (I don't believe they are compatible with Ubuntu)
  • Windows 10, latest windows updates & WSL.
  • The steps related to 8814au drivers can be modified as necessary.
  • For changes to take effect, WSL requires the "6 second rule" between restarts when modifying WSL related configuration files. Meaning if you issue a wsl --shutdown wait 6 seconds before issuing wsl.

Dependencies

sudo apt update && sudo apt upgrade
sudo apt install flex bison libssl-dev libelf-dev git dwarves bc make libncurses-dev python3

Change working directory to home

Make sure you're not inside a /mnt/c path.

cd ~

Pull kernel source & extract

Credit to kevin for this ingenius method, much faster than cloning github repo.

wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-$(uname -r | cut -d- -f 1).tar.gz
tar -xvf linux-msft-wsl-$(uname -r | cut -d- -f 1).tar.gz

Change directory into kernel source

What would we do without auto-complete..

cd WSL{TAB}

Use current kernel config as template

cat /proc/config.gz | gunzip > .config

Configure kernel

make menuconfig

Enable the following in kernel config (*), exit & save

I opted to integrate into the kernel (*), you can also choose to compile as modules (M) this will require more setting up later (auto starting at boot)

  • Networking support
    • Wireless (*)
      • cfg80211 (*)

Compile kernel, modules_install needed for DKMS

make modules -j $(expr $(nproc) - 1)
sudo make modules_install

Build kernel bzImage

make -j $(expr $(nproc) - 1)

Move kernel image to %UserProfile%

Replace USERNAME with your own (duh)

mv arch/x86/boot/bzImage /mnt/c/Users/USERNAME

Some useful tools & 8814au drivers

sudo apt install usbip usbutils iw wireshark realtek-rtl8814au-dkms

Enable systemd, needed for module autostart & other useful services

sudo nano /etc/wsl.conf

Contents:

[boot]
systemd = true

Auto start kernel module on WSL startup

If you decided to configure cfg80211 as a module, you want to also create a autostart conf for it also

echo "8814au" | sudo tee -a /etc/modules-load.d/8814au.conf

Shut down WSL on host machine

wsl --shutdown

Create .wslconfig in %UserProfile%

Replace USERNAME with your own (duh)

Contents:

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel
kernel=C:\\Users\\USERNAME\\bzImage

Restart WSL on host machine

wsl

Verify kernel module is loaded

lsmod

Output:

Module                  Size  Used by
8814au               2682880  0

Attach Wireless USB (8814au)

Either on host with

usbipd wsl attach -b <BUSID>

or on VM

sudo usbip attach -r <HOSTIP/172.20.32.1> -b <BUSID>

Verify 8814au attached & more importantly driver is being used

lsusb -t

Output:

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=vhci_hcd/8p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=vhci_hcd/8p, 480M
    |__ Port 1: Dev 2, If 0, Class=Vendor Specific Class, Driver=rtl8814au, 480M

Auto attach USB on startup & set monitor mode on wlan0

sudo nano ~/wsl.sh

Contents:

#!/bin/sh

sudo usbip attach --remote 172.20.32.1 --busid=3-2

while true; do
    if [ -z $(sudo iw dev | grep -o wlan0) ]; then
        sleep 1  # network not yet up
    else
        break   # network up
    fi
done

sudo ip link set wlan0 down
sudo iw wlan0 set monitor control
sudo ip link set wlan0 up

Set permissions & enable in crontab

sudo chmod +x ~/wsl.sh
sudo crontab -e

May have to select editor if first time running crontab -e (obviously nano, unless you're a masochist).. contents:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

@reboot sh /home/ruckus/wsl.sh

Shutdown WSL on host machine

Shutdown & wait for USB chime, USB chime is used as an indication it's safe to reboot.

wsl --shutdown

Start WSL on host machine

At this stage kernel module should auto load, USB should auto attach & wireless interface should be set in monitor mode.

wsl

Test wireshark

Launch as sudo, otherwise you won't see network adapters

sudo wireshark

Refrences

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