Skip to content

Commit

Permalink
fixing raspi image (#2712)
Browse files Browse the repository at this point in the history
* wip: fixing raspi image

* fix pi build
  • Loading branch information
dr-bonez authored Oct 18, 2024
1 parent c9f3e1b commit 2fa0a57
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
25 changes: 19 additions & 6 deletions image-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion image-recipe/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down Expand Up @@ -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
Expand All @@ -104,17 +104,14 @@ 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

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
Expand Down

0 comments on commit 2fa0a57

Please sign in to comment.