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 custom_overlay_label="custom-ov"
20 root_snapshot_label="live-sn"
21 home_snapshot_label="home-sn"
22 persistence_list="live.persist"
29 for ARGUMENT in $(cat /proc/cmdline)
38 export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
42 ACCESS="${ARGUMENT#access=}"
47 DEFCONSOLE="${ARGUMENT#*=}"
63 # Force dhcp even while netbooting
64 # Use for debugging in case somebody works on fixing dhclient
74 DEVICE="${ARGUMENT#ethdevice=}"
76 export DEVICE ETHDEVICE
80 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
85 FETCH="${ARGUMENT#fetch=}"
90 FORCEPERSISTENTFSCK="Yes"
91 export FORCEPERSISTENTFSCK
95 FTPFS="${ARGUMENT#ftpfs=}"
100 HTTPFS="${ARGUMENT#httpfs=}"
105 ISCSI="${ARGUMENT#iscsi=}"
106 #ip:port - separated by ;
107 ISCSI_PORTAL="${ISCSI%;*}"
108 if echo "${ISCSI_PORTAL}" | grep -q , ; then
109 ISCSI_SERVER="${ISCSI_PORTAL%,*}"
110 ISCSI_PORT="${ISCSI_PORTAL#*,}"
113 ISCSI_TARGET="${ISCSI#*;}"
114 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
118 FROMISO="${ARGUMENT#*=}"
128 INTEGRITY_CHECK="Yes"
129 export INTEGRITY_CHECK
133 STATICIP="${ARGUMENT#ip=}"
135 if [ -z "${STATICIP}" ]
148 live-media=*|bootfrom=*)
149 LIVE_MEDIA="${ARGUMENT#*=}"
153 live-media-encryption=*|encryption=*)
154 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
155 export LIVE_MEDIA_ENCRYPTION
159 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
160 export LIVE_MEDIA_OFFSET
164 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
165 export LIVE_MEDIA_PATH
168 live-media-timeout=*)
169 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
170 export LIVE_MEDIA_TIMEOUT
174 MODULE="${ARGUMENT#module=}"
179 NETBOOT="${ARGUMENT#netboot=}"
184 NFSOPTS="${ARGUMENT#nfsopts=}"
189 NFS_COW="${ARGUMENT#nfscow=}"
194 NOACCESSIBILITY="Yes"
195 export NOACCESSIBILITY
214 ramdisk_size="${ARGUMENT#ramdisk-size=}"
227 persistent-encryption=*)
228 PERSISTENT_ENCRYPTION="${ARGUMENT#*=}"
229 export PERSISTENT_ENCRYPTION
233 PERSISTENT_MEDIA="${ARGUMENT#*=}"
234 export PERSISTENT_MEDIA
237 PERSISTENT_METHOD="${ARGUMENT#*=}"
238 export PERSISTENT_METHOD
242 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
243 export PERSISTENT_PATH
245 persistent-read-only)
246 PERSISTENT_READONLY="Yes"
247 export PERSISTENT_READONLY
250 persistent-storage=*)
251 PERSISTENT_STORAGE="${ARGUMENT#persistent-storage=}"
252 export PERSISTENT_STORAGE
255 persistent-subtext=*)
256 root_overlay_label="${root_overlay_label}-${ARGUMENT#persistent-subtext=}"
257 custom_overlay_label="${custom_overlay_label}-${ARGUMENT#persistent-subtext=}"
258 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
259 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
273 NOPROMPT="${ARGUMENT#noprompt=}"
278 QUICKUSBMODULES="Yes"
279 export QUICKUSBMODULES
282 preseed/file=*|file=*)
283 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
293 question="${ARGUMENT%%=*}"
294 value="${ARGUMENT#*=}"
295 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
310 TODISK="${ARGUMENT#todisk=}"
321 MODULETORAM="${ARGUMENT#toram=}"
322 export TORAM MODULETORAM
336 SKIP_UNION_MOUNTS="Yes"
337 export SKIP_UNION_MOUNTS
341 ROOT="${ARGUMENT#root=}"
346 UNIONTYPE="${ARGUMENT#union=}"
352 # sort of compatibility with netboot.h from linux docs
353 if [ -z "${NETBOOT}" ]
355 if [ "${ROOT}" = "/dev/nfs" ]
359 elif [ "${ROOT}" = "/dev/cifs" ]
366 if [ -z "${MODULE}" ]
372 if [ -z "${UNIONTYPE}" ]
378 if [ -z "${PERSISTENT_ENCRYPTION}" ]
380 PERSISTENT_ENCRYPTION="none"
381 export PERSISTENT_ENCRYPTION
382 elif echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>"
384 if ! modprobe dm-crypt
386 log_warning_msg "Unable to load module dm-crypt"
387 PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
388 export PERSISTENT_ENCRYPTION
391 if [ ! -x /lib/cryptsetup/askpass ] || [ ! -x /sbin/cryptsetup ]
393 log_warning_msg "cryptsetup in unavailable"
394 PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
395 export PERSISTENT_ENCRYPTION
399 if [ -z "${PERSISTENT_METHOD}" ]
401 PERSISTENT_METHOD="snapshot,overlay"
402 export PERSISTENT_METHOD
405 if [ -z "${PERSISTENT_STORAGE}" ]
407 PERSISTENT_STORAGE="filesystem,file"
408 export PERSISTENT_STORAGE
415 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
423 for dev in "${sysblock}"/* "${sysblock}"
425 if [ -e "${dev}/dev" ]
436 black_listed_devices="${1}"
437 white_listed_devices="${2}"
439 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
441 fulldevname=$(sys2dev "${sysblock}")
443 if echo "${black_listed_devices}" | grep -qe "\<${fulldevname}\>" || \
444 [ -n "${white_listed_devices}" ] && \
445 echo "${white_listed_devices}" | grep -qve "\<${fulldevname}\>"
447 # skip this device entirely
451 for dev in $(subdevices "${sysblock}")
453 devname=$(sys2dev "${dev}")
455 if echo "${black_listed_devices}" | grep -qe "\<${devname}\>"
457 # skip this subdevice
470 # Validate input first
471 if [ -z "${fstype}" ]
476 # Try to look if it is already supported by the kernel
477 if grep -q ${fstype} /proc/filesystems
481 # Then try to add support for it the gentle way using the initramfs capabilities
483 if grep -q ${fstype} /proc/filesystems
486 # Then try the hard way if /root is already reachable
488 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
489 if [ -e "${kmodule}" ]
492 if grep -q ${fstype} /proc/filesystems
505 /sbin/blkid -s TYPE -o value $1 2>/dev/null
512 if grep -q "^${device} " /proc/mounts
514 # return the first found
515 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
532 mounts="$(awk '{print $2}' /proc/mounts)"
533 testpath="$(busybox realpath ${testpath})"
537 if echo "${mounts}" | grep -qs "^${testpath}"
539 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
543 testpath=$(dirname $testpath)
550 # Returns used/free fs kbytes + 5% more
551 # You could pass a block device as ${1} or the mount point as ${2}
557 if [ -z "${mountp}" ]
559 mountp="$(where_is_mounted ${dev})"
561 if [ -z "${mountp}" ]
563 mountp="/mnt/tmp_fs_size"
566 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
572 if [ "${used}" = "used" ]
574 size=$(du -ks ${mountp} | cut -f1)
575 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
578 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
581 if [ -n "${doumount}" ]
583 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
593 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
595 loadkeys /etc/boottime.kmap.gz
605 local encryption=${5}
608 # the output of setup_loop is evaluated in other functions,
609 # modprobe leaks kernel options like "libata.dma=0"
610 # as "options libata dma=0" on stdout, causing serious
611 # problems therefor, so instead always avoid output to stdout
612 modprobe -q -b "${module}" 1>/dev/null
616 for loopdev in ${pattern}
618 if [ "$(cat ${loopdev}/size)" -eq 0 ]
620 dev=$(sys2dev "${loopdev}")
623 if [ -n "${readonly}" ]
625 if losetup --help 2>&1 | grep -q -- "-r\b"
627 options="${options} -r"
631 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
633 options="${options} -o ${offset}"
636 if [ -z "${encryption}" ]
638 losetup ${options} "${dev}" "${fspath}"
640 # Loop AES encryption
645 echo -n "Enter passphrase for root filesystem: " >&6
647 echo "${passphrase}" > /tmp/passphrase
649 exec 9</tmp/passphrase
650 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
653 rm -f /tmp/passphrase
655 if [ 0 -eq ${error} ]
662 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
665 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
678 panic "No loop devices available"
688 old_mountp="$(where_is_mounted ${dev})"
690 if [ -n "${old_mountp}" ]
692 if [ "${opts}" != "ro" ]
694 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
697 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
699 if [ -z "${fstype}" ]
701 fstype=$(get_fstype "${dev}")
703 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
704 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > live-boot.log && return 0 )
711 name="$(basename ${dev})"
713 if [ -n "${PERSISTENT_READONLY}" ]
715 opts="${opts} --readonly"
722 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
723 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
727 luks_device="/dev/mapper/${name}"
733 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
736 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
745 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
750 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
753 probe_for_gpt_name ()
755 local overlays="${1}"
756 local snapshots="${2}"
759 if ! is_gpt_device ${dev} || \
760 ( echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<luks\>" && \
761 /sbin/cryptsetup isLuks ${dev} > /dev/null 2>&1 )
765 for label in ${overlays} ${snapshots}
767 if [ "$(get_gpt_name ${dev})" = "${label}" ]
769 echo "${label}=${dev}"
774 probe_for_fs_label () {
775 local overlays="${1}"
776 local snapshots="${2}"
779 for label in ${overlays} ${snapshots}
781 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
783 echo "${label}=${dev}"
788 probe_for_file_name () {
789 local overlays="${1}"
790 local snapshots="${2}"
793 local devfstype="$(get_fstype ${dev})"
794 local backing="${rootmnt}/live/persistent/$(basename ${dev})"
796 if is_supported_fs ${devfstype} && mkdir -p "${backing}" && \
797 try_mount "${dev}" "${backing}" "rw" "${devfstype}"
799 for label in ${overlays}
801 path=${backing}/${PERSISTENT_PATH}${label}
804 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
805 ret="${ret} ${label}=${loopdev}"
808 for label in ${snapshots}
810 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
812 path="${PERSISTENT_PATH}${label}.${ext}"
813 if [ -f "${backing}/${path}" ]
815 ret="${ret} ${label}=${dev}:${backing}:${path}"
824 umount ${backing} > /dev/null 2>&1 || true
829 find_persistent_media ()
831 # Scans devices for overlays and snapshots, and returns a whitespace
832 # separated list of how to use them. Only overlays with a partition
833 # label or file name in ${overlays} are returned, and ditto for
834 # snapshots with labels in ${snapshots}.
836 # When scanning a LUKS device, the user will be asked to enter the
837 # passphrase; on failure to enter it, or if no persistent partitions
838 # or files were found, the LUKS device is closed.
840 # For a snapshot file the return value is ${label}=${snapdata}", where
841 # ${snapdata} is the parameter used for try_snap().
843 # For all other cases (overlay/snapshot partition and overlay file) the
844 # return value is "${label}=${device}", where ${device} a device that
845 # can mount the content. In the case of an overlay file, the device
846 # containing the file will remain mounted as a side-effect.
848 # No devices in ${black_listed_devices} will be scanned, and if
849 # ${white_list_devices} is non-empty, only devices in it will be
852 local overlays="${1}"
853 local snapshots="${2}"
854 local black_listed_devices="${3}"
855 local white_listed_devices="${4}"
858 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
864 # Check if it's a luks device; we'll have to open the device
865 # in order to probe any filesystem it contains, like we do
866 # below. do_custom_mounts() also depends on that any luks
867 # device already has been opened.
868 if echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>" && \
869 /sbin/cryptsetup isLuks ${dev} >/dev/null 2>&1
871 if luks_device=$(open_luks_device "${dev}")
876 # skip $dev since we failed/chose not to open it
879 elif echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<none\>"
881 # skip $dev since we don't allow unencrypted storage
885 # Probe for matching GPT partition names or filesystem labels
886 if echo ${PERSISTENT_STORAGE} | grep -qe "\<filesystem\>"
888 local gpt_dev="${dev}"
889 if [ -n "${luks_device}" ]
891 # When we probe GPT partitions we need to look
892 # at the real device, not the virtual, opened
894 gpt_dev="${real_dev}"
896 result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${gpt_dev})
897 if [ -n "${result}" ]
899 ret="${ret} ${result}"
903 result=$(probe_for_fs_label "${overlays}" "${snapshots}" ${dev})
904 if [ -n "${result}" ]
906 ret="${ret} ${result}"
911 # Probe for files with matching name on mounted partition
912 if echo ${PERSISTENT_STORAGE} | grep -qe "\<file\>"
914 result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
915 if [ -n "${result}" ]
917 ret="${ret} ${result}"
922 # Close luks device if it isn't used
923 if [ -z "${result}" ] && [ -n "${luks_device}" ] && \
924 /sbin/cryptsetup status "${luks_device}" 1> /dev/null 2>&1
926 /sbin/cryptsetup luksClose "${luks_device}"
940 for adaptor in /sys/class/net/*
942 status="$(cat ${adaptor}/iflink)"
944 if [ "${status}" -eq 2 ]
946 mac="$(cat ${adaptor}/address)"
947 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
957 if [ -x /sbin/cryptsetup ]
959 /sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}
973 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
976 if [ "$(cat ${sysblock}/removable)" = "1" ]
978 if [ -z "${want_usb}" ]
982 if readlink ${sysblock} | grep -q usb
989 if [ "${dev_ok}" = "yes" ]
991 case "${output_format}" in
993 ret="${ret} ${sysblock}"
996 devname=$(sys2dev "${sysblock}")
997 ret="${ret} ${devname}"
1006 removable_usb_dev ()
1008 output_format="${1}"
1010 removable_dev "${output_format}" "want_usb"
1013 non_removable_dev ()
1015 output_format="${1}"
1018 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1020 if [ "$(cat ${sysblock}/removable)" = "0" ]
1022 case "${output_format}" in
1024 ret="${ret} ${sysblock}"
1027 devname=$(sys2dev "${sysblock}")
1028 ret="${ret} ${devname}"
1039 # create source's directory structure in dest, and recursively
1040 # create symlinks in dest to to all files in source. if mask
1041 # is non-empty, remove mask from all source paths when
1042 # creating links (will be necessary if we change root, which
1043 # live-boot normally does (into $rootmnt)).
1045 # remove multiple /:s and ensure ending on /
1046 local src_dir="$(echo "${1}"/ | sed -e 's|/\+|/|g')"
1047 local dest_dir="$(echo "${2}"/ | sed -e 's|/\+|/|g')"
1048 local src_mask="${3}"
1050 # This check can only trigger on the inital, non-recursive call since
1051 # we create the destination before recursive calls
1052 if [ ! -d "${dest_dir}" ];
1054 log_warning_msg "Must link_files into a directory"
1058 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read x; do
1060 local dest="${dest_dir}$(basename "${x}")"
1063 if [ -z "$(ls -A "${src}")" ];
1067 if [ ! -d "${dest}" ];
1070 prev="$(dirname "${dest}")"
1071 chown --reference "${prev}" "${dest}"
1072 chmod --reference "${prev}" "${dest}"
1074 link_files "${src}" "${dest}" "${src_mask}"
1076 if [ -n "${src_mask}" ]
1078 src="$(echo ${src} | sed "s|^${src_mask}||")"
1080 rm -rf "${dest}" 2> /dev/null
1081 ln -s "${src}" "${dest}"
1087 local unionmountpoint="${1}" # directory where the union is mounted
1088 local unionrw="${2}" # branch where the union changes are stored
1089 local unionro1="${3}" # first underlying read-only branch (optional)
1090 local unionro2="${4}" # second underlying read-only branch (optional)
1092 if [ "${UNIONTYPE}" = "aufs" ]
1097 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1106 case "${UNIONTYPE}" in
1108 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1109 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
1110 if [ -n "${unionro1}" ]
1112 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1114 if [ -n "${unionro2}" ]
1116 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1118 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1119 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1120 ( mkdir -p /run/sendsigs.omit.d
1121 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1125 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1126 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
1127 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
1128 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1132 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1133 if [ -n "${unionro1}" ]
1135 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1137 if [ -n "${unionro2}" ]
1139 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1141 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1146 get_custom_mounts () {
1147 # Side-effect: leaves $devices with live.persist mounted in ${rootmnt}/live/persistent
1148 # Side-effect: prints info to file $custom_mounts
1150 local devices="${1}"
1151 local custom_mounts="${2}" # print result to this file
1152 local rootmnt="${3}" # should be set empty post-live-boot
1154 local bindings="/bindings.list"
1155 local links="/links.list"
1156 rm -rf ${bindings} ${links} 2> /dev/null
1157 local persistent_backing="${rootmnt}/live/persistent"
1159 for device in ${devices}
1161 if [ ! -b "${device}" ]
1166 local device_name="$(basename ${device})"
1167 local device_used=""
1168 # $device may already have been mounted by
1169 # probe_for_file_name() in find_persistent_media() ...
1170 local backing=$(where_is_mounted ${device})
1171 if [ -z "${backing}" ]
1173 # ... otherwise we mount it now
1174 backing="${persistent_backing}/${device_name}"
1175 mkdir -p "${backing}"
1176 local device_fstype="$(get_fstype ${device})"
1177 if [ -z "${PERSISTENT_READONLY}" ]
1179 device_mount_opts="rw,noatime"
1181 device_mount_opts="ro,noatime"
1183 if ! mount -t "${device_fstype}" -o "${device_mount_opts}" "${device}" "${backing}" >/dev/null 2>&1
1185 log_warning_msg "Could not mount persistent media ${device} (${device_fstype})"
1188 local include_list="${backing}/${persistence_list}"
1189 if [ ! -r "${include_list}" ]
1191 umount "${backing}" >/dev/null 2>&1
1192 rmdir "${backing}" >/dev/null 2>&1
1193 if /sbin/cryptsetup status ${device_name} >/dev/null 2>&1
1195 /sbin/cryptsetup luksClose "${device_name}"
1200 [ "${DEBUG}" = "Yes" ] && cp ${include_list} ${persistent_backing}/${persistence_list}.${device_name}
1201 while read source dest options # < ${include_list}
1203 if echo ${source} | grep -qe "^[[:space:]]*\(#.*\)\?$"
1205 # skipping empty or commented lines
1209 if echo ${dest} | grep -qe "^[^/]"
1213 elif [ -z "${dest}" ]
1218 if echo ${dest} | grep -qe "^/\+$\|^/\+live\(/.*\)\?$"
1220 # mounting on / or /live could cause trouble
1221 log_warning_msg "Skipping unsafe custom mount on ${dest}"
1225 for opt in $(echo ${options} | tr ',' ' ');
1231 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
1237 # FIXME: handle case: we already have /a/b in
1238 # $bindings added from current $device, but
1239 # now we find /a -- /a should replace /a/b in
1242 # FIXME: handle case: we have /a in $bindings
1243 # from current $device, now we find /a/b, so
1246 # ensure that no multiple-/ occur in paths
1247 local full_source="$(echo ${backing}/${source}/ | sed -e 's|/\+|/|g')"
1248 local full_dest="$(echo ${rootmnt}/${dest}/ | sed -e 's|/\+|/|g')"
1250 if echo ${options} | grep -qe "\<linkfiles\>";
1252 echo "${full_source} ${full_dest} ${options}" >> ${links}
1254 echo "${full_source} ${full_dest} ${options}" >> ${bindings}
1256 done < ${include_list}
1258 if [ -z "${device_used}" ]
1260 # this device was not used for / earlier, or
1261 # custom mount point now, so it's useless
1267 # We sort the list according to destination so we're sure that
1268 # we won't hide a previous mount. We also ignore duplicate
1269 # destinations in a more or less arbitrary way.
1270 [ -e "${bindings}" ] && sort -k2 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
1272 # After all mounts are considered we add symlinks so they
1273 # won't be hidden by some mount.
1274 [ -e "${links}" ] && sort -k2 -sbu ${links} >> ${custom_mounts} && rm ${links}
1277 do_custom_mounts () {
1278 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1279 local rootmnt="${2}" # should be set empty post-live-boot
1281 while read source dest options # < ${custom_mounts}
1283 local opt_linkfiles=""
1285 for opt in $(echo ${options} | tr ',' ' ');
1297 if mountpoint -q "${dest}";
1299 log_warning_msg "Skipping custom mount ${source} on ${dest}: destination is already a mount point"
1303 # FIXME: we don't handle already existing
1304 # non-directory files in the paths of both $source and
1307 if [ ! -d "${dest}" ]
1309 # if ${dest} is in /home/$user, try fixing
1311 # FIXME: this should really be handled by
1312 # live-config since we don't know for sure
1313 # which uid a certain user has until then
1314 if echo ${dest} | grep -qe "^${rootmnt}/*home/\+[^/]\+"
1317 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1323 # assume that the intended user is the first, which is usually the case
1324 chown 1000:1000 ${path}
1332 # if ${source} doesn't exist on our persistent media
1333 # we bootstrap it with $dest from the live filesystem.
1334 # this both makes sense and is critical if we're
1335 # dealing with /etc or other system dir.
1336 if [ ! -d "${source}" ]
1338 if [ -n "${PERSISTENT_READONLY}" ] || [ -n "${opt_linkfiles}" ]
1341 elif [ -n "${opt_union}" ]
1343 # union's don't need to be bootstrapped
1346 # ensure that $dest is not copied *into* $source
1347 mkdir -p "$(dirname ${source})"
1348 cp -a "${dest}" "${source}"
1352 rofs_dest_backing=""
1353 for d in ${rootmnt}/live/rofs/*
1355 if [ -n "${rootmnt}" ]
1357 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1359 rofs_dest_backing="${d}/${dest}"
1362 if [ -d "${rofs_dest_backing}" ]
1366 rofs_dest_backing=""
1370 if [ -z "${PERSISTENT_READONLY}" ]
1372 if [ -n "${opt_linkfiles}" ]
1374 links_source="${source}"
1375 links_dest="${dest}"
1376 elif [ -n "${opt_union}" ]
1378 do_union ${dest} ${source} ${rofs_dest_backing}
1380 mount --bind "${source}" "${dest}"
1383 if [ -n "${opt_linkfiles}" ]
1385 links_dest="${dest}"
1386 dest="$(mktemp -d ${persistent_backing}/links_source-XXXXXX)"
1387 links_source="${dest}"
1389 if [ -n "${rootmnt}" ]
1391 cow_dir="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
1393 cow_dir="/live/cow/${dest}"
1396 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1399 if [ -n "${opt_linkfiles}" ]
1401 link_files "${links_source}" "${links_dest}" "${rootmnt}"
1404 PERSISTENCE_IS_ON="1"
1405 export PERSISTENCE_IS_ON
1406 done < ${custom_mounts}