From 48bf9b50567d8b850396eac39b98c40a0bbbd3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Tue, 21 Jan 2025 18:40:07 +0100 Subject: [PATCH] Move rauc.db to boot partition (#3810) * Move rauc.db to boot partition The RAUC metadata file contains information that is tightly related to the system and kernel partitions. With the possibility to migrate data disk, the rauc.db can contain bogus information when moved to a different system. Removal of the file on "device wipe" is also not desirable, because the information about slot status is lost. Relocate the rauc.db to the boot partition after a system upgrade (as this can't be handled by RAUC hooks, because it needs to be executed after all slots and metadata is written) and adjust the script for recreating it. The downside is that its content in /mnt/data would be recreated if the boot slot is changed or system downgraded but this should be handled quite gracefully. Also remove the raucdb-first-boot service which is no longer necessary with the file not present in the data partition. * Fix shellcheck and mount path --- buildroot-external/ota/rauc-hook | 11 +++++++++++ buildroot-external/ota/system.conf.gtpl | 2 +- .../lib/systemd/system/raucdb-first-boot.service | 14 -------------- .../usr/lib/systemd/system/raucdb-migrate.service | 13 +++++++++++++ .../usr/lib/systemd/system/raucdb-update.service | 2 +- .../rootfs-overlay/usr/libexec/raucdb-update | 9 +++++++-- 6 files changed, 33 insertions(+), 18 deletions(-) delete mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-first-boot.service create mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-migrate.service diff --git a/buildroot-external/ota/rauc-hook b/buildroot-external/ota/rauc-hook index f366d5c7e..661c75750 100755 --- a/buildroot-external/ota/rauc-hook +++ b/buildroot-external/ota/rauc-hook @@ -52,6 +52,17 @@ install_boot() { sed -i '/device_tree=bcm2711-rpi-cm4-ha-yellow.dtb/d; s/\[all\]/\[cm4\]\ndevice_tree=bcm2711-rpi-cm4-ha-yellow.dtb\n\n\[cm5\]\ndevice_tree=bcm2712-rpi-cm5-ha-yellow.dtb\n\n\[all\]/' "${BOOT_MNT}/config.txt" fi fi + + # Prepare rauc.db for migration, should be removed in HAOS 16 + # (along with raucdb-migrate.service and related raucdb-update changes) + if [ -f /mnt/data/rauc.db ]; then + # shellcheck disable=SC1091 + . /etc/os-release + # Do not migrate if already running on OS 15. + if [ "${VERSION_ID%%.*}" != "15" ]; then + touch /mnt/boot/migrate-raucdb + fi + fi } install_spl() { diff --git a/buildroot-external/ota/system.conf.gtpl b/buildroot-external/ota/system.conf.gtpl index 4d15e371c..4a183d84b 100644 --- a/buildroot-external/ota/system.conf.gtpl +++ b/buildroot-external/ota/system.conf.gtpl @@ -1,7 +1,7 @@ [system] compatible={{ env "ota_compatible" }} mountprefix=/run/rauc -statusfile=/mnt/data/rauc.db +statusfile=/mnt/boot/rauc.db {{- if eq (env "BOOTLOADER") "tryboot" }} bootloader=custom {{- else }} diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-first-boot.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-first-boot.service deleted file mode 100644 index efc724261..000000000 --- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-first-boot.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Remove adopted rauc.db on first boot -After=rauc.service -Before=raucdb-update.service -RequiresMountsFor=/mnt/data -ConditionFirstBoot=yes -ConditionFileNotEmpty=/mnt/data/rauc.db - -[Service] -Type=oneshot -ExecStart=/bin/rm -f /mnt/data/rauc.db - -[Install] -WantedBy=multi-user.target diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-migrate.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-migrate.service new file mode 100644 index 000000000..e6b6323aa --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-migrate.service @@ -0,0 +1,13 @@ +[Unit] +Description=Migrate rauc.db to boot partition +Before=rauc.service +RequiresMountsFor=/mnt/boot /mnt/data +ConditionPathExists=/mnt/boot/migrate-raucdb + +[Service] +Type=oneshot +ExecStart=/bin/cp /mnt/data/rauc.db /mnt/boot/ +ExecStartPost=/bin/rm /mnt/boot/migrate-raucdb + +[Install] +WantedBy=multi-user.target diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service index d38d50bca..e1e996ba1 100644 --- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/raucdb-update.service @@ -2,7 +2,7 @@ Description=Ensure rauc.db contains version information After=rauc.service Before=hassos-supervisor.service -RequiresMountsFor=/mnt/data +RequiresMountsFor=/mnt/boot /mnt/data [Service] Type=oneshot diff --git a/buildroot-external/rootfs-overlay/usr/libexec/raucdb-update b/buildroot-external/rootfs-overlay/usr/libexec/raucdb-update index 0bf04211a..ac08309d6 100755 --- a/buildroot-external/rootfs-overlay/usr/libexec/raucdb-update +++ b/buildroot-external/rootfs-overlay/usr/libexec/raucdb-update @@ -3,7 +3,12 @@ set -e -if grep -q 'slot\.boot\.0' /mnt/data/rauc.db; then +# Remove rauc.db from old location before migration in HAOS 15. +if [ -f /mnt/data/rauc.db ]; then + rm -f /mnt/data/rauc.db +fi + +if grep -q 'slot\.boot\.0' /mnt/boot/rauc.db; then echo "[INFO] rauc.db already contains slot information" exit 0 fi @@ -21,7 +26,7 @@ CURRENT_SLOT_ID=$(test "${RAUC_SYSTEM_BOOTED_BOOTNAME}" = "A" && echo 0 || echo . /etc/os-release -cat >> /mnt/data/rauc.db <> /mnt/boot/rauc.db <