Handle partition labels; replace multiple tr with awk

This commit is contained in:
Chris Stackpole 2021-07-07 21:31:05 -05:00
parent ad078656b6
commit dd2066bc5d
1 changed files with 6 additions and 4 deletions

View File

@ -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