3 is_in_list_separator_helper () {
9 echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
12 is_in_space_sep_list () {
15 is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
18 is_in_comma_sep_list () {
21 is_in_list_separator_helper "," "${element}" "${*}"
27 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
35 for dev in "${sysblock}"/* "${sysblock}"
37 if [ -e "${dev}/dev" ]
48 black_listed_devices="${1}"
49 white_listed_devices="${2}"
51 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
53 fulldevname=$(sys2dev "${sysblock}")
55 if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
56 [ -n "${white_listed_devices}" ] && \
57 ! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
59 # skip this device entirely
63 for dev in $(subdevices "${sysblock}")
65 devname=$(sys2dev "${dev}")
67 if is_in_space_sep_list ${devname} ${black_listed_devices}
82 # Validate input first
88 # Try to look if it is already supported by the kernel
89 if grep -q ${fstype} /proc/filesystems
93 # Then try to add support for it the gentle way using the initramfs capabilities
95 if grep -q ${fstype} /proc/filesystems
98 # Then try the hard way if /root is already reachable
100 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
101 if [ -e "${kmodule}" ]
104 if grep -q ${fstype} /proc/filesystems
117 /sbin/blkid -s TYPE -o value $1 2>/dev/null
124 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
128 # remove all unnecessary /:s in the path, including last one (except
129 # if path is just "/")
130 echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|'
133 what_is_mounted_on ()
135 local dir="$(trim_path ${1})"
136 grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
141 local reference="${1}"
144 local owner=$(stat -c %u:%g "${reference}")
145 chown -h ${owner} ${targets}
150 local reference="${1}"
153 local rights=$(stat -c %a "${reference}")
154 chmod ${rights} ${targets}
170 mounts="$(awk '{print $2}' /proc/mounts)"
171 testpath="$(busybox realpath ${testpath})"
175 if echo "${mounts}" | grep -qs "^${testpath}"
177 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
181 testpath=$(dirname $testpath)
188 # Returns used/free fs kbytes + 5% more
189 # You could pass a block device as ${1} or the mount point as ${2}
195 if [ -z "${mountp}" ]
197 mountp="$(where_is_mounted ${dev})"
199 if [ -z "${mountp}" ]
201 mountp="/mnt/tmp_fs_size"
204 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
210 if [ "${used}" = "used" ]
212 size=$(du -ks ${mountp} | cut -f1)
213 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
216 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
219 if [ -n "${doumount}" ]
221 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
231 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
233 loadkeys /etc/boottime.kmap.gz
243 local encryption=${5}
246 # the output of setup_loop is evaluated in other functions,
247 # modprobe leaks kernel options like "libata.dma=0"
248 # as "options libata dma=0" on stdout, causing serious
249 # problems therefor, so instead always avoid output to stdout
250 modprobe -q -b "${module}" 1>/dev/null
254 for loopdev in ${pattern}
256 if [ "$(cat ${loopdev}/size)" -eq 0 ]
258 dev=$(sys2dev "${loopdev}")
261 if [ -n "${readonly}" ]
263 if losetup --help 2>&1 | grep -q -- "-r\b"
265 options="${options} -r"
269 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
271 options="${options} -o ${offset}"
274 if [ -z "${encryption}" ]
276 losetup ${options} "${dev}" "${fspath}"
278 # Loop AES encryption
283 echo -n "Enter passphrase for root filesystem: " >&6
285 echo "${passphrase}" > /tmp/passphrase
287 exec 9</tmp/passphrase
288 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
291 rm -f /tmp/passphrase
293 if [ 0 -eq ${error} ]
300 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
303 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
316 panic "No loop devices available"
326 old_mountp="$(where_is_mounted ${dev})"
328 if [ -n "${old_mountp}" ]
330 if [ "${opts}" != "ro" ]
332 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
335 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
337 if [ -z "${fstype}" ]
339 fstype=$(get_fstype "${dev}")
341 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
342 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > boot.log && return 0 )
346 mount_persistence_media ()
351 local backing="/live/persistence/$(basename ${device})"
353 mkdir -p "${backing}"
354 local old_backing="$(where_is_mounted ${device})"
355 if [ -z "${old_backing}" ]
357 local fstype="$(get_fstype ${device})"
358 local mount_opts="rw,noatime"
359 if [ -n "${PERSISTENCE_READONLY}" ]
361 mount_opts="ro,noatime"
363 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
368 [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}"
372 elif [ "${backing}" != "${old_backing}" ]
374 if mount --move ${old_backing} ${backing} >/dev/null
379 [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
387 close_persistence_media () {
389 local backing="$(where_is_mounted ${device})"
391 if [ -d "${backing}" ]
393 umount "${backing}" >/dev/null 2>&1
394 rmdir "${backing}" >/dev/null 2>&1
397 if is_active_luks_mapping ${device}
399 /sbin/cryptsetup luksClose ${device}
406 name="$(basename ${dev})"
408 if [ -n "${PERSISTENCE_READONLY}" ]
410 opts="${opts} --readonly"
413 if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
415 re="^[[:space:]]*device:[[:space:]]*\([^[:space:]]*\)$"
416 opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
417 if [ "${opened_dev}" = "${dev}" ]
419 luks_device="/dev/mapper/${name}"
423 log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name"
432 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
433 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
437 luks_device="/dev/mapper/${name}"
443 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
446 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
456 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
462 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
465 probe_for_gpt_name ()
467 local overlays="${1}"
468 local snapshots="${2}"
471 local gpt_dev="${dev}"
472 if is_active_luks_mapping ${dev}
474 # if $dev is an opened luks device, we need to check
475 # GPT stuff on the backing device
476 gpt_dev=$(get_luks_backing_device "${dev}")
479 if ! is_gpt_device ${gpt_dev}
484 local gpt_name=$(get_gpt_name ${gpt_dev})
485 for label in ${overlays} ${snapshots}
487 if [ "${gpt_name}" = "${label}" ]
489 echo "${label}=${dev}"
494 probe_for_fs_label ()
496 local overlays="${1}"
497 local snapshots="${2}"
500 for label in ${overlays} ${snapshots}
502 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
504 echo "${label}=${dev}"
509 probe_for_file_name ()
511 local overlays="${1}"
512 local snapshots="${2}"
516 local backing="$(mount_persistence_media ${dev} probe)"
517 if [ -z "${backing}" ]
522 for label in ${overlays}
524 path=${backing}/${PERSISTENCE_PATH}${label}
527 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
528 ret="${ret} ${label}=${loopdev}"
531 for label in ${snapshots}
533 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
535 path="${PERSISTENCE_PATH}${label}.${ext}"
536 if [ -f "${backing}/${path}" ]
538 ret="${ret} ${label}=${dev}:${backing}:${path}"
547 umount ${backing} > /dev/null 2>&1 || true
551 find_persistence_media ()
553 # Scans devices for overlays and snapshots, and returns a whitespace
554 # separated list of how to use them. Only overlays with a partition
555 # label or file name in ${overlays} are returned, and ditto for
556 # snapshots with labels in ${snapshots}.
558 # When scanning a LUKS device, the user will be asked to enter the
559 # passphrase; on failure to enter it, or if no persistence partitions
560 # or files were found, the LUKS device is closed.
562 # For a snapshot file the return value is ${label}=${snapdata}", where
563 # ${snapdata} is the parameter used for try_snap().
565 # For all other cases (overlay/snapshot partition and overlay file) the
566 # return value is "${label}=${device}", where ${device} a device that
567 # can mount the content. In the case of an overlay file, the device
568 # containing the file will remain mounted as a side-effect.
570 # No devices in ${black_listed_devices} will be scanned, and if
571 # ${white_list_devices} is non-empty, only devices in it will be
574 local overlays="${1}"
575 local snapshots="${2}"
576 local white_listed_devices="${3}"
579 local black_listed_devices="$(what_is_mounted_on /live/image)"
581 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
586 # Check if it's a luks device; we'll have to open the device
587 # in order to probe any filesystem it contains, like we do
588 # below. activate_custom_mounts() also depends on that any luks
589 # device already has been opened.
590 if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && \
591 is_luks_partition ${dev}
593 if luks_device=$(open_luks_device "${dev}")
597 # skip $dev since we failed/chose not to open it
600 elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION}
602 # skip $dev since we don't allow unencrypted storage
606 # Probe for matching GPT partition names or filesystem labels
607 if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE}
609 result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${dev})
610 if [ -n "${result}" ]
612 ret="${ret} ${result}"
616 result=$(probe_for_fs_label "${overlays}" "${snapshots}" ${dev})
617 if [ -n "${result}" ]
619 ret="${ret} ${result}"
624 # Probe for files with matching name on mounted partition
625 if is_in_comma_sep_list file ${PERSISTENCE_STORAGE}
627 result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
628 if [ -n "${result}" ]
630 ret="${ret} ${result}"
635 # Close luks device if it isn't used
636 if [ -z "${result}" ] && [ -n "${luks_device}" ] && \
637 is_active_luks_mapping "${luks_device}"
639 /sbin/cryptsetup luksClose "${luks_device}"
653 for adaptor in /sys/class/net/*
655 status="$(cat ${adaptor}/iflink)"
657 if [ "${status}" -eq 2 ]
659 mac="$(cat ${adaptor}/address)"
660 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
670 /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1
673 is_active_luks_mapping ()
676 /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1
679 get_luks_backing_device () {
681 cryptsetup status ${device} 2> /dev/null | \
682 awk '{if ($1 == "device:") print $2}'
691 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
694 if [ "$(cat ${sysblock}/removable)" = "1" ]
696 if [ -z "${want_usb}" ]
700 if readlink ${sysblock} | grep -q usb
707 if [ "${dev_ok}" = "yes" ]
709 case "${output_format}" in
711 ret="${ret} ${sysblock}"
714 devname=$(sys2dev "${sysblock}")
715 ret="${ret} ${devname}"
728 removable_dev "${output_format}" "want_usb"
736 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
738 if [ "$(cat ${sysblock}/removable)" = "0" ]
740 case "${output_format}" in
742 ret="${ret} ${sysblock}"
745 devname=$(sys2dev "${sysblock}")
746 ret="${ret} ${devname}"
757 # create source's directory structure in dest, and recursively
758 # create symlinks in dest to to all files in source. if mask
759 # is non-empty, remove mask from all source paths when
760 # creating links (will be necessary if we change root, which
761 # live-boot normally does (into $rootmnt)).
763 # remove multiple /:s and ensure ending on /
764 local src_dir="$(trim_path ${1})/"
765 local dest_dir="$(trim_path ${2})/"
766 local src_mask="${3}"
768 # This check can only trigger on the inital, non-recursive call since
769 # we create the destination before recursive calls
770 if [ ! -d "${dest_dir}" ]
772 log_warning_msg "Must link_files into a directory"
776 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read src; do
777 local dest="${dest_dir}$(basename "${src}")"
780 if [ -z "$(ls -A "${src}")" ]
784 if [ ! -d "${dest}" ]
787 chown_ref "${src}" "${dest}"
788 chmod_ref "${src}" "${dest}"
790 link_files "${src}" "${dest}" "${src_mask}"
792 local final_src=${src}
793 if [ -n "${src_mask}" ]
795 final_src="$(echo ${final_src} | sed "s|^${src_mask}||")"
797 rm -rf "${dest}" 2> /dev/null
798 ln -s "${final_src}" "${dest}"
799 chown_ref "${src}" "${dest}"
806 local unionmountpoint="${1}" # directory where the union is mounted
807 local unionrw="${2}" # branch where the union changes are stored
808 local unionro1="${3}" # first underlying read-only branch (optional)
809 local unionro2="${4}" # second underlying read-only branch (optional)
811 if [ "${UNIONTYPE}" = "aufs" ]
816 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
825 case "${UNIONTYPE}" in
827 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
828 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
829 if [ -n "${unionro1}" ]
831 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
833 if [ -n "${unionro2}" ]
835 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
837 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
838 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
839 ( mkdir -p /run/sendsigs.omit.d
840 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
844 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
845 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
846 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
847 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
851 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
852 if [ -n "${unionro1}" ]
854 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
856 if [ -n "${unionro2}" ]
858 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
860 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
867 # Side-effect: leaves $devices with live-persistence.conf mounted in /live/persistence
868 # Side-effect: prints info to file $custom_mounts
870 local custom_mounts=${1}
874 local bindings="/tmp/bindings.list"
875 local links="/tmp/links.list"
876 rm -rf ${bindings} ${links} 2> /dev/null
878 for device in ${devices}
880 if [ ! -b "${device}" ]
885 local device_name="$(basename ${device})"
886 local backing=$(mount_persistence_media ${device})
887 if [ -z "${backing}" ]
892 local include_list="${backing}/${persistence_list}"
893 if [ ! -r "${include_list}" ]
898 if [ -n "${DEBUG}" ] && [ -e "${include_list}" ]
900 cp ${include_list} /live/persistence/${persistence_list}.${device_name}
903 while read dir options # < ${include_list}
905 if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$"
907 # skipping empty or commented lines
911 if trim_path ${dir} | grep -q -e "^[^/]" -e "^/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
913 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."
919 for opt in $(echo ${options} | tr ',' ' ');
923 opt_source=${opt#source=}
931 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
937 local source="${dir}"
938 if [ -n "${opt_source}" ]
940 if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${source}" != "." ]
942 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"
945 source="${opt_source}"
949 local full_source="$(trim_path ${backing}/${source})"
950 local full_dest="$(trim_path ${rootmnt}/${dir})"
951 if [ -n "${opt_link}" ]
953 echo "${device} ${full_source} ${full_dest} ${options}" >> ${links}
955 echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings}
957 done < ${include_list}
960 # We sort the list according to destination so we're sure that
961 # we won't hide a previous mount. We also ignore duplicate
962 # destinations in a more or less arbitrary way.
963 [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
965 # After all mounts are considered we add symlinks so they
966 # won't be hidden by some mount.
967 [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
969 # We need to make sure that no two custom mounts have the same sources
970 # or are nested; if that is the case, too much weird stuff can happen.
971 local prev_source="impossible source" # first iteration must not match
973 # This sort will ensure that a source /a comes right before a source
974 # /a/b so we only need to look at the previous source
975 sort -k2 -b ${custom_mounts} |
976 while read device source dest options
978 if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
980 panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
982 prev_source=${source}
987 activate_custom_mounts ()
989 local custom_mounts="${1}" # the ouput from get_custom_mounts()
990 local used_devices=""
992 while read device source dest options # < ${custom_mounts}
997 for opt in $(echo ${options} | tr ',' ' ');
1002 unset opt_link opt_union
1006 unset opt_bind opt_union
1010 unset opt_bind opt_link
1015 if [ -n "$(what_is_mounted_on "${dest}")" ]
1017 if [ "${dest}" = "${rootmnt}" ]
1021 log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1026 if [ ! -d "${dest}" ]
1028 # create the destination and delete existing files in
1029 # its path that are in the way
1031 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1033 path=$(trim_path ${path}/${dir})
1041 if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+"
1043 # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case
1044 # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
1045 chown 1000:1000 ${path}
1051 # if ${source} doesn't exist on our persistence media
1052 # we bootstrap it with $dest from the live filesystem.
1053 # this both makes sense and is critical if we're
1054 # dealing with /etc or other system dir.
1055 if [ ! -d "${source}" ]
1057 if [ -n "${PERSISTENCE_READONLY}" ]
1060 elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ]
1062 # unions and don't need to be bootstrapped
1063 # link dirs can't be bootstrapped in a sensible way
1064 mkdir -p "${source}"
1065 chown_ref "${dest}" "${source}"
1066 chmod_ref "${dest}" "${source}"
1067 elif [ -n "${opt_bind}" ]
1069 # ensure that $dest is not copied *into* $source
1070 mkdir -p "$(dirname ${source})"
1071 cp -a "${dest}" "${source}"
1075 # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can
1076 # ignore the loop below and set rofs_dest_backing=$dest
1077 local rofs_dest_backing=""
1078 if [ -n "${opt_link}"]
1080 for d in /live/rofs/*
1082 if [ -n "${rootmnt}" ]
1084 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1086 rofs_dest_backing="${d}/${dest}"
1088 if [ -d "${rofs_dest_backing}" ]
1092 rofs_dest_backing=""
1097 if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1099 link_files ${source} ${dest} ${rootmnt}
1100 elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1102 mkdir -p /live/persistence
1103 local links_source=$(mktemp -d /live/persistence/links-source-XXXXXX)
1104 chown_ref ${source} ${links_source}
1105 chmod_ref ${source} ${links_source}
1106 # We put the cow dir in the below strange place to
1107 # make it absolutely certain that the link source
1108 # has its own directory and isn't nested with some
1109 # other custom mount (if so that mount's files would
1110 # be linked, causing breakage.
1111 local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})"
1113 chown_ref "${source}" "${cow_dir}"
1114 chmod_ref "${source}" "${cow_dir}"
1115 do_union ${links_source} ${cow_dir} ${source} ${rofs_dest_backing}
1116 link_files ${links_source} ${dest} ${rootmnt}
1117 elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1119 do_union ${dest} ${source} ${rofs_dest_backing}
1120 elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1122 mount --bind "${source}" "${dest}"
1123 elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1125 # bind-mount and union mount are handled the same
1126 # in read-only mode, but note that rofs_dest_backing
1127 # is non-empty (and necessary) only for unions
1128 if [ -n "${rootmnt}" ]
1130 local cow_dir="$(echo ${dest} | sed -e "s|^${rootmnt}|/live/overlay/|")"
1132 # This is happens if persistence is activated
1134 local cow_dir="/live/overlay/${dest}"
1136 if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
1138 # If an earlier custom mount has files here
1139 # it will "block" the current mount's files
1140 # which is undesirable
1144 chown_ref "${source}" "${cow_dir}"
1145 chmod_ref "${source}" "${cow_dir}"
1146 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1149 PERSISTENCE_IS_ON="1"
1150 export PERSISTENCE_IS_ON
1152 if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1154 used_devices="${used_devices} ${device}"
1156 done < ${custom_mounts}
1158 echo ${used_devices}
1161 fix_backwards_compatibility ()
1167 if [ -n "${PERSISTENCE_READONLY}" ]
1172 local backing="$(mount_persistence_media ${device})"
1173 if [ -z "${backing}" ]
1178 local include_list="${backing}/${persistence_list}"
1179 if [ ! -r "${include_list}" ]
1181 echo "# persistence backwards compatibility:
1182 ${dir} ${opt},source=." > "${include_list}"
1190 [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ]