Patch by Steven Shiau <steven@nchc.org.tw>. The only changes so far are:
[live-boot-grml.git] / components / 9990-misc-helpers.sh
index fcd2b07..315e3b1 100755 (executable)
@@ -1292,16 +1292,22 @@ do_union ()
                        rw_opt="rw"
                        ro_opt="rr+wh"
                        noxino_opt="noxino"
+
+                       unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
+                       if [ -n "${unionro}" ]
+                       then
+                               for rofs in ${unionro}
+                               do
+                                       unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
+                               done
+                       fi
+                       mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
                        ;;
 
-               *)
+               overlay)
                        rw_opt="rw"
                        ro_opt="ro"
-                       ;;
-       esac
 
-       case "${UNIONTYPE}" in
-               overlay)
                        # XXX: can multiple unionro be used? (overlay only handles two dirs, but perhaps they can be chained?)
                        # XXX: and can unionro be optional? i.e. can overlay skip lowerdir?
                        if echo ${unionro} | grep -q " "
@@ -1312,19 +1318,19 @@ do_union ()
                                panic "overlay needs at least one lower filesystem (read-only branch)."
                        fi
                        unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}"
-                       mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
-                       ;;
-
-               *)
-                       unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
-                       if [ -n "${unionro}" ]
+                       if ! mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}" 2>/dev/null
                        then
-                               for rofs in ${unionro}
-                               do
-                                       unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
-                               done
+                               # Ref: kiwi from OpenSuse kiwi-7.02.18-1.1
+                               # overlayfs in version >= v22 behaves differently
+                               # + renamed from overlayfs to overlay
+                               # + requires a workdir to become mounted
+                               # + requires workdir and upperdir to reside under the same mount
+                               # + requires workdir and upperdir to be in separate subdirs
+                               mkdir ${unionrw}/rw
+                               mkdir ${unionrw}/work
+                               unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}/rw,workdir=${unionrw}/work"
+                               mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
                        fi
-                       mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
                        ;;
        esac
 }