make the build initramfs-less #10

Merged xogium merged 6 commits into LuminaSensum:stable-dev-board from LuminaSensum:WIP_initramfs-less on 11 Aug 2020
@xogium xogium commented on 9 Aug 2020

This pull request allows the build to no longer depend on an initramfs. This has several adventages:

  • Faster build, because everything is done via a single defconfig.
  • A decrease of the boot time of about 6.5 seconds.
  • And less messy and complicated in general (no need for a postbuild script that cleans up the initramfs, etc).

I've done two branches off of this:

  • WIP_noinitrd-net to fix Ethernet
  • WIP_noinitrd-machineid to set /etc/machine-id to barebox's machine-id (or set barebox's) if no machine-id is set

I also did manage to set up a hacky overlayfs prototype, but I'll either need to use a C or busybox to do this as I need to pivot the root filesystem mount from / to /tmp/overlay/upper then boot systemd- which is hard to do with shell scripts as I execute external programs, programs I don't have without a root filesystem.

I'm ashamed of the code, but here's the example if you REALLY want to try:

#!/bin/bash
mount -t proc none /proc
mount -t sysfs none /sys
mkdir -p /run/lock
DEFAULT_MACHINE_ID="402de934e3cca78c23ce21875f309dcf"
MACHINE_ID="$(barebox-state -g machine-id)"
if [[ "${MACHINE_ID}" == "${DEFAULT_MACHINE_ID}" ]]; then
  MACHINE_ID="$(dbus-uuidgen)"
  barebox-state -s machine-id="${MACHINE_ID}"
fi
echo "${MACHINE_ID}" > /etc/machine-id
mount -t tmpfs none /tmp
mkdir /tmp/overlay
cd /tmp/overlay
mkdir lower upper work merged
cd /
mount /dev/mmcblk1p4 lower
mount -t overlay overlay -o lowerdir=/tmp/overlay/lower,upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work /tmp/overlay/merged
umount /proc
umount /sys
exec chroot /tmp/overlay/merged /sbin/init

Since we're not pivoting root and just chrooting, the original root mount is still active and systemd can't free it. Nasty.

Okay here's the code to make an overlay that removes access to filesystem:

mkdir -p /overlay/
mount -t tmpfs none /overlay
cd /overlay/
mkdir lower upper work merged
ln -s /lower/bin bin
ln -s /lower/sbin sbin
ln -s /lower/lib lib
/sbin/pivot_root . lower
/bin/rmdir /lower/overlay
/bin/mount -t overlay overlay -o lowerdir=/lower,upperdir=/upper,workdir=/work /merged
exec /sbin/chroot merged /sbin/init
@xogium xogium changed title from WIP make the build initramfs-less to make the build initramfs-less on 11 Aug 2020
@xogium xogium referenced the pull request on 11 Aug 2020

Do not depend on an initramfs any longer.

@xogium xogium merged commit bd5571e into stable-dev-board from WIP_initramfs-less on 11 Aug 2020
@xogium xogium closed this pull request on 11 Aug 2020
Labels

Priority
default
Milestone
No milestone
Assignee
No one assigned
2 participants
@xogium @Jookia