emmc-image: misc fix for logs and cleanup
This fixes some logs in error conditions, also there is no need to stop
services if the merge did not happen.
Tested: Logs can be printed correctly and cleanup still works
Platforms-Affected: eMMC image platforms
Fusion-Link: fusion2 N/A only affects certain platforms
Google-Bug-Id: 439627429
Change-Id: I73d9eac206c33de64f55df9e231796aa69592a84
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
(cherry picked from commit 0a6945141cb148fafd3dc0e11253581d3358010a)
diff --git a/recipes-google/emmc-image/emmc-image-setup/emmc-image-setup.sh b/recipes-google/emmc-image/emmc-image-setup/emmc-image-setup.sh
index a97dc8f..904eed0 100644
--- a/recipes-google/emmc-image/emmc-image-setup/emmc-image-setup.sh
+++ b/recipes-google/emmc-image/emmc-image-setup/emmc-image-setup.sh
@@ -30,17 +30,17 @@
if [ $1 == "start" ]; then
if [[ -f "/run/emmc-image-runtime/VERSION" ]]; then
- echo "already have a running eMMC image, probably in netboot" &>2
+ echo "already have a running eMMC image, probably in netboot" >&2
exit 0
fi
if ! source "${hashfile}"; then
- echo "${emmcimg}: hash file not found" &>2
+ echo "${emmcimg}: hash file not found" >&2
exit 1
fi
if [[ ! -f "${emmcdir}/VERSION" ]]; then
- echo "${emmcimg}: VERSION file not found" &>2
+ echo "${emmcimg}: VERSION file not found" >&2
exit 1
fi
@@ -77,6 +77,8 @@
# skip process when reboot
systemctl is-active -q reboot.target && exit 0
+ # skip clean up if eMMC does not exist
+ [[ -f "${emmcdir}/VERSION" ]] || exit 0
echo "clearing emmc image configurations in best effort" >&2
echo "This should be an operation only during maintenance" >&2
rm -rf "${mountdir}/VERSION"
@@ -86,11 +88,12 @@
systemd-confext unmerge
systemd-sysext unmerge
systemctl daemon-reload
+ rm -rf ${mutableconfdir}
+ # services running after merge is possibly still using the mount.
+ # stop them here
+ clear_mount_ref
fi
- # services running after merge is possibly still using the mount.
- # stop them here
- clear_mount_ref
- rm -rf ${mutableconfdir} /run/extensions /run/confexts
+ rm -rf /run/extensions /run/confexts
umount -l /dev/mapper/${img}
rm -rf "${mountdir}/${img}"