From 1a521a0bb218262d7c69eb837a5bb3d95d37b02d Mon Sep 17 00:00:00 2001 From: Mark Verlinde Date: Tue, 29 Jun 2021 18:25:38 +0200 Subject: [PATCH 1/6] Minor cleanup - RPI's do not have a bootlaoder known by linux distro's - chrony is already enabled @services - remove scipt for wifi fix, it is already done @image creation - rootfs-expand needs root privileges --- Rocky8_Rpi4.ks | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/Rocky8_Rpi4.ks b/Rocky8_Rpi4.ks index 65aac5b..f5e2ce4 100644 --- a/Rocky8_Rpi4.ks +++ b/Rocky8_Rpi4.ks @@ -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 @@ -36,7 +32,7 @@ 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,10 +58,6 @@ 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 @@ -116,7 +108,7 @@ 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. @@ -124,27 +116,6 @@ 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 From 437e7dd0e23d2a740d13fb40739d8da58f1b5aac Mon Sep 17 00:00:00 2001 From: Mark Verlinde Date: Tue, 29 Jun 2021 22:05:05 +0200 Subject: [PATCH 2/6] Group sections in function units - first all system related tweaks - second user creation - last cleanup --- Rocky8_Rpi4.ks | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/Rocky8_Rpi4.ks b/Rocky8_Rpi4.ks index f5e2ce4..acba5e7 100644 --- a/Rocky8_Rpi4.ks +++ b/Rocky8_Rpi4.ks @@ -58,26 +58,17 @@ aarch64-img-extra-config # Post install scripts: %post -# 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 + +# 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 mkdir -p /home/rocky chown 1000:1000 /home/rocky @@ -116,10 +107,6 @@ EOF chown 1000 /home/rocky/README -# 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 - - # Add rpi-kernel repo: cat >/etc/yum.repos.d/Rocky_Rpi_kernel.repo << 'EOF' @@ -139,5 +126,16 @@ 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* %end From b9bb3b7090e141a780333461f3f5b1256711b4ae Mon Sep 17 00:00:00 2001 From: Mark Verlinde Date: Tue, 29 Jun 2021 21:53:48 +0200 Subject: [PATCH 3/6] Clean yum cache - should reduce size shipped compressed image --- Rocky8_Rpi4.ks | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Rocky8_Rpi4.ks b/Rocky8_Rpi4.ks index acba5e7..6078684 100644 --- a/Rocky8_Rpi4.ks +++ b/Rocky8_Rpi4.ks @@ -138,4 +138,7 @@ touch /etc/machine-id # Ensure no ssh keys are present rm -f /etc/ssh/*_key* +# Clean yum cache +yum clean all + %end From 7d83ec6dbc937457fd1cc61d7acbdd643240f69e Mon Sep 17 00:00:00 2001 From: Mark Verlinde Date: Tue, 29 Jun 2021 22:10:47 +0200 Subject: [PATCH 4/6] Refactor default user creation - FIXME: why does the kickstart fail to create a user with appliance-tools? --- Rocky8_Rpi4.ks | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Rocky8_Rpi4.ks b/Rocky8_Rpi4.ks index 6078684..2528c42 100644 --- a/Rocky8_Rpi4.ks +++ b/Rocky8_Rpi4.ks @@ -25,7 +25,8 @@ 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 @@ -66,12 +67,10 @@ 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 -# 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 -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. @@ -105,7 +104,7 @@ It should fill your main rootfs partition to the end of the disk. EOF -chown 1000 /home/rocky/README +chown -R rocky:rocky /home/rocky # Add rpi-kernel repo: From 4760f97fd9e79e8d74f7ebed8ff33c8173076bda Mon Sep 17 00:00:00 2001 From: Mark Verlinde Date: Thu, 15 Jul 2021 19:32:41 +0200 Subject: [PATCH 5/6] Move PARRTUUID to a %post action in the ks - also chown the result ro the $SUDO_USER if ran with sudo --- Rocky8_Rpi4.ks | 21 +++++++++++++++++++-- Rocky8_Rpi4_mkimage.sh | 38 +------------------------------------- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/Rocky8_Rpi4.ks b/Rocky8_Rpi4.ks index 2528c42..8b343e1 100644 --- a/Rocky8_Rpi4.ks +++ b/Rocky8_Rpi4.ks @@ -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 diff --git a/Rocky8_Rpi4_mkimage.sh b/Rocky8_Rpi4_mkimage.sh index 56cc59b..efbdd1c 100755 --- a/Rocky8_Rpi4_mkimage.sh +++ b/Rocky8_Rpi4_mkimage.sh @@ -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}" \ No newline at end of file From a0ec8c12a3454c22d206e771a25f7a1354a75e9d Mon Sep 17 00:00:00 2001 From: Mark Verlinde Date: Thu, 22 Jul 2021 10:03:08 +0200 Subject: [PATCH 6/6] Do not capitalize PARTUUID - it is not needed for booting the "Raspberry PI OS" way - it breaks booting with an intitramfs --- Rocky8_Rpi4.ks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rocky8_Rpi4.ks b/Rocky8_Rpi4.ks index 8b343e1..3e96535 100644 --- a/Rocky8_Rpi4.ks +++ b/Rocky8_Rpi4.ks @@ -150,7 +150,7 @@ UUID_ROOTFS="$(/bin/cat $INSTALL_ROOT/etc/fstab | \ # 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 '"' )" +/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