live-bootstrap/steps/improve/make_bootable.sh
Gábor Stefanik 11d3605b08 Upgrade Linux kernel to 4.14.336
This is the last LTS version buildable using GCC 4.0.x. The next one,
version 4.19, requires at least GCC 4.6.

Fortunately, this is also the first version of the Linux kernel
without firmware blobs being included in /firmware, so the FSFLA
deblob scripts aren't needed anymore to ensure a fully auditable
kernel - the 3 remaining drivers that do include blobs masquerading
as source code are removed via a patch, avoiding all the other side
effects of the deblob scripts.
This doesn't compromise the trustworthiness of the bootstrapped
environment, since all the other drivers deblob would remove use
the firmware loader mechanism, which does nothing when the actual
firmware blobs aren't installed on the system separately. Features
dependent on firmware still won't work, but many drivers that load
firmware do so only optionally. This includes r8169, the driver for
the Realtek gigabit NICs found on many x86 motherboards.

This kernel is considerably larger than 4.9.10, and we build more
of it (including drivers that would previously get stripped away by
the deblob script, such as r8169), so to accommodate that, Fiwix
initrd size is increased by 64MiB, while lowering kexec space by
the same amount to ensure enough userspace memory available in Fiwix.
Fiwix's maximum open file count is also bumped from 1.5K to 2.5K.

The Documentation folder is deleted before build, to further save
space in the ramdisk.
2024-02-17 15:37:33 +01:00

69 lines
1.8 KiB
Bash

#!/bin/sh
# SPDX-FileCopyrightText: 2024 Gábor Stefanik <netrolller.3d@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# find the physical disk name
PHYSICAL=${DISK}
# take care of e.g. "sda1"
if echo "${DISK}" | grep -Eq '^[a-z]{3}[0-9]+$'
then
PHYSICAL=$(echo "${DISK}" | sed -E 's/^([a-z]{3})[0-9]+$/\1/')
fi
# take care of e.g. "mmcblk0p1"
if echo "${DISK}" | grep -Eq '^[a-z0-9]{3,}p[0-9]+$'
then
PHYSICAL=$(echo "${DISK}" | sed -E 's/^([a-z0-9]{3,})p[0-9]+$/\1/')
fi
grub-install "/dev/${PHYSICAL}"
cat > /boot/grub/grub.cfg <<- EOF
set timeout=5
set default=0
menuentry 'Linux live-bootstrap' {
insmod part_msdos
set root='$(grub-probe -d /dev/${DISK} -t bios_hints | sed -e 's/ //g')'
set gfxpayload=auto
linux /boot/vmlinuz root=/dev/${DISK} rw $(cat /proc/cmdline)
}
EOF
cat > /init <<- 'EOF'
#!/usr/bin/bash
cd /steps
. ./bootstrap.cfg
. ./env
. ./helpers.sh
trap 'env PATH=${PREFIX}/bin PS1="[TRAP] \w # " bash -i' ERR
# /dev is automounted by the kernel at this point
mount | grep '/proc' &> /dev/null || (mkdir -p /proc; mount -t proc proc /proc)
mount | grep '/sys' &> /dev/null || (mkdir -p /sys; mount -t sysfs sysfs /sys)
# Make /tmp a ramdisk (speeds up configure etc significantly)
mount | grep '/tmp' &> /dev/null || (mkdir -p /tmp; mount -t tmpfs tmpfs /tmp)
mount | grep '/dev/shm' &> /dev/null || (mkdir -p /dev/shm; mount -t tmpfs tmpfs /dev/shm)
if test -f /swapfile; then
swapon /swapfile
fi
if [ "${CHROOT}" = False ]; then
dhcpcd --waitip=4
fi
env - PATH=${PREFIX}/bin PS1="\w # " setsid openvt -fec1 -- bash -i
# ignore errors due to fstab or swapfile not existing
swapoff -a &> /dev/null || true
sync
# sysrq to avoid device busy; then mount to wait for it to finish
echo u > /proc/sysrq-trigger
mount -o remount,ro /
echo o > /proc/sysrq-trigger # power off
while true; do sleep 1; done
EOF
chmod +x /init