From 0d104aa6afab303f511327910822d4720d8036ef Mon Sep 17 00:00:00 2001 From: Stack Date: Wed, 7 Jul 2021 18:06:43 -0500 Subject: [PATCH 1/3] Ran through ShellCheck. --- Rocky8_Rpi4_mkimage.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Rocky8_Rpi4_mkimage.sh b/Rocky8_Rpi4_mkimage.sh index 57f6c68..0337570 100755 --- a/Rocky8_Rpi4_mkimage.sh +++ b/Rocky8_Rpi4_mkimage.sh @@ -18,12 +18,12 @@ if [[ -z "$OUTDIR" ]]; then exit 1 fi -mkdir -p ${OUTDIR} +mkdir -p "${OUTDIR}" # Actually create the image. Our kickstart data should be in the same git repo as this script: # (This takes a while, especially building on an rpi. Patience!) -appliance-creator -v -c ./Rocky8_Rpi4.ks -n RockyRpi --version=20210626 --release=1 --vmem=2048 --vcpu=2 --no-compress -o ${OUTDIR} +appliance-creator -v -c ./Rocky8_Rpi4.ks -n RockyRpi --version=20210626 --release=1 --vmem=2048 --vcpu=2 --no-compress -o "${OUTDIR}" @@ -33,12 +33,12 @@ appliance-creator -v -c ./Rocky8_Rpi4.ks -n RockyRpi --version=20210626 --relea mkdir -p /mnt/tmp # find the image we just made, and make it available on /dev/maper/loop* devices: -image=`find ${OUTDIR} -iname *.raw | head -1` +image=$(find "${OUTDIR}" -iname '*.raw' | head -1) echo "Getting UUID and inserting to boot from ${image} ...." -kpartx -av ${image} +kpartx -av "${image}" # Get the UUID of our root partition (the ext4 one) (UUID=e3984938429 , strip out quotes(")) -partuuid=`blkid | grep "mapper/loop0p3" | head -1 | awk '{print $NF}' | tr -d '"' | tr '[:lower:]' '[:upper:]'` +partuuid=$(blkid | grep "mapper/loop0p3" | head -1 | awk '{print $NF}' | tr -d '"' | tr '[:lower:]' '[:upper:]') # Mount the /boot partition: mkdir -p /mnt/tmp @@ -54,5 +54,4 @@ cat /mnt/tmp/cmdline.txt # Finished, unmount and clean loopbacks: umount /mnt/tmp -kpartx -d ${image} - +kpartx -d "${image}" From ad078656b6b2a42165cc21377fccc1cd4c925a81 Mon Sep 17 00:00:00 2001 From: Stack Date: Wed, 7 Jul 2021 20:55:50 -0500 Subject: [PATCH 2/3] Remove dupliate mkdir --- Rocky8_Rpi4_mkimage.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/Rocky8_Rpi4_mkimage.sh b/Rocky8_Rpi4_mkimage.sh index 0337570..015a1fa 100755 --- a/Rocky8_Rpi4_mkimage.sh +++ b/Rocky8_Rpi4_mkimage.sh @@ -41,7 +41,6 @@ kpartx -av "${image}" partuuid=$(blkid | grep "mapper/loop0p3" | head -1 | awk '{print $NF}' | tr -d '"' | tr '[:lower:]' '[:upper:]') # Mount the /boot partition: -mkdir -p /mnt/tmp umount /mnt/tmp mount /dev/mapper/loop0p1 /mnt/tmp From dd2066bc5d08797f5eea6bc2484856f46883762d Mon Sep 17 00:00:00 2001 From: Stack Date: Wed, 7 Jul 2021 21:31:05 -0500 Subject: [PATCH 3/3] Handle partition labels; replace multiple tr with awk --- Rocky8_Rpi4_mkimage.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Rocky8_Rpi4_mkimage.sh b/Rocky8_Rpi4_mkimage.sh index 015a1fa..426ddfa 100755 --- a/Rocky8_Rpi4_mkimage.sh +++ b/Rocky8_Rpi4_mkimage.sh @@ -37,12 +37,14 @@ image=$(find "${OUTDIR}" -iname '*.raw' | head -1) echo "Getting UUID and inserting to boot from ${image} ...." kpartx -av "${image}" -# Get the UUID of our root partition (the ext4 one) (UUID=e3984938429 , strip out quotes(")) -partuuid=$(blkid | grep "mapper/loop0p3" | head -1 | awk '{print $NF}' | tr -d '"' | tr '[:lower:]' '[:upper:]') +# Get the loop partition; it might be loop0p3, loop1p3, ... +looppart=$(kpartx -l "${image}" | awk '/p3/{print $1}') +# Get the UUID of our root partition (the ext4 one) (UUID=e3984938429 , strip out quotes("), and force upper case) +partuuid=$(blkid | grep "mapper/${looppart}" | head -1 | awk '{gsub(/\"/,"", $NF); print toupper($0)}') -# Mount the /boot partition: +# Mount the /boot partition (swap the 3rd partition for the first): umount /mnt/tmp -mount /dev/mapper/loop0p1 /mnt/tmp +mount /dev/mapper/${looppart/3/1} /mnt/tmp # Swap out the "root=" part of cmdline.txt for our "root=UUID=blah" sed -i "s/root= /root=${partuuid} /" /mnt/tmp/cmdline.txt