Merge branch 'merge_request' into 'main'

Minor cleanups & Move appending PARRTUUID to a %post action in the ks

See merge request skip/RockyRpi!5
This commit is contained in:
Skip Grube 2021-07-30 20:51:52 +00:00
commit 8c0652f11c
2 changed files with 45 additions and 93 deletions

View File

@ -4,10 +4,6 @@
# (pull from pgreco: https://github.com/psgreco/sig-core-AltArch/tree/master/image_build
# Basic setup information
#%include "Rocky8_Rpi4/020_common.ksi"
#%include "Rocky8_Rpi4/040_packages.ksi"
# Disk setup
clearpart --initlabel --all
part /boot --asprimary --fstype=vfat --size=300 --label=boot
@ -29,14 +25,15 @@ repo --name="Rpi-Kernel" --baseurl=https://rocky.lowend.ninja/RockyRpi/Rpi-Kerne
install
keyboard us --xlayouts=us --vckeymap=us
rootpw --lock
user --name="rocky" --password="rockylinux" --plaintext --gecos="Rocky default user" --groups=wheel --uid=1000
# FIXME user creation here does not work ?
# user --name="rocky" --password="rockylinux" --plaintext --gecos="Rocky default user" --groups=wheel --uid=1000
timezone --isUtc --nontp UTC
selinux --enforcing
firewall --enabled --port=22:tcp
network --bootproto=dhcp --device=link --activate --onboot=on
services --enabled=sshd,NetworkManager,chronyd
shutdown
bootloader --location=mbr --extlinux
bootloader --location=none
lang en_US.UTF-8
@ -62,36 +59,20 @@ aarch64-img-extra-config
# Post install scripts:
%post
# Enabling chronyd on boot
systemctl enable chronyd
# Remove ifcfg-link on pre generated images
rm -f /etc/sysconfig/network-scripts/ifcfg-link
# Remove machine-id on pre generated images
rm -f /etc/machine-id
touch /etc/machine-id
# Apparently kickstart user was not working, attempt to do it here?
/sbin/useradd -c "Rocky Linux default user" -u 1000 -G wheel -m -U rocky
echo "rockylinux" | passwd --stdin rocky
# Ensure no ssh keys are present
rm -f /etc/ssh/*_key*
cat > /boot/cmdline.txt << EOF
console=ttyAMA0,115200 console=tty1 root= rootfstype=ext4 elevator=deadline rootwait
EOF
# Run this once to fix the wifi:
sed -i 's/boardflags3=0x48200100/boardflags3=0x44200100/g' /lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,4-model-b.txt
mkdir -p /home/rocky
chown 1000:1000 /home/rocky
# Apparently kickstart user was not working, attempt to do it here?
/sbin/useradd -c "Rocky Linux default user" -G wheel -m -U rocky
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
@ -116,38 +97,13 @@ IMAGE NOTES / DIFFERENCES FROM STOCK ROCKY 8:
If you want to automatically resize your / partition, just type the following (as root user):
rootfs-expand
sudo rootfs-expand
It should fill your main rootfs partition to the end of the disk.
EOF
chown 1000 /home/rocky/README
# Next, script to fix the wifi firmware setting:
cat >/home/rocky/fix-wifi-rpi4.sh << 'EOF'
#!/bin/bash
# Simple hacky fix to correct wifi settings on the Rpi4 so it loads properly:
sed -i 's/boardflags3=0x48200100/boardflags3=0x44200100/g' /lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,4-model-b.txt
echo "Patched /lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,4-model-b.txt . You can reboot and wifi should work, or do: rmmod brcmfmac; modprobe brcmfmac; "
EOF
chown 1000 /home/rocky/fix-wifi-rpi4.sh
chmod 755 /home/rocky/fix-wifi-rpi4.sh
# Link the rootfs-expand script:
ln -s /usr/bin/rootfs-expand /home/rocky/
# Run this once to fix the wifi:
sed -i 's/boardflags3=0x48200100/boardflags3=0x44200100/g' /lib/firmware/brcm/brcmfmac43455-sdio.raspberrypi,4-model-b.txt
chown -R rocky:rocky /home/rocky
# Add rpi-kernel repo:
@ -168,5 +124,37 @@ enabled=1
EOF
# Cleanup before shipping an image
# Remove ifcfg-link on pre generated images
rm -f /etc/sysconfig/network-scripts/ifcfg-link
# Remove machine-id on pre generated images
rm -f /etc/machine-id
touch /etc/machine-id
# Ensure no ssh keys are present
rm -f /etc/ssh/*_key*
# Clean yum cache
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 $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

View File

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