Skip to content

Build and Release WSL2 Kernel #9

Build and Release WSL2 Kernel

Build and Release WSL2 Kernel #9

Workflow file for this run

name: Build WSL2 Kernel
on:
workflow_dispatch:
inputs:
kernel_version:
description: "WSL2 kernel version (e.g. 5.15.90.4)"
required: true
default: "5.15.90.4"
release_tag:
description: "GitHub Release tag (e.g. v5.15.90.4)"
required: true
default: "v5.15.90.4"
jobs:
build:
runs-on: ubuntu-latest
env:
KERNEL_VERSION: ${{ github.event.inputs.kernel_version }}
KERNEL_DIR: linux-${{ github.event.inputs.kernel_version }}
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
steps:
- uses: actions/checkout@v4
- name: Setup environment
run: |
sudo apt-get update
sudo apt-get install -y build-essential flex bison dwarves libssl-dev libelf-dev libncurses-dev
- name: Download and extract kernel
run: |
mkdir -p kernel-build
cd kernel-build
wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-${{ env.KERNEL_VERSION }}.tar.gz
tar -xzf linux-msft-wsl-${{ env.KERNEL_VERSION }}.tar.gz
# 确保目录重命名与后续步骤一致
mv WSL2-Linux-Kernel-linux-msft-wsl-${{ env.KERNEL_VERSION }} linux-${{ env.KERNEL_VERSION }}
echo "KERNEL_DIR=$(pwd)/linux-${{ env.KERNEL_VERSION }}" >> $GITHUB_ENV
- name: Configure kernel
run: |
cd ${{ env.KERNEL_DIR }}
cp Microsoft/config-wsl .config
make olddefconfig
- name: Build kernel
run: |
cd ${{ env.KERNEL_DIR }}
make -j$(nproc)
- name: Verify build
run: |
ls -lh ${{ env.KERNEL_DIR }}/arch/x86/boot/bzImage
file ${{ env.KERNEL_DIR }}/arch/x86/boot/bzImage
- name: Package artifact
run: |
mkdir -p artifact
cp ${{ env.KERNEL_DIR }}/arch/x86/boot/bzImage artifact/
cp ${{ env.KERNEL_DIR }}/.config artifact/
echo "KERNEL_VERSION=${{ env.KERNEL_VERSION }}" > artifact/version.txt
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: wsl2-kernel-${{ env.KERNEL_VERSION }}
path: artifact
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: "WSL2 Kernel ${{ env.KERNEL_VERSION }}"
draft: false
prerelease: false
- name: Upload Kernel Image
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.KERNEL_DIR }}/arch/x86/boot/bzImage
asset_name: bzImage-${{ env.KERNEL_VERSION }}
asset_content_type: application/octet-stream
- name: Upload Kernel Config
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.KERNEL_DIR }}/.config
asset_name: config-${{ env.KERNEL_VERSION }}.txt
asset_content_type: text/plain