Warning
With linux-msft-wsl-6.6.36.3, (which is mainline LTS currently) and kernel module support, dkms should suffice in most cases, although I have not tried yet. And I've migrated my infrastructure to eliminate the need of WSL. As a result, this repo is now deprecated and would not get updated unless I return to WSL one day.
Patch to build my own custom WSL2-Linux-Kernel.
- Native-CPU Optimized (via make flag
CFLAGS='-march=native -O2 -pipe'
) - USB Support (WSL has partial native support now)
- Enable extra cryptos for DM-Crypt, which makes mounting VeraCrypt volumes inside WSL possible
- Make sure the source code released by Microsoft is really functional
- Add whatever you like in the kernel name, which would later be reflected in Neofetch or screenFetch
Check latest releases for patched make config to customize it yourself.
Tip
Remember to replace the version number with the latest!
- Backup config and generate patch that will be used later, run in unpacked WSL kernel directory:
# Change version
KERNEL_VER="5.15.153.1"
# Backup config
cp Microsoft/config-wsl $HOME/linux-msft-wsl-${KERNEL_VER}.config
cp .config $HOME/dm-crypt-plus-usb-kernel.config
# Geterante patch
TZ=UTC diff -u Microsoft/config-wsl .config > $HOME/dm-crypt-plus-usb.patch
unset KERNEL_VER
- How to use patch:
cp Microsoft/config-wsl .config
patch .config < dm-crypt-plus-usb.patch
- Make sure we are safe by comparing with current custom kernel config (if you use my config previously):
cp /proc/config.gz config.gz
gunzip config.gz
diff config .config
- The output should be something like:
3c3
< # Linux/x86 5.15.62.114514 Kernel Configuration
---
> # Linux/x86 5.15.68.114514 Kernel Configuration
- (Optional) If anything goes wrong, just revert the patch:
patch -R .config < dm-crypt-plus-usb.patch
- Create
.wslconfig
in%USERPROFILE%
to replace the WSL kernel without replacing$Env:SystemRoot\System32\lxss\tools\kernel
.
[wsl2]
kernel=C:\\WSL\\bzImage
Only do this after you have compiled the kernel,
and make sure you are inside the kernel root folder.
This will compile and copy the necessary library to the system,
you may want to backup libusbip.so.0
to reuse it on other distros.
# Compile USBIP
cd tools/usb/usbip
bash ./autogen.sh
bash ./configure
make install
# Make USBIP toolchain accessible by USBIP
cp libsrc/.libs/libusbip.so.0 /lib/libusbip.so.0
# Backup USBIP & config
cp libsrc/.libs/libusbip.so.0 /mnt/c/WSL/libusbip.so.0
cd ../../../
cp .config /mnt/c/WSL/dm-crypt-plus-usb-kernel.config
cp dm-crypt-plus-usb.patch /mnt/c/WSL/dm-crypt-plus-usb.patch
You may check out my blog Linux From Scratch (LFS) 编译记录 (written in Chinese, but most comments in code blocks are in English) on this for details.