1 # live-boot helper functions, used by live-boot on boot and by live-snapshot
3 if [ ! -x "/bin/fstype" ]
5 # klibc not in path -> not in initramfs
6 export PATH="${PATH}:/usr/lib/klibc/bin"
9 # handle upgrade path from old udev (using udevinfo) to
10 # recent versions of udev (using udevadm info)
11 if [ -x /sbin/udevadm ]
13 udevinfo='/sbin/udevadm info'
18 root_overlay_label="full-ov"
19 old_root_overlay_label="live-rw"
20 old_home_overlay_label="home-rw"
21 custom_overlay_label="custom-ov"
22 root_snapshot_label="live-sn"
23 old_root_snapshot_label="live-sn"
24 home_snapshot_label="home-sn"
25 persistence_list="live.persist"
32 for ARGUMENT in $(cat /proc/cmdline)
41 export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
45 ACCESS="${ARGUMENT#access=}"
50 DEFCONSOLE="${ARGUMENT#*=}"
66 # Force dhcp even while netbooting
67 # Use for debugging in case somebody works on fixing dhclient
77 DEVICE="${ARGUMENT#ethdevice=}"
79 export DEVICE ETHDEVICE
83 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
88 FETCH="${ARGUMENT#fetch=}"
93 FORCEPERSISTENTFSCK="Yes"
94 export FORCEPERSISTENTFSCK
98 FTPFS="${ARGUMENT#ftpfs=}"
103 HTTPFS="${ARGUMENT#httpfs=}"
108 ISCSI="${ARGUMENT#iscsi=}"
109 #ip:port - separated by ;
110 ISCSI_PORTAL="${ISCSI%;*}"
111 if echo "${ISCSI_PORTAL}" | grep -q , ; then
112 ISCSI_SERVER="${ISCSI_PORTAL%,*}"
113 ISCSI_PORT="${ISCSI_PORTAL#*,}"
116 ISCSI_TARGET="${ISCSI#*;}"
117 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
121 FROMISO="${ARGUMENT#*=}"
131 INTEGRITY_CHECK="Yes"
132 export INTEGRITY_CHECK
136 STATICIP="${ARGUMENT#ip=}"
138 if [ -z "${STATICIP}" ]
151 live-media=*|bootfrom=*)
152 LIVE_MEDIA="${ARGUMENT#*=}"
156 live-media-encryption=*|encryption=*)
157 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
158 export LIVE_MEDIA_ENCRYPTION
162 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
163 export LIVE_MEDIA_OFFSET
167 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
168 export LIVE_MEDIA_PATH
171 live-media-timeout=*)
172 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
173 export LIVE_MEDIA_TIMEOUT
177 MODULE="${ARGUMENT#module=}"
182 NETBOOT="${ARGUMENT#netboot=}"
187 NFSOPTS="${ARGUMENT#nfsopts=}"
192 NFS_COW="${ARGUMENT#nfscow=}"
197 NOACCESSIBILITY="Yes"
198 export NOACCESSIBILITY
217 ramdisk_size="${ARGUMENT#ramdisk-size=}"
230 persistent-encryption=*)
231 PERSISTENT_ENCRYPTION="${ARGUMENT#*=}"
232 export PERSISTENT_ENCRYPTION
236 PERSISTENT_MEDIA="${ARGUMENT#*=}"
237 export PERSISTENT_MEDIA
240 PERSISTENT_METHOD="${ARGUMENT#*=}"
241 export PERSISTENT_METHOD
245 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
246 export PERSISTENT_PATH
248 persistent-read-only)
249 PERSISTENT_READONLY="Yes"
250 export PERSISTENT_READONLY
253 persistent-storage=*)
254 PERSISTENT_STORAGE="${ARGUMENT#persistent-storage=}"
255 export PERSISTENT_STORAGE
258 persistent-subtext=*)
259 root_overlay_label="${root_overlay_label}-${ARGUMENT#persistent-subtext=}"
260 old_root_overlay_label="${old_root_overlay_label}-${ARGUMENT#persistent-subtext=}"
261 old_home_overlay_label="${old_home_overlay_label}-${ARGUMENT#persistent-subtext=}"
262 custom_overlay_label="${custom_overlay_label}-${ARGUMENT#persistent-subtext=}"
263 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
264 old_root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
265 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
279 NOPROMPT="${ARGUMENT#noprompt=}"
284 QUICKUSBMODULES="Yes"
285 export QUICKUSBMODULES
288 preseed/file=*|file=*)
289 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
299 question="${ARGUMENT%%=*}"
300 value="${ARGUMENT#*=}"
301 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
316 TODISK="${ARGUMENT#todisk=}"
327 MODULETORAM="${ARGUMENT#toram=}"
328 export TORAM MODULETORAM
342 SKIP_UNION_MOUNTS="Yes"
343 export SKIP_UNION_MOUNTS
347 ROOT="${ARGUMENT#root=}"
352 UNIONTYPE="${ARGUMENT#union=}"
358 # sort of compatibility with netboot.h from linux docs
359 if [ -z "${NETBOOT}" ]
361 if [ "${ROOT}" = "/dev/nfs" ]
365 elif [ "${ROOT}" = "/dev/cifs" ]
372 if [ -z "${MODULE}" ]
378 if [ -z "${UNIONTYPE}" ]
384 if [ -z "${PERSISTENT_ENCRYPTION}" ]
386 PERSISTENT_ENCRYPTION="none"
387 export PERSISTENT_ENCRYPTION
388 elif echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>"
390 if ! modprobe dm-crypt
392 log_warning_msg "Unable to load module dm-crypt"
393 PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
394 export PERSISTENT_ENCRYPTION
397 if [ ! -x /lib/cryptsetup/askpass ] || [ ! -x /sbin/cryptsetup ]
399 log_warning_msg "cryptsetup in unavailable"
400 PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
401 export PERSISTENT_ENCRYPTION
405 if [ -z "${PERSISTENT_METHOD}" ]
407 PERSISTENT_METHOD="snapshot,overlay"
408 export PERSISTENT_METHOD
411 if [ -z "${PERSISTENT_STORAGE}" ]
413 PERSISTENT_STORAGE="filesystem,file"
414 export PERSISTENT_STORAGE
421 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
429 for dev in "${sysblock}"/* "${sysblock}"
431 if [ -e "${dev}/dev" ]
442 black_listed_devices="${1}"
443 white_listed_devices="${2}"
445 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
447 fulldevname=$(sys2dev "${sysblock}")
449 if echo "${black_listed_devices}" | grep -qe "\<${fulldevname}\>" || \
450 [ -n "${white_listed_devices}" ] && \
451 echo "${white_listed_devices}" | grep -qve "\<${fulldevname}\>"
453 # skip this device entirely
457 for dev in $(subdevices "${sysblock}")
459 devname=$(sys2dev "${dev}")
461 if echo "${black_listed_devices}" | grep -qe "\<${devname}\>"
463 # skip this subdevice
476 # Validate input first
477 if [ -z "${fstype}" ]
482 # Try to look if it is already supported by the kernel
483 if grep -q ${fstype} /proc/filesystems
487 # Then try to add support for it the gentle way using the initramfs capabilities
489 if grep -q ${fstype} /proc/filesystems
492 # Then try the hard way if /root is already reachable
494 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
495 if [ -e "${kmodule}" ]
498 if grep -q ${fstype} /proc/filesystems
511 /sbin/blkid -s TYPE -o value $1 2>/dev/null
518 if grep -q "^${device} " /proc/mounts
520 # return the first found
521 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
538 mounts="$(awk '{print $2}' /proc/mounts)"
539 testpath="$(busybox realpath ${testpath})"
543 if echo "${mounts}" | grep -qs "^${testpath}"
545 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
549 testpath=$(dirname $testpath)
556 # Returns used/free fs kbytes + 5% more
557 # You could pass a block device as ${1} or the mount point as ${2}
563 if [ -z "${mountp}" ]
565 mountp="$(where_is_mounted ${dev})"
567 if [ -z "${mountp}" ]
569 mountp="/mnt/tmp_fs_size"
572 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
578 if [ "${used}" = "used" ]
580 size=$(du -ks ${mountp} | cut -f1)
581 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
584 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
587 if [ -n "${doumount}" ]
589 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
599 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
601 loadkeys /etc/boottime.kmap.gz
611 local encryption=${5}
614 # the output of setup_loop is evaluated in other functions,
615 # modprobe leaks kernel options like "libata.dma=0"
616 # as "options libata dma=0" on stdout, causing serious
617 # problems therefor, so instead always avoid output to stdout
618 modprobe -q -b "${module}" 1>/dev/null
622 for loopdev in ${pattern}
624 if [ "$(cat ${loopdev}/size)" -eq 0 ]
626 dev=$(sys2dev "${loopdev}")
629 if [ -n "${readonly}" ]
631 if losetup --help 2>&1 | grep -q -- "-r\b"
633 options="${options} -r"
637 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
639 options="${options} -o ${offset}"
642 if [ -z "${encryption}" ]
644 losetup ${options} "${dev}" "${fspath}"
646 # Loop AES encryption
651 echo -n "Enter passphrase for root filesystem: " >&6
653 echo "${passphrase}" > /tmp/passphrase
655 exec 9</tmp/passphrase
656 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
659 rm -f /tmp/passphrase
661 if [ 0 -eq ${error} ]
668 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
671 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
684 panic "No loop devices available"
694 old_mountp="$(where_is_mounted ${dev})"
696 if [ -n "${old_mountp}" ]
698 if [ "${opts}" != "ro" ]
700 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
703 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
705 if [ -z "${fstype}" ]
707 fstype=$(get_fstype "${dev}")
709 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
710 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > live-boot.log && return 0 )
717 name="$(basename ${dev})"
719 if [ -n "${PERSISTENT_READONLY}" ]
721 opts="${opts} --readonly"
728 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
729 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
733 luks_device="/dev/mapper/${name}"
739 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
742 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
751 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
756 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
759 probe_for_gpt_name ()
761 local overlays="${1}"
762 local snapshots="${2}"
765 if ! is_gpt_device ${dev} || \
766 ( echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<luks\>" && \
767 /sbin/cryptsetup isLuks ${dev} > /dev/null 2>&1 )
771 for label in ${overlays} ${snapshots}
773 if [ "$(get_gpt_name ${dev})" = "${label}" ]
775 echo "${label}=${dev}"
780 probe_for_fs_label () {
781 local overlays="${1}"
782 local snapshots="${2}"
785 for label in ${overlays} ${snapshots}
787 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
789 echo "${label}=${dev}"
794 probe_for_file_name () {
795 local overlays="${1}"
796 local snapshots="${2}"
799 local devfstype="$(get_fstype ${dev})"
800 local backing="${rootmnt}/live/persistent/$(basename ${dev})"
802 if is_supported_fs ${devfstype} && mkdir -p "${backing}" && \
803 try_mount "${dev}" "${backing}" "rw" "${devfstype}"
805 for label in ${overlays}
807 path=${backing}/${PERSISTENT_PATH}${label}
810 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
811 ret="${ret} ${label}=${loopdev}"
814 for label in ${snapshots}
816 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
818 path="${PERSISTENT_PATH}${label}.${ext}"
819 if [ -f "${backing}/${path}" ]
821 ret="${ret} ${label}=${dev}:${backing}:${path}"
830 umount ${backing} > /dev/null 2>&1 || true
835 find_persistent_media ()
837 # Scans devices for overlays and snapshots, and returns a whitespace
838 # separated list of how to use them. Only overlays with a partition
839 # label or file name in ${overlays} are returned, and ditto for
840 # snapshots with labels in ${snapshots}.
842 # When scanning a LUKS device, the user will be asked to enter the
843 # passphrase; on failure to enter it, or if no persistent partitions
844 # or files were found, the LUKS device is closed.
846 # For a snapshot file the return value is ${label}=${snapdata}", where
847 # ${snapdata} is the parameter used for try_snap().
849 # For all other cases (overlay/snapshot partition and overlay file) the
850 # return value is "${label}=${device}", where ${device} a device that
851 # can mount the content. In the case of an overlay file, the device
852 # containing the file will remain mounted as a side-effect.
854 # No devices in ${black_listed_devices} will be scanned, and if
855 # ${white_list_devices} is non-empty, only devices in it will be
858 local overlays="${1}"
859 local snapshots="${2}"
860 local black_listed_devices="${3}"
861 local white_listed_devices="${4}"
864 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
870 # Check if it's a luks device; we'll have to open the device
871 # in order to probe any filesystem it contains, like we do
872 # below. do_custom_mounts() also depends on that any luks
873 # device already has been opened.
874 if echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>" && \
875 /sbin/cryptsetup isLuks ${dev} >/dev/null 2>&1
877 if luks_device=$(open_luks_device "${dev}")
882 # skip $dev since we failed/chose not to open it
885 elif echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<none\>"
887 # skip $dev since we don't allow unencrypted storage
891 # Probe for matching GPT partition names or filesystem labels
892 if echo ${PERSISTENT_STORAGE} | grep -qe "\<filesystem\>"
894 local gpt_dev="${dev}"
895 if [ -n "${luks_device}" ]
897 # When we probe GPT partitions we need to look
898 # at the real device, not the virtual, opened
900 gpt_dev="${real_dev}"
902 result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${gpt_dev})
903 if [ -n "${result}" ]
905 ret="${ret} ${result}"
909 result=$(probe_for_fs_label "${overlays}" "${snapshots}" ${dev})
910 if [ -n "${result}" ]
912 ret="${ret} ${result}"
917 # Probe for files with matching name on mounted partition
918 if echo ${PERSISTENT_STORAGE} | grep -qe "\<file\>"
920 result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
921 if [ -n "${result}" ]
923 ret="${ret} ${result}"
928 # Close luks device if it isn't used
929 if [ -z "${result}" ] && [ -n "${luks_device}" ] && \
930 /sbin/cryptsetup status "${luks_device}" 1> /dev/null 2>&1
932 /sbin/cryptsetup luksClose "${luks_device}"
946 for adaptor in /sys/class/net/*
948 status="$(cat ${adaptor}/iflink)"
950 if [ "${status}" -eq 2 ]
952 mac="$(cat ${adaptor}/address)"
953 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
963 if [ -x /sbin/cryptsetup ]
965 /sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}
979 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
982 if [ "$(cat ${sysblock}/removable)" = "1" ]
984 if [ -z "${want_usb}" ]
988 if readlink ${sysblock} | grep -q usb
995 if [ "${dev_ok}" = "yes" ]
997 case "${output_format}" in
999 ret="${ret} ${sysblock}"
1002 devname=$(sys2dev "${sysblock}")
1003 ret="${ret} ${devname}"
1012 removable_usb_dev ()
1014 output_format="${1}"
1016 removable_dev "${output_format}" "want_usb"
1019 non_removable_dev ()
1021 output_format="${1}"
1024 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1026 if [ "$(cat ${sysblock}/removable)" = "0" ]
1028 case "${output_format}" in
1030 ret="${ret} ${sysblock}"
1033 devname=$(sys2dev "${sysblock}")
1034 ret="${ret} ${devname}"
1045 # create source's directory structure in dest, and recursively
1046 # create symlinks in dest to to all files in source. if mask
1047 # is non-empty, remove mask from all source paths when
1048 # creating links (will be necessary if we change root, which
1049 # live-boot normally does (into $rootmnt)).
1051 # remove multiple /:s and ensure ending on /
1052 local src_dir="$(echo "${1}"/ | sed -e 's|/\+|/|g')"
1053 local dest_dir="$(echo "${2}"/ | sed -e 's|/\+|/|g')"
1054 local src_mask="${3}"
1056 # This check can only trigger on the inital, non-recursive call since
1057 # we create the destination before recursive calls
1058 if [ ! -d "${dest_dir}" ];
1060 log_warning_msg "Must link_files into a directory"
1064 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read x; do
1066 local dest="${dest_dir}$(basename "${x}")"
1069 if [ -z "$(ls -A "${src}")" ];
1073 if [ ! -d "${dest}" ];
1076 prev="$(dirname "${dest}")"
1077 chown --reference "${prev}" "${dest}"
1078 chmod --reference "${prev}" "${dest}"
1080 link_files "${src}" "${dest}" "${src_mask}"
1082 if [ -n "${src_mask}" ]
1084 src="$(echo ${src} | sed "s|^${src_mask}||")"
1086 rm -rf "${dest}" 2> /dev/null
1087 ln -s "${src}" "${dest}"
1093 local unionmountpoint="${1}" # directory where the union is mounted
1094 local unionrw="${2}" # branch where the union changes are stored
1095 local unionro1="${3}" # first underlying read-only branch (optional)
1096 local unionro2="${4}" # second underlying read-only branch (optional)
1098 if [ "${UNIONTYPE}" = "aufs" ]
1103 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1112 case "${UNIONTYPE}" in
1114 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1115 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
1116 if [ -n "${unionro1}" ]
1118 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1120 if [ -n "${unionro2}" ]
1122 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1124 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1125 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1126 ( mkdir -p /run/sendsigs.omit.d
1127 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1131 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1132 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
1133 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
1134 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1138 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1139 if [ -n "${unionro1}" ]
1141 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1143 if [ -n "${unionro2}" ]
1145 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1147 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1152 get_custom_mounts () {
1153 # Side-effect: leaves $devices with live.persist mounted in ${rootmnt}/live/persistent
1154 # Side-effect: prints info to file $custom_mounts
1156 local devices="${1}"
1157 local custom_mounts="${2}" # print result to this file
1158 local rootmnt="${3}" # should be set empty post-live-boot
1160 local bindings="/bindings.list"
1161 local links="/links.list"
1162 rm -rf ${bindings} ${links} 2> /dev/null
1163 local persistent_backing="${rootmnt}/live/persistent"
1165 for device in ${devices}
1167 if [ ! -b "${device}" ]
1172 local device_name="$(basename ${device})"
1173 local device_used=""
1174 # $device may already have been mounted by
1175 # probe_for_file_name() in find_persistent_media() ...
1176 local backing=$(where_is_mounted ${device})
1177 if [ -z "${backing}" ]
1179 # ... otherwise we mount it now
1180 backing="${persistent_backing}/${device_name}"
1181 mkdir -p "${backing}"
1182 local device_fstype="$(get_fstype ${device})"
1183 if [ -z "${PERSISTENT_READONLY}" ]
1185 device_mount_opts="rw,noatime"
1187 device_mount_opts="ro,noatime"
1189 if ! mount -t "${device_fstype}" -o "${device_mount_opts}" "${device}" "${backing}" >/dev/null 2>&1
1191 log_warning_msg "Could not mount persistent media ${device} (${device_fstype})"
1194 local include_list="${backing}/${persistence_list}"
1195 if [ ! -r "${include_list}" ]
1197 umount "${backing}" >/dev/null 2>&1
1198 rmdir "${backing}" >/dev/null 2>&1
1199 if /sbin/cryptsetup status ${device_name} >/dev/null 2>&1
1201 /sbin/cryptsetup luksClose "${device_name}"
1206 [ "${DEBUG}" = "Yes" ] && cp ${include_list} ${persistent_backing}/${persistence_list}.${device_name}
1207 while read source dest options # < ${include_list}
1209 if echo ${source} | grep -qe "^[[:space:]]*\(#.*\)\?$"
1211 # skipping empty or commented lines
1215 if echo ${dest} | grep -qe "^[^/]"
1219 elif [ -z "${dest}" ]
1224 if echo ${dest} | grep -qe "^/\+$\|^/\+live\(/.*\)\?$"
1226 # mounting on / or /live could cause trouble
1227 log_warning_msg "Skipping unsafe custom mount on ${dest}"
1231 for opt in $(echo ${options} | tr ',' ' ');
1237 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
1243 # FIXME: handle case: we already have /a/b in
1244 # $bindings added from current $device, but
1245 # now we find /a -- /a should replace /a/b in
1248 # FIXME: handle case: we have /a in $bindings
1249 # from current $device, now we find /a/b, so
1252 # ensure that no multiple-/ occur in paths
1253 local full_source="$(echo ${backing}/${source}/ | sed -e 's|/\+|/|g')"
1254 local full_dest="$(echo ${rootmnt}/${dest}/ | sed -e 's|/\+|/|g')"
1256 if echo ${options} | grep -qe "\<linkfiles\>";
1258 echo "${full_source} ${full_dest} ${options}" >> ${links}
1260 echo "${full_source} ${full_dest} ${options}" >> ${bindings}
1262 done < ${include_list}
1264 if [ -z "${device_used}" ]
1266 # this device was not used for / earlier, or
1267 # custom mount point now, so it's useless
1273 # We sort the list according to destination so we're sure that
1274 # we won't hide a previous mount. We also ignore duplicate
1275 # destinations in a more or less arbitrary way.
1276 [ -e "${bindings}" ] && sort -k2 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
1278 # After all mounts are considered we add symlinks so they
1279 # won't be hidden by some mount.
1280 [ -e "${links}" ] && sort -k2 -sbu ${links} >> ${custom_mounts} && rm ${links}
1283 do_custom_mounts () {
1284 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1285 local rootmnt="${2}" # should be set empty post-live-boot
1287 while read source dest options # < ${custom_mounts}
1289 local opt_linkfiles=""
1291 for opt in $(echo ${options} | tr ',' ' ');
1303 if mountpoint -q "${dest}";
1305 log_warning_msg "Skipping custom mount ${source} on ${dest}: destination is already a mount point"
1309 # FIXME: we don't handle already existing
1310 # non-directory files in the paths of both $source and
1313 if [ ! -d "${dest}" ]
1315 # if ${dest} is in /home/$user, try fixing
1317 # FIXME: this should really be handled by
1318 # live-config since we don't know for sure
1319 # which uid a certain user has until then
1320 if echo ${dest} | grep -qe "^${rootmnt}/*home/\+[^/]\+"
1323 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1329 # assume that the intended user is the first, which is usually the case
1330 chown 1000:1000 ${path}
1338 # if ${source} doesn't exist on our persistent media
1339 # we bootstrap it with $dest from the live filesystem.
1340 # this both makes sense and is critical if we're
1341 # dealing with /etc or other system dir.
1342 if [ ! -d "${source}" ]
1344 if [ -n "${PERSISTENT_READONLY}" ] || [ -n "${opt_linkfiles}" ]
1347 elif [ -n "${opt_union}" ]
1349 # union's don't need to be bootstrapped
1352 # ensure that $dest is not copied *into* $source
1353 mkdir -p "$(dirname ${source})"
1354 cp -a "${dest}" "${source}"
1358 rofs_dest_backing=""
1359 for d in ${rootmnt}/live/rofs/*
1361 if [ -n "${rootmnt}" ]
1363 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1365 rofs_dest_backing="${d}/${dest}"
1368 if [ -d "${rofs_dest_backing}" ]
1372 rofs_dest_backing=""
1376 if [ -z "${PERSISTENT_READONLY}" ]
1378 if [ -n "${opt_linkfiles}" ]
1380 links_source="${source}"
1381 links_dest="${dest}"
1382 elif [ -n "${opt_union}" ]
1384 do_union ${dest} ${source} ${rofs_dest_backing}
1386 mount --bind "${source}" "${dest}"
1389 if [ -n "${opt_linkfiles}" ]
1391 links_dest="${dest}"
1392 dest="$(mktemp -d ${persistent_backing}/links_source-XXXXXX)"
1393 links_source="${dest}"
1395 if [ -n "${rootmnt}" ]
1397 cow_dir="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
1399 cow_dir="/live/cow/${dest}"
1402 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1405 if [ -n "${opt_linkfiles}" ]
1407 link_files "${links_source}" "${links_dest}" "${rootmnt}"
1410 PERSISTENCE_IS_ON="1"
1411 export PERSISTENCE_IS_ON
1412 done < ${custom_mounts}
1415 fix_home_rw_compatibility ()
1419 if [ -n "${PERSISTENT_READONLY}" ]
1424 local backing="$(where_is_mounted ${device})"
1425 if [ -z "${backing}" ]
1427 backing="${rootmnt}/live/persistent/$(basename ${device})"
1428 mkdir -p "${backing}"
1429 local device_fstype="$(get_fstype ${device})"
1430 local device_mount_opts="rw,noatime"
1431 if ! mount -t "${device_fstype}" -o "${device_mount_opts}" "${device}" "${backing}" >/dev/null 2>&1
1436 local include_list="${backing}/${persistence_list}"
1437 if [ ! -r "${include_list}" ]
1439 echo "# home-rw backwards compatibility:
1440 . /home" > "${include_list}"