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" ]
743 find_persistent_media ()
745 # Scans devices for overlays and snapshots, and returns a whitespace
746 # separated list of how to use them. Only overlays with a partition
747 # label or file name in ${overlays} are returned, and ditto for
748 # snapshots with labels in ${snapshots}.
750 # When scanning a LUKS device, the user will be asked to enter the
751 # passphrase; on failure to enter it, or if no persistent partitions
752 # or files were found, the LUKS device is closed.
754 # For a snapshot file the return value is ${label}=${snapdata}", where
755 # ${snapdata} is the parameter used for try_snap().
757 # For all other cases (overlay/snapshot partition and overlay file) the
758 # return value is "${label}=${device}", where ${device} a device that
759 # can mount the content. In the case of an overlay file, the device
760 # containing the file will remain mounted as a side-effect.
762 # No devices in ${black_listed_devices} will be scanned, and if
763 # ${white_list_devices} is non-empty, only devices in it will be
768 black_listed_devices="${3}"
769 white_listed_devices="${4}"
770 persistent_backing="${rootmnt}/live/persistent"
772 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
776 # Checking for a luks device
777 if echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>" && \
778 /sbin/cryptsetup isLuks ${dev}
780 if luks_device=$(open_luks_device "${dev}")
784 # skip $dev since we failed/chose not to open it
787 elif echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<none\>"
789 # skip $dev since we don't allow unencrypted storage
793 if echo ${PERSISTENT_STORAGE} | grep -qe "\<filesystem\>"
795 for label in ${overlays} ${snapshots}
797 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
799 echo "${label}=${dev}"
800 # skip to the next device
808 if echo ${PERSISTENT_STORAGE} | grep -qe "\<file\>"
810 devfstype="$(get_fstype ${dev})"
811 backing="${persistent_backing}/$(basename ${dev})"
812 mkdir -p "${backing}"
813 if is_supported_fs ${devfstype} && try_mount "${dev}" "${backing}" "rw" "${devfstype}"
815 for label in ${overlays}
817 path=${backing}/${PERSISTENT_PATH}${label}
821 echo "${label}=$(setup_loop "${path}" "loop" "/sys/block/loop*")"
825 for label in ${snapshots}
827 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
829 path="${PERSISTENT_PATH}${label}.${ext}"
830 if [ -f "${backing}/${path}" ]
832 snapshot_on_dev="yes"
833 echo "${label}=${dev}:${backing}:${path}"
838 if [ -z "${overlay_on_dev}" ] && [ -z "${snapshot_on_dev}" ]
840 umount ${backing} > /dev/null 2>&1 || true
843 if [ -z "${overlay_on_dev}" ] && [ -z "${snapshot_on_dev}" ] && \
844 [ -n "${luks_device}" ] && \
845 /sbin/cryptsetup status "${luks_device}" 1> /dev/null 2>&1
847 /sbin/cryptsetup luksClose "${luks_device}"
856 for adaptor in /sys/class/net/*
858 status="$(cat ${adaptor}/iflink)"
860 if [ "${status}" -eq 2 ]
862 mac="$(cat ${adaptor}/address)"
863 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
873 if [ -x /sbin/cryptsetup ]
875 /sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}
889 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
892 if [ "$(cat ${sysblock}/removable)" = "1" ]
894 if [ -z "${want_usb}" ]
898 if readlink ${sysblock} | grep -q usb
905 if [ "${dev_ok}" = "yes" ]
907 case "${output_format}" in
909 ret="${ret} ${sysblock}"
912 devname=$(sys2dev "${sysblock}")
913 ret="${ret} ${devname}"
926 removable_dev "${output_format}" "want_usb"
934 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
936 if [ "$(cat ${sysblock}/removable)" = "0" ]
938 case "${output_format}" in
940 ret="${ret} ${sysblock}"
943 devname=$(sys2dev "${sysblock}")
944 ret="${ret} ${devname}"
955 # create source's directory structure in dest, and recursively
956 # create symlinks in dest to to all files in source. if mask
957 # is non-empty, remove mask from all source paths when
958 # creating links (will be necessary if we change root, which
959 # live-boot normally does (into $rootmnt)).
961 # remove multiple /:s and ensure ending on /
962 local src_dir="$(echo "${1}"/ | sed -e 's|/\+|/|g')"
963 local dest_dir="$(echo "${2}"/ | sed -e 's|/\+|/|g')"
964 local src_mask="${3}"
966 # This check can only trigger on the inital, non-recursive call since
967 # we create the destination before recursive calls
968 if [ ! -d "${dest_dir}" ];
970 log_warning_msg "Must link_files into a directory"
974 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read x; do
976 local dest="${dest_dir}$(basename "${x}")"
979 if [ -z "$(ls -A "${src}")" ];
983 if [ ! -d "${dest}" ];
986 prev="$(dirname "${dest}")"
987 chown $(stat -c %u:%g "${prev}") "${dest}"
988 chmod $(stat -c %a "${prev}") "${dest}"
990 link_files "${src}" "${dest}" "${src_mask}"
992 if [ -n "${src_mask}" ]
994 src="$(echo ${src} | sed "s|^${src_mask}||")"
996 rm -rf "${dest}" 2> /dev/null
997 ln -s "${src}" "${dest}"
1003 local unionmountpoint="${1}" # directory where the union is mounted
1004 local unionrw="${2}" # branch where the union changes are stored
1005 local unionro1="${3}" # first underlying read-only branch (optional)
1006 local unionro2="${4}" # second underlying read-only branch (optional)
1008 if [ "${UNIONTYPE}" = "aufs" ]
1013 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1022 case "${UNIONTYPE}" in
1024 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1025 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
1026 if [ -n "${unionro1}" ]
1028 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1030 if [ -n "${unionro2}" ]
1032 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1034 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1035 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1036 ( mkdir -p /run/sendsigs.omit.d
1037 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1041 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1042 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
1043 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
1044 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1048 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1049 if [ -n "${unionro1}" ]
1051 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1053 if [ -n "${unionro2}" ]
1055 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1057 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1062 get_custom_mounts () {
1063 # Side-effect: leaves $devices with live.persist mounted in ${rootmnt}/live/persistent
1064 # Side-effect: prints info to file $custom_mounts
1066 local devices="${1}"
1067 local custom_mounts="${2}" # print result to this file
1068 local rootmnt="${3}" # should be set empty post-live-boot
1070 local bindings="/bindings.list"
1071 local links="/links.list"
1072 rm -rf ${bindings} ${links} 2> /dev/null
1073 local persistent_backing="${rootmnt}/live/persistent"
1075 for device in ${devices}
1077 if [ ! -b "${device}" ]
1081 local device_name="$(basename ${device})"
1082 local backing="${persistent_backing}/${device_name}"
1083 mkdir -p "${backing}"
1084 local device_fstype="$(get_fstype ${device})"
1085 if [ -z "${PERSISTENT_READONLY}" ]
1087 device_mount_opts="rw,noatime"
1089 device_mount_opts="ro,noatime"
1091 local device_used=""
1092 mount -t "${device_fstype}" -o "${device_mount_opts}" "${device}" "${backing}"
1093 local include_list="${backing}/${persistence_list}"
1094 if [ ! -r "${include_list}" ]
1101 [ "${DEBUG}" = "Yes" ] && cp ${include_list} ${persistent_backing}/${persistence_list}.${device_name}
1102 while read source dest options # < ${include_list}
1104 if echo ${source} | grep -qe "^[[:space:]]*\(#.*\)\?$"
1106 # skipping empty or commented lines
1110 if echo ${dest} | grep -qe "^[^/]"
1114 elif [ -z "${dest}" ]
1119 if echo ${dest} | grep -qe "^/\+$\|^/\+live\(/.*\)\?$"
1121 # mounting on / or /live could cause trouble
1122 log_warning_msg "Skipping unsafe custom mount on ${dest}"
1126 for opt in $(echo ${options} | tr ',' ' ');
1132 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
1138 # FIXME: handle case: we already have /a/b in
1139 # $bindings added from current $device, but
1140 # now we find /a -- /a should replace /a/b in
1143 # FIXME: handle case: we have /a in $bindings
1144 # from current $device, now we find /a/b, so
1147 # ensure that no multiple-/ occur in paths
1148 local full_source="$(echo ${backing}/${source}/ | sed -e 's|/\+|/|g')"
1149 local full_dest="$(echo ${rootmnt}/${dest}/ | sed -e 's|/\+|/|g')"
1151 if echo ${options} | grep -qe "\<linkfiles\>";
1153 echo "${full_source} ${full_dest} ${options}" >> ${links}
1155 echo "${full_source} ${full_dest} ${options}" >> ${bindings}
1157 done < ${include_list}
1159 if [ -z "${device_used}" ]
1161 # this device was not used for / earlier, or
1162 # custom mount point now, so it's useless
1168 # We sort the list according to destination so we're sure that
1169 # we won't hide a previous mount. We also ignore duplicate
1170 # destinations in a more or less arbitrary way.
1171 [ -e "${bindings}" ] && sort -k2 -sbu ${bindings} >> ${custom_mounts}
1174 # After all mounts are considered we add symlinks so they
1175 # won't be hidden by some mount.
1176 [ -e "${links}" ] && sort -k2 -sbu ${links} >> ${custom_mounts}
1179 rm -f ${bindings} ${links} 2> /dev/null
1180 echo ${custom_mounts}
1183 do_custom_mounts () {
1184 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1185 local rootmnt="${2}" # should be set empty post-live-boot
1187 while read source dest options # < ${custom_mounts}
1189 local opt_linkfiles=""
1191 for opt in $(echo ${options} | tr ',' ' ');
1203 if mountpoint -q "${dest}";
1205 log_warning_msg "Skipping custom mount ${source} on ${dest}: destination is already a mount point"
1209 # FIXME: we don't handle already existing
1210 # non-directory files in the paths of both $source and
1213 if [ ! -d "${dest}" ]
1215 # if ${dest} is in /home/$user, try fixing
1217 # FIXME: this should really be handled by
1218 # live-config since we don't know for sure
1219 # which uid a certain user has until then
1220 if echo ${dest} | grep -qe "^${rootmnt}/*home/\+[^/]\+"
1223 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1229 # assume that the intended user is the first, which is usually the case
1230 chown 1000:1000 ${path}
1238 # if ${source} doesn't exist on our persistent media
1239 # we bootstrap it with $dest from the live filesystem.
1240 # this both makes sense and is critical if we're
1241 # dealing with /etc or other system dir.
1242 if [ ! -d "${source}" ]
1244 if [ -n "${PERSISTENT_READONLY}" ] || [ -n "${opt_linkfiles}" ]
1247 elif [ -n "${opt_union}" ]
1249 # union's don't need to be bootstrapped
1252 # ensure that $dest is not copied *into* $source
1253 mkdir -p "$(dirname ${source})"
1254 cp -a "${dest}" "${source}"
1258 rofs_dest_backing=""
1259 for d in ${rootmnt}/live/rofs/*
1261 if [ -n "${rootmnt}" ]
1263 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1265 rofs_dest_backing="${d}/${dest}"
1268 if [ -d "${rofs_dest_backing}" ]
1272 rofs_dest_backing=""
1276 if [ -z "${PERSISTENT_READONLY}" ]
1278 if [ -n "${opt_linkfiles}" ]
1280 links_source="${source}"
1281 links_dest="${dest}"
1282 elif [ -n "${opt_union}" ]
1284 do_union ${dest} ${source} ${rofs_dest_backing}
1286 mount --bind "${source}" "${dest}"
1289 if [ -n "${opt_linkfiles}" ]
1291 links_dest="${dest}"
1292 dest="$(mktemp -d ${persistent_backing}/links_source-XXXXXX)"
1293 links_source="${dest}"
1295 if [ -n "${rootmnt}" ]
1297 cow_dir="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
1299 cow_dir="/live/cow/${dest}"
1302 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1305 if [ -n "${opt_linkfiles}" ]
1307 link_files "${links_source}" "${links_dest}" "${rootmnt}"
1310 PERSISTENCE_IS_ON="1"
1311 export PERSISTENCE_IS_ON
1312 done < ${custom_mounts}