base-files: prevent issues w/ overlay on powerloss after sysupgrade
authorSergey Ryazanov <ryazanov.s.a@gmail.com>
Fri, 24 Apr 2020 14:04:14 +0000 (17:04 +0300)
committerPetr Štetiar <ynezz@true.cz>
Wed, 3 Jun 2020 14:49:28 +0000 (16:49 +0200)
Due to filesystem write caching the old configuration data could stay
out of flash for a long time during a first boot after the sysupgrade.
Power loss during this period could damage the overlay data and even
make device inaccessable via the network.

Fix this by syncing data to a flash as soon as the previous
configuration will be unpacked after the sysupgrade. Also sync the FS
state after the sysupgrade.tgz archive removing to prevent duplicative
extraction of a previous configuration.

Tested with AMD Geode based board.

Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
package/base-files/files/etc/init.d/done
package/base-files/files/lib/preinit/80_mount_root

index 374353a23c37145d7456875715c5b94b0b4a7cf8..32d6118df760aa0f6780051459b9db4197eee567 100755 (executable)
@@ -4,7 +4,7 @@
 START=95
 boot() {
        mount_root done
-       rm -f /sysupgrade.tgz
+       rm -f /sysupgrade.tgz && sync
 
        # process user commands
        [ -f /etc/rc.local ] && {
index f3fe788e198729613d97f0f6179b78663db333f3..265a3f18df49043824a6d70609e6c95dc017496a 100644 (file)
@@ -9,6 +9,8 @@ do_mount_root() {
                echo "- config restore -"
                cd /
                tar xzf /sysupgrade.tgz
+               # Prevent configuration corruption on a power loss
+               sync
        }
 }