Files
aero3/scripts/04-kernel.sh
T
2026-06-19 10:02:12 -04:00

51 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# scripts/04-kernel.sh — configure + build Linux 7.1 and install into chroot.
source "$(dirname "${BASH_SOURCE[0]}")/lib/common.sh"
require_root
LFS="$AEROS_ROOT"
KVER="$(pkg_version linux)"
trap 'mountpoint -q "$LFS/sources" && umount -l "$LFS/sources"; umount_vkfs 2>/dev/null || true' EXIT
step "Linux kernel $KVER (x86-64)"
mount_vkfs
mkdir -p "$LFS/sources"
mountpoint -q "$LFS/sources" || mount --bind "$AEROS_SOURCES" "$LFS/sources"
install -Dm644 "$AEROS_TOP/config/kernel/aeros.config" "$LFS/root/aeros.config"
[[ -x "$LFS/usr/bin/bc" ]] || die "stage 04 requires bc inside the chroot; run: sudo ./build.sh stage 03"
[[ -x "$LFS/usr/bin/rsync" ]] || die "stage 04 requires rsync inside the chroot; run: sudo ./build.sh stage 03"
# Inner build: defconfig + merge our fragment + build + modules_install + install
cat > "$LFS/root/build-kernel.sh" <<INNER
#!/bin/bash
set -Eeuo pipefail
export MAKEFLAGS="-j${AEROS_JOBS}"
cd /tmp; rm -rf linux-src; mkdir linux-src
tar -xf "/sources/$(pkg_tarball linux)" -C linux-src --strip-components=1
cd linux-src
make mrproper
make x86_64_defconfig
# merge AeroOS options on top of defconfig
scripts/kconfig/merge_config.sh -m .config /root/aeros.config
make olddefconfig
# build kernel image + modules
make
make modules_install
# install kernel + map + config to /boot
install -Dm644 arch/x86/boot/bzImage /boot/vmlinuz-aeros-${KVER}
install -Dm644 System.map /boot/System.map-${KVER}
install -Dm644 .config /boot/config-${KVER}
# kernel headers for building DKMS/userspace later
make headers_install INSTALL_HDR_PATH=/usr
echo "kernel ${KVER} installed to /boot"
INNER
chmod +x "$LFS/root/build-kernel.sh"
in_chroot "/root/build-kernel.sh"
mountpoint -q "$LFS/sources" && umount -l "$LFS/sources" || true
umount_vkfs
ok "kernel $KVER built and installed"