From 2bfc5245462c0cb0a9ad7f62cc6c17cd0709e01b Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Mon, 20 Nov 2023 23:04:00 +0100 Subject: [PATCH] board/common: mnt: Correctly reset /var as part of a factory-reset Before this change, the following would happen in /lib/infix/mnt if a factory-reset was performed: 1. Copy the contents of /var from Squash into /mnt/var and bind mount /mnt/var over /var 2. Check for factory-reset 3. Clear /mnt/cfg/* and /mnt/var/* 4. Mount overlays This ordering leaves the system with a completely empty /var on the boot when a factory-reset is executed. Finit will fixup some of this via its tmpfiles scripts, but we want the ability to ship files under /var as part of the Squash and have these be available after the bind mount, just like what happens at every other boot, when we don't perform a factory-reset. We solve this by delaying the bind mount (1) until after the reset has been performed, together with all the overlays (4). While we're here, make the fallback case, where no persistent /var is available, use a bind mount as well. This should allow containers to be tested on such setups, and it's one less flavor to test. New order: 1. Check for factory-reset 2. Clear /mnt/cfg/* and /mnt/var/* 3. Mount overlays 4. Copy the contents of /var from Squash into /mnt/var and bind mount /mnt/var over /var Now the only difference between a regular boot and a "factory-reset-boot" is whether (2) executed or not. --- board/common/rootfs/lib/infix/mnt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/board/common/rootfs/lib/infix/mnt b/board/common/rootfs/lib/infix/mnt index 06332cf6..6d8ffe85 100755 --- a/board/common/rootfs/lib/infix/mnt +++ b/board/common/rootfs/lib/infix/mnt @@ -109,12 +109,8 @@ varsrc=/mnt/var if ! mount_rw var >/dev/null 2>&1; then logger $opt -p user.warn -t "$nm" \ "No persistent storage found for /var, only /var/lib is persisted." - varsrc=/mnt/tmp + varsrc=/mnt/tmp/infix/var vlibsrc=/mnt/cfg/vlib -else - mount_bind "$varsrc" /var - varsrc= - vlibsrc= fi cfgsrc=/mnt/cfg @@ -145,9 +141,9 @@ mount_overlay cfg $cfgsrc /cfg mount_overlay etc $etcsrc /etc mount_overlay home $cfgsrc /home mount_overlay root $cfgsrc /root +mount_bind "$varsrc" /var -[ "$varsrc" ] && mount_overlay var "$varsrc" /var -[ "$vlibsrc" ] && mount_bind "$vlibsrc" /var/lib +[ "$vlibsrc" ] && mount_bind "$vlibsrc" /var/lib # Keep transient configs in a ramdisk and symlink out to /cfg for # startup.