Move PARRTUUID to a %post action in the ks
- also chown the result ro the $SUDO_USER if ran with sudo
This commit is contained in:
parent
7d83ec6dbc
commit
4760f97fd9
@ -61,7 +61,7 @@ aarch64-img-extra-config
|
||||
%post
|
||||
|
||||
cat > /boot/cmdline.txt << EOF
|
||||
console=ttyAMA0,115200 console=tty1 root= rootfstype=ext4 elevator=deadline rootwait
|
||||
console=ttyAMA0,115200 console=tty1 root= rootfstype=ext4 elevator=deadline rootwait
|
||||
EOF
|
||||
|
||||
# Run this once to fix the wifi:
|
||||
@ -73,7 +73,6 @@ sed -i 's/boardflags3=0x48200100/boardflags3=0x44200100/g' /lib/firmware/brcm/
|
||||
echo "rockylinux" | passwd --stdin rocky
|
||||
|
||||
# Need to write several files to help with various things here.
|
||||
|
||||
# First, the all-important README :
|
||||
|
||||
cat >/home/rocky/README << EOF
|
||||
@ -141,3 +140,21 @@ rm -f /etc/ssh/*_key*
|
||||
yum clean all
|
||||
|
||||
%end
|
||||
|
||||
# Add the PARTUUID of the rootfs partition to the kernel command line
|
||||
%post --nochroot
|
||||
|
||||
# Extract the UUID of the rootfs partition from /etc/fstab
|
||||
UUID_ROOTFS="$(/bin/cat $INSTALL_ROOT/etc/fstab | \
|
||||
/bin/awk -F'[ =]' '/\/ / {print $2}')"
|
||||
|
||||
# Get the PARTUUID of the rootfs partition
|
||||
PART_UUID_ROOTFS="$(/sbin/blkid "$(/sbin/blkid --uuid $UUID_ROOTFS)" | \
|
||||
/bin/awk '{print toupper($NF)}' | /bin/tr -d '"' )"
|
||||
|
||||
# Configure the kernel commandline
|
||||
/bin/sed -i "s/root= /root=${PART_UUID_ROOTFS} /" $INSTALL_ROOT/boot/cmdline.txt
|
||||
echo "cmdline.txt looks like this, please review:"
|
||||
/bin/cat $INSTALL_ROOT/boot/cmdline.txt
|
||||
|
||||
%end
|
||||
|
@ -25,40 +25,4 @@ mkdir -p "${OUTDIR}"
|
||||
# (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}"
|
||||
|
||||
|
||||
|
||||
# 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?)
|
||||
|
||||
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)
|
||||
echo "Getting UUID and inserting to boot from ${image} ...."
|
||||
kpartx -av "${image}"
|
||||
|
||||
# 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 '{print $NF}' | tr -d '"' | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
|
||||
# Get the boot partition and mount it
|
||||
# (change 3rd partition for 1st, so loop0p3 becomes loop0p1):
|
||||
bootloop=$(echo "${looppart}" | sed 's/p3$/p1/')
|
||||
|
||||
umount /mnt/tmp
|
||||
mount /dev/mapper/${bootloop} /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
|
||||
|
||||
# Debug check to make sure it looks right:
|
||||
echo "cmdline.txt looks like this, please review:"
|
||||
cat /mnt/tmp/cmdline.txt
|
||||
|
||||
# Finished, unmount and clean loopbacks:
|
||||
umount /mnt/tmp
|
||||
kpartx -d "${image}"
|
||||
chown -R $SUDO_USER. "${OUTDIR}"
|
Loading…
Reference in New Issue
Block a user