From 2fa0a57d2b1c3e9e08b454e94318eb73379aae19 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:17:56 -0600 Subject: [PATCH] fixing raspi image (#2712) * wip: fixing raspi image * fix pi build --- image-recipe/build.sh | 25 ++++++++++++++----- image-recipe/prepare.sh | 3 ++- .../usr/lib/startos/scripts/init_resize.sh | 11 +++----- .../etc/{embassy => startos}/config.yaml | 0 4 files changed, 25 insertions(+), 14 deletions(-) rename image-recipe/raspberrypi/squashfs/etc/{embassy => startos}/config.yaml (100%) diff --git a/image-recipe/build.sh b/image-recipe/build.sh index 5635e94f3..c183218ff 100755 --- a/image-recipe/build.sh +++ b/image-recipe/build.sh @@ -317,18 +317,31 @@ elif [ "${IMAGE_TYPE}" = img ]; then TMPDIR=$(mktemp -d) - mount `partition_for ${OUTPUT_DEVICE} 2` $TMPDIR - mkdir $TMPDIR/boot + mkdir -p $TMPDIR/boot $TMPDIR/root + mount `partition_for ${OUTPUT_DEVICE} 2` $TMPDIR/root mount `partition_for ${OUTPUT_DEVICE} 1` $TMPDIR/boot - unsquashfs -f -d $TMPDIR $prep_results_dir/binary/live/filesystem.squashfs + unsquashfs -n -f -d $TMPDIR $prep_results_dir/binary/live/filesystem.squashfs boot + + mkdir $TMPDIR/root/images $TMPDIR/root/config + B3SUM=$(b3sum $prep_results_dir/binary/live/filesystem.squashfs | head -c 16) + cp $prep_results_dir/binary/live/filesystem.squashfs $TMPDIR/root/images/$B3SUM.rootfs + ln -rsf $TMPDIR/root/images/$B3SUM.rootfs $TMPDIR/root/config/current.rootfs + + mkdir -p $TMPDIR/next $TMPDIR/lower $TMPDIR/root/config/work $TMPDIR/root/config/overlay + mount $TMPDIR/root/config/current.rootfs $TMPDIR/lower + + mount -t overlay -o lowerdir=$TMPDIR/lower,workdir=$TMPDIR/root/config/work,upperdir=$TMPDIR/root/config/overlay overlay $TMPDIR/next if [ "${IB_TARGET_PLATFORM}" = "raspberrypi" ]; then - sed -i 's| boot=startos| init=/usr/lib/startos/scripts/init_resize\.sh|' $TMPDIR/boot/cmdline.txt - rsync -a $base_dir/raspberrypi/img/ $TMPDIR/ + sed -i 's| boot=startos| boot=startos init=/usr/lib/startos/scripts/init_resize\.sh|' $TMPDIR/boot/cmdline.txt + rsync -a $base_dir/raspberrypi/img/ $TMPDIR/next/ fi + umount $TMPDIR/next + umount $TMPDIR/lower + umount $TMPDIR/boot - umount $TMPDIR + umount $TMPDIR/root e2fsck -fy `partition_for ${OUTPUT_DEVICE} 2` resize2fs -M `partition_for ${OUTPUT_DEVICE} 2` diff --git a/image-recipe/prepare.sh b/image-recipe/prepare.sh index 8962d8448..c31f6ada0 100755 --- a/image-recipe/prepare.sh +++ b/image-recipe/prepare.sh @@ -21,7 +21,8 @@ apt-get install -yq \ dosfstools \ e2fsprogs \ squashfs-tools \ - rsync + rsync \ + b3sum # TODO: remove when util-linux is released at v2.39.3 apt-get install -yq \ git \ diff --git a/image-recipe/raspberrypi/img/usr/lib/startos/scripts/init_resize.sh b/image-recipe/raspberrypi/img/usr/lib/startos/scripts/init_resize.sh index cf6489f5f..9e357cd57 100755 --- a/image-recipe/raspberrypi/img/usr/lib/startos/scripts/init_resize.sh +++ b/image-recipe/raspberrypi/img/usr/lib/startos/scripts/init_resize.sh @@ -1,7 +1,7 @@ #!/bin/bash get_variables () { - ROOT_PART_DEV=$(findmnt / -o source -n) + ROOT_PART_DEV=$(findmnt /media/startos/root -o source -n) ROOT_PART_NAME=$(echo "$ROOT_PART_DEV" | cut -d "/" -f 3) ROOT_DEV_NAME=$(echo /sys/block/*/"${ROOT_PART_NAME}" | cut -d "/" -f 4) ROOT_DEV="/dev/${ROOT_DEV_NAME}" @@ -89,12 +89,12 @@ main () { resize2fs $ROOT_PART_DEV - if ! systemd-machine-id-setup; then + if ! systemd-machine-id-setup --root=/media/startos/config/overlay/; then FAIL_REASON="systemd-machine-id-setup failed" return 1 fi - if ! ssh-keygen -A; then + if ! mkdir -p /media/startos/config/overlay/etc/ssh && ssh-keygen -A -f /media/startos/config/overlay/; then FAIL_REASON="ssh host key generation failed" return 1 fi @@ -104,9 +104,6 @@ main () { return 0 } -mount -t proc proc /proc -mount -t sysfs sys /sys -mount -t tmpfs tmp /run mkdir -p /run/systemd mount /boot mount / -o remount,ro @@ -114,7 +111,7 @@ mount / -o remount,ro beep if main; then - sed -i 's| init=/usr/lib/startos/scripts/init_resize\.sh| boot=startos|' /boot/cmdline.txt + sed -i 's| init=/usr/lib/startos/scripts/init_resize\.sh||' /boot/cmdline.txt echo "Resized root filesystem. Rebooting in 5 seconds..." sleep 5 else diff --git a/image-recipe/raspberrypi/squashfs/etc/embassy/config.yaml b/image-recipe/raspberrypi/squashfs/etc/startos/config.yaml similarity index 100% rename from image-recipe/raspberrypi/squashfs/etc/embassy/config.yaml rename to image-recipe/raspberrypi/squashfs/etc/startos/config.yaml