firecracker-netns/rootfs-kernel/kernel.sh

54 lines
1.9 KiB
Bash
Raw Normal View History

2024-01-06 13:21:23 +00:00
#!/usr/bin/env bash
# inspired by https://github.com/oraoto/archlinux-firecracker/blob/master/scripts/build-arch-kernel.sh
set -ex
2024-01-06 13:21:23 +00:00
KERNEL_VERSION=$1
WD=../out
NPROC=4
2024-01-06 13:21:23 +00:00
## Install build tools
# pacman -Syu base-devel bc pahole --ignore linux-firmware
# disabling CONFIG_DEBUG_INFO_BTF so no pahole required
2024-01-06 13:21:23 +00:00
sudo rm -rf "$WD"/linux
2024-01-06 13:21:23 +00:00
## Get kernel source
git clone --depth 1 --branch v$KERNEL_VERSION https://github.com/torvalds/linux.git "$WD"/linux
2024-01-06 13:21:23 +00:00
## Get Archlinux kernel config
curl -o "$WD"/linux/.config https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/raw/5.11.16.arch1-1/config?ref_type=tags
CONFIG_PATH="$WD"/linux/.config
2024-01-06 13:21:23 +00:00
## 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"
sed 's/\(.*\)BTF\(.*\)=y/\1BTF\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"
2024-01-06 13:21:23 +00:00
## Add KVM guest support
make -C "$WD"/linux/ kvm_guest.config
2024-01-06 13:21:23 +00:00
make -C "$WD"/linux/ -j$NPROC EXTRA_CFLAGS=-Wno-error=use-after-free
#make -j$NPROC WERROR=0
cp ./vmlinux "$WD"/vmlinux-$KERNEL_VERSION
sudo rm -rf "$WD"/linux