9 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
11 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
13 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
25 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
31 uuid="$(cat /conf/uuid.conf)"
33 for try_uuid_file in "${path}/.disk/live-uuid"*
35 [ -e "${try_uuid_file}" ] || continue
37 try_uuid="$(cat "${try_uuid_file}")"
39 if [ "${uuid}" = "${try_uuid}" ]
51 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
52 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
60 panic "Unrecognized live filesystem: ${1}"
67 # Does any files match pattern ${1} ?
70 if [ "$(echo ${pattern})" != "${pattern}" ]
78 mount_images_in_directory ()
84 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
85 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
86 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
87 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
88 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
89 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
91 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
92 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
94 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
100 sysfs_path="${1#/sys}"
102 if /sbin/udevadm test-builtin path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)"
105 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
108 elif echo ${sysfs_path} | grep -q "^/block/dm-"
111 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
123 skip_uuid_check="${3}"
125 # support for fromiso=.../isofrom=....
128 ISO_DEVICE=$(dirname $FROMISO)
129 if ! [ -b $ISO_DEVICE ]
131 # to support unusual device names like /dev/cciss/c0d0p1
132 # as well we have to identify the block device name, let's
133 # do that for up to 15 levels
135 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
137 ISO_DEVICE=$(dirname ${ISO_DEVICE})
138 [ -b "$ISO_DEVICE" ] && break
143 if [ "$ISO_DEVICE" = "/" ]
145 echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
147 fs_type=$(get_fstype "${ISO_DEVICE}")
148 if is_supported_fs ${fs_type}
151 mount -t $fs_type "$ISO_DEVICE" /live/fromiso
152 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
153 loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
154 devname="${loopdevname}"
156 echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
161 if [ -z "${devname}" ]
163 devname=$(sys2dev "${sysdev}")
166 if [ -d "${devname}" ]
168 mount -o bind "${devname}" $mountpoint || continue
170 if is_live_path $mountpoint
180 for device in ${devname}
185 if [ -x /scripts/local-top/lvm2 ]
187 ROOT="$device" resume="" /scripts/local-top/lvm2
192 # Adding raid support
193 if [ -x /scripts/local-top/mdadm ]
195 cp /conf/conf.d/md /conf/conf.d/md.orig
196 echo "MD_DEVS=$device " >> /conf/conf.d/md
197 /scripts/local-top/mdadm
198 mv /conf/conf.d/md.orig /conf/conf.d/md
205 [ -n "$device" ] && devname="$device"
207 [ -e "$devname" ] || continue
209 if [ -n "${LIVE_MEDIA_OFFSET}" ]
211 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
212 devname="${loopdevname}"
215 fstype=$(get_fstype "${devname}")
217 if is_supported_fs ${fstype}
219 devuid=$(blkid -o value -s UUID "$devname")
220 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
221 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
222 [ -n "$devuid" ] && echo "$devuid" >> $tried
224 if [ -n "${FINDISO}" ]
226 if [ -f ${mountpoint}/${FINDISO} ]
229 mkdir -p /live/findiso
230 mount -t ${fstype} -o ro,noatime "${devname}" /live/findiso
231 loopdevname=$(setup_loop "/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
232 devname="${loopdevname}"
233 mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint}
239 if is_live_path ${mountpoint} && \
240 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
245 umount ${mountpoint} 2>/dev/null
249 if [ -n "${LIVE_MEDIA_OFFSET}" ]
251 losetup -d "${loopdevname}"
261 # don't start autodetection before timeout has expired
262 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
264 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
270 # first look at the one specified in the command line
271 case "${LIVE_MEDIA}" in
273 for sysblock in $(removable_usb_dev "sys")
275 for dev in $(subdevices "${sysblock}")
277 if check_dev "${dev}"
287 for sysblock in $(removable_dev "sys")
289 for dev in $(subdevices "${sysblock}")
291 if check_dev "${dev}"
301 if [ ! -z "${LIVE_MEDIA}" ]
303 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
311 # or do the scan of block devices
312 # prefer removable devices over non-removable devices, so scan them first
313 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
315 for sysblock in $devices_to_scan
317 devname=$(sys2dev "${sysblock}")
318 [ -e "$devname" ] || continue
319 fstype=$(get_fstype "${devname}")
321 if /lib/udev/cdrom_id ${devname} > /dev/null
323 if check_dev "null" "${devname}"
327 elif is_nice_device "${sysblock}"
329 for dev in $(subdevices "${sysblock}")
331 if check_dev "${dev}"
336 elif [ "${fstype}" = "squashfs" -o \
337 "${fstype}" = "btrfs" -o \
338 "${fstype}" = "ext2" -o \
339 "${fstype}" = "ext3" -o \
340 "${fstype}" = "ext4" -o \
341 "${fstype}" = "jffs2" ]
343 # This is an ugly hack situation, the block device has
344 # an image directly on it. It's hopefully
345 # live-boot, so take it and run with it.
346 ln -s "${devname}" "${devname}.${fstype}"
347 echo "${devname}.${fstype}"
358 VALUE="$(eval echo -n \${$STRING})"
360 if [ -f /live.vars ] && grep -sq "export ${STRING}" /live.vars
362 sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars
364 echo "export ${STRING}=\"${VALUE}\"" >> /live.vars
367 eval export "${STRING}"="${VALUE}"
370 is_in_list_separator_helper ()
377 echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
380 is_in_space_sep_list ()
384 is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
387 is_in_comma_sep_list ()
391 is_in_list_separator_helper "," "${element}" "${*}"
397 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
405 for dev in "${sysblock}"/* "${sysblock}"
407 if [ -e "${dev}/dev" ]
418 black_listed_devices="${1}"
419 white_listed_devices="${2}"
421 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
423 fulldevname=$(sys2dev "${sysblock}")
425 if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
426 [ -n "${white_listed_devices}" ] && \
427 ! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
429 # skip this device entirely
433 for dev in $(subdevices "${sysblock}")
435 devname=$(sys2dev "${dev}")
437 if is_in_space_sep_list ${devname} ${black_listed_devices}
439 # skip this subdevice
452 # Validate input first
453 if [ -z "${fstype}" ]
458 # Try to look if it is already supported by the kernel
459 if grep -q ${fstype} /proc/filesystems
463 # Then try to add support for it the gentle way using the initramfs capabilities
465 if grep -q ${fstype} /proc/filesystems
468 # Then try the hard way if /root is already reachable
470 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
471 if [ -e "${kmodule}" ]
474 if grep -q ${fstype} /proc/filesystems
487 /sbin/blkid -s TYPE -o value $1 2>/dev/null
494 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
499 # remove all unnecessary /:s in the path, including last one (except
500 # if path is just "/")
501 echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|'
504 what_is_mounted_on ()
506 local dir="$(trim_path ${1})"
507 grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
512 local reference="${1}"
515 local owner=$(stat -c %u:%g "${reference}")
516 chown -h ${owner} ${targets}
521 local reference="${1}"
524 local rights=$(stat -c %a "${reference}")
525 chmod ${rights} ${targets}
541 mounts="$(awk '{print $2}' /proc/mounts)"
542 testpath="$(busybox realpath ${testpath})"
546 if echo "${mounts}" | grep -qs "^${testpath}"
548 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
552 testpath=$(dirname $testpath)
559 # Returns used/free fs kbytes + 5% more
560 # You could pass a block device as ${1} or the mount point as ${2}
566 if [ -z "${mountp}" ]
568 mountp="$(where_is_mounted ${dev})"
570 if [ -z "${mountp}" ]
572 mountp="/mnt/tmp_fs_size"
575 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
581 if [ "${used}" = "used" ]
583 size=$(du -ks ${mountp} | cut -f1)
584 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
587 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
590 if [ -n "${doumount}" ]
592 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
602 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
604 loadkeys /etc/boottime.kmap.gz
614 local encryption=${5}
617 # the output of setup_loop is evaluated in other functions,
618 # modprobe leaks kernel options like "libata.dma=0"
619 # as "options libata dma=0" on stdout, causing serious
620 # problems therefor, so instead always avoid output to stdout
621 modprobe -q -b "${module}" 1>/dev/null
625 for loopdev in ${pattern}
627 if [ "$(cat ${loopdev}/size)" -eq 0 ]
629 dev=$(sys2dev "${loopdev}")
632 if [ -n "${readonly}" ]
634 if losetup --help 2>&1 | grep -q -- "-r\b"
636 options="${options} -r"
640 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
642 options="${options} -o ${offset}"
645 if [ -z "${encryption}" ]
647 losetup ${options} "${dev}" "${fspath}"
649 # Loop AES encryption
654 echo -n "Enter passphrase for root filesystem: " >&6
656 echo "${passphrase}" > /tmp/passphrase
658 exec 9</tmp/passphrase
659 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
662 rm -f /tmp/passphrase
664 if [ 0 -eq ${error} ]
671 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
674 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
687 panic "No loop devices available"
697 old_mountp="$(where_is_mounted ${dev})"
699 if [ -n "${old_mountp}" ]
701 if [ "${opts}" != "ro" ]
703 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
706 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
708 if [ -z "${fstype}" ]
710 fstype=$(get_fstype "${dev}")
712 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
713 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > boot.log && return 0 )
717 mount_persistence_media ()
722 local backing="/live/persistence/$(basename ${device})"
724 mkdir -p "${backing}"
725 local old_backing="$(where_is_mounted ${device})"
726 if [ -z "${old_backing}" ]
728 local fstype="$(get_fstype ${device})"
729 local mount_opts="rw,noatime"
730 if [ -n "${PERSISTENCE_READONLY}" ]
732 mount_opts="ro,noatime"
734 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
739 [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}"
743 elif [ "${backing}" != "${old_backing}" ]
745 if mount --move ${old_backing} ${backing} >/dev/null
750 [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
758 close_persistence_media ()
761 local backing="$(where_is_mounted ${device})"
763 if [ -d "${backing}" ]
765 umount "${backing}" >/dev/null 2>&1
766 rmdir "${backing}" >/dev/null 2>&1
769 if is_active_luks_mapping ${device}
771 /sbin/cryptsetup luksClose ${device}
778 name="$(basename ${dev})"
780 if [ -n "${PERSISTENCE_READONLY}" ]
782 opts="${opts} --readonly"
785 if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
787 re="^[[:space:]]*device:[[:space:]]*\([^[:space:]]*\)$"
788 opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
789 if [ "${opened_dev}" = "${dev}" ]
791 luks_device="/dev/mapper/${name}"
795 log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name"
804 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
805 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
809 luks_device="/dev/mapper/${name}"
815 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
818 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
828 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
834 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
837 probe_for_gpt_name ()
839 local overlays="${1}"
842 local gpt_dev="${dev}"
843 if is_active_luks_mapping ${dev}
845 # if $dev is an opened luks device, we need to check
846 # GPT stuff on the backing device
847 gpt_dev=$(get_luks_backing_device "${dev}")
850 if ! is_gpt_device ${gpt_dev}
855 local gpt_name=$(get_gpt_name ${gpt_dev})
856 for label in ${overlays}
858 if [ "${gpt_name}" = "${label}" ]
860 echo "${label}=${dev}"
865 probe_for_fs_label ()
867 local overlays="${1}"
870 for label in ${overlays}
872 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
874 echo "${label}=${dev}"
879 probe_for_file_name ()
881 local overlays="${1}"
885 local backing="$(mount_persistence_media ${dev} probe)"
886 if [ -z "${backing}" ]
891 for label in ${overlays}
893 path=${backing}/${PERSISTENCE_PATH}${label}
896 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
897 ret="${ret} ${label}=${loopdev}"
905 # unmount and remove mountpoint
906 umount ${backing} > /dev/null 2>&1 || true
907 rmdir ${backing} > /dev/null 2>&1 || true
911 find_persistence_media ()
913 # Scans devices for overlays, and returns a whitespace
914 # separated list of how to use them. Only overlays with a partition
915 # label or file name in ${overlays} are returned.
917 # When scanning a LUKS device, the user will be asked to enter the
918 # passphrase; on failure to enter it, or if no persistence partitions
919 # or files were found, the LUKS device is closed.
921 # For all other cases (overlay partition and overlay file) the
922 # return value is "${label}=${device}", where ${device} a device that
923 # can mount the content. In the case of an overlay file, the device
924 # containing the file will remain mounted as a side-effect.
926 # No devices in ${black_listed_devices} will be scanned, and if
927 # ${white_list_devices} is non-empty, only devices in it will be
930 local overlays="${1}"
931 local white_listed_devices="${2}"
934 local black_listed_devices="$(what_is_mounted_on /live/medium)"
936 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
941 # Check if it's a luks device; we'll have to open the device
942 # in order to probe any filesystem it contains, like we do
943 # below. activate_custom_mounts() also depends on that any luks
944 # device already has been opened.
945 if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${dev}
947 if luks_device=$(open_luks_device "${dev}")
951 # skip $dev since we failed/chose not to open it
954 elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION}
956 # skip $dev since we don't allow unencrypted storage
960 # Probe for matching GPT partition names or filesystem labels
961 if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE}
963 result=$(probe_for_gpt_name "${overlays}" ${dev})
964 if [ -n "${result}" ]
966 ret="${ret} ${result}"
970 result=$(probe_for_fs_label "${overlays}" ${dev})
971 if [ -n "${result}" ]
973 ret="${ret} ${result}"
978 # Probe for files with matching name on mounted partition
979 if is_in_comma_sep_list file ${PERSISTENCE_STORAGE}
981 result=$(probe_for_file_name "${overlays}" ${dev})
982 if [ -n "${result}" ]
984 ret="${ret} ${result}"
989 # Close luks device if it isn't used
990 if [ -z "${result}" ] && [ -n "${luks_device}" ] && is_active_luks_mapping "${luks_device}"
992 /sbin/cryptsetup luksClose "${luks_device}"
1006 for adaptor in /sys/class/net/*
1008 status="$(cat ${adaptor}/iflink)"
1010 if [ "${status}" -eq 2 ]
1012 mac="$(cat ${adaptor}/address)"
1013 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
1020 is_luks_partition ()
1023 /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1
1026 is_active_luks_mapping ()
1029 /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1
1032 get_luks_backing_device ()
1035 cryptsetup status ${device} 2> /dev/null | \
1036 awk '{if ($1 == "device:") print $2}'
1041 output_format="${1}"
1045 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1048 if [ "$(cat ${sysblock}/removable)" = "1" ]
1050 if [ -z "${want_usb}" ]
1054 if readlink ${sysblock} | grep -q usb
1061 if [ "${dev_ok}" = "true" ]
1063 case "${output_format}" in
1065 ret="${ret} ${sysblock}"
1068 devname=$(sys2dev "${sysblock}")
1069 ret="${ret} ${devname}"
1078 removable_usb_dev ()
1080 output_format="${1}"
1082 removable_dev "${output_format}" "want_usb"
1085 non_removable_dev ()
1087 output_format="${1}"
1090 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1092 if [ "$(cat ${sysblock}/removable)" = "0" ]
1094 case "${output_format}" in
1096 ret="${ret} ${sysblock}"
1099 devname=$(sys2dev "${sysblock}")
1100 ret="${ret} ${devname}"
1111 # create source's directory structure in dest, and recursively
1112 # create symlinks in dest to to all files in source. if mask
1113 # is non-empty, remove mask from all source paths when
1114 # creating links (will be necessary if we change root, which
1115 # live-boot normally does (into $rootmnt)).
1117 # remove multiple /:s and ensure ending on /
1118 local src_dir="$(trim_path ${1})/"
1119 local dest_dir="$(trim_path ${2})/"
1120 local src_mask="${3}"
1122 # This check can only trigger on the inital, non-recursive call since
1123 # we create the destination before recursive calls
1124 if [ ! -d "${dest_dir}" ]
1126 log_warning_msg "Must link_files into a directory"
1130 find "${src_dir}" -mindepth 1 -maxdepth 1 | \
1133 local dest="${dest_dir}$(basename "${src}")"
1136 if [ -z "$(ls -A "${src}")" ]
1140 if [ ! -d "${dest}" ]
1143 chown_ref "${src}" "${dest}"
1144 chmod_ref "${src}" "${dest}"
1146 link_files "${src}" "${dest}" "${src_mask}"
1148 local final_src=${src}
1149 if [ -n "${src_mask}" ]
1151 final_src="$(echo ${final_src} | sed "s|^${src_mask}||")"
1153 rm -rf "${dest}" 2> /dev/null
1154 ln -s "${final_src}" "${dest}"
1155 chown_ref "${src}" "${dest}"
1162 local unionmountpoint="${1}" # directory where the union is mounted
1163 local unionrw="${2}" # branch where the union changes are stored
1164 local unionro1="${3}" # first underlying read-only branch (optional)
1165 local unionro2="${4}" # second underlying read-only branch (optional)
1167 case "${UNIONTYPE}" in
1185 case "${UNIONTYPE}" in
1187 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1188 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
1189 if [ -n "${unionro1}" ]
1191 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1193 if [ -n "${unionro2}" ]
1195 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1197 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1198 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1199 ( mkdir -p /run/sendsigs.omit.d
1200 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1204 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1205 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
1206 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
1207 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1211 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1212 if [ -n "${unionro1}" ]
1214 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1216 if [ -n "${unionro2}" ]
1218 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1220 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1225 get_custom_mounts ()
1227 # Side-effect: leaves $devices with persistence.conf mounted in /live/persistence
1228 # Side-effect: prints info to file $custom_mounts
1230 local custom_mounts=${1}
1234 local bindings="/tmp/bindings.list"
1235 local links="/tmp/links.list"
1236 rm -rf ${bindings} ${links} 2> /dev/null
1238 for device in ${devices}
1240 if [ ! -b "${device}" ]
1245 local device_name="$(basename ${device})"
1246 local backing=$(mount_persistence_media ${device})
1247 if [ -z "${backing}" ]
1253 if [ -r "${backing}/${persistence_list}" ]
1255 include_list="${backing}/${persistence_list}"
1256 elif [ -r "${backing}/${old_persistence_list}" ]
1258 include_list="${backing}/${old_persistence_list}"
1263 if [ -n "${DEBUG}" ] && [ -e "${include_list}" ]
1265 cp ${include_list} /live/persistence/${persistence_list}.${device_name}
1268 while read dir options # < ${include_list}
1270 if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$"
1272 # skipping empty or commented lines
1276 if trim_path ${dir} | grep -q -e "^[^/]" -e "^/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
1278 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."
1284 for opt in $(echo ${options} | tr ',' ' ');
1288 opt_source=${opt#source=}
1296 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
1302 local source="${dir}"
1303 if [ -n "${opt_source}" ]
1305 if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${opt_source}" != "." ]
1307 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"
1310 source="${opt_source}"
1314 local full_source="$(trim_path ${backing}/${source})"
1315 local full_dest="$(trim_path ${rootmnt}/${dir})"
1316 if [ -n "${opt_link}" ]
1318 echo "${device} ${full_source} ${full_dest} ${options}" >> ${links}
1320 echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings}
1322 done < ${include_list}
1325 # We sort the list according to destination so we're sure that
1326 # we won't hide a previous mount. We also ignore duplicate
1327 # destinations in a more or less arbitrary way.
1328 [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
1330 # After all mounts are considered we add symlinks so they
1331 # won't be hidden by some mount.
1332 [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
1334 # We need to make sure that no two custom mounts have the same sources
1335 # or are nested; if that is the case, too much weird stuff can happen.
1336 local prev_source="impossible source" # first iteration must not match
1338 # This sort will ensure that a source /a comes right before a source
1339 # /a/b so we only need to look at the previous source
1340 sort -k2 -b ${custom_mounts} |
1341 while read device source dest options
1343 if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
1345 panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
1347 prev_source=${source}
1352 activate_custom_mounts ()
1354 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1355 local used_devices=""
1357 while read device source dest options # < ${custom_mounts}
1359 local opt_bind="true"
1362 for opt in $(echo ${options} | tr ',' ' ');
1367 unset opt_link opt_union
1371 unset opt_bind opt_union
1375 unset opt_bind opt_link
1380 if [ -n "$(what_is_mounted_on "${dest}")" ]
1382 if [ "${dest}" = "${rootmnt}" ]
1386 log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1391 if [ ! -d "${dest}" ]
1393 # create the destination and delete existing files in
1394 # its path that are in the way
1396 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1398 path=$(trim_path ${path}/${dir})
1406 if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+"
1408 # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case
1409 # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
1410 chown 1000:1000 ${path}
1416 # if ${source} doesn't exist on our persistence media
1417 # we bootstrap it with $dest from the live filesystem.
1418 # this both makes sense and is critical if we're
1419 # dealing with /etc or other system dir.
1420 if [ ! -d "${source}" ]
1422 if [ -n "${PERSISTENCE_READONLY}" ]
1425 elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ]
1427 # unions and don't need to be bootstrapped
1428 # link dirs can't be bootstrapped in a sensible way
1429 mkdir -p "${source}"
1430 chown_ref "${dest}" "${source}"
1431 chmod_ref "${dest}" "${source}"
1432 elif [ -n "${opt_bind}" ]
1434 # ensure that $dest is not copied *into* $source
1435 mkdir -p "$(dirname ${source})"
1436 cp -a "${dest}" "${source}"
1440 # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can
1441 # ignore the loop below and set rootfs_dest_backing=$dest
1442 local rootfs_dest_backing=""
1443 if [ -n "${opt_link}"]
1445 for d in /live/rootfs/*
1447 if [ -n "${rootmnt}" ]
1449 rootfs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1451 rootfs_dest_backing="${d}/${dest}"
1453 if [ -d "${rootfs_dest_backing}" ]
1457 rootfs_dest_backing=""
1462 if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1464 link_files ${source} ${dest} ${rootmnt}
1465 elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1467 mkdir -p /live/persistence
1468 local links_source=$(mktemp -d /live/persistence/links-source-XXXXXX)
1469 chown_ref ${source} ${links_source}
1470 chmod_ref ${source} ${links_source}
1471 # We put the cow dir in the below strange place to
1472 # make it absolutely certain that the link source
1473 # has its own directory and isn't nested with some
1474 # other custom mount (if so that mount's files would
1475 # be linked, causing breakage.
1476 local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})"
1478 chown_ref "${source}" "${cow_dir}"
1479 chmod_ref "${source}" "${cow_dir}"
1480 do_union ${links_source} ${cow_dir} ${source} ${rootfs_dest_backing}
1481 link_files ${links_source} ${dest} ${rootmnt}
1482 elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1484 do_union ${dest} ${source} ${rootfs_dest_backing}
1485 elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1487 mount --bind "${source}" "${dest}"
1488 elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1490 # bind-mount and union mount are handled the same
1491 # in read-only mode, but note that rootfs_dest_backing
1492 # is non-empty (and necessary) only for unions
1493 if [ -n "${rootmnt}" ]
1495 local cow_dir="$(echo ${dest} | sed -e "s|^${rootmnt}|/live/overlay/|")"
1497 # This is happens if persistence is activated
1499 local cow_dir="/live/overlay/${dest}"
1501 if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
1503 # If an earlier custom mount has files here
1504 # it will "block" the current mount's files
1505 # which is undesirable
1509 chown_ref "${source}" "${cow_dir}"
1510 chmod_ref "${source}" "${cow_dir}"
1511 do_union ${dest} ${cow_dir} ${source} ${rootfs_dest_backing}
1514 PERSISTENCE_IS_ON="1"
1515 export PERSISTENCE_IS_ON
1517 if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1519 used_devices="${used_devices} ${device}"
1521 done < ${custom_mounts}
1523 echo ${used_devices}
1530 [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ]