From ba06216e840fbb20aeb893e4e33aa679632c3a7d Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 15 Feb 2022 17:02:36 -0700 Subject: [PATCH] allow for making the image directly on a sdX device --- build/make-image.sh | 14 +++++++++++--- build/write-image.sh | 30 +++++++++++++++++++----------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/build/make-image.sh b/build/make-image.sh index 5988e1e5e..0c2fb7fad 100755 --- a/build/make-image.sh +++ b/build/make-image.sh @@ -2,6 +2,14 @@ set -e +function partition_for () { + if [[ "$1" =~ [0-9]+$ ]]; then + echo "$1p$2" + else + echo "$1$2" + fi +} + SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" @@ -22,9 +30,9 @@ fi export LOOPDEV=$(sudo losetup --show -fP raspios.img) ./build/partitioning.sh ./build/write-image.sh -sudo e2fsck -f ${OUTPUT_DEVICE}p3 -sudo resize2fs -M ${OUTPUT_DEVICE}p3 -BLOCK_INFO=$(sudo dumpe2fs ${OUTPUT_DEVICE}p3) +sudo e2fsck -f `partition_for ${OUTPUT_DEVICE} 3` +sudo resize2fs -M `partition_for ${OUTPUT_DEVICE} 3` +BLOCK_INFO=$(sudo dumpe2fs `partition_for ${OUTPUT_DEVICE} 3`) BLOCK_COUNT=$(echo "$BLOCK_INFO" | grep "Block count:" | sed 's/Block count:\s\+//g') BLOCK_SIZE=$(echo "$BLOCK_INFO" | grep "Block size:" | sed 's/Block size:\s\+//g') echo "YOUR GREEN FILESYSTEM is '$[$BLOCK_COUNT*$BLOCK_SIZE]' BYTES" diff --git a/build/write-image.sh b/build/write-image.sh index cdc5be25f..ba344f738 100755 --- a/build/write-image.sh +++ b/build/write-image.sh @@ -2,24 +2,32 @@ set -e +function partition_for () { + if [[ "$1" =~ [0-9]+$ ]]; then + echo "$1p$2" + else + echo "$1$2" + fi +} + # Write contents of LOOPDEV (Ubuntu image) to sd card and make filesystems, then detach the loop device echo USING $LOOPDEV TO IMAGE $OUTPUT_DEVICE -sudo dd if=${LOOPDEV}p1 of=${OUTPUT_DEVICE}p1 bs=1M iflag=fullblock oflag=direct conv=fsync status=progress -sudo mkfs.vfat -F 32 ${OUTPUT_DEVICE}p2 -sudo dd if=${LOOPDEV}p2 of=${OUTPUT_DEVICE}p3 bs=1M iflag=fullblock oflag=direct conv=fsync status=progress -sudo mkfs.ext4 ${OUTPUT_DEVICE}p4 +sudo dd if=${LOOPDEV}p1 of=`partition_for ${OUTPUT_DEVICE} 1` bs=1M iflag=fullblock oflag=direct conv=fsync status=progress +sudo mkfs.vfat -F 32 `partition_for ${OUTPUT_DEVICE} 2` +sudo dd if=${LOOPDEV}p2 of=`partition_for ${OUTPUT_DEVICE} 3` bs=1M iflag=fullblock oflag=direct conv=fsync status=progress +sudo mkfs.ext4 `partition_for ${OUTPUT_DEVICE} 4` sudo losetup -d $LOOPDEV # Label the filesystems -sudo fatlabel ${OUTPUT_DEVICE}p1 system-boot -sudo fatlabel ${OUTPUT_DEVICE}p2 EMBASSY -sudo e2label ${OUTPUT_DEVICE}p3 green -sudo e2label ${OUTPUT_DEVICE}p4 blue +sudo fatlabel `partition_for ${OUTPUT_DEVICE} 1` system-boot +sudo fatlabel `partition_for ${OUTPUT_DEVICE} 2` EMBASSY +sudo e2label `partition_for ${OUTPUT_DEVICE} 3` green +sudo e2label `partition_for ${OUTPUT_DEVICE} 4` blue # Mount the boot partition and config mkdir -p /tmp/eos-mnt -sudo mount ${OUTPUT_DEVICE}p1 /tmp/eos-mnt +sudo mount `partition_for ${OUTPUT_DEVICE} 1` /tmp/eos-mnt if [[ "$ENVIRONMENT" =~ (^|-)dev($|-) ]]; then sudo cp build/user-data-dev /tmp/eos-mnt/user-data @@ -40,11 +48,11 @@ sudo touch /tmp/eos-mnt/ssh # Unmount the boot partition and mount embassy partition sudo umount /tmp/eos-mnt -sudo mount ${OUTPUT_DEVICE}p2 /tmp/eos-mnt +sudo mount `partition_for ${OUTPUT_DEVICE} 2` /tmp/eos-mnt if [ "$NO_KEY" != "1" ]; then sudo cp product_key.txt /tmp/eos-mnt; else echo "This image is being written with no product key"; fi sudo umount /tmp/eos-mnt -sudo mount ${OUTPUT_DEVICE}p3 /tmp/eos-mnt +sudo mount `partition_for ${OUTPUT_DEVICE} 3` /tmp/eos-mnt sudo mkdir /tmp/eos-mnt/media/boot-rw sudo mkdir /tmp/eos-mnt/embassy-os