5 is_in_list_separator_helper () {
11 echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
14 is_in_space_sep_list () {
17 is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
20 is_in_comma_sep_list () {
23 is_in_list_separator_helper "," "${element}" "${*}"
29 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
37 for dev in "${sysblock}"/* "${sysblock}"
39 if [ -e "${dev}/dev" ]
50 black_listed_devices="${1}"
51 white_listed_devices="${2}"
53 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
55 fulldevname=$(sys2dev "${sysblock}")
57 if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
58 [ -n "${white_listed_devices}" ] && \
59 ! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
61 # skip this device entirely
65 for dev in $(subdevices "${sysblock}")
67 devname=$(sys2dev "${dev}")
69 if is_in_space_sep_list ${devname} ${black_listed_devices}
84 # Validate input first
90 # Try to look if it is already supported by the kernel
91 if grep -q ${fstype} /proc/filesystems
95 # Then try to add support for it the gentle way using the initramfs capabilities
97 if grep -q ${fstype} /proc/filesystems
100 # Then try the hard way if /root is already reachable
102 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
103 if [ -e "${kmodule}" ]
106 if grep -q ${fstype} /proc/filesystems
119 /sbin/blkid -s TYPE -o value $1 2>/dev/null
126 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
130 # remove all unnecessary /:s in the path, including last one (except
131 # if path is just "/")
132 echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|'
135 what_is_mounted_on ()
137 local dir="$(trim_path ${1})"
138 grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
143 local reference="${1}"
146 local owner=$(stat -c %u:%g "${reference}")
147 chown -h ${owner} ${targets}
152 local reference="${1}"
155 local rights=$(stat -c %a "${reference}")
156 chmod ${rights} ${targets}
172 mounts="$(awk '{print $2}' /proc/mounts)"
173 testpath="$(busybox realpath ${testpath})"
177 if echo "${mounts}" | grep -qs "^${testpath}"
179 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
183 testpath=$(dirname $testpath)
190 # Returns used/free fs kbytes + 5% more
191 # You could pass a block device as ${1} or the mount point as ${2}
197 if [ -z "${mountp}" ]
199 mountp="$(where_is_mounted ${dev})"
201 if [ -z "${mountp}" ]
203 mountp="/mnt/tmp_fs_size"
206 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
212 if [ "${used}" = "used" ]
214 size=$(du -ks ${mountp} | cut -f1)
215 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
218 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
221 if [ -n "${doumount}" ]
223 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
233 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
235 loadkeys /etc/boottime.kmap.gz
245 local encryption=${5}
248 # the output of setup_loop is evaluated in other functions,
249 # modprobe leaks kernel options like "libata.dma=0"
250 # as "options libata dma=0" on stdout, causing serious
251 # problems therefor, so instead always avoid output to stdout
252 modprobe -q -b "${module}" 1>/dev/null
256 for loopdev in ${pattern}
258 if [ "$(cat ${loopdev}/size)" -eq 0 ]
260 dev=$(sys2dev "${loopdev}")
263 if [ -n "${readonly}" ]
265 if losetup --help 2>&1 | grep -q -- "-r\b"
267 options="${options} -r"
271 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
273 options="${options} -o ${offset}"
276 if [ -z "${encryption}" ]
278 losetup ${options} "${dev}" "${fspath}"
280 # Loop AES encryption
285 echo -n "Enter passphrase for root filesystem: " >&6
287 echo "${passphrase}" > /tmp/passphrase
289 exec 9</tmp/passphrase
290 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
293 rm -f /tmp/passphrase
295 if [ 0 -eq ${error} ]
302 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
305 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
318 panic "No loop devices available"
328 old_mountp="$(where_is_mounted ${dev})"
330 if [ -n "${old_mountp}" ]
332 if [ "${opts}" != "ro" ]
334 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
337 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
339 if [ -z "${fstype}" ]
341 fstype=$(get_fstype "${dev}")
343 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
344 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > boot.log && return 0 )
348 mount_persistence_media ()
353 local backing="/live/persistence/$(basename ${device})"
355 mkdir -p "${backing}"
356 local old_backing="$(where_is_mounted ${device})"
357 if [ -z "${old_backing}" ]
359 local fstype="$(get_fstype ${device})"
360 local mount_opts="rw,noatime"
361 if [ -n "${PERSISTENCE_READONLY}" ]
363 mount_opts="ro,noatime"
365 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
370 [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}"
374 elif [ "${backing}" != "${old_backing}" ]
376 if mount --move ${old_backing} ${backing} >/dev/null
381 [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
389 close_persistence_media () {
391 local backing="$(where_is_mounted ${device})"
393 if [ -d "${backing}" ]
395 umount "${backing}" >/dev/null 2>&1
396 rmdir "${backing}" >/dev/null 2>&1
399 if is_active_luks_mapping ${device}
401 /sbin/cryptsetup luksClose ${device}
408 name="$(basename ${dev})"
410 if [ -n "${PERSISTENCE_READONLY}" ]
412 opts="${opts} --readonly"
415 if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
417 re="^[[:space:]]*device:[[:space:]]*\([^[:space:]]*\)$"
418 opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
419 if [ "${opened_dev}" = "${dev}" ]
421 luks_device="/dev/mapper/${name}"
425 log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name"
434 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
435 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
439 luks_device="/dev/mapper/${name}"
445 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
448 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
458 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
464 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
467 probe_for_gpt_name ()
469 local overlays="${1}"
470 local snapshots="${2}"
473 local gpt_dev="${dev}"
474 if is_active_luks_mapping ${dev}
476 # if $dev is an opened luks device, we need to check
477 # GPT stuff on the backing device
478 gpt_dev=$(get_luks_backing_device "${dev}")
481 if ! is_gpt_device ${gpt_dev}
486 local gpt_name=$(get_gpt_name ${gpt_dev})
487 for label in ${overlays} ${snapshots}
489 if [ "${gpt_name}" = "${label}" ]
491 echo "${label}=${dev}"
496 probe_for_fs_label ()
498 local overlays="${1}"
499 local snapshots="${2}"
502 for label in ${overlays} ${snapshots}
504 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
506 echo "${label}=${dev}"
511 probe_for_file_name ()
513 local overlays="${1}"
514 local snapshots="${2}"
518 local backing="$(mount_persistence_media ${dev} probe)"
519 if [ -z "${backing}" ]
524 for label in ${overlays}
526 path=${backing}/${PERSISTENCE_PATH}${label}
529 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
530 ret="${ret} ${label}=${loopdev}"
533 for label in ${snapshots}
535 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
537 path="${PERSISTENCE_PATH}${label}.${ext}"
538 if [ -f "${backing}/${path}" ]
540 ret="${ret} ${label}=${dev}:${backing}:${path}"
549 umount ${backing} > /dev/null 2>&1 || true
553 find_persistence_media ()
555 # Scans devices for overlays and snapshots, and returns a whitespace
556 # separated list of how to use them. Only overlays with a partition
557 # label or file name in ${overlays} are returned, and ditto for
558 # snapshots with labels in ${snapshots}.
560 # When scanning a LUKS device, the user will be asked to enter the
561 # passphrase; on failure to enter it, or if no persistence partitions
562 # or files were found, the LUKS device is closed.
564 # For a snapshot file the return value is ${label}=${snapdata}", where
565 # ${snapdata} is the parameter used for try_snap().
567 # For all other cases (overlay/snapshot partition and overlay file) the
568 # return value is "${label}=${device}", where ${device} a device that
569 # can mount the content. In the case of an overlay file, the device
570 # containing the file will remain mounted as a side-effect.
572 # No devices in ${black_listed_devices} will be scanned, and if
573 # ${white_list_devices} is non-empty, only devices in it will be
576 local overlays="${1}"
577 local snapshots="${2}"
578 local white_listed_devices="${3}"
581 local black_listed_devices="$(what_is_mounted_on /live/image)"
583 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
588 # Check if it's a luks device; we'll have to open the device
589 # in order to probe any filesystem it contains, like we do
590 # below. activate_custom_mounts() also depends on that any luks
591 # device already has been opened.
592 if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && \
593 is_luks_partition ${dev}
595 if luks_device=$(open_luks_device "${dev}")
599 # skip $dev since we failed/chose not to open it
602 elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION}
604 # skip $dev since we don't allow unencrypted storage
608 # Probe for matching GPT partition names or filesystem labels
609 if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE}
611 result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${dev})
612 if [ -n "${result}" ]
614 ret="${ret} ${result}"
618 result=$(probe_for_fs_label "${overlays}" "${snapshots}" ${dev})
619 if [ -n "${result}" ]
621 ret="${ret} ${result}"
626 # Probe for files with matching name on mounted partition
627 if is_in_comma_sep_list file ${PERSISTENCE_STORAGE}
629 result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
630 if [ -n "${result}" ]
632 ret="${ret} ${result}"
637 # Close luks device if it isn't used
638 if [ -z "${result}" ] && [ -n "${luks_device}" ] && \
639 is_active_luks_mapping "${luks_device}"
641 /sbin/cryptsetup luksClose "${luks_device}"
655 for adaptor in /sys/class/net/*
657 status="$(cat ${adaptor}/iflink)"
659 if [ "${status}" -eq 2 ]
661 mac="$(cat ${adaptor}/address)"
662 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
672 /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1
675 is_active_luks_mapping ()
678 /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1
681 get_luks_backing_device () {
683 cryptsetup status ${device} 2> /dev/null | \
684 awk '{if ($1 == "device:") print $2}'
693 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
696 if [ "$(cat ${sysblock}/removable)" = "1" ]
698 if [ -z "${want_usb}" ]
702 if readlink ${sysblock} | grep -q usb
709 if [ "${dev_ok}" = "yes" ]
711 case "${output_format}" in
713 ret="${ret} ${sysblock}"
716 devname=$(sys2dev "${sysblock}")
717 ret="${ret} ${devname}"
730 removable_dev "${output_format}" "want_usb"
738 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
740 if [ "$(cat ${sysblock}/removable)" = "0" ]
742 case "${output_format}" in
744 ret="${ret} ${sysblock}"
747 devname=$(sys2dev "${sysblock}")
748 ret="${ret} ${devname}"
759 # create source's directory structure in dest, and recursively
760 # create symlinks in dest to to all files in source. if mask
761 # is non-empty, remove mask from all source paths when
762 # creating links (will be necessary if we change root, which
763 # live-boot normally does (into $rootmnt)).
765 # remove multiple /:s and ensure ending on /
766 local src_dir="$(trim_path ${1})/"
767 local dest_dir="$(trim_path ${2})/"
768 local src_mask="${3}"
770 # This check can only trigger on the inital, non-recursive call since
771 # we create the destination before recursive calls
772 if [ ! -d "${dest_dir}" ]
774 log_warning_msg "Must link_files into a directory"
778 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read src; do
779 local dest="${dest_dir}$(basename "${src}")"
782 if [ -z "$(ls -A "${src}")" ]
786 if [ ! -d "${dest}" ]
789 chown_ref "${src}" "${dest}"
790 chmod_ref "${src}" "${dest}"
792 link_files "${src}" "${dest}" "${src_mask}"
794 local final_src=${src}
795 if [ -n "${src_mask}" ]
797 final_src="$(echo ${final_src} | sed "s|^${src_mask}||")"
799 rm -rf "${dest}" 2> /dev/null
800 ln -s "${final_src}" "${dest}"
801 chown_ref "${src}" "${dest}"
808 local unionmountpoint="${1}" # directory where the union is mounted
809 local unionrw="${2}" # branch where the union changes are stored
810 local unionro1="${3}" # first underlying read-only branch (optional)
811 local unionro2="${4}" # second underlying read-only branch (optional)
813 if [ "${UNIONTYPE}" = "aufs" ]
818 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
827 case "${UNIONTYPE}" in
829 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
830 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
831 if [ -n "${unionro1}" ]
833 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
835 if [ -n "${unionro2}" ]
837 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
839 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
840 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
841 ( mkdir -p /run/sendsigs.omit.d
842 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
846 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
847 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
848 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
849 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
853 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
854 if [ -n "${unionro1}" ]
856 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
858 if [ -n "${unionro2}" ]
860 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
862 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
869 # Side-effect: leaves $devices with live-persistence.conf mounted in /live/persistence
870 # Side-effect: prints info to file $custom_mounts
872 local custom_mounts=${1}
876 local bindings="/tmp/bindings.list"
877 local links="/tmp/links.list"
878 rm -rf ${bindings} ${links} 2> /dev/null
880 for device in ${devices}
882 if [ ! -b "${device}" ]
887 local device_name="$(basename ${device})"
888 local backing=$(mount_persistence_media ${device})
889 if [ -z "${backing}" ]
894 local include_list="${backing}/${persistence_list}"
895 if [ ! -r "${include_list}" ]
900 if [ -n "${DEBUG}" ] && [ -e "${include_list}" ]
902 cp ${include_list} /live/persistence/${persistence_list}.${device_name}
905 while read dir options # < ${include_list}
907 if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$"
909 # skipping empty or commented lines
913 if trim_path ${dir} | grep -q -e "^[^/]" -e "^/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
915 log_warning_msg "Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/live\" or any sub-directory therein."
921 for opt in $(echo ${options} | tr ',' ' ');
925 opt_source=${opt#source=}
933 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
939 local source="${dir}"
940 if [ -n "${opt_source}" ]
942 if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${source}" != "." ]
944 log_warning_msg "Skipping unsafe custom mount with option source=${opt_source}: must be either \".\" (the media root) or a relative path w.r.t. the media root that contains neither comas, nor the special \".\" and \"..\" path components"
947 source="${opt_source}"
951 local full_source="$(trim_path ${backing}/${source})"
952 local full_dest="$(trim_path ${rootmnt}/${dir})"
953 if [ -n "${opt_link}" ]
955 echo "${device} ${full_source} ${full_dest} ${options}" >> ${links}
957 echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings}
959 done < ${include_list}
962 # We sort the list according to destination so we're sure that
963 # we won't hide a previous mount. We also ignore duplicate
964 # destinations in a more or less arbitrary way.
965 [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
967 # After all mounts are considered we add symlinks so they
968 # won't be hidden by some mount.
969 [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
971 # We need to make sure that no two custom mounts have the same sources
972 # or are nested; if that is the case, too much weird stuff can happen.
973 local prev_source="impossible source" # first iteration must not match
975 # This sort will ensure that a source /a comes right before a source
976 # /a/b so we only need to look at the previous source
977 sort -k2 -b ${custom_mounts} |
978 while read device source dest options
980 if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
982 panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
984 prev_source=${source}
989 activate_custom_mounts ()
991 local custom_mounts="${1}" # the ouput from get_custom_mounts()
992 local used_devices=""
994 while read device source dest options # < ${custom_mounts}
999 for opt in $(echo ${options} | tr ',' ' ');
1004 unset opt_link opt_union
1008 unset opt_bind opt_union
1012 unset opt_bind opt_link
1017 if [ -n "$(what_is_mounted_on "${dest}")" ]
1019 if [ "${dest}" = "${rootmnt}" ]
1023 log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1028 if [ ! -d "${dest}" ]
1030 # create the destination and delete existing files in
1031 # its path that are in the way
1033 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1035 path=$(trim_path ${path}/${dir})
1043 if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+"
1045 # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case
1046 # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
1047 chown 1000:1000 ${path}
1053 # if ${source} doesn't exist on our persistence media
1054 # we bootstrap it with $dest from the live filesystem.
1055 # this both makes sense and is critical if we're
1056 # dealing with /etc or other system dir.
1057 if [ ! -d "${source}" ]
1059 if [ -n "${PERSISTENCE_READONLY}" ]
1062 elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ]
1064 # unions and don't need to be bootstrapped
1065 # link dirs can't be bootstrapped in a sensible way
1066 mkdir -p "${source}"
1067 chown_ref "${dest}" "${source}"
1068 chmod_ref "${dest}" "${source}"
1069 elif [ -n "${opt_bind}" ]
1071 # ensure that $dest is not copied *into* $source
1072 mkdir -p "$(dirname ${source})"
1073 cp -a "${dest}" "${source}"
1077 # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can
1078 # ignore the loop below and set rofs_dest_backing=$dest
1079 local rofs_dest_backing=""
1080 if [ -n "${opt_link}"]
1082 for d in /live/rofs/*
1084 if [ -n "${rootmnt}" ]
1086 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1088 rofs_dest_backing="${d}/${dest}"
1090 if [ -d "${rofs_dest_backing}" ]
1094 rofs_dest_backing=""
1099 if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1101 link_files ${source} ${dest} ${rootmnt}
1102 elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1104 mkdir -p /live/persistence
1105 local links_source=$(mktemp -d /live/persistence/links-source-XXXXXX)
1106 chown_ref ${source} ${links_source}
1107 chmod_ref ${source} ${links_source}
1108 # We put the cow dir in the below strange place to
1109 # make it absolutely certain that the link source
1110 # has its own directory and isn't nested with some
1111 # other custom mount (if so that mount's files would
1112 # be linked, causing breakage.
1113 local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})"
1115 chown_ref "${source}" "${cow_dir}"
1116 chmod_ref "${source}" "${cow_dir}"
1117 do_union ${links_source} ${cow_dir} ${source} ${rofs_dest_backing}
1118 link_files ${links_source} ${dest} ${rootmnt}
1119 elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1121 do_union ${dest} ${source} ${rofs_dest_backing}
1122 elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1124 mount --bind "${source}" "${dest}"
1125 elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1127 # bind-mount and union mount are handled the same
1128 # in read-only mode, but note that rofs_dest_backing
1129 # is non-empty (and necessary) only for unions
1130 if [ -n "${rootmnt}" ]
1132 local cow_dir="$(echo ${dest} | sed -e "s|^${rootmnt}|/live/overlay/|")"
1134 # This is happens if persistence is activated
1136 local cow_dir="/live/overlay/${dest}"
1138 if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
1140 # If an earlier custom mount has files here
1141 # it will "block" the current mount's files
1142 # which is undesirable
1146 chown_ref "${source}" "${cow_dir}"
1147 chmod_ref "${source}" "${cow_dir}"
1148 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1151 PERSISTENCE_IS_ON="1"
1152 export PERSISTENCE_IS_ON
1154 if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1156 used_devices="${used_devices} ${device}"
1158 done < ${custom_mounts}
1160 echo ${used_devices}
1163 fix_backwards_compatibility ()
1169 if [ -n "${PERSISTENCE_READONLY}" ]
1174 local backing="$(mount_persistence_media ${device})"
1175 if [ -z "${backing}" ]
1180 local include_list="${backing}/${persistence_list}"
1181 if [ ! -r "${include_list}" ]
1183 echo "# persistence backwards compatibility:
1184 ${dir} ${opt},source=." > "${include_list}"
1192 [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ]