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
This commit is contained in:
Jan Čermák 2025-01-21 18:40:07 +01:00 committed by GitHub
parent af7b36e100
commit 48bf9b5056
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 18 deletions

View File

@ -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() {

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <<EOF
cat >> /mnt/boot/rauc.db <<EOF
[slot.boot.0]
bundle.compatible=${RAUC_SYSTEM_COMPATIBLE}