8 VALUE="$(eval echo -n \${$STRING})"
10 if [ -f /live.vars ] && grep -sq "export ${STRING}" /live.vars
12 sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars
14 echo "export ${STRING}=\"${VALUE}\"" >> /live.vars
17 eval export "${STRING}"="${VALUE}"
20 is_in_list_separator_helper () {
26 echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
29 is_in_space_sep_list () {
32 is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
35 is_in_comma_sep_list () {
38 is_in_list_separator_helper "," "${element}" "${*}"
44 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
52 for dev in "${sysblock}"/* "${sysblock}"
54 if [ -e "${dev}/dev" ]
65 black_listed_devices="${1}"
66 white_listed_devices="${2}"
68 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
70 fulldevname=$(sys2dev "${sysblock}")
72 if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
73 [ -n "${white_listed_devices}" ] && \
74 ! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
76 # skip this device entirely
80 for dev in $(subdevices "${sysblock}")
82 devname=$(sys2dev "${dev}")
84 if is_in_space_sep_list ${devname} ${black_listed_devices}
99 # Validate input first
100 if [ -z "${fstype}" ]
105 # Try to look if it is already supported by the kernel
106 if grep -q ${fstype} /proc/filesystems
110 # Then try to add support for it the gentle way using the initramfs capabilities
112 if grep -q ${fstype} /proc/filesystems
115 # Then try the hard way if /root is already reachable
117 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
118 if [ -e "${kmodule}" ]
121 if grep -q ${fstype} /proc/filesystems
134 /sbin/blkid -s TYPE -o value $1 2>/dev/null
141 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
145 # remove all unnecessary /:s in the path, including last one (except
146 # if path is just "/")
147 echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|'
150 what_is_mounted_on ()
152 local dir="$(trim_path ${1})"
153 grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
158 local reference="${1}"
161 local owner=$(stat -c %u:%g "${reference}")
162 chown -h ${owner} ${targets}
167 local reference="${1}"
170 local rights=$(stat -c %a "${reference}")
171 chmod ${rights} ${targets}
187 mounts="$(awk '{print $2}' /proc/mounts)"
188 testpath="$(busybox realpath ${testpath})"
192 if echo "${mounts}" | grep -qs "^${testpath}"
194 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
198 testpath=$(dirname $testpath)
205 # Returns used/free fs kbytes + 5% more
206 # You could pass a block device as ${1} or the mount point as ${2}
212 if [ -z "${mountp}" ]
214 mountp="$(where_is_mounted ${dev})"
216 if [ -z "${mountp}" ]
218 mountp="/mnt/tmp_fs_size"
221 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
227 if [ "${used}" = "used" ]
229 size=$(du -ks ${mountp} | cut -f1)
230 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
233 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
236 if [ -n "${doumount}" ]
238 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
248 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
250 loadkeys /etc/boottime.kmap.gz
260 local encryption=${5}
263 # the output of setup_loop is evaluated in other functions,
264 # modprobe leaks kernel options like "libata.dma=0"
265 # as "options libata dma=0" on stdout, causing serious
266 # problems therefor, so instead always avoid output to stdout
267 modprobe -q -b "${module}" 1>/dev/null
271 for loopdev in ${pattern}
273 if [ "$(cat ${loopdev}/size)" -eq 0 ]
275 dev=$(sys2dev "${loopdev}")
278 if [ -n "${readonly}" ]
280 if losetup --help 2>&1 | grep -q -- "-r\b"
282 options="${options} -r"
286 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
288 options="${options} -o ${offset}"
291 if [ -z "${encryption}" ]
293 losetup ${options} "${dev}" "${fspath}"
295 # Loop AES encryption
300 echo -n "Enter passphrase for root filesystem: " >&6
302 echo "${passphrase}" > /tmp/passphrase
304 exec 9</tmp/passphrase
305 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
308 rm -f /tmp/passphrase
310 if [ 0 -eq ${error} ]
317 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
320 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
333 panic "No loop devices available"
343 old_mountp="$(where_is_mounted ${dev})"
345 if [ -n "${old_mountp}" ]
347 if [ "${opts}" != "ro" ]
349 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
352 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
354 if [ -z "${fstype}" ]
356 fstype=$(get_fstype "${dev}")
358 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
359 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > boot.log && return 0 )
363 mount_persistence_media ()
368 local backing="/live/persistence/$(basename ${device})"
370 mkdir -p "${backing}"
371 local old_backing="$(where_is_mounted ${device})"
372 if [ -z "${old_backing}" ]
374 local fstype="$(get_fstype ${device})"
375 local mount_opts="rw,noatime"
376 if [ -n "${PERSISTENCE_READONLY}" ]
378 mount_opts="ro,noatime"
380 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
385 [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}"
389 elif [ "${backing}" != "${old_backing}" ]
391 if mount --move ${old_backing} ${backing} >/dev/null
396 [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
404 close_persistence_media () {
406 local backing="$(where_is_mounted ${device})"
408 if [ -d "${backing}" ]
410 umount "${backing}" >/dev/null 2>&1
411 rmdir "${backing}" >/dev/null 2>&1
414 if is_active_luks_mapping ${device}
416 /sbin/cryptsetup luksClose ${device}
423 name="$(basename ${dev})"
425 if [ -n "${PERSISTENCE_READONLY}" ]
427 opts="${opts} --readonly"
430 if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
432 re="^[[:space:]]*device:[[:space:]]*\([^[:space:]]*\)$"
433 opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
434 if [ "${opened_dev}" = "${dev}" ]
436 luks_device="/dev/mapper/${name}"
440 log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name"
449 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
450 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
454 luks_device="/dev/mapper/${name}"
460 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
463 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
473 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
479 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
482 probe_for_gpt_name ()
484 local overlays="${1}"
485 local snapshots="${2}"
488 local gpt_dev="${dev}"
489 if is_active_luks_mapping ${dev}
491 # if $dev is an opened luks device, we need to check
492 # GPT stuff on the backing device
493 gpt_dev=$(get_luks_backing_device "${dev}")
496 if ! is_gpt_device ${gpt_dev}
501 local gpt_name=$(get_gpt_name ${gpt_dev})
502 for label in ${overlays} ${snapshots}
504 if [ "${gpt_name}" = "${label}" ]
506 echo "${label}=${dev}"
511 probe_for_fs_label ()
513 local overlays="${1}"
514 local snapshots="${2}"
517 for label in ${overlays} ${snapshots}
519 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
521 echo "${label}=${dev}"
526 probe_for_file_name ()
528 local overlays="${1}"
529 local snapshots="${2}"
533 local backing="$(mount_persistence_media ${dev} probe)"
534 if [ -z "${backing}" ]
539 for label in ${overlays}
541 path=${backing}/${PERSISTENCE_PATH}${label}
544 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
545 ret="${ret} ${label}=${loopdev}"
548 for label in ${snapshots}
550 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
552 path="${PERSISTENCE_PATH}${label}.${ext}"
553 if [ -f "${backing}/${path}" ]
555 ret="${ret} ${label}=${dev}:${backing}:${path}"
564 umount ${backing} > /dev/null 2>&1 || true
568 find_persistence_media ()
570 # Scans devices for overlays and snapshots, and returns a whitespace
571 # separated list of how to use them. Only overlays with a partition
572 # label or file name in ${overlays} are returned, and ditto for
573 # snapshots with labels in ${snapshots}.
575 # When scanning a LUKS device, the user will be asked to enter the
576 # passphrase; on failure to enter it, or if no persistence partitions
577 # or files were found, the LUKS device is closed.
579 # For a snapshot file the return value is ${label}=${snapdata}", where
580 # ${snapdata} is the parameter used for try_snap().
582 # For all other cases (overlay/snapshot partition and overlay file) the
583 # return value is "${label}=${device}", where ${device} a device that
584 # can mount the content. In the case of an overlay file, the device
585 # containing the file will remain mounted as a side-effect.
587 # No devices in ${black_listed_devices} will be scanned, and if
588 # ${white_list_devices} is non-empty, only devices in it will be
591 local overlays="${1}"
592 local snapshots="${2}"
593 local white_listed_devices="${3}"
596 local black_listed_devices="$(what_is_mounted_on /live/image)"
598 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
603 # Check if it's a luks device; we'll have to open the device
604 # in order to probe any filesystem it contains, like we do
605 # below. activate_custom_mounts() also depends on that any luks
606 # device already has been opened.
607 if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && \
608 is_luks_partition ${dev}
610 if luks_device=$(open_luks_device "${dev}")
614 # skip $dev since we failed/chose not to open it
617 elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION}
619 # skip $dev since we don't allow unencrypted storage
623 # Probe for matching GPT partition names or filesystem labels
624 if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE}
626 result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${dev})
627 if [ -n "${result}" ]
629 ret="${ret} ${result}"
633 result=$(probe_for_fs_label "${overlays}" "${snapshots}" ${dev})
634 if [ -n "${result}" ]
636 ret="${ret} ${result}"
641 # Probe for files with matching name on mounted partition
642 if is_in_comma_sep_list file ${PERSISTENCE_STORAGE}
644 result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
645 if [ -n "${result}" ]
647 ret="${ret} ${result}"
652 # Close luks device if it isn't used
653 if [ -z "${result}" ] && [ -n "${luks_device}" ] && \
654 is_active_luks_mapping "${luks_device}"
656 /sbin/cryptsetup luksClose "${luks_device}"
670 for adaptor in /sys/class/net/*
672 status="$(cat ${adaptor}/iflink)"
674 if [ "${status}" -eq 2 ]
676 mac="$(cat ${adaptor}/address)"
677 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
687 /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1
690 is_active_luks_mapping ()
693 /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1
696 get_luks_backing_device () {
698 cryptsetup status ${device} 2> /dev/null | \
699 awk '{if ($1 == "device:") print $2}'
708 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
711 if [ "$(cat ${sysblock}/removable)" = "1" ]
713 if [ -z "${want_usb}" ]
717 if readlink ${sysblock} | grep -q usb
724 if [ "${dev_ok}" = "yes" ]
726 case "${output_format}" in
728 ret="${ret} ${sysblock}"
731 devname=$(sys2dev "${sysblock}")
732 ret="${ret} ${devname}"
745 removable_dev "${output_format}" "want_usb"
753 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
755 if [ "$(cat ${sysblock}/removable)" = "0" ]
757 case "${output_format}" in
759 ret="${ret} ${sysblock}"
762 devname=$(sys2dev "${sysblock}")
763 ret="${ret} ${devname}"
774 # create source's directory structure in dest, and recursively
775 # create symlinks in dest to to all files in source. if mask
776 # is non-empty, remove mask from all source paths when
777 # creating links (will be necessary if we change root, which
778 # live-boot normally does (into $rootmnt)).
780 # remove multiple /:s and ensure ending on /
781 local src_dir="$(trim_path ${1})/"
782 local dest_dir="$(trim_path ${2})/"
783 local src_mask="${3}"
785 # This check can only trigger on the inital, non-recursive call since
786 # we create the destination before recursive calls
787 if [ ! -d "${dest_dir}" ]
789 log_warning_msg "Must link_files into a directory"
793 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read src; do
794 local dest="${dest_dir}$(basename "${src}")"
797 if [ -z "$(ls -A "${src}")" ]
801 if [ ! -d "${dest}" ]
804 chown_ref "${src}" "${dest}"
805 chmod_ref "${src}" "${dest}"
807 link_files "${src}" "${dest}" "${src_mask}"
809 local final_src=${src}
810 if [ -n "${src_mask}" ]
812 final_src="$(echo ${final_src} | sed "s|^${src_mask}||")"
814 rm -rf "${dest}" 2> /dev/null
815 ln -s "${final_src}" "${dest}"
816 chown_ref "${src}" "${dest}"
823 local unionmountpoint="${1}" # directory where the union is mounted
824 local unionrw="${2}" # branch where the union changes are stored
825 local unionro1="${3}" # first underlying read-only branch (optional)
826 local unionro2="${4}" # second underlying read-only branch (optional)
828 if [ "${UNIONTYPE}" = "aufs" ]
833 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
842 case "${UNIONTYPE}" in
844 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
845 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
846 if [ -n "${unionro1}" ]
848 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
850 if [ -n "${unionro2}" ]
852 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
854 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
855 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
856 ( mkdir -p /run/sendsigs.omit.d
857 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
861 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
862 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
863 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
864 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
868 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
869 if [ -n "${unionro1}" ]
871 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
873 if [ -n "${unionro2}" ]
875 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
877 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
884 # Side-effect: leaves $devices with live-persistence.conf mounted in /live/persistence
885 # Side-effect: prints info to file $custom_mounts
887 local custom_mounts=${1}
891 local bindings="/tmp/bindings.list"
892 local links="/tmp/links.list"
893 rm -rf ${bindings} ${links} 2> /dev/null
895 for device in ${devices}
897 if [ ! -b "${device}" ]
902 local device_name="$(basename ${device})"
903 local backing=$(mount_persistence_media ${device})
904 if [ -z "${backing}" ]
909 local include_list="${backing}/${persistence_list}"
910 if [ ! -r "${include_list}" ]
915 if [ -n "${DEBUG}" ] && [ -e "${include_list}" ]
917 cp ${include_list} /live/persistence/${persistence_list}.${device_name}
920 while read dir options # < ${include_list}
922 if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$"
924 # skipping empty or commented lines
928 if trim_path ${dir} | grep -q -e "^[^/]" -e "^/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
930 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."
936 for opt in $(echo ${options} | tr ',' ' ');
940 opt_source=${opt#source=}
948 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
954 local source="${dir}"
955 if [ -n "${opt_source}" ]
957 if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${source}" != "." ]
959 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"
962 source="${opt_source}"
966 local full_source="$(trim_path ${backing}/${source})"
967 local full_dest="$(trim_path ${rootmnt}/${dir})"
968 if [ -n "${opt_link}" ]
970 echo "${device} ${full_source} ${full_dest} ${options}" >> ${links}
972 echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings}
974 done < ${include_list}
977 # We sort the list according to destination so we're sure that
978 # we won't hide a previous mount. We also ignore duplicate
979 # destinations in a more or less arbitrary way.
980 [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
982 # After all mounts are considered we add symlinks so they
983 # won't be hidden by some mount.
984 [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
986 # We need to make sure that no two custom mounts have the same sources
987 # or are nested; if that is the case, too much weird stuff can happen.
988 local prev_source="impossible source" # first iteration must not match
990 # This sort will ensure that a source /a comes right before a source
991 # /a/b so we only need to look at the previous source
992 sort -k2 -b ${custom_mounts} |
993 while read device source dest options
995 if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
997 panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
999 prev_source=${source}
1004 activate_custom_mounts ()
1006 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1007 local used_devices=""
1009 while read device source dest options # < ${custom_mounts}
1011 local opt_bind="yes"
1014 for opt in $(echo ${options} | tr ',' ' ');
1019 unset opt_link opt_union
1023 unset opt_bind opt_union
1027 unset opt_bind opt_link
1032 if [ -n "$(what_is_mounted_on "${dest}")" ]
1034 if [ "${dest}" = "${rootmnt}" ]
1038 log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1043 if [ ! -d "${dest}" ]
1045 # create the destination and delete existing files in
1046 # its path that are in the way
1048 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1050 path=$(trim_path ${path}/${dir})
1058 if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+"
1060 # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case
1061 # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
1062 chown 1000:1000 ${path}
1068 # if ${source} doesn't exist on our persistence media
1069 # we bootstrap it with $dest from the live filesystem.
1070 # this both makes sense and is critical if we're
1071 # dealing with /etc or other system dir.
1072 if [ ! -d "${source}" ]
1074 if [ -n "${PERSISTENCE_READONLY}" ]
1077 elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ]
1079 # unions and don't need to be bootstrapped
1080 # link dirs can't be bootstrapped in a sensible way
1081 mkdir -p "${source}"
1082 chown_ref "${dest}" "${source}"
1083 chmod_ref "${dest}" "${source}"
1084 elif [ -n "${opt_bind}" ]
1086 # ensure that $dest is not copied *into* $source
1087 mkdir -p "$(dirname ${source})"
1088 cp -a "${dest}" "${source}"
1092 # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can
1093 # ignore the loop below and set rofs_dest_backing=$dest
1094 local rofs_dest_backing=""
1095 if [ -n "${opt_link}"]
1097 for d in /live/rofs/*
1099 if [ -n "${rootmnt}" ]
1101 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1103 rofs_dest_backing="${d}/${dest}"
1105 if [ -d "${rofs_dest_backing}" ]
1109 rofs_dest_backing=""
1114 if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1116 link_files ${source} ${dest} ${rootmnt}
1117 elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1119 mkdir -p /live/persistence
1120 local links_source=$(mktemp -d /live/persistence/links-source-XXXXXX)
1121 chown_ref ${source} ${links_source}
1122 chmod_ref ${source} ${links_source}
1123 # We put the cow dir in the below strange place to
1124 # make it absolutely certain that the link source
1125 # has its own directory and isn't nested with some
1126 # other custom mount (if so that mount's files would
1127 # be linked, causing breakage.
1128 local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})"
1130 chown_ref "${source}" "${cow_dir}"
1131 chmod_ref "${source}" "${cow_dir}"
1132 do_union ${links_source} ${cow_dir} ${source} ${rofs_dest_backing}
1133 link_files ${links_source} ${dest} ${rootmnt}
1134 elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1136 do_union ${dest} ${source} ${rofs_dest_backing}
1137 elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1139 mount --bind "${source}" "${dest}"
1140 elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1142 # bind-mount and union mount are handled the same
1143 # in read-only mode, but note that rofs_dest_backing
1144 # is non-empty (and necessary) only for unions
1145 if [ -n "${rootmnt}" ]
1147 local cow_dir="$(echo ${dest} | sed -e "s|^${rootmnt}|/live/overlay/|")"
1149 # This is happens if persistence is activated
1151 local cow_dir="/live/overlay/${dest}"
1153 if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
1155 # If an earlier custom mount has files here
1156 # it will "block" the current mount's files
1157 # which is undesirable
1161 chown_ref "${source}" "${cow_dir}"
1162 chmod_ref "${source}" "${cow_dir}"
1163 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1166 PERSISTENCE_IS_ON="1"
1167 export PERSISTENCE_IS_ON
1169 if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1171 used_devices="${used_devices} ${device}"
1173 done < ${custom_mounts}
1175 echo ${used_devices}
1178 fix_backwards_compatibility ()
1184 if [ -n "${PERSISTENCE_READONLY}" ]
1189 local backing="$(mount_persistence_media ${device})"
1190 if [ -z "${backing}" ]
1195 local include_list="${backing}/${persistence_list}"
1196 if [ ! -r "${include_list}" ]
1198 echo "# persistence backwards compatibility:
1199 ${dir} ${opt},source=." > "${include_list}"
1207 [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ]