Skip to content

Instantly share code, notes, and snippets.

@pvoliveira
Last active November 23, 2022 09:20
Show Gist options
  • Save pvoliveira/b7f5f972c5e954b7d6669d04d8f1fafa to your computer and use it in GitHub Desktop.
Save pvoliveira/b7f5f972c5e954b7d6669d04d8f1fafa to your computer and use it in GitHub Desktop.
Scripts to compile WSL2 Kernel
.PHONY: build
build:
docker run --name wsl-kernel-builder --rm -it -v $(shell pwd):/scripts ubuntu:latest bash /scripts/script.sh
WSL_COMMIT_REF=linux-msft-wsl-5.15.74.2 # change this line to the version you want to build
WSL_KERNEL_PATH=/wsl2kernel
# Install dependencies
apt update \
&& apt install -y git build-essential flex bison dwarves libssl-dev libelf-dev python3 bc
# Checkout WSL2 Kernel repo
mkdir ${WSL_KERNEL_PATH} \
&& cd ${WSL_KERNEL_PATH} \
&& git init \
&& git remote add origin https://github.com/microsoft/WSL2-Linux-Kernel.git \
&& git config --local gc.auto 0 \
&& git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +${WSL_COMMIT_REF}:refs/remotes/origin/build/linux-msft-wsl-5.15.y \
&& git checkout --progress --force -B build/linux-msft-wsl-5.15.y refs/remotes/origin/build/linux-msft-wsl-5.15.y
sed -i 's/# CONFIG_NETFILTER_XT_MATCH_RECENT is not set/CONFIG_NETFILTER_XT_MATCH_RECENT=y/' ${WSL_KERNEL_PATH}/Microsoft/config-wsl
make -j2 KCONFIG_CONFIG=${WSL_KERNEL_PATH}/Microsoft/config-wsl
cp ${WSL_KERNEL_PATH}/arch/x86/boot/bzImage /scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment