+ [ -d "$UPPER" ] || die "UPPER=$UPPER is not a directory"
+ [ -d "$LOWER" ] || die "LOWER=LOWPER is not a directory"
+ [ -d "$LIVE" ] || die "LOWER=LOWPER is not a directory"
+ [ -x "${PREMOUNT%% *}" ] || die "PREMOUNT=${PREMOUNT%% *} not executable"
+ [ -f "${PREMOUNT%% *}" ] || die "PREMOUNT='$PREMOUNT' is not a command"
+ [ -x "${POSTMOUNT%% *}" ] || \
+ die "POSTMOUNT=${POSTMOUNT%% *} not executable"
+ [ -f "${POSTMOUNT%% *}" ] || \
+ die "POSTMOUNT='$POSTMOUNT' is not a command"
+
+ # UPPER is the same as LOWER then skip the overlay mount
+ if [ "$UPPER" != "$LOWER" ] ; then
+ # sanity check
+ [ -d "$WORK" ] || die "WORK=$WORK is not a directory"
+
+ env CONFIG="$CONFIG" $PREMOUNT "$UPPER"
+
+ OLY="-olowerdir=$3,upperdir=$UPPER,workdir=$5"
+ if ! mount -t overlay "$OLY" $1 $2 ; then
+ umount -R "$UPPER/dev"
+ umount "$UPPER/run"
+ die "Cannot set up the overlay mount $2"
+ fi
+ elif [ "$LIVE" != "$UPPER" ] ; then
+ # With UPPER = LOWER we rather make a bind mount to LIVE
+ env CONFIG="$CONFIG" $PREMOUNT "$UPPER"
+ mount --bind $UPPER $LOWER
+ fi
+
+ env CONFIG="$CONFIG" $POSTMOUNT "LIVE" "$UPPER"
+}
+
+# Find the "unshare" process for $1 and echo the its pid and the pids
+# of its child processes.