Prepare-overlay service: check for mountpoint before removing workdir

The service was getting called twice, resulting in a removal of the
overlayfs workdir while the overlay was mounted. Solve this by checking
if the /etc overlay is mounted yet before removing the workdir. Need to
add mountpoint to busybox for this.

Resolves openbmc/openbmc#2429

Change-Id: I407a07dcc3f3856af12a7f3a52966fe7c3d756c3
Signed-off-by: Edward A. James <eajames@us.ibm.com>
diff --git a/meta-phosphor/common/recipes-core/busybox/busybox/mountpoint.cfg b/meta-phosphor/common/recipes-core/busybox/busybox/mountpoint.cfg
new file mode 100644
index 0000000..8b00951
--- /dev/null
+++ b/meta-phosphor/common/recipes-core/busybox/busybox/mountpoint.cfg
@@ -0,0 +1 @@
+CONFIG_MOUNTPOINT=y
diff --git a/meta-phosphor/common/recipes-core/busybox/busybox_%.bbappend b/meta-phosphor/common/recipes-core/busybox/busybox_%.bbappend
index 39a6033..e6678fc 100644
--- a/meta-phosphor/common/recipes-core/busybox/busybox_%.bbappend
+++ b/meta-phosphor/common/recipes-core/busybox/busybox_%.bbappend
@@ -1,4 +1,5 @@
 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
 SRC_URI += "file://busybox.cfg"
 SRC_URI += "file://flash.cfg"
+SRC_URI += "file://mountpoint.cfg"
 SRC_URI += "file://0001-Stop-watchdog-first-on-startup.patch"
diff --git a/meta-phosphor/common/recipes-phosphor/mount-overlay-help/mount-overlay-help/prepare-overlay.service b/meta-phosphor/common/recipes-phosphor/mount-overlay-help/mount-overlay-help/prepare-overlay.service
index ae5f461..66843b3 100644
--- a/meta-phosphor/common/recipes-phosphor/mount-overlay-help/mount-overlay-help/prepare-overlay.service
+++ b/meta-phosphor/common/recipes-phosphor/mount-overlay-help/mount-overlay-help/prepare-overlay.service
@@ -4,6 +4,6 @@
 DefaultDependencies=false
 
 [Service]
-ExecStart=/bin/sh -c "rm -rf /var/persist/etc-work && mkdir -p /var/persist/etc /var/persist/etc-work /var/persist/home/root"
+ExecStart=/bin/sh -c "if ! mountpoint /etc; then rm -rf /var/persist/etc-work && mkdir -p /var/persist/etc-work; fi; mkdir -p /var/persist/etc /var/persist/home/root"
 Type=oneshot
 RemainAfterExit=no