12 DIRECTORY="${1}/${LIVE_MEDIA_PATH}"
13 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs
15 if file_pattern_matches "${DIRECTORY}/"*.${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}"
65 mount_images_in_directory ()
71 if is_live_path "${directory}"
73 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
74 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
76 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
82 sysfs_path="${1#/sys}"
84 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)"
87 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
90 elif echo ${sysfs_path} | grep -q "^/block/dm-"
93 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
105 skip_uuid_check="${3}"
107 # support for fromiso=.../isofrom=....
110 ISO_DEVICE=$(dirname $FROMISO)
111 if ! [ -b $ISO_DEVICE ]
113 # to support unusual device names like /dev/cciss/c0d0p1
114 # as well we have to identify the block device name, let's
115 # do that for up to 15 levels
117 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
119 ISO_DEVICE=$(dirname ${ISO_DEVICE})
120 [ -b "$ISO_DEVICE" ] && break
125 if [ "$ISO_DEVICE" = "/" ]
127 echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
129 fs_type=$(get_fstype "${ISO_DEVICE}")
130 if is_supported_fs ${fs_type}
133 mount -t $fs_type "$ISO_DEVICE" /live/fromiso
134 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
135 loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
136 devname="${loopdevname}"
138 echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
143 if [ -z "${devname}" ]
145 devname=$(sys2dev "${sysdev}")
148 if [ -d "${devname}" ]
150 mount -o bind "${devname}" $mountpoint || continue
152 if is_live_path $mountpoint
162 for device in ${devname}
167 if [ -x /scripts/local-top/lvm2 ]
169 ROOT="$device" resume="" /scripts/local-top/lvm2
174 # Adding raid support
175 if [ -x /scripts/local-top/mdadm ]
177 cp /conf/conf.d/md /conf/conf.d/md.orig
178 echo "MD_DEVS=$device " >> /conf/conf.d/md
179 /scripts/local-top/mdadm
180 mv /conf/conf.d/md.orig /conf/conf.d/md
187 [ -n "$device" ] && devname="$device"
189 [ -e "$devname" ] || continue
191 if [ -n "${LIVE_MEDIA_OFFSET}" ]
193 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
194 devname="${loopdevname}"
197 fstype=$(get_fstype "${devname}")
199 if is_supported_fs ${fstype}
201 devuid=$(blkid -o value -s UUID "$devname")
202 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
203 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
204 [ -n "$devuid" ] && echo "$devuid" >> $tried
206 if [ -n "${FINDISO}" ]
208 if [ -f ${mountpoint}/${FINDISO} ]
211 mkdir -p /live/findiso
212 mount -t ${fstype} -o ro,noatime "${devname}" /live/findiso
213 loopdevname=$(setup_loop "/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
214 devname="${loopdevname}"
215 mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint}
221 if is_live_path ${mountpoint} && \
222 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
227 umount ${mountpoint} 2>/dev/null
231 if [ -n "${LIVE_MEDIA_OFFSET}" ]
233 losetup -d "${loopdevname}"
243 # don't start autodetection before timeout has expired
244 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
246 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
252 # first look at the one specified in the command line
253 case "${LIVE_MEDIA}" in
255 for sysblock in $(removable_usb_dev "sys")
257 for dev in $(subdevices "${sysblock}")
259 if check_dev "${dev}"
269 for sysblock in $(removable_dev "sys")
271 for dev in $(subdevices "${sysblock}")
273 if check_dev "${dev}"
283 if [ ! -z "${LIVE_MEDIA}" ]
285 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
293 # or do the scan of block devices
294 # prefer removable devices over non-removable devices, so scan them first
295 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
297 for sysblock in $devices_to_scan
299 devname=$(sys2dev "${sysblock}")
300 [ -e "$devname" ] || continue
301 fstype=$(get_fstype "${devname}")
303 if /lib/udev/cdrom_id ${devname} > /dev/null
305 if check_dev "null" "${devname}"
309 elif is_nice_device "${sysblock}"
311 for dev in $(subdevices "${sysblock}")
313 if check_dev "${dev}"
318 elif [ "${fstype}" = "squashfs" -o \
319 "${fstype}" = "btrfs" -o \
320 "${fstype}" = "ext2" -o \
321 "${fstype}" = "ext3" -o \
322 "${fstype}" = "ext4" -o \
323 "${fstype}" = "jffs2" ]
325 # This is an ugly hack situation, the block device has
326 # an image directly on it. It's hopefully
327 # live-boot, so take it and run with it.
328 ln -s "${devname}" "${devname}.${fstype}"
329 echo "${devname}.${fstype}"
340 VALUE="$(eval echo -n \${$STRING})"
342 if [ -f /live.vars ] && grep -sq "export ${STRING}" /live.vars
344 sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars
346 echo "export ${STRING}=\"${VALUE}\"" >> /live.vars
349 eval export "${STRING}"="${VALUE}"
352 is_in_list_separator_helper ()
354 local sep element list
360 echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
363 is_in_space_sep_list ()
368 is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
371 is_in_comma_sep_list ()
376 is_in_list_separator_helper "," "${element}" "${*}"
382 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
390 for dev in "${sysblock}"/* "${sysblock}"
392 if [ -e "${dev}/dev" ]
403 black_listed_devices="${1}"
404 white_listed_devices="${2}"
406 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
408 fulldevname=$(sys2dev "${sysblock}")
410 if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
411 [ -n "${white_listed_devices}" ] && \
412 ! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
414 # skip this device entirely
418 for dev in $(subdevices "${sysblock}")
420 devname=$(sys2dev "${dev}")
422 if is_in_space_sep_list ${devname} ${black_listed_devices}
424 # skip this subdevice
437 # Validate input first
438 if [ -z "${fstype}" ]
443 # Try to look if it is already supported by the kernel
444 if grep -q ${fstype} /proc/filesystems
448 # Then try to add support for it the gentle way using the initramfs capabilities
450 if grep -q ${fstype} /proc/filesystems
453 # Then try the hard way if /root is already reachable
455 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
456 if [ -e "${kmodule}" ]
459 if grep -q ${fstype} /proc/filesystems
472 /sbin/blkid -s TYPE -o value $1 2>/dev/null
479 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
484 # remove all unnecessary /:s in the path, including last one (except
485 # if path is just "/")
486 echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|'
489 what_is_mounted_on ()
492 dir="$(trim_path ${1})"
493 grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
498 local reference targets owner
502 owner=$(stat -c %u:%g "${reference}")
503 chown -h ${owner} ${targets}
508 local reference targets rights
512 rights=$(stat -c %a "${reference}")
513 chmod ${rights} ${targets}
529 mounts="$(awk '{print $2}' /proc/mounts)"
530 testpath="$(busybox realpath ${testpath})"
534 if echo "${mounts}" | grep -qs "^${testpath}"
536 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
540 testpath=$(dirname $testpath)
547 # Returns used/free fs kbytes + 5% more
548 # You could pass a block device as ${1} or the mount point as ${2}
554 if [ -z "${mountp}" ]
556 mountp="$(where_is_mounted ${dev})"
558 if [ -z "${mountp}" ]
560 mountp="/mnt/tmp_fs_size"
563 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
569 if [ "${used}" = "used" ]
571 size=$(du -ks ${mountp} | cut -f1)
572 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
575 size="$(df -kP | grep -s ${mountp} | awk '{print $4}')"
578 if [ -n "${doumount}" ]
580 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
590 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
592 loadkeys --quiet /etc/boottime.kmap.gz
598 local fspath module pattern offset encryption readonly
606 # the output of setup_loop is evaluated in other functions,
607 # modprobe leaks kernel options like "libata.dma=0"
608 # as "options libata dma=0" on stdout, causing serious
609 # problems therefor, so instead always avoid output to stdout
610 modprobe -q -b "${module}" 1>/dev/null
614 for loopdev in ${pattern}
616 if [ "$(cat ${loopdev}/size)" -eq 0 ]
618 dev=$(sys2dev "${loopdev}")
621 if [ -n "${readonly}" ]
623 if losetup --help 2>&1 | grep -q -- "-r\b"
625 options="${options} -r"
629 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
631 options="${options} -o ${offset}"
634 if [ -z "${encryption}" ]
636 losetup ${options} "${dev}" "${fspath}"
638 # Loop AES encryption
643 echo -n "Enter passphrase for root filesystem: " >&6
645 echo "${passphrase}" > /tmp/passphrase
647 exec 9</tmp/passphrase
648 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
651 rm -f /tmp/passphrase
653 if [ 0 -eq ${error} ]
660 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
663 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
676 panic "No loop devices available"
686 old_mountp="$(where_is_mounted ${dev})"
688 if [ -n "${old_mountp}" ]
690 if [ "${opts}" != "ro" ]
692 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
695 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
697 if [ -z "${fstype}" ]
699 fstype=$(get_fstype "${dev}")
701 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
702 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > boot.log && return 0 )
706 # Try to mount $device to the place expected by live-boot. If $device
707 # is already mounted somewhere, move it to the expected place. If
708 # we're only probing $device (to check if it has custom persistence)
709 # $probe should be set, which suppresses warnings upon failure. On
710 # success, print the mount point for $device.
711 mount_persistence_media ()
713 local device probe backing old_backing fstype mount_opts
717 backing="/live/persistence/$(basename ${device})"
719 mkdir -p "${backing}"
720 old_backing="$(where_is_mounted ${device})"
721 if [ -z "${old_backing}" ]
723 fstype="$(get_fstype ${device})"
724 mount_opts="rw,noatime"
725 if [ -n "${PERSISTENCE_READONLY}" ]
727 mount_opts="ro,noatime"
729 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
734 [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}"
738 elif [ "${backing}" != "${old_backing}" ]
740 if mount --move ${old_backing} ${backing} >/dev/null
745 [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
750 # This means that $device has already been mounted on
751 # the place expected by live-boot, so we're done.
757 close_persistence_media ()
761 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" ]
829 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
836 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
839 probe_for_gpt_name ()
841 local overlays dev gpt_dev gpt_name
846 if is_active_luks_mapping ${dev}
848 # if $dev is an opened luks device, we need to check
849 # GPT stuff on the backing device
850 gpt_dev=$(get_luks_backing_device "${dev}")
853 if ! is_gpt_device ${gpt_dev}
858 gpt_name=$(get_gpt_name ${gpt_dev})
859 for label in ${overlays}
861 if [ "${gpt_name}" = "${label}" ]
863 echo "${label}=${dev}"
868 probe_for_fs_label ()
874 for label in ${overlays}
876 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
878 echo "${label}=${dev}"
883 probe_for_file_name ()
885 local overlays dev ret backing
890 backing="$(mount_persistence_media ${dev} probe)"
891 if [ -z "${backing}" ]
896 for label in ${overlays}
898 path=${backing}/${PERSISTENCE_PATH}${label}
902 loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
903 ret="${ret} ${label}=${loopdev}"
911 # unmount and remove mountpoint
912 umount ${backing} > /dev/null 2>&1 || true
913 rmdir ${backing} > /dev/null 2>&1 || true
917 find_persistence_media ()
919 # Scans devices for overlays, and returns a whitespace
920 # separated list of how to use them. Only overlays with a partition
921 # label or file name in ${overlays} are returned.
923 # When scanning a LUKS device, the user will be asked to enter the
924 # passphrase; on failure to enter it, or if no persistence partitions
925 # or files were found, the LUKS device is closed.
927 # For all other cases (overlay partition and overlay file) the
928 # return value is "${label}=${device}", where ${device} a device that
929 # can mount the content. In the case of an overlay file, the device
930 # containing the file will remain mounted as a side-effect.
932 # No devices in ${black_listed_devices} will be scanned, and if
933 # ${white_list_devices} is non-empty, only devices in it will be
936 local overlays white_listed_devices ret black_listed_devices
938 white_listed_devices="${2}"
941 black_listed_devices="$(what_is_mounted_on /live/medium) $(what_is_mounted_on /live/findiso) $(what_is_mounted_on /live/fromiso)"
943 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
945 local result luks_device
949 # Check if it's a luks device; we'll have to open the device
950 # in order to probe any filesystem it contains, like we do
951 # below. activate_custom_mounts() also depends on that any luks
952 # device already has been opened.
953 if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${dev}
955 if luks_device=$(open_luks_device "${dev}")
959 # skip $dev since we failed/chose not to open it
962 elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION}
964 # skip $dev since we don't allow unencrypted storage
968 # Probe for matching GPT partition names or filesystem labels
969 if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE}
971 result=$(probe_for_gpt_name "${overlays}" ${dev})
972 if [ -n "${result}" ]
974 ret="${ret} ${result}"
978 result=$(probe_for_fs_label "${overlays}" ${dev})
979 if [ -n "${result}" ]
981 ret="${ret} ${result}"
986 # Probe for files with matching name on mounted partition
987 if is_in_comma_sep_list file ${PERSISTENCE_STORAGE}
989 result=$(probe_for_file_name "${overlays}" ${dev})
990 if [ -n "${result}" ]
993 loopdevice=${result##*=}
994 if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${loopdevice}
998 if luksfile=$(open_luks_device "${loopdevice}")
1000 result=${result%%=*}
1001 result="${result}=${luksfile}"
1003 losetup -d $loopdevice
1007 ret="${ret} ${result}"
1012 # Close luks device if it isn't used
1013 if [ -z "${result}" ] && [ -n "${luks_device}" ] && is_active_luks_mapping "${luks_device}"
1015 /sbin/cryptsetup luksClose "${luks_device}"
1029 for adaptor in /sys/class/net/*
1031 status="$(cat ${adaptor}/iflink)"
1033 if [ "${status}" -eq 2 ]
1035 mac="$(cat ${adaptor}/address)"
1036 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
1043 is_luks_partition ()
1046 /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1
1049 is_active_luks_mapping ()
1052 /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1
1055 get_luks_backing_device ()
1058 cryptsetup status ${device} 2> /dev/null | \
1059 awk '{if ($1 == "device:") print $2}'
1064 output_format="${1}"
1068 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1071 if [ "$(cat ${sysblock}/removable)" = "1" ]
1073 if [ -z "${want_usb}" ]
1077 if readlink ${sysblock} | grep -q usb
1084 if [ "${dev_ok}" = "true" ]
1086 case "${output_format}" in
1088 ret="${ret} ${sysblock}"
1091 devname=$(sys2dev "${sysblock}")
1092 ret="${ret} ${devname}"
1101 removable_usb_dev ()
1103 output_format="${1}"
1105 removable_dev "${output_format}" "want_usb"
1108 non_removable_dev ()
1110 output_format="${1}"
1113 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1115 if [ "$(cat ${sysblock}/removable)" = "0" ]
1117 case "${output_format}" in
1119 ret="${ret} ${sysblock}"
1122 devname=$(sys2dev "${sysblock}")
1123 ret="${ret} ${devname}"
1134 # create source's directory structure in dest, and recursively
1135 # create symlinks in dest to to all files in source. if mask
1136 # is non-empty, remove mask from all source paths when
1137 # creating links (will be necessary if we change root, which
1138 # live-boot normally does (into $rootmnt)).
1139 local src_dir dest_dir src_transform
1141 # remove multiple /:s and ensure ending on /
1142 src_dir="$(trim_path ${1})/"
1143 dest_dir="$(trim_path ${2})/"
1144 src_transform="${3}"
1146 # This check can only trigger on the inital, non-recursive call since
1147 # we create the destination before recursive calls
1148 if [ ! -d "${dest_dir}" ]
1150 log_warning_msg "Must link_files into a directory"
1154 find "${src_dir}" -mindepth 1 -maxdepth 1 | \
1157 local dest final_src
1158 dest="${dest_dir}$(basename "${src}")"
1161 if [ -z "$(ls -A "${src}")" ]
1165 if [ ! -d "${dest}" ]
1168 chown_ref "${src}" "${dest}"
1169 chmod_ref "${src}" "${dest}"
1171 link_files "${src}" "${dest}" "${src_transform}"
1174 if [ -n "${src_transform}" ]
1176 final_src="$(echo ${final_src} | sed "${src_transform}")"
1178 rm -rf "${dest}" 2> /dev/null
1179 ln -s "${final_src}" "${dest}"
1180 chown_ref "${src}" "${dest}"
1187 local unionmountpoint unionrw unionro
1188 unionmountpoint="${1}" # directory where the union is mounted
1190 unionrw="${1}" # branch where the union changes are stored
1192 unionro="${*}" # space separated list of read-only branches (optional)
1194 case "${UNIONTYPE}" in
1212 case "${UNIONTYPE}" in
1214 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1215 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
1216 if [ -n "${unionro}" ]
1218 for rofs in ${unionro}
1220 unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
1223 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1224 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1225 ( mkdir -p /run/sendsigs.omit.d
1226 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1230 # XXX: can multiple unionro be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1231 # XXX: and can unionro be optional? i.e. can overlayfs skip lowerdir?
1232 if echo ${unionro} | grep -q " "
1234 panic "Multiple lower filesystems are currently not supported with overlayfs (unionro = ${unionro})."
1235 elif [ -z "${unionro}" ]
1237 panic "Overlayfs needs at least one lower filesystem (read-only branch)."
1239 unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}"
1240 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1244 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1245 if [ -n "${unionro}" ]
1247 for rofs in ${unionro}
1249 unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
1252 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1257 get_custom_mounts ()
1259 # Side-effect: leaves $devices with persistence.conf mounted in /live/persistence
1260 # Side-effect: prints info to file $custom_mounts
1262 local custom_mounts devices bindings links
1267 bindings="/tmp/bindings.list"
1268 links="/tmp/links.list"
1269 rm -rf ${bindings} ${links} 2> /dev/null
1271 for device in ${devices}
1273 if [ ! -b "${device}" ]
1278 local device_name backing include_list
1279 device_name="$(basename ${device})"
1280 backing=$(mount_persistence_media ${device})
1281 if [ -z "${backing}" ]
1286 if [ -r "${backing}/${persistence_list}" ]
1288 include_list="${backing}/${persistence_list}"
1289 elif [ -r "${backing}/${old_persistence_list}" ]
1291 include_list="${backing}/${old_persistence_list}"
1296 if [ -n "${LIVE_BOOT_DEBUG}" ] && [ -e "${include_list}" ]
1298 cp ${include_list} /live/persistence/${persistence_list}.${device_name}
1301 while read dir options # < ${include_list}
1303 if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$"
1305 # skipping empty or commented lines
1309 if trim_path ${dir} | grep -q -e "^[^/]" -e "^/lib" -e "^/lib/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
1311 log_warning_msg "Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/lib\", or \"/lib/live\" or any of its sub-directories."
1315 local opt_source opt_link source full_source full_dest
1318 for opt in $(echo ${options} | tr ',' ' ');
1322 opt_source=${opt#source=}
1330 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
1337 if [ -n "${opt_source}" ]
1339 if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${opt_source}" != "." ]
1341 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"
1344 source="${opt_source}"
1348 full_source="$(trim_path ${backing}/${source})"
1349 full_dest="$(trim_path ${rootmnt}/${dir})"
1350 if [ -n "${opt_link}" ]
1352 echo "${device} ${full_source} ${full_dest} ${options}" >> ${links}
1354 echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings}
1356 done < ${include_list}
1359 # We sort the list according to destination so we're sure that
1360 # we won't hide a previous mount. We also ignore duplicate
1361 # destinations in a more or less arbitrary way.
1362 [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
1364 # After all mounts are considered we add symlinks so they
1365 # won't be hidden by some mount.
1366 [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
1368 # We need to make sure that no two custom mounts have the same sources
1369 # or are nested; if that is the case, too much weird stuff can happen.
1370 local prev_source prev_dest
1371 prev_source="impossible source" # first iteration must not match
1373 # This sort will ensure that a source /a comes right before a source
1374 # /a/b so we only need to look at the previous source
1375 sort -k2 -b ${custom_mounts} |
1376 while read device source dest options
1378 if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
1380 panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
1382 prev_source=${source}
1387 activate_custom_mounts ()
1389 local custom_mounts used_devices
1390 custom_mounts="${1}" # the ouput from get_custom_mounts()
1393 while read device source dest options # < ${custom_mounts}
1395 local opt_bind opt_link opt_union
1399 for opt in $(echo ${options} | tr ',' ' ');
1404 unset opt_link opt_union
1408 unset opt_bind opt_union
1412 unset opt_bind opt_link
1417 if [ -n "$(what_is_mounted_on "${dest}")" ]
1419 if [ "${dest}" = "${rootmnt}" ]
1423 log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1428 if [ ! -d "${dest}" ]
1430 # create the destination and delete existing files in
1431 # its path that are in the way
1433 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1435 path=$(trim_path ${path}/${dir})
1443 if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+"
1445 # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case
1446 # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
1447 chown 1000:1000 ${path}
1453 # if ${source} doesn't exist on our persistence media
1454 # we bootstrap it with $dest from the live filesystem.
1455 # this both makes sense and is critical if we're
1456 # dealing with /etc or other system dir.
1457 if [ ! -d "${source}" ]
1459 if [ -n "${PERSISTENCE_READONLY}" ]
1462 elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ]
1464 # unions and don't need to be bootstrapped
1465 # link dirs can't be bootstrapped in a sensible way
1466 mkdir -p "${source}"
1467 chown_ref "${dest}" "${source}"
1468 chmod_ref "${dest}" "${source}"
1469 elif [ -n "${opt_bind}" ]
1471 # ensure that $dest is not copied *into* $source
1472 mkdir -p "$(dirname ${source})"
1473 cp -a "${dest}" "${source}"
1477 # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can
1478 # ignore the loop below and set rootfs_dest_backing=$dest
1479 local rootfs_dest_backing
1480 rootfs_dest_backing=""
1481 if [ -n "${opt_link}" ] || [ -n "${opt_union}" ]
1483 for d in /live/rootfs/*
1485 if [ -n "${rootmnt}" ]
1487 fs="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1493 rootfs_dest_backing="${rootfs_dest_backing} ${fs}"
1498 local cow_dir links_source
1499 if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1501 link_files ${source} ${dest} "s|^/live/|/lib/live/mount/|"
1502 elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1504 mkdir -p ${rootmnt}/lib/live/mount/persistence
1505 links_source=$(mktemp -d ${rootmnt}/lib/live/mount/persistence/links-source-XXXXXX)
1506 chown_ref ${source} ${links_source}
1507 chmod_ref ${source} ${links_source}
1508 # We put the cow dir in the below strange place to
1509 # make it absolutely certain that the link source
1510 # has its own directory and isn't nested with some
1511 # other custom mount (if so that mount's files would
1512 # be linked, causing breakage.
1513 cow_dir="/live/overlay/lib/live/mount/persistence/$(basename ${links_source})"
1515 chown_ref "${source}" "${cow_dir}"
1516 chmod_ref "${source}" "${cow_dir}"
1517 do_union ${links_source} ${cow_dir} ${source} ${rootfs_dest_backing}
1518 link_files ${links_source} ${dest} "s|^${rootmnt}||"
1519 elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1521 do_union ${dest} ${source} ${rootfs_dest_backing}
1522 elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1524 mount --bind "${source}" "${dest}"
1525 elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1527 # bind-mount and union mount are handled the same
1528 # in read-only mode, but note that rootfs_dest_backing
1529 # is non-empty (and necessary) only for unions
1530 cow_dir="/live/overlay/${dest}"
1531 if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
1533 # If an earlier custom mount has files here
1534 # it will "block" the current mount's files
1535 # which is undesirable
1539 chown_ref "${source}" "${cow_dir}"
1540 chmod_ref "${source}" "${cow_dir}"
1541 do_union ${dest} ${cow_dir} ${source} ${rootfs_dest_backing}
1544 PERSISTENCE_IS_ON="1"
1545 export PERSISTENCE_IS_ON
1547 if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1549 used_devices="${used_devices} ${device}"
1551 done < ${custom_mounts}
1553 echo ${used_devices}
1560 [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ]