From 43dc85ba7873de02518d112ab2d2cb460654fa46 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 Aug 2017 10:09:37 +0200 Subject: Build custom kernel with longer command line --- bootstrap | 223 ++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 160 insertions(+), 63 deletions(-) (limited to 'bootstrap') diff --git a/bootstrap b/bootstrap index 9335d08..63ebd32 100755 --- a/bootstrap +++ b/bootstrap @@ -19,15 +19,16 @@ # # 1 - bootstrap phase 1 # 2 - bootstrap phase 2 -# 3 - setup -# 4 - create footfs -# 5 - create kernel image and initrd +# 3 - kernel build +# 4 - setup +# 5 - create footfs +# 6 - create kernel image and initrd # usage="usage: $0" id="$(id -un)" btrfs=/btrfs -release="unstable" +release="testing" mirror="https://deb.debian.org/debian/" passwd="123" #@@ TMP root passwd. macaddr="de:ad:be:ef:b8:da" # Mac address for testing. @@ -42,7 +43,7 @@ function info () { echo "$*" 1>&2; } function error () { info "$*"; exit 1; } stage="1" -stage_max="5" +stage_max="6" while [ "$#" -gt 0 ]; do case "$1" in @@ -104,15 +105,18 @@ fi # Spawn a systemd namespace container (systemd-nspawn) # -function nspawn () # +function nspawn () # { - sudo systemd-nspawn --register=no -D "$root" "$@" + local r="$1" + shift + + sudo systemd-nspawn --register=no -D "$r" "$@" # systemd-nspawn may create the /var/lib/machines subvolume which prevents # the deletion of the containing submodule. So we clean it up. # - if sudo btrfs subvol show "$root/var/lib/machines" 1>/dev/null 2>&1; then - sudo btrfs subvol delete "$root/var/lib/machines" + if sudo btrfs subvol show "$r/var/lib/machines" 1>/dev/null 2>&1; then + sudo btrfs subvol delete "$r/var/lib/machines" fi } @@ -120,14 +124,24 @@ function nspawn () # # # write <<<'localhost' /etc/hostname # -function write () # +function write () # [] { - sudo tee "$root$1" >/dev/null + local r="$2" + if [ -z "$r" ]; then + r="$root" + fi + + sudo tee "$r$1" >/dev/null } -function append () # +function append () # [] { - sudo tee -a "$root$1" >/dev/null + local r="$2" + if [ -z "$r" ]; then + r="$root" + fi + + sudo tee -a "$r$1" >/dev/null } # Stage 1: debootstrap, phase 1. @@ -142,11 +156,13 @@ if [ "$stage" -eq "1" ]; then # # - systemd-container seems to be required by host systemd-nspawn. # + # - no linux-image-amd64 since building custom below + # comps="main,contrib,non-free" - pkgs="locales,klibc-utils,sudo,systemd-container" + pkgs="locales,klibc-utils,sudo,systemd-container,udev" - pkgs+=",linux-image-amd64,irqbalance,pciutils,usbutils" + pkgs+=",kmod,linux-base,firmware-linux-free,irqbalance,pciutils,usbutils" pkgs+=",intel-microcode,amd64-microcode" @@ -202,7 +218,6 @@ if [ "$stage" -le "2" ]; then #!/bin/bash trap "exit 1" ERR - set -x # Hack around systemd bug#79306 (changes /etc/localtime) by removing it now @@ -228,24 +243,24 @@ chattr +i /etc/localtime # cat </etc/os-release NAME="Build OS" -VERSION="0.5.0" +VERSION="0.6.0" ID=buildos ID_LIKE=debian -PRETTY_NAME="Build OS 0.5.0 (Based on Debian)" -VERSION_ID="0.5" +PRETTY_NAME="Build OS 0.6.0 (Based on Debian)" +VERSION_ID="0.6" HOME_URL="https://build2.org/" SUPPORT_URL="https://lists.build2.org/" BUG_REPORT_URL="https://lists.build2.org/" EOF1 cat </etc/issue -Build OS 0.5.0 (Based on Debian) \n \l +Build OS 0.6.0 (Based on Debian) \n \l EOF1 cat </etc/motd -Welcome to Build OS 0.5.0 (https://build2.org)! +Welcome to Build OS 0.6.0 (https://build2.org)! EOF1 @@ -275,24 +290,135 @@ EOF # - Failed to create directory .../sys/fs/selinux: Read-only file system is # harmless and fixed upstream (systemd issue#3748). # - nspawn /bootstrap/bootstrap + nspawn "$root" /bootstrap/bootstrap subvol_snapshot -r "$root" "$root-2" fi -# Stage 3: setup. +# Stage 3: kernel build. # if [ "$stage" -le "3" ]; then - # Create the setup script/service that will finish the setup from within the - # installation via systemd-nspawn --boot. + # Create the setup service that will be used by both this stage and the + # setup stage below. Note that we will do actual building (which requires + # installing extra packages) in a snapshot on the side. # sudo mkdir -p "$root/bootstrap" + + # Note that when started via systemd-nspawn, we get /dev/console, not + # /dev/tty0. + # + write </dev/console 1>&0 2>&1" + # + subvol_delete "$root-3-kernel" + subvol_snapshot "$root" "$root-3-kernel" + + write <linux/.config +cd linux + +# Adjust kernel command line size limit. +# +sed -i -re 's/^(#define COMMAND_LINE_SIZE ).+$/\1 4096/' arch/x86/include/asm/setup.h +make oldconfig +scripts/config --disable DEBUG_INFO + +make clean +make deb-pkg LOCALVERSION=-buildos KDEB_PKGVERSION=1 -j 8 + +# Clean up and shutdown. +# +rm /bootstrap/setup +systemctl poweroff + +EOF + sudo chmod u+x "$root-3-kernel/bootstrap/setup" + + nspawn "$root-3-kernel" --boot + + # Copy the kernel over and install it. + # + sudo cp "$root-3-kernel/usr/src/linux-image-"*.deb "$root/usr/src/" + write < "$owd/buildos-rootfs.cpio.gz" cd "$owd" - subvol_snapshot -r "$root" "$root-4" + subvol_snapshot -r "$root" "$root-5" fi -# Stage 5: generate initrd. +# Stage 6: generate initrd. # -if [ "$stage" -le "5" ]; then +if [ "$stage" -le "6" ]; then # Generate buildid and store it in /etc/os-release and in buildos-buildid. # These are used by the monitor to detect when it's time to reboot. @@ -423,7 +520,7 @@ EOF cp "$root/vmlinuz" buildos-image echo "$buildid" >buildos-buildid - subvol_snapshot -r "$root" "$root-5" + subvol_snapshot -r "$root" "$root-6" fi exit 0 -- cgit v1.1