firecracker-netns/rootfs-kernel/kernel.sh
RouxAntoine b266e4487e
increased loading time by a bit
Signed-off-by: RouxAntoine <antoinroux@hotmail.fr>
2024-01-06 19:39:50 +01:00

54 lines
1.9 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=$1
WD=../out
NPROC=4
## Install build tools
# pacman -Syu base-devel bc pahole --ignore linux-firmware
# disabling CONFIG_DEBUG_INFO_BTF so no pahole required
sudo rm -rf "$WD"/linux
## Get kernel source
git clone --depth 1 --branch v$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/main/config?ref_type=heads
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"
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"
## Add KVM guest support
make -C "$WD"/linux/ kvm_guest.config
#make -C "$WD"/linux/ -j$NPROC EXTRA_CFLAGS=-Wno-error=use-after-free
make -C "$WD"/linux/ -j$NPROC WERROR=0
cp ./vmlinux "$WD"/vmlinux-$KERNEL_VERSION
sudo rm -rf "$WD"/linux