2021-06-26 13:04:06 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
2021-06-26 20:46:22 +00:00
|
|
|
# Simple script that runs a Rocky Raspberry pi creation (via appliance-creator), then inserts a UUID to the kernel boot line of the image
|
|
|
|
# after-the-fact
|
|
|
|
#
|
|
|
|
# Usage: ./Rocky8_Rpi4_mkimage.sh /path/to/outputfolder/
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Needs to be run in the same directory as the rocky rpi kickstart, as it relies on it!
|
|
|
|
#
|
|
|
|
|
|
|
|
# Exit with error if we don't have an output directory:
|
2021-06-26 14:31:50 +00:00
|
|
|
OUTDIR=$1
|
2021-06-26 13:04:06 +00:00
|
|
|
|
2021-06-26 20:46:22 +00:00
|
|
|
if [[ -z "$OUTDIR" ]]; then
|
|
|
|
echo "Need to run this script with a path to output directory. Like: ${0} /path/to/output/"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-06-26 13:04:06 +00:00
|
|
|
mkdir -p ${OUTDIR}
|
|
|
|
|
|
|
|
|
2021-06-26 20:46:22 +00:00
|
|
|
# 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}
|
|
|
|
|
2021-06-26 13:04:06 +00:00
|
|
|
|
|
|
|
|
2021-06-26 20:46:22 +00:00
|
|
|
# Post appliance-creator sequence to add UUID to the cmdline.txt file under /boot :
|
|
|
|
# (We don't want to rely on a /dev/ device name, what if a user wants to use a non-sdcard boot mechanism?)
|
2021-06-26 13:04:06 +00:00
|
|
|
|
|
|
|
mkdir -p /mnt/tmp
|
|
|
|
|
|
|
|
# find the image we just made, and make it available on /dev/maper/loop* devices:
|
2021-06-26 13:09:56 +00:00
|
|
|
image=`find ${OUTDIR} -iname *.raw | head -1`
|
2021-06-26 14:31:50 +00:00
|
|
|
echo "Getting UUID and inserting to boot from ${image} ...."
|
2021-06-26 13:04:06 +00:00
|
|
|
kpartx -av ${image}
|
|
|
|
|
|
|
|
# Get the UUID of our root partition (the ext4 one) (UUID=e3984938429 , strip out quotes("))
|
2021-06-26 20:46:22 +00:00
|
|
|
partuuid=`blkid | grep "mapper/loop0p3" | head -1 | awk '{print $NF}' | tr -d '"' | tr '[:lower:]' '[:upper:]'`
|
2021-06-26 13:04:06 +00:00
|
|
|
|
|
|
|
# Mount the /boot partition:
|
|
|
|
mkdir -p /mnt/tmp
|
|
|
|
umount /mnt/tmp
|
|
|
|
mount /dev/mapper/loop0p1 /mnt/tmp
|
|
|
|
|
|
|
|
# Swap out the "root=" part of cmdline.txt for our "root=UUID=blah"
|
2021-06-26 20:46:22 +00:00
|
|
|
sed -i "s/root= /root=${partuuid} /" /mnt/tmp/cmdline.txt
|
2021-06-26 13:04:06 +00:00
|
|
|
|
|
|
|
# Debug check to make sure it looks right:
|
|
|
|
echo "cmdline.txt looks like this, please review:"
|
|
|
|
cat /mnt/tmp/cmdline.txt
|
|
|
|
|
2021-06-26 20:46:22 +00:00
|
|
|
# Finished, unmount and clean loopbacks:
|
2021-06-26 13:04:06 +00:00
|
|
|
umount /mnt/tmp
|
2021-06-26 20:46:22 +00:00
|
|
|
kpartx -d ${image}
|
2021-06-26 13:04:06 +00:00
|
|
|
|