From a74dc716c472347a2da57aab13f18f6bef86e452 Mon Sep 17 00:00:00 2001 From: Stephan Wendel Date: Wed, 12 Apr 2023 17:48:25 +0200 Subject: [PATCH] chore: revert firstboot fix This reverts changes made in #214 as described in #213. Fix is already merged in https://github.com/RPi-Distro/raspberrypi-sys-mods/pull/71 Raspberry hasn't released updated image yet, but should work as we upgrade during build ci. Signed-off-by: Stephan Wendel --- config/raspberry/default | 2 +- src/modules/rpi_firstb_fix/config | 13 - .../usr/lib/raspberrypi-sys-mods/firstboot | 264 ------------------ .../rpi_firstb_fix/start_chroot_script | 32 --- 4 files changed, 1 insertion(+), 310 deletions(-) delete mode 100644 src/modules/rpi_firstb_fix/config delete mode 100755 src/modules/rpi_firstb_fix/filesystem/root/usr/lib/raspberrypi-sys-mods/firstboot delete mode 100644 src/modules/rpi_firstb_fix/start_chroot_script diff --git a/config/raspberry/default b/config/raspberry/default index e43627344..65d8dd99e 100644 --- a/config/raspberry/default +++ b/config/raspberry/default @@ -9,7 +9,7 @@ BASE_IMAGE_RESIZEROOT=600 # Compress not needed due compression done in workflow BASE_RELEASE_COMPRESS=no # Modules are valid for 32bit and 64bit images -MODULES="base,pkgupgrade,rpi_firstb_fix,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename" +MODULES="base,pkgupgrade,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename" # export Variables export BASE_IMAGE_ENLARGEROOT diff --git a/src/modules/rpi_firstb_fix/config b/src/modules/rpi_firstb_fix/config deleted file mode 100644 index 82afc5d89..000000000 --- a/src/modules/rpi_firstb_fix/config +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Shebang for better file detection -#### rpi_firstb_fix module -#### -#### Written by Stephan Wendel aka KwadFan -#### Copyright 2023 - till today -#### https://github.com/mainsail-crew/MainsailOS -#### -#### This File is distributed under GPLv3 -#### - -# Intentionally left blank -# See start_chroot_script for information diff --git a/src/modules/rpi_firstb_fix/filesystem/root/usr/lib/raspberrypi-sys-mods/firstboot b/src/modules/rpi_firstb_fix/filesystem/root/usr/lib/raspberrypi-sys-mods/firstboot deleted file mode 100755 index bd1a1f87e..000000000 --- a/src/modules/rpi_firstb_fix/filesystem/root/usr/lib/raspberrypi-sys-mods/firstboot +++ /dev/null @@ -1,264 +0,0 @@ -#!/bin/bash -# shellcheck disable=all - - -reboot_pi () { - umount /boot - mount / -o remount,ro - sync - if [ "$NOOBS" = "1" ]; then - if [ "$NEW_KERNEL" = "1" ]; then - reboot -f "$BOOT_PART_NUM" - sleep 5 - else - echo "$BOOT_PART_NUM" > "/sys/module/${BCM_MODULE}/parameters/reboot_part" - fi - fi - reboot -f - sleep 5 - exit 0 -} - -check_noobs () { - if [ "$BOOT_PART_NUM" = "1" ]; then - NOOBS=0 - else - NOOBS=1 - fi -} - -get_variables () { - ROOT_PART_DEV=$(findmnt / -o source -n) - ROOT_PART_NAME=$(echo "$ROOT_PART_DEV" | cut -d "/" -f 3) - ROOT_DEV_NAME=$(echo /sys/block/*/"${ROOT_PART_NAME}" | cut -d "/" -f 4) - ROOT_DEV="/dev/${ROOT_DEV_NAME}" - ROOT_PART_NUM=$(cat "/sys/block/${ROOT_DEV_NAME}/${ROOT_PART_NAME}/partition") - - BOOT_PART_DEV=$(findmnt /boot -o source -n) - BOOT_PART_NAME=$(echo "$BOOT_PART_DEV" | cut -d "/" -f 3) - BOOT_DEV_NAME=$(echo /sys/block/*/"${BOOT_PART_NAME}" | cut -d "/" -f 4) - BOOT_PART_NUM=$(cat "/sys/block/${BOOT_DEV_NAME}/${BOOT_PART_NAME}/partition") - - OLD_DISKID=$(fdisk -l "$ROOT_DEV" | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p') - - check_noobs - - ROOT_DEV_SIZE=$(cat "/sys/block/${ROOT_DEV_NAME}/size") - TARGET_END=$((ROOT_DEV_SIZE - 1)) - - PARTITION_TABLE=$(parted -m "$ROOT_DEV" unit s print | tr -d 's') - - LAST_PART_NUM=$(echo "$PARTITION_TABLE" | tail -n 1 | cut -d ":" -f 1) - - ROOT_PART_LINE=$(echo "$PARTITION_TABLE" | grep -e "^${ROOT_PART_NUM}:") - ROOT_PART_START=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 2) - ROOT_PART_END=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 3) - - if [ "$NOOBS" = "1" ]; then - EXT_PART_LINE=$(echo "$PARTITION_TABLE" | grep ":::;" | head -n 1) - EXT_PART_NUM=$(echo "$EXT_PART_LINE" | cut -d ":" -f 1) - EXT_PART_START=$(echo "$EXT_PART_LINE" | cut -d ":" -f 2) - EXT_PART_END=$(echo "$EXT_PART_LINE" | cut -d ":" -f 3) - fi -} - -fix_partuuid() { - mount -o remount,rw "$ROOT_PART_DEV" - mount -o remount,rw "$BOOT_PART_DEV" - MAJOR="$(uname -r | cut -f1 -d.)" - if [[ "$MAJOR" -eq "6" ]] && [[ -c /dev/hwrng ]]; then - dd if=/dev/hwrng of=/dev/urandom count=1 bs=256 status=none - fi - DISKID="$(tr -dc 'a-f0-9' < /dev/urandom | dd bs=1 count=8 2>/dev/null)" - fdisk "$ROOT_DEV" > /dev/null < /dev/null 2>&1 - RET="$?" - if [ "$RET" -ne 0 ]; then - FAIL_REASON="Root partition resize failed\n$FAIL_REASON" - fi - - mount -o remount,ro / - return "$RET" -} - -regenerate_ssh_host_keys () { - mount -o remount,rw / - /usr/lib/raspberrypi-sys-mods/regenerate_ssh_host_keys - RET="$?" - mount -o remount,ro / - return "$RET" -} - -apply_custom () { - CONFIG_FILE="$1" - mount -o remount,rw / - mount -o remount,rw /boot - if ! python3 -c "import toml" 2> /dev/null; then - FAIL_REASON="custom.toml provided, but python3-toml is not installed\n$FAIL_REASON" - else - set -o pipefail - /usr/lib/raspberrypi-sys-mods/init_config "$CONFIG_FILE" |& tee /run/firstboot.log | while read -r line; do - MSG="$MSG\n$line" - whiptail --infobox "$MSG" 20 60 - done - if [ "$?" -ne 0 ]; then - mv /run/firstboot.log /var/log/firstboot.log - FAIL_REASON="Failed to apply customisations from custom.toml\n\nLog file saved as /var/log/firstboot.log\n$FAIL_REASON" - fi - set +o pipefail - fi - rm -f "$CONFIG_FILE" - mount -o remount,ro /boot - mount -o remount,ro / -} - -main () { - get_variables - - if check_variables; then - do_resize - fi - - # Switch to dhcpcd here if Imager < v1.7.3 was used to generate firstrun.sh - fix_wpa > /dev/null 2>&1 - - whiptail --infobox "Generating SSH keys..." 20 60 - regenerate_ssh_host_keys - - if [ -f "/boot/custom.toml" ]; then - MSG="Applying customisations from custom.toml...\n" - whiptail --infobox "$MSG" 20 60 - apply_custom "/boot/custom.toml" - fi - - whiptail --infobox "Fix PARTUUID..." 20 60 - fix_partuuid - - return 0 -} - -mount -t proc proc /proc -mount -t sysfs sys /sys -mount -t tmpfs tmp /run -mkdir -p /run/systemd - -mount /boot -mount / -o remount,ro - -sed -i 's| init=/usr/lib/raspberrypi-sys-mods/firstboot||' /boot/cmdline.txt -sed -i 's| sdhci\.debug_quirks2=4||' /boot/cmdline.txt - -if ! grep -q splash /boot/cmdline.txt; then - sed -i "s/ quiet//g" /boot/cmdline.txt -fi -mount /boot -o remount,ro -sync - -main - -if [ -z "$FAIL_REASON" ]; then - whiptail --infobox "Rebooting in 5 seconds..." 20 60 - sleep 5 -else - whiptail --msgbox "Failed running firstboot:\n${FAIL_REASON}" 20 60 -fi - -reboot_pi diff --git a/src/modules/rpi_firstb_fix/start_chroot_script b/src/modules/rpi_firstb_fix/start_chroot_script deleted file mode 100644 index 281ba3a10..000000000 --- a/src/modules/rpi_firstb_fix/start_chroot_script +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash -#### rpi_firstb_fix module -#### -#### Written by Stephan Wendel aka KwadFan -#### Copyright 2023 - till today -#### https://github.com/mainsail-crew/MainsailOS -#### -#### This File is distributed under GPLv3 -#### - -#### Description: -#### This is intended to patch behaviour of raspberry's firstboot script. -#### Related to https://github.com/mainsail-crew/MainsailOS/issues/213 - -# shellcheck enable=require-variable-braces -## Source error handling, leave this in place -set -Ee - -# Set DEBIAN_FRONTEND to noninteractive -if [[ "${DEBIAN_FRONTEND}" != "noninteractive" ]]; then - export DEBIAN_FRONTEND=noninteractive -fi - -## Source CustomPIOS common.sh -# shellcheck disable=SC1091 -source /common.sh -install_cleanup_trap - -## Step 1: Patch firstboot issue -echo_green "Patch firstboot issue..." -unpack filesystem/root / -## END Step 1