allow for making the image directly on a sdX device

This commit is contained in:
Aiden McClelland
2022-02-15 17:02:36 -07:00
committed by Aiden McClelland
parent 3ab2a93ea7
commit ba06216e84
2 changed files with 30 additions and 14 deletions

View File

@@ -2,6 +2,14 @@
set -e set -e
function partition_for () {
if [[ "$1" =~ [0-9]+$ ]]; then
echo "$1p$2"
else
echo "$1$2"
fi
}
SOURCE="${BASH_SOURCE[0]}" SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
@@ -22,9 +30,9 @@ fi
export LOOPDEV=$(sudo losetup --show -fP raspios.img) export LOOPDEV=$(sudo losetup --show -fP raspios.img)
./build/partitioning.sh ./build/partitioning.sh
./build/write-image.sh ./build/write-image.sh
sudo e2fsck -f ${OUTPUT_DEVICE}p3 sudo e2fsck -f `partition_for ${OUTPUT_DEVICE} 3`
sudo resize2fs -M ${OUTPUT_DEVICE}p3 sudo resize2fs -M `partition_for ${OUTPUT_DEVICE} 3`
BLOCK_INFO=$(sudo dumpe2fs ${OUTPUT_DEVICE}p3) BLOCK_INFO=$(sudo dumpe2fs `partition_for ${OUTPUT_DEVICE} 3`)
BLOCK_COUNT=$(echo "$BLOCK_INFO" | grep "Block count:" | sed 's/Block count:\s\+//g') 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') BLOCK_SIZE=$(echo "$BLOCK_INFO" | grep "Block size:" | sed 's/Block size:\s\+//g')
echo "YOUR GREEN FILESYSTEM is '$[$BLOCK_COUNT*$BLOCK_SIZE]' BYTES" echo "YOUR GREEN FILESYSTEM is '$[$BLOCK_COUNT*$BLOCK_SIZE]' BYTES"

View File

@@ -2,24 +2,32 @@
set -e 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 # Write contents of LOOPDEV (Ubuntu image) to sd card and make filesystems, then detach the loop device
echo USING $LOOPDEV TO IMAGE $OUTPUT_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 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 ${OUTPUT_DEVICE}p2 sudo mkfs.vfat -F 32 `partition_for ${OUTPUT_DEVICE} 2`
sudo dd if=${LOOPDEV}p2 of=${OUTPUT_DEVICE}p3 bs=1M iflag=fullblock oflag=direct conv=fsync status=progress sudo dd if=${LOOPDEV}p2 of=`partition_for ${OUTPUT_DEVICE} 3` bs=1M iflag=fullblock oflag=direct conv=fsync status=progress
sudo mkfs.ext4 ${OUTPUT_DEVICE}p4 sudo mkfs.ext4 `partition_for ${OUTPUT_DEVICE} 4`
sudo losetup -d $LOOPDEV sudo losetup -d $LOOPDEV
# Label the filesystems # Label the filesystems
sudo fatlabel ${OUTPUT_DEVICE}p1 system-boot sudo fatlabel `partition_for ${OUTPUT_DEVICE} 1` system-boot
sudo fatlabel ${OUTPUT_DEVICE}p2 EMBASSY sudo fatlabel `partition_for ${OUTPUT_DEVICE} 2` EMBASSY
sudo e2label ${OUTPUT_DEVICE}p3 green sudo e2label `partition_for ${OUTPUT_DEVICE} 3` green
sudo e2label ${OUTPUT_DEVICE}p4 blue sudo e2label `partition_for ${OUTPUT_DEVICE} 4` blue
# Mount the boot partition and config # Mount the boot partition and config
mkdir -p /tmp/eos-mnt 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 if [[ "$ENVIRONMENT" =~ (^|-)dev($|-) ]]; then
sudo cp build/user-data-dev /tmp/eos-mnt/user-data 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 # Unmount the boot partition and mount embassy partition
sudo umount /tmp/eos-mnt 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 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 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/media/boot-rw
sudo mkdir /tmp/eos-mnt/embassy-os sudo mkdir /tmp/eos-mnt/embassy-os