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}"
22 if [ "$1" != "C" ]; then
23 # Match the language code with 3rd field in languagelist
24 line=$(grep -v "^#" /usr/share/live-boot/languagelist | cut -f1,3,6 -d\; | grep -v ';C$' | grep "^$langpart;")
25 if [ -n "$line" ]; then
26 if [ "$(echo "$line" | grep -c '')" -gt 1 ]; then
27 # More than one match; try matching the
30 if [ "$countrypart" = "$1" ]; then
31 countryline="$(echo "$line" | head -n1)"
32 echo "${countryline##*;}"
35 countrypart="${countrypart%%[@.]*}"
36 countryline="$(echo "$line" | grep ";$countrypart;" | head -n1 || true)"
37 if [ "$countryline" ]; then
38 echo "${countryline##*;}"
49 is_in_list_separator_helper () {
55 echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
58 is_in_space_sep_list () {
61 is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
64 is_in_comma_sep_list () {
67 is_in_list_separator_helper "," "${element}" "${*}"
73 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
81 for dev in "${sysblock}"/* "${sysblock}"
83 if [ -e "${dev}/dev" ]
94 black_listed_devices="${1}"
95 white_listed_devices="${2}"
97 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
99 fulldevname=$(sys2dev "${sysblock}")
101 if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
102 [ -n "${white_listed_devices}" ] && \
103 ! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
105 # skip this device entirely
109 for dev in $(subdevices "${sysblock}")
111 devname=$(sys2dev "${dev}")
113 if is_in_space_sep_list ${devname} ${black_listed_devices}
115 # skip this subdevice
128 # Validate input first
129 if [ -z "${fstype}" ]
134 # Try to look if it is already supported by the kernel
135 if grep -q ${fstype} /proc/filesystems
139 # Then try to add support for it the gentle way using the initramfs capabilities
141 if grep -q ${fstype} /proc/filesystems
144 # Then try the hard way if /root is already reachable
146 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
147 if [ -e "${kmodule}" ]
150 if grep -q ${fstype} /proc/filesystems
163 /sbin/blkid -s TYPE -o value $1 2>/dev/null
170 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
174 # remove all unnecessary /:s in the path, including last one (except
175 # if path is just "/")
176 echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|'
179 what_is_mounted_on ()
181 local dir="$(trim_path ${1})"
182 grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
187 local reference="${1}"
190 local owner=$(stat -c %u:%g "${reference}")
191 chown -h ${owner} ${targets}
196 local reference="${1}"
199 local rights=$(stat -c %a "${reference}")
200 chmod ${rights} ${targets}
216 mounts="$(awk '{print $2}' /proc/mounts)"
217 testpath="$(busybox realpath ${testpath})"
221 if echo "${mounts}" | grep -qs "^${testpath}"
223 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
227 testpath=$(dirname $testpath)
234 # Returns used/free fs kbytes + 5% more
235 # You could pass a block device as ${1} or the mount point as ${2}
241 if [ -z "${mountp}" ]
243 mountp="$(where_is_mounted ${dev})"
245 if [ -z "${mountp}" ]
247 mountp="/mnt/tmp_fs_size"
250 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
256 if [ "${used}" = "used" ]
258 size=$(du -ks ${mountp} | cut -f1)
259 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
262 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
265 if [ -n "${doumount}" ]
267 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
277 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
279 loadkeys /etc/boottime.kmap.gz
289 local encryption=${5}
292 # the output of setup_loop is evaluated in other functions,
293 # modprobe leaks kernel options like "libata.dma=0"
294 # as "options libata dma=0" on stdout, causing serious
295 # problems therefor, so instead always avoid output to stdout
296 modprobe -q -b "${module}" 1>/dev/null
300 for loopdev in ${pattern}
302 if [ "$(cat ${loopdev}/size)" -eq 0 ]
304 dev=$(sys2dev "${loopdev}")
307 if [ -n "${readonly}" ]
309 if losetup --help 2>&1 | grep -q -- "-r\b"
311 options="${options} -r"
315 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
317 options="${options} -o ${offset}"
320 if [ -z "${encryption}" ]
322 losetup ${options} "${dev}" "${fspath}"
324 # Loop AES encryption
329 echo -n "Enter passphrase for root filesystem: " >&6
331 echo "${passphrase}" > /tmp/passphrase
333 exec 9</tmp/passphrase
334 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
337 rm -f /tmp/passphrase
339 if [ 0 -eq ${error} ]
346 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
349 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
362 panic "No loop devices available"
372 old_mountp="$(where_is_mounted ${dev})"
374 if [ -n "${old_mountp}" ]
376 if [ "${opts}" != "ro" ]
378 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
381 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
383 if [ -z "${fstype}" ]
385 fstype=$(get_fstype "${dev}")
387 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
388 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > boot.log && return 0 )
392 mount_persistence_media ()
397 local backing="/live/persistence/$(basename ${device})"
399 mkdir -p "${backing}"
400 local old_backing="$(where_is_mounted ${device})"
401 if [ -z "${old_backing}" ]
403 local fstype="$(get_fstype ${device})"
404 local mount_opts="rw,noatime"
405 if [ -n "${PERSISTENCE_READONLY}" ]
407 mount_opts="ro,noatime"
409 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
414 [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}"
418 elif [ "${backing}" != "${old_backing}" ]
420 if mount --move ${old_backing} ${backing} >/dev/null
425 [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
433 close_persistence_media () {
435 local backing="$(where_is_mounted ${device})"
437 if [ -d "${backing}" ]
439 umount "${backing}" >/dev/null 2>&1
440 rmdir "${backing}" >/dev/null 2>&1
443 if is_active_luks_mapping ${device}
445 /sbin/cryptsetup luksClose ${device}
452 name="$(basename ${dev})"
454 if [ -n "${PERSISTENCE_READONLY}" ]
456 opts="${opts} --readonly"
459 if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
461 re="^[[:space:]]*device:[[:space:]]*\([^[:space:]]*\)$"
462 opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
463 if [ "${opened_dev}" = "${dev}" ]
465 luks_device="/dev/mapper/${name}"
469 log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name"
478 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
479 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
483 luks_device="/dev/mapper/${name}"
489 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
492 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
502 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
508 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
511 probe_for_gpt_name ()
513 local overlays="${1}"
514 local snapshots="${2}"
517 local gpt_dev="${dev}"
518 if is_active_luks_mapping ${dev}
520 # if $dev is an opened luks device, we need to check
521 # GPT stuff on the backing device
522 gpt_dev=$(get_luks_backing_device "${dev}")
525 if ! is_gpt_device ${gpt_dev}
530 local gpt_name=$(get_gpt_name ${gpt_dev})
531 for label in ${overlays} ${snapshots}
533 if [ "${gpt_name}" = "${label}" ]
535 echo "${label}=${dev}"
540 probe_for_fs_label ()
542 local overlays="${1}"
543 local snapshots="${2}"
546 for label in ${overlays} ${snapshots}
548 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
550 echo "${label}=${dev}"
555 probe_for_file_name ()
557 local overlays="${1}"
558 local snapshots="${2}"
562 local backing="$(mount_persistence_media ${dev} probe)"
563 if [ -z "${backing}" ]
568 for label in ${overlays}
570 path=${backing}/${PERSISTENCE_PATH}${label}
573 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
574 ret="${ret} ${label}=${loopdev}"
577 for label in ${snapshots}
579 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
581 path="${PERSISTENCE_PATH}${label}.${ext}"
582 if [ -f "${backing}/${path}" ]
584 ret="${ret} ${label}=${dev}:${backing}:${path}"
593 umount ${backing} > /dev/null 2>&1 || true
597 find_persistence_media ()
599 # Scans devices for overlays and snapshots, and returns a whitespace
600 # separated list of how to use them. Only overlays with a partition
601 # label or file name in ${overlays} are returned, and ditto for
602 # snapshots with labels in ${snapshots}.
604 # When scanning a LUKS device, the user will be asked to enter the
605 # passphrase; on failure to enter it, or if no persistence partitions
606 # or files were found, the LUKS device is closed.
608 # For a snapshot file the return value is ${label}=${snapdata}", where
609 # ${snapdata} is the parameter used for try_snap().
611 # For all other cases (overlay/snapshot partition and overlay file) the
612 # return value is "${label}=${device}", where ${device} a device that
613 # can mount the content. In the case of an overlay file, the device
614 # containing the file will remain mounted as a side-effect.
616 # No devices in ${black_listed_devices} will be scanned, and if
617 # ${white_list_devices} is non-empty, only devices in it will be
620 local overlays="${1}"
621 local snapshots="${2}"
622 local white_listed_devices="${3}"
625 local black_listed_devices="$(what_is_mounted_on /live/image)"
627 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
632 # Check if it's a luks device; we'll have to open the device
633 # in order to probe any filesystem it contains, like we do
634 # below. activate_custom_mounts() also depends on that any luks
635 # device already has been opened.
636 if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && \
637 is_luks_partition ${dev}
639 if luks_device=$(open_luks_device "${dev}")
643 # skip $dev since we failed/chose not to open it
646 elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION}
648 # skip $dev since we don't allow unencrypted storage
652 # Probe for matching GPT partition names or filesystem labels
653 if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE}
655 result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${dev})
656 if [ -n "${result}" ]
658 ret="${ret} ${result}"
662 result=$(probe_for_fs_label "${overlays}" "${snapshots}" ${dev})
663 if [ -n "${result}" ]
665 ret="${ret} ${result}"
670 # Probe for files with matching name on mounted partition
671 if is_in_comma_sep_list file ${PERSISTENCE_STORAGE}
673 result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
674 if [ -n "${result}" ]
676 ret="${ret} ${result}"
681 # Close luks device if it isn't used
682 if [ -z "${result}" ] && [ -n "${luks_device}" ] && \
683 is_active_luks_mapping "${luks_device}"
685 /sbin/cryptsetup luksClose "${luks_device}"
699 for adaptor in /sys/class/net/*
701 status="$(cat ${adaptor}/iflink)"
703 if [ "${status}" -eq 2 ]
705 mac="$(cat ${adaptor}/address)"
706 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
716 /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1
719 is_active_luks_mapping ()
722 /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1
725 get_luks_backing_device () {
727 cryptsetup status ${device} 2> /dev/null | \
728 awk '{if ($1 == "device:") print $2}'
737 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
740 if [ "$(cat ${sysblock}/removable)" = "1" ]
742 if [ -z "${want_usb}" ]
746 if readlink ${sysblock} | grep -q usb
753 if [ "${dev_ok}" = "yes" ]
755 case "${output_format}" in
757 ret="${ret} ${sysblock}"
760 devname=$(sys2dev "${sysblock}")
761 ret="${ret} ${devname}"
774 removable_dev "${output_format}" "want_usb"
782 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
784 if [ "$(cat ${sysblock}/removable)" = "0" ]
786 case "${output_format}" in
788 ret="${ret} ${sysblock}"
791 devname=$(sys2dev "${sysblock}")
792 ret="${ret} ${devname}"
803 # create source's directory structure in dest, and recursively
804 # create symlinks in dest to to all files in source. if mask
805 # is non-empty, remove mask from all source paths when
806 # creating links (will be necessary if we change root, which
807 # live-boot normally does (into $rootmnt)).
809 # remove multiple /:s and ensure ending on /
810 local src_dir="$(trim_path ${1})/"
811 local dest_dir="$(trim_path ${2})/"
812 local src_mask="${3}"
814 # This check can only trigger on the inital, non-recursive call since
815 # we create the destination before recursive calls
816 if [ ! -d "${dest_dir}" ]
818 log_warning_msg "Must link_files into a directory"
822 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read src; do
823 local dest="${dest_dir}$(basename "${src}")"
826 if [ -z "$(ls -A "${src}")" ]
830 if [ ! -d "${dest}" ]
833 chown_ref "${src}" "${dest}"
834 chmod_ref "${src}" "${dest}"
836 link_files "${src}" "${dest}" "${src_mask}"
838 local final_src=${src}
839 if [ -n "${src_mask}" ]
841 final_src="$(echo ${final_src} | sed "s|^${src_mask}||")"
843 rm -rf "${dest}" 2> /dev/null
844 ln -s "${final_src}" "${dest}"
845 chown_ref "${src}" "${dest}"
852 local unionmountpoint="${1}" # directory where the union is mounted
853 local unionrw="${2}" # branch where the union changes are stored
854 local unionro1="${3}" # first underlying read-only branch (optional)
855 local unionro2="${4}" # second underlying read-only branch (optional)
857 if [ "${UNIONTYPE}" = "aufs" ]
862 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
871 case "${UNIONTYPE}" in
873 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
874 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
875 if [ -n "${unionro1}" ]
877 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
879 if [ -n "${unionro2}" ]
881 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
883 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
884 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
885 ( mkdir -p /run/sendsigs.omit.d
886 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
890 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
891 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
892 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
893 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
897 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
898 if [ -n "${unionro1}" ]
900 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
902 if [ -n "${unionro2}" ]
904 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
906 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
913 # Side-effect: leaves $devices with live-persistence.conf mounted in /live/persistence
914 # Side-effect: prints info to file $custom_mounts
916 local custom_mounts=${1}
920 local bindings="/tmp/bindings.list"
921 local links="/tmp/links.list"
922 rm -rf ${bindings} ${links} 2> /dev/null
924 for device in ${devices}
926 if [ ! -b "${device}" ]
931 local device_name="$(basename ${device})"
932 local backing=$(mount_persistence_media ${device})
933 if [ -z "${backing}" ]
938 local include_list="${backing}/${persistence_list}"
939 if [ ! -r "${include_list}" ]
944 if [ -n "${DEBUG}" ] && [ -e "${include_list}" ]
946 cp ${include_list} /live/persistence/${persistence_list}.${device_name}
949 while read dir options # < ${include_list}
951 if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$"
953 # skipping empty or commented lines
957 if trim_path ${dir} | grep -q -e "^[^/]" -e "^/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
959 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."
965 for opt in $(echo ${options} | tr ',' ' ');
969 opt_source=${opt#source=}
977 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
983 local source="${dir}"
984 if [ -n "${opt_source}" ]
986 if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${source}" != "." ]
988 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"
991 source="${opt_source}"
995 local full_source="$(trim_path ${backing}/${source})"
996 local full_dest="$(trim_path ${rootmnt}/${dir})"
997 if [ -n "${opt_link}" ]
999 echo "${device} ${full_source} ${full_dest} ${options}" >> ${links}
1001 echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings}
1003 done < ${include_list}
1006 # We sort the list according to destination so we're sure that
1007 # we won't hide a previous mount. We also ignore duplicate
1008 # destinations in a more or less arbitrary way.
1009 [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
1011 # After all mounts are considered we add symlinks so they
1012 # won't be hidden by some mount.
1013 [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
1015 # We need to make sure that no two custom mounts have the same sources
1016 # or are nested; if that is the case, too much weird stuff can happen.
1017 local prev_source="impossible source" # first iteration must not match
1019 # This sort will ensure that a source /a comes right before a source
1020 # /a/b so we only need to look at the previous source
1021 sort -k2 -b ${custom_mounts} |
1022 while read device source dest options
1024 if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
1026 panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
1028 prev_source=${source}
1033 activate_custom_mounts ()
1035 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1036 local used_devices=""
1038 while read device source dest options # < ${custom_mounts}
1040 local opt_bind="yes"
1043 for opt in $(echo ${options} | tr ',' ' ');
1048 unset opt_link opt_union
1052 unset opt_bind opt_union
1056 unset opt_bind opt_link
1061 if [ -n "$(what_is_mounted_on "${dest}")" ]
1063 if [ "${dest}" = "${rootmnt}" ]
1067 log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1072 if [ ! -d "${dest}" ]
1074 # create the destination and delete existing files in
1075 # its path that are in the way
1077 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1079 path=$(trim_path ${path}/${dir})
1087 if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+"
1089 # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case
1090 # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
1091 chown 1000:1000 ${path}
1097 # if ${source} doesn't exist on our persistence media
1098 # we bootstrap it with $dest from the live filesystem.
1099 # this both makes sense and is critical if we're
1100 # dealing with /etc or other system dir.
1101 if [ ! -d "${source}" ]
1103 if [ -n "${PERSISTENCE_READONLY}" ]
1106 elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ]
1108 # unions and don't need to be bootstrapped
1109 # link dirs can't be bootstrapped in a sensible way
1110 mkdir -p "${source}"
1111 chown_ref "${dest}" "${source}"
1112 chmod_ref "${dest}" "${source}"
1113 elif [ -n "${opt_bind}" ]
1115 # ensure that $dest is not copied *into* $source
1116 mkdir -p "$(dirname ${source})"
1117 cp -a "${dest}" "${source}"
1121 # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can
1122 # ignore the loop below and set rofs_dest_backing=$dest
1123 local rofs_dest_backing=""
1124 if [ -n "${opt_link}"]
1126 for d in /live/rofs/*
1128 if [ -n "${rootmnt}" ]
1130 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1132 rofs_dest_backing="${d}/${dest}"
1134 if [ -d "${rofs_dest_backing}" ]
1138 rofs_dest_backing=""
1143 if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1145 link_files ${source} ${dest} ${rootmnt}
1146 elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1148 mkdir -p /live/persistence
1149 local links_source=$(mktemp -d /live/persistence/links-source-XXXXXX)
1150 chown_ref ${source} ${links_source}
1151 chmod_ref ${source} ${links_source}
1152 # We put the cow dir in the below strange place to
1153 # make it absolutely certain that the link source
1154 # has its own directory and isn't nested with some
1155 # other custom mount (if so that mount's files would
1156 # be linked, causing breakage.
1157 local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})"
1159 chown_ref "${source}" "${cow_dir}"
1160 chmod_ref "${source}" "${cow_dir}"
1161 do_union ${links_source} ${cow_dir} ${source} ${rofs_dest_backing}
1162 link_files ${links_source} ${dest} ${rootmnt}
1163 elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1165 do_union ${dest} ${source} ${rofs_dest_backing}
1166 elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1168 mount --bind "${source}" "${dest}"
1169 elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1171 # bind-mount and union mount are handled the same
1172 # in read-only mode, but note that rofs_dest_backing
1173 # is non-empty (and necessary) only for unions
1174 if [ -n "${rootmnt}" ]
1176 local cow_dir="$(echo ${dest} | sed -e "s|^${rootmnt}|/live/overlay/|")"
1178 # This is happens if persistence is activated
1180 local cow_dir="/live/overlay/${dest}"
1182 if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
1184 # If an earlier custom mount has files here
1185 # it will "block" the current mount's files
1186 # which is undesirable
1190 chown_ref "${source}" "${cow_dir}"
1191 chmod_ref "${source}" "${cow_dir}"
1192 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1195 PERSISTENCE_IS_ON="1"
1196 export PERSISTENCE_IS_ON
1198 if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1200 used_devices="${used_devices} ${device}"
1202 done < ${custom_mounts}
1204 echo ${used_devices}
1207 fix_backwards_compatibility ()
1213 if [ -n "${PERSISTENCE_READONLY}" ]
1218 local backing="$(mount_persistence_media ${device})"
1219 if [ -z "${backing}" ]
1224 local include_list="${backing}/${persistence_list}"
1225 if [ ! -r "${include_list}" ]
1227 echo "# persistence backwards compatibility:
1228 ${dir} ${opt},source=." > "${include_list}"
1236 [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ]