NEED_RESIZEFS=1
USERFS_ENCRYPTED=0
FS_RETRY_COUNT=10
+BOOT_MODE=
BLKID_LINES=()
fi
}
+#------------------------------------------------
+# restore_checkpoint
+#------------------------------------------------
+restore_checkpoint() {
+ # Any existing checkpoint means that the RW update was unexpectedly
+ # aborded, so we must roll back the changes and update again.
+ echo "Checkpoint restore"
+ PART="${1}"
+ FS_TYPE="$(blkid -o value -s TYPE "${PART}")"
+ if [ "$FS_TYPE" = "ext4" ]; then
+ bow-restore "${PART}"
+ elif [ "$FS_TYPE" = "f2fs" ]; then
+ # f2fs does not need a restore - if the data was not commited before
+ # the reboot, any changes were discarded
+ :
+ else
+ echo "Checkpoint restore error: unknown filesystem ${FS_TYPE} on ${PART}"
+ fi
+}
+
+#------------------------------------------------
+# restore_partitions
+#------------------------------------------------
+restore_partitions() {
+ echo "Restore partitions"
+
+ if [ ! "z${USERFS}" = "z" ]; then
+ restore_checkpoint "${USERFS}"
+ fi
+ if [ ! "z${DATAFS}" = "z" ]; then
+ restore_checkpoint "${DATAFS}"
+ fi
+}
function process_rootfs()
{
/sbin/resize2fs -f $DATAFS
fi
/sbin/fsck -y $DATAFS
- /bin/mount $DATAFS $DATAFS_MNT
+
+ # We don't mount $DATAFS here, platform mounts it,
+ # because if it's an upgrade, we may need to create a checkpoint
+ # /bin/mount $DATAFS $DATAFS_MNT
}
/sbin/fsck -y $USERFS
fi
- # We don't mount $USERFS here, platform mounts it.
+ # We don't mount $USERFS here, platform mounts it,
+ # because if it's an upgrade, we may need to create a checkpoint
}
function process_halfs()
if [ x"$DATAFS" = "x" ]; then return; fi
if [ "$NEED_RESIZEFS" = "0" ]; then return; fi
+ # We want to create a flag indicating that resize2fs has already been
+ # executed, but DATAFS partition will be mounted by systemd later. So we
+ # have to do this kind of ugly mouting and unmounting, to be able to create
+ # flag, and then for systemd to mount the partition in the normal way or
+ # via dm-bow (during an upgrade).
+ # Fortunately, it will only execute once, on the first boot after the
+ # images have been flashed.
+ /bin/mount "$DATAFS" "$DATAFS_MNT"
+
echo " " > ${DATAFS_MNT}/var/.resizefs_done
+
+ /bin/umount "$DATAFS_MNT"
}
function change_root()
{
+ ADDON=
+ INIT_BINARY=/sbin/init
+ if [ "$BOOT_MODE" == "fota" ]; then
+ ADDON="--unit=online-update.target"
+ INIT_BINARY=/usr/lib/systemd/systemd
+ fi
+
if [ $$ = 1 ]
then
if [ "$IN_INITRD" = "1" ]
then
- exec chroot . /sbin/init $@
+ exec chroot . "$INIT_BINARY" "$ADDON" $@
elif [ "$IN_INITRAMFS" = "1" ]
then
- exec switch_root $ROOTFS_MNT /sbin/init $@
+ exec switch_root $ROOTFS_MNT "$INIT_BINARY" "$ADDON" $@
else
- exec /usr/lib/systemd/systemd $@
+ exec /usr/lib/systemd/systemd "$ADDON" $@
fi
fi
}
mount -o nosuid,noexec,nodev -t proc proc /proc
}
+check_bootmode() {
+ read -r cmdline </proc/cmdline
+ echo "Kernel command line: $cmdline"
+ for element in $cmdline; do
+ key="${element%%=*}"
+ if [ "$key" = "bootmode" ]; then
+ BOOT_MODE="${element#*=}"
+ break;
+ fi
+ done
+}
+
if [ x$container = "x" ]; then
process_special_filesystem
else
check_network
setup_nbd
wait_find_partitions
+restore_partitions
check_flags
process_rootfs
load_kernel_modules
pivot_root
+check_bootmode
change_root $@
# WARNING! never rearch