Remove sourcing /scripts/functions in components
[live-boot-grml.git] / components / 9990-overlay.sh
index d293ead..61b1f26 100755 (executable)
@@ -8,23 +8,14 @@ setup_unionfs ()
        rootmnt="${2}"
        addimage_directory="${3}"
 
-       case ${UNIONTYPE} in
-               aufs|overlay)
-                       if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
-                       then
-                               panic "${UNIONTYPE} not available."
-                       fi
+       modprobe -q -b ${UNIONTYPE}
 
-                       modprobe -q -b ${UNIONTYPE}
-                       ;;
-       esac
-
-       # run-init can't deal with images in a subdir, but we're going to
-       # move all of these away before it runs anyway.  No, we're not,
-       # put them in / since move-mounting them into / breaks mono and
-       # some other apps.
+       if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
+       then
+               panic "${UNIONTYPE} not available."
+       fi
 
-       croot="/"
+       croot="/run/live/rootfs"
 
        # Let's just mount the read-only file systems first
        rootfslist=""
@@ -114,22 +105,15 @@ setup_unionfs ()
                                                ;;
                                esac
 
-                               case "${UNIONTYPE}" in
-                                       unionmount)
-                                               mpoint="${rootmnt}"
-                                               rootfslist="${rootmnt} ${rootfslist}"
-                                               ;;
-
-                                       *)
-                                               mpoint="${croot}/${imagename}"
-                                               rootfslist="${mpoint} ${rootfslist}"
-                                               ;;
-                               esac
+                               mpoint=$(trim_path "${croot}/${imagename}")
+                               rootfslist="${mpoint} ${rootfslist}"
 
                                mkdir -p "${mpoint}"
                                log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
                                mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
                                log_end_msg
+                       else
+                               log_warning_msg "Could not find image '${image}'. Most likely it is listed in a .module file, perhaps by mistake."
                        fi
                done
        else
@@ -146,8 +130,7 @@ setup_unionfs ()
 
        # tmpfs file systems
        touch /etc/fstab
-       mkdir -p /live/overlay
-       mount -t tmpfs tmpfs /live/overlay
+       mkdir -p /run/live/overlay
 
        # Looking for persistence devices or files
        if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
@@ -251,30 +234,27 @@ setup_unionfs ()
        then
                cowdevice="tmpfs"
                cow_fstype="tmpfs"
-               cow_mountopt="rw,noatime,mode=755"
+               cow_mountopt="rw,noatime,mode=755,size=${OVERLAY_SIZE:-50%}"
        fi
 
-       if [ "${UNIONTYPE}" != "unionmount" ]
+       if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
        then
-               if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
-               then
-                       mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
-                       root_backing="/live/persistence/$(basename ${cowdevice})-root"
-                       mkdir -p ${root_backing}
-               else
-                       root_backing="/live/overlay"
-               fi
+               mount -t tmpfs -o rw,noatime,mode=755,size=${OVERLAY_SIZE:-50%} tmpfs "/run/live/overlay"
+               root_backing="/run/live/persistence/$(basename ${cowdevice})-root"
+               mkdir -p ${root_backing}
+       else
+               root_backing="/run/live/overlay"
+       fi
 
-               if [ "${cow_fstype}" = "nfs" ]
-               then
-                       log_begin_msg \
-                               "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
-                       nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
-                               panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
-               else
-                       mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
-                               panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
-               fi
+       if [ "${cow_fstype}" = "nfs" ]
+       then
+               log_begin_msg \
+                       "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
+               nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
+                       panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
+       else
+               mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
+                       panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
        fi
 
        rootfscount=$(echo ${rootfslist} |wc -w)
@@ -288,7 +268,7 @@ setup_unionfs ()
                        panic "only one RO file system supported with exposedroot: ${rootfslist}"
                fi
 
-               mount --bind ${rootfs} ${rootmnt} || \
+               mount -bind ${rootfs} ${rootmnt} || \
                        panic "bind mount of ${rootfs} failed"
 
                if [ -z "${SKIP_UNION_MOUNTS}" ]
@@ -301,34 +281,23 @@ setup_unionfs ()
                cow_dirs="/"
        fi
 
-       if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
-       then
-               true # FIXME: Maybe it does, I don't really know.
-               #panic "unionmount does not support subunions (${cow_dirs})."
-       fi
-
        for dir in ${cow_dirs}; do
-               unionmountpoint="${rootmnt}${dir}"
+               unionmountpoint=$(trim_path "${rootmnt}${dir}")
                mkdir -p ${unionmountpoint}
-               if [ "${UNIONTYPE}" = "unionmount" ]
+               cow_dir=$(trim_path "/run/live/overlay${dir}")
+               rootfs_dir="${rootfs}${dir}"
+               mkdir -p ${cow_dir}
+               if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
                then
-                       # FIXME: handle PERSISTENCE_READONLY
-                       unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
-                       # unionmount only works with util-linux mount
-                       mount.util-linux $unionmountopts "${unionmountpoint}"
+                       do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
                else
-                       cow_dir="/live/overlay${dir}"
-                       rootfs_dir="${rootfs}${dir}"
-                       mkdir -p ${cow_dir}
-                       if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
-                       then
-                               do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
-                       else
-                               do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
-                       fi
+                       do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
                fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
        done
 
+       # Remove persistence depending on boot parameter
+       Remove_persistence
+
        # Correct the permissions of /:
        chmod 0755 "${rootmnt}"
 
@@ -338,22 +307,6 @@ setup_unionfs ()
                chmod 1777 "${rootmnt}"/tmp
        fi
 
-       live_rootfs_list=""
-       for d in ${rootfslist}
-       do
-               live_rootfs="/live/rootfs/${d##*/}"
-               live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
-               mkdir -p "${live_rootfs}"
-               case "${d}" in
-                       *.dir)
-                               # do nothing # mount -o bind "${d}" "${live_rootfs}"
-                               ;;
-                       *)
-                               mount -o move "${d}" "${live_rootfs}"
-                               ;;
-               esac
-       done
-
        # Adding custom persistence
        if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
        then
@@ -364,7 +317,7 @@ setup_unionfs ()
                # Gather information about custom mounts from devies detected as overlays
                get_custom_mounts ${custom_mounts} ${overlay_devices}
 
-               [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
+               [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/run/live/persistence"
 
                # Now we do the actual mounting (and symlinking)
                local used_overlays
@@ -381,9 +334,4 @@ setup_unionfs ()
                        fi
                done
        fi
-
-        # ensure that a potentially stray tmpfs gets removed
-        # otherways, initramfs-tools is unable to remove /live
-        # and fails to boot
-        umount /live/overlay > /dev/null 2>&1 || true
 }