+ else
+ 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
+
+ unionmountopts=""
+ unionmountpoint=""
+
+ for dir in ${cow_dirs}; do
+ mkdir -p /cow${dir}
+
+ unionmountpoint="${rootmnt}${dir}"
+ unionrw="/cow${dir}"
+ unionro="${rofs}${dir}"
+ # We don't handle spaces and other junk gracefully here, hopefully not needed.
+ case "${UNIONTYPE}" in
+ unionfs-fuse)
+ unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
+ unionmountopts="${unionmountopts} ${unionrw}=RW:${unionro}=RO"
+ ( 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 )
+ ;;
+
+ unionmount)
+ unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
+ mount_full $unionmountopts "${unionmountpoint}"
+ ;;
+
+ overlayfs)
+ unionmountopts="-o noatime,${noxino_opt},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:${persistent_root}=${roopt}:${unionro}=${roopt}"
+ else
+ unionmountopts="-o noatime,${noxino_opt}dirs=${unionrw}=rw:${unionro}=${roopt}"
+ fi
+ mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
+ ;;
+ esac || \
+ panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
+ done
+
+ # Correct the permissions of /:
+ chmod 0755 "${rootmnt}"
+
+ # tmpfs file systems
+ touch /etc/fstab
+ mkdir -p "${rootmnt}/live"
+ mount -t tmpfs tmpfs ${rootmnt}/live
+
+ # Adding other custom mounts
+ if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
+ then
+ bindings="/${persistence_list}"
+ touch ${bindings}
+ for device in ${overlay_devices}
+ do
+ if [ ! -b "${device}" ]
+ then
+ continue
+ fi
+ backing="/$(basename ${device})-backing"
+ mkdir -p "${backing}"
+ device_fstype="$(get_fstype ${device})"
+ if [ -z "${PERSISTENT_READONLY}" ]
+ then
+ device_mount_opts="rw,noatime"
+ else
+ device_mount_opts="ro,noatime"
+ fi
+ device_used=""
+ mount -t "${device_fstype}" -o "${device_mount_opts}" "${device}" "${backing}"
+ include_list="${backing}/${persistence_list}"
+ if [ ! -r "${include_list}" ]
+ then
+ umount "${backing}"
+ rmdir "${backing}"
+ continue
+ fi
+
+ # FIXME: debug stuff, remove me?
+ [ "${DEBUG}" == "Yes" ] && cat ${include_list} >> ${rootmnt}/${bindings}-origs
+ while read source dest
+ do
+ if echo ${source} | grep -qe "^[[:space:]]*#"
+ then
+ # skipping commented line
+ continue
+ fi
+ if [ -z "${dest}" ]
+ then
+ dest="${source}"
+ fi
+ if echo ${dest} | grep -qe "^/\+$"
+ then
+ log_warning_msg "Skipping custom mount on /"
+ continue
+ fi
+
+ # FIXME: handle case: we already have /a/b in $bindings, but now we find /a -- /a should replace /a/b in $bindings.
+ # FIXME: handle case: we have /a in $bindings, now we find /a/b, so we skip /a/b
+
+ # ensure that no multiple-/ occur in paths
+ full_source="$(echo ${backing}/${source}/ | sed -e 's|/\+|/|g')"
+ full_dest="$(echo ${rootmnt}/${dest}/ | sed -e 's|/\+|/|g')"
+ device_used="yes"
+ echo "${full_source} ${full_dest}" >> ${bindings}
+ done < ${include_list}
+
+ if [ -z "${device_used}" ]
+ then
+ # this device was not used for / earlier, or custom mount point now, so it's useless
+ umount "${backing}"
+ rmdir "${backing}"
+ fi
+ done
+
+ # we sort the list according to destination so we're sure that we won't hide a previous mount. we also ignore duplicate destinations in a more or less arbitrary way
+ sort -k2 -sbu ${bindings} -o ${bindings}
+
+ # FIXME: debug stuff, remove me?
+ [ "${DEBUG}" == "Yes" ] && cp ${bindings} ${rootmnt}/${bindings}-results
+
+ while read source dest
+ do
+ if mountpoint -q "${dest}";
+ then
+ log_warning_msg "Skipping custom mount ${source} on ${dest}: destination is already a mount point"
+ continue
+ fi
+
+ # FIXME: we don't handle already existing non-directory files in the paths of both $source and $dest.
+
+ if [ ! -d "${dest}" ]
+ then
+ # if ${dest} is in /home/$user, try fixing proper ownership
+ # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
+ if echo ${dest} | grep -qe "^${rootmnt}/*home/\+[^/]\+"
+ then
+ path="/"
+ for dir in $(echo ${dest} | sed -e 's|/\+| |g')
+ do
+ path=${path}/${dir}
+ if [ ! -e ${path} ]
+ then
+ mkdir -p ${path}
+ # assume that the intended user is the first, which is usually the case
+ chown 1000:1000 ${path}
+ fi
+ done
+ else
+ mkdir -p ${dest}
+ fi
+ fi
+
+ # FIXME: could we instead only save the aufs-diff in the persistent media? implications? What about when there's changes in the live image?
+
+ # if ${source} doesn't exist on our persistent media we
+ # bootstrap it with $dest from the live filesystem.
+ # this both makes sense and is critical if we're
+ # dealing with /etc or other system dir.
+ if [ ! -d "${source}" ]
+ then
+ if [ -n "${PERSISTENT_READONLY}" ]
+ then
+ continue
+ fi
+ # ensure that $dest is not copied *into* $source
+ mkdir -p "$(dirname ${source})"
+ cp -a "${dest}" "${source}"
+ fi
+
+ if [ -z "${PERSISTENT_READONLY}" ]
+ then
+ mount --bind "${source}" "${dest}"
+ else
+ unionrw="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
+ mkdir -p ${unionrw}
+ unionmountopts="noatime,${noxino_opt}dirs=${unionrw}=rw:${source}=${roopt}"
+ mount -t "${UNIONTYPE}" -o "${unionmountopts}" "${UNIONTYPE}" "${dest}"
+ fi
+ done < ${bindings}
+ rm ${bindings}