Skip to content

Alpine Build Minimal BusyBox Kernel #19

Alpine Build Minimal BusyBox Kernel

Alpine Build Minimal BusyBox Kernel #19

Workflow file for this run

name: Build Minimal BusyBox Kernel
on:
workflow_dispatch:
env:
GH_TOKEN: ${{ github.token }}
jobs:
build:
name: Build (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
container:
image: alpine:latest
strategy:
matrix:
include:
- arch: x86_64
runner: ubuntu-latest
kernel_target: bzImage
kernel_path: arch/x86/boot/bzImage
release_name: x86_64
- arch: arm64
runner: ubuntu-24.04-arm
kernel_target: Image
kernel_path: arch/arm64/boot/Image
release_name: aarch64
steps:
- name: Build
run: |
set -e
echo ">>> Installing dependencies..."
apk add --no-cache \
git github-cli build-base ncurses-dev \
bison flex bc perl elfutils-dev linux-headers
echo ">>> Cloning repositories..."
git clone https://github.com/mirror/busybox /busybox
git clone --depth=1 https://github.com/torvalds/linux /linux
git clone --depth=1 https://github.com/mlyxshi/flake /flake
echo ">>> Preparing build files..."
mkdir -p /build
for f in init kernel.config busybox.config cloud-init-networkcfg.c udhcpc-script.sh; do
cp /flake/dd/busybox/$f /build
done
echo ">>> Compiling helper..."
gcc -s --static /build/cloud-init-networkcfg.c -o /build/cloud-init-networkcfg
echo ">>> Building BusyBox..."
cd /busybox
# https://bugs.busybox.net/show_bug.cgi?id=10296
git restore --source 0b1c62934215a08351a80977c7cf8e9346683a1e^ -- scripts/kconfig/conf.c
make allnoconfig KCONFIG_ALLCONFIG=/build/busybox.config
LDFLAGS="--static" make -j$(nproc)
cp busybox /build
echo ">>> Creating initramfs..."
cat > /build/cpio.list <<EOF
dir /dev 0755 0 0
nod /dev/console 0600 0 0 c 5 1
file /init /build/init 0755 0 0
dir /bin 0755 0 0
file /bin/busybox /build/busybox 0755 0 0
file /bin/udhcpc-script.sh /build/udhcpc-script.sh 0755 0 0
file /bin/cloud-init-networkcfg /build/cloud-init-networkcfg 0755 0 0
EOF
echo ">>> Building kernel..."
cd /linux
echo 'CONFIG_INITRAMFS_SOURCE="/build/cpio.list"' >> /build/kernel.config
make ARCH=${{ matrix.arch }} KCONFIG_ALLCONFIG=/build/kernel.config allnoconfig
make ${{ matrix.kernel_target }} -j$(nproc)
cp ${{ matrix.kernel_path }} /build/busybox-kernel
echo ">>> Uploading release..."
gh release -R mlyxshi/flake upload ${{ matrix.release_name }} /build/busybox-kernel --clobber