firecracker-netns/rootfs-kernel/kernel.sh
2024-01-06 15:55:17 +01:00

47 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# inspired by https://github.com/oraoto/archlinux-firecracker/blob/master/scripts/build-arch-kernel.sh
set -ex
KERNEL_VERSION=v5.11
WD=../out
## Install build tools
# pacman -Syu base-devel bc pahole --ignore linux-firmware
## Get kernel source
git clone --depth 1 --branch $KERNEL_VERSION https://github.com/torvalds/linux.git "$WD"/linux
## Get Archlinux kernel config
curl -o "$WD"/linux/.config https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/raw/2db49d4fbcda88d76a4c236ccb5a7986715d70ba/config
CONFIG_PATH="$WD"/linux/.config
## Disable modules
sed 's/\(.*\)=m/#\1 is not set/g' -i "$CONFIG_PATH"
sed 's/\(.*\)MOUSE\(.*\)=y/\1MOUSE\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)USB\(.*\)=y/\1USB\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)TOUCHSCREEN\(.*\)=y/\1TOUCHSCREEN\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)HID\(.*\)=y/\1HID\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)GPU\(.*\)=y/\1GPU\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)GPIO\(.*\)=y/\1GPIO\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)NVDIMM\(.*\)=y/\1NVDIMM\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)MFD\(.*\)=y/\1MFD\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)XEN\(.*\)=y/\1XEN\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)VIDEO\(.*\)=y/\1VIDEO\2=n/g' -i "$CONFIG_PATH"
# sed 's/\(.*\)PCI\(.*\)=y/\1PCI\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)WLAN\(.*\)=y/\1WLAN\2=n/g' -i "$CONFIG_PATH"
sed 's/\(.*\)DRM\(.*\)=y/\1DRM\2=n/g' -i "$CONFIG_PATH"
cat kernel-config/virtio.config >> "$CONFIG_PATH"
cat kernel-config/fs.config >> "$CONFIG_PATH"
cat kernel-config/net.config >> "$CONFIG_PATH"
## Add KVM guest support
make -C "$WD"/linux/ kvm_guest.config
#make -j$(nproc)
#
#./scripts/extract-vmlinux ./arch/x86_64/boot/bzImage > "$WD"/vmlinux-$KERNEL_VERSION.bin