xanmod-kernel-WSL2 icon indicating copy to clipboard operation
xanmod-kernel-WSL2 copied to clipboard

[TODO] Distribute Kernel Modules & Headers as VHD

Open Locietta opened this issue 9 months ago • 8 comments

Latest WSL2 6.6.y kernel update provides instructions for bundle kernel module files into a VHD. But they don't give any details about how to use the generated modules.vhdx. I'm expecting WSL2 team will give us some options in .wslconfig and it will just work out of box.

If so, we can easily implement kernel update with modules via scoop. Users don't have to update kernel module files manually for each distro & each release, which is nice. We don't have to build everything into the kernel then.

Also it's not difficult to bundle kernel headers as a VHD too, it will be more convenient for people who somehow need original kernel headers (e.g. to develop kernel drivers on WSL2).

I do find some instructions to mount VHDX manually via PowerShell/WSL commands, but this requires per-distro setup (e.g., fstab, partition mounting).

Upstream: https://github.com/microsoft/WSL/issues/12586

Locietta avatar Feb 15 '25 05:02 Locietta

I still prefer to have everything built-in in order to get fully covered LTO and CFI, but bundled headers are very useful indeed.

Incidentally, Fuchsia Clang will soon be built with PGO, which is expected to reduce kernel build times by 20%, which alleviates the need to modularize the kernel for build time reasons..

Andarwinux avatar Feb 15 '25 06:02 Andarwinux

I'm thinking to add those less often used features as modules, something like https://github.com/Locietta/xanmod-kernel-WSL2/issues/99. I'm not sure whether there are enough such features though.

Locietta avatar Feb 15 '25 06:02 Locietta

Latest WSL2 6.6.y kernel update provides instructions for bundle kernel module files into a VHD. But they don't give any details about how to use the generated modules.vhdx. I'm expecting WSL2 team will give us some options in .wslconfig and it will just work out of box.

If so, we can easily implement kernel update with modules via scoop. Users don't have to update kernel module files manually for each distro & each release, which is nice. We don't have to build everything into the kernel then.

Also it's not difficult to bundle kernel headers as a VHD too, it will be more convenient for people who somehow need original kernel headers (e.g. to develop kernel drivers on WSL2).

I do find some instructions to mount VHDX manually via PowerShell/WSL commands, but this requires per-distro setup (e.g., fstab, partition mounting).

Upstream: microsoft/WSL#12586

In .wslconfig like this:

kernel=C:\\.wsl\\6.13.6-microsoft-standard-WSL2-bzImage
kernelModules=C:\\.wsl\\6.13.6-microsoft-standard-WSL2-modules.vhdx

johnlockejrr avatar Mar 13 '25 21:03 johnlockejrr

Remember for scoop paths important

  • https://github.com/microsoft/WSL/issues/12819#issuecomment-2799961131

I still prefer to have everything built-in in order to get fully covered LTO and CFI, but bundled headers are very useful indeed.

This.

Hi, if you are still considering adding support for VHDX images in kernel modules, please check out my repository. It might be helpful.

Nevuly avatar Jul 05 '25 03:07 Nevuly

For gui use, wsl settings app has a vendor tab to select and add kernel module vhd.

Image

lkyu-ly avatar Aug 04 '25 16:08 lkyu-ly

Heads-up: this is now supported upstream. The WSL docs list a .wslconfig key kernelModules that points to a modules VHD/VHDX.

# the WSL2 kernel repo ships a script to generate it.
sudo ./Microsoft/scripts/gen_modules_vhdx.sh "$PWD/modules" "$(make -s kernelrelease)" modules.vhdx
# %UserProfile%\.wslconfig
[wsl2]
kernel=C:\\.wsl\\xanmod\\bzImage
kernelModules=C:\\.wsl\\xanmod\\modules.vhdx

the VHDX is auto-mounted under /lib/modules/<kernelrelease>. uname -r inside WSL exactly matches the release used for modules.vhdx.

Heads-up: this is now supported upstream. The WSL docs list a .wslconfig key kernelModules that points to a modules VHD/VHDX.

the WSL2 kernel repo ships a script to generate it.

sudo ./Microsoft/scripts/gen_modules_vhdx.sh "$PWD/modules" "$(make -s kernelrelease)" modules.vhdx

%UserProfile%.wslconfig

[wsl2] kernel=C:\.wsl\xanmod\bzImage kernelModules=C:\.wsl\xanmod\modules.vhdx the VHDX is auto-mounted under /lib/modules/<kernelrelease>. uname -r inside WSL exactly matches the release used for modules.vhdx.

As I stated on 13th March https://github.com/Locietta/xanmod-kernel-WSL2/issues/114#issuecomment-2722780027

johnlockejrr avatar Aug 16 '25 12:08 johnlockejrr

Completed by #144.

Locietta avatar Nov 18 '25 02:11 Locietta