Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
This adds a Dockerfile for the kernel build, the WSL2 Linux Kernel as
a git submodule and a GitHub workflow to build and release the kernel
using the Docker image.

The submodule initially points to the WSL2 Linux Kernel tag v5.4.
  • Loading branch information
carlfriedrich committed Feb 4, 2024
0 parents commit c0d316e
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build

on:
push:
branches:
- '**'
paths:
- WSL2-Linux-Kernel

jobs:

Build:
runs-on: ubuntu-latest

env:
# Both of these will be set dynamically in a later step
GIT_VERSION:
KERNEL_VERSION:

defaults:
run:
working-directory: WSL2-Linux-Kernel

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

# Necessary for git describe. This takes some time, but we want to make sure
# to have the correct version baked into the kernel image in the end.
- name: Fetch kernel tags
run: git fetch --tags

- name: Get kernel config from tag "linux-msft-5.4.91"
run: git show linux-msft-5.4.91:Microsoft/config-wsl > .config

- name: Build kernel
uses: addnab/docker-run-action@v3
with:
image: carlfriedrich/wsl-kernel-build:latest
options: |
-v ${{ github.workspace }}/WSL2-Linux-Kernel:/src
--hostname wsl-kernel-build
run: bash -c "make -j 32 CONFIG_LOCALVERSION_AUTO=y KCONFIG_CONFIG=.config"

- name: Get kernel version
run: |
KERNEL_VERSION=$(scripts/extract-vmlinux arch/x86/boot/bzImage \
| grep -a 'Linux version' | head -1 | cut -d" " -f3)
echo "KERNEL_VERSION=${KERNEL_VERSION}" >> $GITHUB_ENV
- name: Get git version
run: echo "GIT_VERSION=$(git describe)" >> $GITHUB_ENV

- name: Put kernel version into filename
run: mv arch/x86/boot/bzImage bzImage-${{env.KERNEL_VERSION}}

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: bzImage-${{env.KERNEL_VERSION}}
path: |
WSL2-Linux-Kernel/bzImage-${{env.KERNEL_VERSION}}
- name: Push tag
uses: mathieudutour/github-tag-action@v6.1
with:
custom_tag: ${{env.GIT_VERSION}}
github_token: ${{secrets.GITHUB_TOKEN}}

- name: Publish release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{env.GIT_VERSION}}
files: bzImage-${{env.KERNEL_VERSION}}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "WSL2-Linux-Kernel"]
path = WSL2-Linux-Kernel
url = https://github.com/microsoft/WSL2-Linux-Kernel.git
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y \
build-essential \
flex \
bison \
dwarves \
libssl-dev \
libelf-dev \
bc \
git \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# WSL Kernel Build

This repository has been set up to run automatic kernel builds for the [Windows
Subsystem for Linux (WSL)][1], specifically aiming to track down its issue
microsoft/WSL#8696.

We have a [Dockerfile][2] for a container to run the builds in. It has been
set up according to the [WSL Kernel build documentation][3]. The built image
is available [on Docker Hub][4].

The [WSL2-Linux-Kernel][5] repository is contained here as a Git submodule. A
pushed change to its revision triggers a [workflow here][6] building the kernel
on this specific codebase, which then will be tagged and provided as a
[release][7]. We're trying to use [`git-bisect`][8] to find the commit
introducing the beforementioned issue.

Since the issue does not appear instantly, but needs some inconsistent time
until it pops up, people are invited to help testing the built kernel images in
their environments. Please follow #1 in this repository for the progress of the
bisection.

To use a custom kernel, add the following lines to your `.wslconfig` file:

```ini
[wsl2]
kernel=C:\\Path\\To\\Kernel\\bzImage-5.4.0-microsoft-standard-WSL2
```

The `.wslconfig` file is located in your `%UserProfile%` directory (usually
something like `C:\Users\your_user_name`) and can be created if it does not
exist. Afterwards, shut down WSL and restart it using either Command Promt or
PowerShell:

```shell
wsl --shutdown
wsl
```

Verify that the configured kernel is used within WSL:

```shell
$ uname --kernel-release
5.4.0-microsoft-standard-WSL2
```

Please note that the kernel version string is formatted differently than the git
tag it was created from due to the [implementation of the kernel version][9].

### Manual kernel build

In case you want to manually build a WSL kernel, you can do so as follows:

```shell
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git
git checkout v5.4
git show linux-msft-5.4.91:Microsoft/config-wsl > .config
docker run --rm --hostname wsl-kernel-build \
-u $(id -u ${USER}):$(id -g ${USER}) \
-v $(pwd):/src \
carlfriedrich/wsl-kernel-build \
bash -c "make -j 32 CONFIG_LOCALVERSION_AUTO=y KCONFIG_CONFIG=.config"
```

If you want to build another version, make sure to clean the build tree before
checking out a new version:

```shell
git reset HEAD --hard
git clean -dfx
```

[1]: https://github.com/microsoft/WSL
[2]: Dockerfile
[3]: https://github.com/microsoft/WSL2-Linux-Kernel/tree/linux-msft-wsl-5.15.57.1?tab=readme-ov-file#build-instructions
[4]: https://hub.docker.com/repository/docker/carlfriedrich/wsl-kernel-build
[5]: https://github.com/microsoft/WSL2-Linux-Kernel
[6]: https://github.com/carlfriedrich/wsl-kernel-build/actions
[7]: https://github.com/carlfriedrich/wsl-kernel-build/releases
[8]: https://git-scm.com/docs/git-bisect
[9]: https://github.com/microsoft/WSL2-Linux-Kernel/blob/linux-msft-wsl-5.15.y/scripts/setlocalversion#L60-L64
1 change: 1 addition & 0 deletions WSL2-Linux-Kernel
Submodule WSL2-Linux-Kernel added at 219d54

0 comments on commit c0d316e

Please sign in to comment.