Refactor union mounting into its own function.
[live-boot-grml.git] / scripts / live-helpers
index aacfe93..3ec1e7b 100644 (file)
@@ -608,3 +608,53 @@ link_files ()
                fi
        done
 }
+
+do_union () {
+       root_backing="${1}"
+       unionrw="${2}"
+       unionro="${3}"
+       unionmountpoint="${4}"
+
+       if [ "${UNIONTYPE}" = "aufs" ]
+       then
+               rw_opt="rw"
+               ro_opt="rr+wh"
+               noxino_opt="noxino,"
+       elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
+       then
+               rw_opt="RW"
+               ro_opt="RO"
+       else
+               rw_opt="rw"
+               ro_opt="ro"
+       fi
+
+       case "${UNIONTYPE}" in
+               unionfs-fuse)
+                       # FIXME: handle PERSISTENT_READONLY
+                       unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
+                       unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}:${unionro}=${ro_opt}"
+                       ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
+                       unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
+                       ( mkdir -p /run/sendsigs.omit.d
+                       pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
+                       ;;
+
+               overlayfs)
+                       # FIXME: is PERSISTENT_READONLY possible? (overlayfs only handles two dirs, but perhaps they can be chained?)
+                       unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}"
+                       mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
+                       ;;
+
+               *)
+                       if [ -n "${PERSISTENT_READONLY}" ]
+                       then
+                               mount -t tmpfs -o rw,noatime,mode=755 tmpfs "${unionrw}"
+                               unionmountopts="-o noatime,${noxino_opt}dirs=${unionrw}=${rw_opt}:${root_backing}=${ro_opt}:${unionro}=${ro_opt}"
+                       else
+                               unionmountopts="-o noatime,${noxino_opt}dirs=${unionrw}=${rw_opt}:${unionro}=${ro_opt}"
+                       fi
+                       mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
+                       ;;
+       esac
+}