Skip to content

Commit da76fd2

Browse files
committed
feat: all in one
1 parent 957a785 commit da76fd2

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

.github/workflows/build-kernel.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build WSL2 Kernel
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
kernel_version:
7+
description: "WSL2 kernel version (e.g. 5.15.150.1)"
8+
required: true
9+
default: "5.15.150.1"
10+
extra_config:
11+
description: "Extra kernel config options (e.g. CONFIG_USB_VIDEO_CLASS=y)"
12+
required: false
13+
default: ""
14+
schedule:
15+
- cron: "0 0 * * 0" # Weekly builds
16+
17+
env:
18+
ARTIFACT_NAME: wsl2-kernel
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v3
26+
27+
- name: Set up build environment
28+
run: |
29+
sudo apt-get update
30+
sudo apt-get install -y build-essential flex bison dwarves libssl-dev libelf-dev libncurses-dev
31+
32+
- name: Download kernel source
33+
run: |
34+
mkdir kernel
35+
cd kernel
36+
wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-${{ github.event.inputs.kernel_version }}.tar.gz
37+
tar -xzf linux-msft-wsl-${{ github.event.inputs.kernel_version }}.tar.gz
38+
mv WSL2-Linux-Kernel-linux-msft-wsl-${{ github.event.inputs.kernel_version}} linux-${{ github.event.inputs.kernel_version }}
39+
echo "KERNEL_SRC=$(pwd)/linux-${{ github.event.inputs.kernel_version }}" >> $GITHUB_ENV
40+
41+
- name: Configure kernel
42+
run: |
43+
cd $KERNEL_SRC
44+
cp Microsoft/config-wsl .config
45+
# Apply extra config if provided
46+
if [ -n "${{ github.event.inputs.extra_config }}" ]; then
47+
echo "${{ github.event.inputs.extra_config }}" >> .config
48+
fi
49+
make olddefconfig
50+
51+
- name: Build kernel
52+
run: |
53+
cd $KERNEL_SRC
54+
make -j$(nproc)
55+
56+
- name: Package artifact
57+
run: |
58+
mkdir -p $ARTIFACT_NAME
59+
cp $KERNEL_SRC/arch/x86/boot/bzImage $ARTIFACT_NAME/bzImage
60+
cp $KERNEL_SRC/.config $ARTIFACT_NAME/config
61+
echo "Kernel version: ${{ github.event.inputs.kernel_version }}" > $ARTIFACT_NAME/version.txt
62+
echo "Build date: $(date)" >> $ARTIFACT_NAME/version.txt
63+
64+
- name: Upload artifact
65+
uses: actions/upload-artifact@v3
66+
with:
67+
name: ${{ env.ARTIFACT_NAME }}-${{ github.event.inputs.kernel_version }}
68+
path: $ARTIFACT_NAME

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# lets-build-wsl2-kernels
1+
# WSL2 Kernel Builder
2+
23
This repository automates building custom WSL2 kernels using GitHub Actions.
4+
5+
## Features
6+
7+
- Build any WSL2 kernel version from Microsoft's repository
8+
- Manual trigger with custom version and config options
9+
- Weekly automatic builds of the latest stable version
10+
- Artifact with compiled kernel and config
11+
12+
## Usage
13+
14+
### Manual Build via GitHub UI
15+
16+
1. Go to "Actions" tab
17+
2. Select "Build WSL2 Kernel"
18+
3. Click "Run workflow"
19+
4. Specify kernel version (e.g. `5.15.150.1`)
20+
5. (Optional) Add extra config options (e.g. `CONFIG_USB_VIDEO_CLASS=y`)
21+
6. Click "Run workflow"
22+
23+
### Download and Use Built Kernel
24+
25+
1. After build completes, download the artifact
26+
2. Extract the `bzImage` file
27+
3. Place it in your desired location (e.g. `C:\Windows\System32\lxss\tools`)
28+
4. Create or modify `%USERPROFILE%\.wslconfig`:
29+
30+
```ini
31+
[wsl2]
32+
kernel=C:\\path\\to\\bzImage
33+
```
34+
35+
5. Restart WSL: `wsl --shutdown`
36+
37+
### Local Build
38+
39+
To build locally, run:
40+
41+
```bash
42+
./scripts/build.sh [version] [extra_config]
43+
```
44+
45+
Example:
46+
```bash
47+
./scripts/build.sh 5.15.150.1 "CONFIG_USB_VIDEO_CLASS=y"
48+
```
49+
50+
## Supported Versions
51+
52+
Check available versions at [Microsoft's WSL2-Linux-Kernel repository](https://github.com/microsoft/WSL2-Linux-Kernel/tags)

scripts/build.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
KERNEL_VERSION=${1:-"5.15.150.1"}
6+
EXTRA_CONFIG=${2:-""}
7+
8+
# Install dependencies
9+
sudo apt-get update
10+
sudo apt-get install -y build-essential flex bison dwarves libssl-dev libelf-dev libncurses-dev
11+
12+
# Download kernel source
13+
mkdir -p kernel
14+
cd kernel
15+
wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-${KERNEL_VERSION}.tar.gz
16+
tar -xzf linux-msft-wsl-${KERNEL_VERSION}.tar.gz
17+
mv WSL2-Linux-Kernel-linux-msft-wsl-${KERNEL_VERSION} linux-${KERNEL_VERSION}
18+
cd linux-${KERNEL_VERSION}
19+
20+
# Configure kernel
21+
cp Microsoft/config-wsl .config
22+
23+
if [ -n "${EXTRA_CONFIG}" ]; then
24+
echo "${EXTRA_CONFIG}" >> .config
25+
fi
26+
27+
make olddefconfig
28+
29+
# Build kernel
30+
make -j$(nproc)
31+
32+
echo "Build completed successfully!"
33+
echo "Kernel image: $(pwd)/arch/x86/boot/bzImage"

0 commit comments

Comments
 (0)