Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup bridge kernel module in /sys/module/ to enable running on WSL2 #17305

Closed
jeteve opened this issue May 24, 2023 · 6 comments · Fixed by #17306
Closed

Lookup bridge kernel module in /sys/module/ to enable running on WSL2 #17305

jeteve opened this issue May 24, 2023 · 6 comments · Fixed by #17306

Comments

@jeteve
Copy link
Contributor

jeteve commented May 24, 2023

Proposal

To find out if the host linux system is capable of bridge networking, the client fingerprinting looks up in /proc/modules , /lib/modules//modules.builtin and in /lib/modules/<kernel/modules.dep.

Sadly none of those places are populated in WSL2 (tested using ubuntu WSL2) in Windows, even though the WSL2 kernel provided by MS has many modules built-in (including the bridge module).

Use-cases

End goal: run nomad on WSL2 with bridge networking capability.

Attempted Solutions

Add a lookup into /sys/module/ . To attempt detecting the availability of the bridge kernel module.

A branch with this solution is provided against this issue

References

See https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-module

@hardkeo
Copy link

hardkeo commented May 25, 2023

Hello @jeteve, today could be your lucky day!

Yesterday I completed a survey on how to do this with minimal steps and/or interventions and I've already tested it in 2 different environments using WSL2 with Ubuntu 22.04.2 vanilla.


Enabling bridge and br_netfilter modules in vanilla WSL2 (Ubuntu-22.04)

1. Downloading the necessary requirements

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

2. Set variable with kernel version

ex: WSL_RELEASE=linux-msft-wsl-5.15.90.1

WSL_RELEASE="linux-msft-wsl-$(echo $(uname -r) | cut -d"-" -f1)"

3. Download the source code of your kernel version used by wsl2

curl -LO https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/${WSL_RELEASE}.zip

4. Unzip the source code

unzip ${WSL_RELEASE}.zip

5. Load your WSL2 kernel configuration file (Kconfig)

cd WSL2-Linux-Kernel-${WSL_RELEASE}
zcat /proc/config.gz > .config

6. Prepare the modules

make prepare modules_prepare -j $(nproc)

7. By default, the modules are already enabled in the ".config", I suggest checking them when opening the config menu

Modules must be enabled with "*" (built-in)

make menuconfig

Settings locations in menuconfig

> Networking support

> Networking options

 > "[*] Network packet filtering framework (Netfilter)"
 > "<*> 802.1d Ethernet Bridging"

8. Compile the modules

make modules -j $(nproc)

9. Activate the modules

sudo make modules_install -j $(nproc)

10. Restart wsl2:

a. In CMD or PowerShell:

wsl --shutdown

b. Reopen wsl2


Have fun!

@jeteve
Copy link
Contributor Author

jeteve commented May 31, 2023

Thanks a lot for the answer! The thing is this bridge module is already built in the MS provided kernel:

~$ cat /sys/module/bridge/version
2.3

It seems to be a bit overkill to rebuild a kernel from scratch when a lookup in this place would allow detecting this built-in bridge module.

@hardkeo
Copy link

hardkeo commented Jun 1, 2023

@jeteve, Sharing is multiplying!

I've seen that too.

~$ cat /sys/module/bridge/version
2.3

Resultados de tradução
Resultado da tradução
I use the system's own source file to use as a source for the .config (zcat /proc/config.gz > .config) which shows both modules enabled (bridge and br_netfilter).

In this process, the only thing I use (apparently), is the reconstruction of the modules' folder and files structure, which is not found by default.

WSL2 default.
image

Structure of folders and files recreated in the process.
wsl2_modules

Another method that I didn't find so elegant but works perfectly, is to copy the folder structure and files (mentioned above) from a corrected WSL2 and put it in another one that doesn't have this structure, (tests in another one that used the same kernel version) , it only excludes the build and source folders from the copy.

Vanilla WSL2, apenas com a pasta modules importada.
image

I'm curious to know how you solved this problem too, in case you care to share.

🖖Live Long and Prosper!

@lgfa29
Copy link
Contributor

lgfa29 commented Jun 3, 2023

Thanks for the detailed steps @hardkeo! I followed them as instructed and bridge network mode started working 🙂

While @jeteve does simplify things a lot by sidestepping all of this I this instructions will be very valuable for those that are still using a previous version of Nomad.

@jeteve
Copy link
Contributor Author

jeteve commented Jun 3, 2023

@hardkeo to run in WSL, I've just did that:

mkdir -p /lib/modules/$(uname -r)/
echo "kernel/bridge.ko" >> /lib/modules/$(uname -r)/modules.builtin

And then the current version of nomad just detects the bridge module :)

@hardkeo
Copy link

hardkeo commented Jun 5, 2023

@jeteve thanks for sharing!

Much simpler.
I used it like this and it worked as expected!

sudo mkdir -p /lib/modules/$(uname -r)

echo -e "kernel/net/bridge/bridge.ko\nkernel/net/bridge/br_netfilter.ko" | sudo tee /lib/modules/$(uname -r)/modules.builtin

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

Successfully merging a pull request may close this issue.

3 participants