feature/build-my-own-kernel-rootfs #2

Merged
antoine merged 15 commits from feature/build-my-own-kernel-rootfs into main 2024-01-06 20:25:13 +00:00
3 changed files with 34 additions and 30 deletions
Showing only changes of commit 66e795d03d - Show all commits

View File

@ -93,7 +93,7 @@ func setupEnv() int {
cfg := firecracker.Config{
SocketPath: socketPath,
KernelImagePath: "./out/vmlinux-5.10.204",
KernelImagePath: "./out/vmlinux",
LogPath: "./out/firecracker.log",
LogLevel: "Debug",
KernelArgs: "console=ttyS0 reboot=k panic=1 pci=off",

View File

@ -11,11 +11,15 @@ use-ubuntu: ../out/ubuntu-22.04.ext4 ../out/ubuntu-22.04.id_rsa
ln -fs $< ../out/rootfs.ext4
kernel: ../out/vmlinux-5.10.204
@echo "linux kernel retrieve"
ln -fs $< ../out/vmlinux
../out/vmlinux-5.10.204:
wget -O $@ https://s3.amazonaws.com/spec.ccfc.min/firecracker-ci/v1.7/$(ARCH)/vmlinux-5.10.204
CONFIG_FILE=$(wildcard ./kernel-config/*.config)
../out/vmvmlinux-custom: ./kernel.sh $(CONFIG_FILE)
bash ./kernel.sh
../out/arch-rootfs.ext4: ./arch-rootfs.sh
bash ./arch-rootfs.sh

View File

@ -2,46 +2,46 @@
# inspired by https://github.com/oraoto/archlinux-firecracker/blob/master/scripts/build-arch-kernel.sh
KERNEL_VERSION=5.11.2
set -ex
mkdir -p build
cd build
KERNEL_VERSION=v5.11
WD=../out
## Install build tools
# pacman -Syu base-devel bc pahole --ignore linux-firmware
## Get kernel source
curl -o linux.tar.xz "https://mirrors.tuna.tsinghua.edu.cn/kernel/v5.x/linux-$KERNEL_VERSION.tar.xz"
tar xf linux.tar.xz
cd linux-$KERNEL_VERSION/
git clone https://github.com/torvalds/linux.git "$WD"/linux
git checkout $KERNEL_VERSION
## Get Archlinux kernel config
curl -o .config https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux
curl -o "$WD"/linux/.config https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux
CONFIG_PATH="$WD"/linux/.config
## Disable modules
sed 's/\(.*\)=m/#\1 is not set/g' -i .config
sed 's/\(.*\)MOUSE\(.*\)=y/\1MOUSE\2=n/g' -i .config
sed 's/\(.*\)USB\(.*\)=y/\1USB\2=n/g' -i .config
sed 's/\(.*\)TOUCHSCREEN\(.*\)=y/\1TOUCHSCREEN\2=n/g' -i .config
sed 's/\(.*\)HID\(.*\)=y/\1HID\2=n/g' -i .config
sed 's/\(.*\)GPU\(.*\)=y/\1GPU\2=n/g' -i .config
sed 's/\(.*\)GPIO\(.*\)=y/\1GPIO\2=n/g' -i .config
sed 's/\(.*\)NVDIMM\(.*\)=y/\1NVDIMM\2=n/g' -i .config
sed 's/\(.*\)MFD\(.*\)=y/\1MFD\2=n/g' -i .config
sed 's/\(.*\)XEN\(.*\)=y/\1XEN\2=n/g' -i .config
sed 's/\(.*\)VIDEO\(.*\)=y/\1VIDEO\2=n/g' -i .config
# sed 's/\(.*\)PCI\(.*\)=y/\1PCI\2=n/g' -i .config
sed 's/\(.*\)WLAN\(.*\)=y/\1WLAN\2=n/g' -i .config
sed 's/\(.*\)DRM\(.*\)=y/\1DRM\2=n/g' -i .config
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 ../../config/virtio.config >> .config
cat ../../config/fs.config >> .config
cat ../../config/net.config >> .config
cat kernel-config/config/virtio.config >> "$CONFIG_PATH"
cat kernel-config/config/fs.config >> "$CONFIG_PATH"
cat kernel-config/config/net.config >> "$CONFIG_PATH"
## Add KVM guest support
make kvm_guest.config
make -j$(nproc)
./scripts/extract-vmlinux ./arch/x86_64/boot/bzImage > ../../output/arch-vmlinux.bin
#make -j$(nproc)
#
#./scripts/extract-vmlinux ./arch/x86_64/boot/bzImage > "$WD"/arch-vmlinux.bin