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'
23 for ARGUMENT in $(cat /proc/cmdline)
32 export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
36 ACCESS="${ARGUMENT#access=}"
41 DEFCONSOLE="${ARGUMENT#*=}"
57 # Force dhcp even while netbooting
58 # Use for debugging in case somebody works on fixing dhclient
68 DEVICE="${ARGUMENT#ethdevice=}"
70 export DEVICE ETHDEVICE
74 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
79 FETCH="${ARGUMENT#fetch=}"
84 FORCEPERSISTENTFSCK="Yes"
85 export FORCEPERSISTENTFSCK
89 FTPFS="${ARGUMENT#ftpfs=}"
94 HTTPFS="${ARGUMENT#httpfs=}"
99 ISCSI="${ARGUMENT#iscsi=}"
100 #ip:port - separated by ;
101 ISCSI_PORTAL="${ISCSI%;*}"
102 if echo "${ISCSI_PORTAL}" | grep -q , ; then
103 ISCSI_SERVER="${ISCSI_PORTAL%,*}"
104 ISCSI_PORT="${ISCSI_PORTAL#*,}"
107 ISCSI_TARGET="${ISCSI#*;}"
108 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
112 FROMISO="${ARGUMENT#*=}"
122 INTEGRITY_CHECK="Yes"
123 export INTEGRITY_CHECK
127 STATICIP="${ARGUMENT#ip=}"
129 if [ -z "${STATICIP}" ]
142 live-media=*|bootfrom=*)
143 LIVE_MEDIA="${ARGUMENT#*=}"
147 live-media-encryption=*|encryption=*)
148 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
149 export LIVE_MEDIA_ENCRYPTION
153 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
154 export LIVE_MEDIA_OFFSET
158 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
159 export LIVE_MEDIA_PATH
162 live-media-timeout=*)
163 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
164 export LIVE_MEDIA_TIMEOUT
168 MODULE="${ARGUMENT#module=}"
173 NETBOOT="${ARGUMENT#netboot=}"
178 NFSOPTS="${ARGUMENT#nfsopts=}"
183 NFS_COW="${ARGUMENT#nfscow=}"
188 NOACCESSIBILITY="Yes"
189 export NOACCESSIBILITY
208 ramdisk_size="${ARGUMENT#ramdisk-size=}"
221 persistent-encryption=*)
222 PERSISTENT_ENCRYPTION="${ARGUMENT#*=}"
223 export PERSISTENT_ENCRYPTION
227 PERSISTENT_MEDIA="${ARGUMENT#*=}"
228 export PERSISTENT_MEDIA
231 PERSISTENT_METHOD="${ARGUMENT#*=}"
232 export PERSISTENT_METHOD
236 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
237 export PERSISTENT_PATH
239 persistent-read-only)
240 PERSISTENT_READONLY="Yes"
241 export PERSISTENT_READONLY
244 persistent-storage=*)
245 PERSISTENT_STORAGE="${ARGUMENT#persistent-storage=}"
246 export PERSISTENT_STORAGE
249 persistent-subtext=*)
250 root_overlay_label="${root_overlay_label}-${ARGUMENT#persistent-subtext=}"
251 custom_overlay_label="${custom_overlay_label}-${ARGUMENT#persistent-subtext=}"
252 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
253 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
267 NOPROMPT="${ARGUMENT#noprompt=}"
272 QUICKUSBMODULES="Yes"
273 export QUICKUSBMODULES
276 preseed/file=*|file=*)
277 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
287 question="${ARGUMENT%%=*}"
288 value="${ARGUMENT#*=}"
289 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
304 TODISK="${ARGUMENT#todisk=}"
315 MODULETORAM="${ARGUMENT#toram=}"
316 export TORAM MODULETORAM
330 SKIP_UNION_MOUNTS="Yes"
331 export SKIP_UNION_MOUNTS
335 ROOT="${ARGUMENT#root=}"
340 UNIONTYPE="${ARGUMENT#union=}"
346 # sort of compatibility with netboot.h from linux docs
347 if [ -z "${NETBOOT}" ]
349 if [ "${ROOT}" = "/dev/nfs" ]
353 elif [ "${ROOT}" = "/dev/cifs" ]
360 if [ -z "${MODULE}" ]
366 if [ -z "${UNIONTYPE}" ]
372 if [ -z "${PERSISTENT_ENCRYPTION}" ]
374 PERSISTENT_ENCRYPTION="none"
375 export PERSISTENT_ENCRYPTION
376 elif echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>"
378 if ! modprobe dm-crypt
380 log_warning_msg "Unable to load module dm-crypt"
381 PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
382 export PERSISTENT_ENCRYPTION
385 if [ ! -x /lib/cryptsetup/askpass ] || [ ! -x /sbin/cryptsetup ]
387 log_warning_msg "cryptsetup in unavailable"
388 PERSISTENT_ENCRYPTION=$(echo ${PERSISTENT_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
389 export PERSISTENT_ENCRYPTION
393 if [ -z "${PERSISTENT_METHOD}" ]
395 PERSISTENT_METHOD="snapshot,overlay"
396 export PERSISTENT_METHOD
399 if [ -z "${PERSISTENT_STORAGE}" ]
401 PERSISTENT_STORAGE="filesystem,file"
402 export PERSISTENT_STORAGE
409 echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
417 for dev in "${sysblock}"/* "${sysblock}"
419 if [ -e "${dev}/dev" ]
430 black_listed_devices="${1}"
431 white_listed_devices="${2}"
433 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd")
435 fulldevname=$(sys2dev "${sysblock}")
437 if echo "${black_listed_devices}" | grep -qe "\<${fulldevname}\>" || \
438 [ -n "${white_listed_devices}" ] && \
439 echo "${white_listed_devices}" | grep -qve "\<${fulldevname}\>"
441 # skip this device entirely
445 for dev in $(subdevices "${sysblock}")
447 devname=$(sys2dev "${dev}")
449 if echo "${black_listed_devices}" | grep -qe "\<${devname}\>"
451 # skip this subdevice
464 # Validate input first
465 if [ -z "${fstype}" ]
470 # Try to look if it is already supported by the kernel
471 if grep -q ${fstype} /proc/filesystems
475 # Then try to add support for it the gentle way using the initramfs capabilities
477 if grep -q ${fstype} /proc/filesystems
480 # Then try the hard way if /root is already reachable
482 kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko"
483 if [ -e "${kmodule}" ]
486 if grep -q ${fstype} /proc/filesystems
499 /sbin/blkid -s TYPE -o value $1 2>/dev/null
506 if grep -q "^${device} " /proc/mounts
508 # return the first found
509 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
526 mounts="$(awk '{print $2}' /proc/mounts)"
527 testpath="$(busybox realpath ${testpath})"
531 if echo "${mounts}" | grep -qs "^${testpath}"
533 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
537 testpath=$(dirname $testpath)
544 # Returns used/free fs kbytes + 5% more
545 # You could pass a block device as ${1} or the mount point as ${2}
551 if [ -z "${mountp}" ]
553 mountp="$(where_is_mounted ${dev})"
555 if [ -z "${mountp}" ]
557 mountp="/mnt/tmp_fs_size"
560 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
566 if [ "${used}" = "used" ]
568 size=$(du -ks ${mountp} | cut -f1)
569 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
572 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
575 if [ -n "${doumount}" ]
577 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
587 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
589 loadkeys /etc/boottime.kmap.gz
599 local encryption=${5}
602 # the output of setup_loop is evaluated in other functions,
603 # modprobe leaks kernel options like "libata.dma=0"
604 # as "options libata dma=0" on stdout, causing serious
605 # problems therefor, so instead always avoid output to stdout
606 modprobe -q -b "${module}" 1>/dev/null
610 for loopdev in ${pattern}
612 if [ "$(cat ${loopdev}/size)" -eq 0 ]
614 dev=$(sys2dev "${loopdev}")
617 if [ -n "${readonly}" ]
619 if losetup --help 2>&1 | grep -q -- "-r\b"
621 options="${options} -r"
625 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
627 options="${options} -o ${offset}"
630 if [ -z "${encryption}" ]
632 losetup ${options} "${dev}" "${fspath}"
634 # Loop AES encryption
639 echo -n "Enter passphrase for root filesystem: " >&6
641 echo "${passphrase}" > /tmp/passphrase
643 exec 9</tmp/passphrase
644 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
647 rm -f /tmp/passphrase
649 if [ 0 -eq ${error} ]
656 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
659 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
672 panic "No loop devices available"
682 old_mountp="$(where_is_mounted ${dev})"
684 if [ -n "${old_mountp}" ]
686 if [ "${opts}" != "ro" ]
688 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
691 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
693 if [ -z "${fstype}" ]
695 fstype=$(get_fstype "${dev}")
697 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
698 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > live-boot.log && return 0 )
705 name="$(basename ${dev})"
707 if [ -n "${PERSISTENT_READONLY}" ]
709 opts="${opts} --readonly"
716 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
717 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
721 luks_device="/dev/mapper/${name}"
727 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
730 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
737 find_persistent_media ()
739 # Scans devices for overlays and snapshots, and returns a whitespace
740 # separated list of how to use them. Only overlays with a partition
741 # label or file name in ${overlays} are returned, and ditto for
742 # snapshots with labels in ${snapshots}.
744 # When scanning a LUKS device, the user will be asked to enter the
745 # passphrase; on failure to enter it, or if no persistent partitions
746 # or files were found, the LUKS device is closed.
748 # For a snapshot file the return value is ${label}=${snapdata}", where
749 # ${snapdata} is the parameter used for try_snap().
751 # For all other cases (overlay/snapshot partition and overlay file) the
752 # return value is "${label}=${device}", where ${device} a device that
753 # can mount the content. In the case of an overlay file, the device
754 # containing the file will remain mounted as a side-effect.
756 # No devices in ${black_listed_devices} will be scanned, and if
757 # ${white_list_devices} is non-empty, only devices in it will be
762 black_listed_devices="${3}"
763 white_listed_devices="${4}"
764 persistent_backing="${rootmnt}/live/persistent"
766 for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
770 # Checking for a luks device
771 if echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>" && \
772 /sbin/cryptsetup isLuks ${dev}
774 if luks_device=$(open_luks_device "${dev}")
778 # skip $dev since we failed/chose not to open it
781 elif echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<none\>"
783 # skip $dev since we don't allow unencrypted storage
787 if echo ${PERSISTENT_STORAGE} | grep -qe "\<filesystem\>"
789 for label in ${overlays} ${snapshots}
791 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
793 echo "${label}=${dev}"
794 # skip to the next device
802 if echo ${PERSISTENT_STORAGE} | grep -qe "\<file\>"
804 devfstype="$(get_fstype ${dev})"
805 backing="${persistent_backing}/$(basename ${dev})"
806 mkdir -p "${backing}"
807 if is_supported_fs ${devfstype} && try_mount "${dev}" "${backing}" "rw" "${devfstype}"
809 for label in ${overlays}
811 path=${backing}/${PERSISTENT_PATH}${label}
815 echo "${label}=$(setup_loop "${path}" "loop" "/sys/block/loop*")"
819 for label in ${snapshots}
821 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
823 path="${PERSISTENT_PATH}${label}.${ext}"
824 if [ -f "${backing}/${path}" ]
826 snapshot_on_dev="yes"
827 echo "${label}=${dev}:${backing}:${path}"
832 if [ -z "${overlay_on_dev}" ] && [ -z "${snapshot_on_dev}" ]
834 umount ${backing} > /dev/null 2>&1 || true
837 if [ -z "${overlay_on_dev}" ] && [ -z "${snapshot_on_dev}" ] && \
838 [ -n "${luks_device}" ] && \
839 /sbin/cryptsetup status "${luks_device}" 1> /dev/null 2>&1
841 /sbin/cryptsetup luksClose "${luks_device}"
850 for adaptor in /sys/class/net/*
852 status="$(cat ${adaptor}/iflink)"
854 if [ "${status}" -eq 2 ]
856 mac="$(cat ${adaptor}/address)"
857 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
867 if [ -x /sbin/cryptsetup ]
869 /sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}
883 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
886 if [ "$(cat ${sysblock}/removable)" = "1" ]
888 if [ -z "${want_usb}" ]
892 if readlink ${sysblock} | grep -q usb
899 if [ "${dev_ok}" = "yes" ]
901 case "${output_format}" in
903 ret="${ret} ${sysblock}"
906 devname=$(sys2dev "${sysblock}")
907 ret="${ret} ${devname}"
920 removable_dev "${output_format}" "want_usb"
928 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
930 if [ "$(cat ${sysblock}/removable)" = "0" ]
932 case "${output_format}" in
934 ret="${ret} ${sysblock}"
937 devname=$(sys2dev "${sysblock}")
938 ret="${ret} ${devname}"
949 # create source's directory structure in dest, and recursively
950 # create symlinks in dest to to all files in source. if mask
951 # is non-empty, remove mask from all source paths when
952 # creating links (will be necessary if we change root, which
953 # live-boot normally does (into $rootmnt)).
955 # remove multiple /:s and ensure ending on /
956 local src_dir="$(echo "${1}"/ | sed -e 's|/\+|/|g')"
957 local dest_dir="$(echo "${2}"/ | sed -e 's|/\+|/|g')"
958 local src_mask="${3}"
960 # This check can only trigger on the inital, non-recursive call since
961 # we create the destination before recursive calls
962 if [ ! -d "${dest_dir}" ];
964 log_warning_msg "Must link_files into a directory"
968 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read x; do
970 local dest="${dest_dir}$(basename "${x}")"
973 if [ -z "$(ls -A "${src}")" ];
977 if [ ! -d "${dest}" ];
980 prev="$(dirname "${dest}")"
981 chown $(stat -c %u:%g "${prev}") "${dest}"
982 chmod $(stat -c %a "${prev}") "${dest}"
984 link_files "${src}" "${dest}" "${src_mask}"
986 if [ -n "${src_mask}" ]
988 src="$(echo ${src} | sed "s|^${src_mask}||")"
990 rm -rf "${dest}" 2> /dev/null
991 ln -s "${src}" "${dest}"
997 local unionmountpoint="${1}" # directory where the union is mounted
998 local unionrw="${2}" # branch where the union changes are stored
999 local unionro1="${3}" # first underlying read-only branch (optional)
1000 local unionro2="${4}" # second underlying read-only branch (optional)
1002 if [ "${UNIONTYPE}" = "aufs" ]
1007 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1016 case "${UNIONTYPE}" in
1018 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1019 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
1020 if [ -n "${unionro1}" ]
1022 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1024 if [ -n "${unionro2}" ]
1026 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1028 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1029 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1030 ( mkdir -p /run/sendsigs.omit.d
1031 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1035 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1036 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
1037 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
1038 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1042 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1043 if [ -n "${unionro1}" ]
1045 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1047 if [ -n "${unionro2}" ]
1049 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1051 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1056 get_custom_mounts () {
1057 # Side-effect: leaves $devices with live.persist mounted in ${rootmnt}/live/persistent
1058 # Side-effect: prints info to file $custom_mounts
1060 local devices="${1}"
1061 local custom_mounts="${2}" # print result to this file
1062 local rootmnt="${3}" # should be set empty post-live-boot
1064 local bindings="/bindings.list"
1065 local links="/links.list"
1066 rm -rf ${bindings} ${links} 2> /dev/null
1067 local persistent_backing="${rootmnt}/live/persistent"
1069 for device in ${devices}
1071 if [ ! -b "${device}" ]
1075 local device_name="$(basename ${device})"
1076 local backing="${persistent_backing}/${device_name}"
1077 mkdir -p "${backing}"
1078 local device_fstype="$(get_fstype ${device})"
1079 if [ -z "${PERSISTENT_READONLY}" ]
1081 device_mount_opts="rw,noatime"
1083 device_mount_opts="ro,noatime"
1085 local device_used=""
1086 mount -t "${device_fstype}" -o "${device_mount_opts}" "${device}" "${backing}"
1087 local include_list="${backing}/${persistence_list}"
1088 if [ ! -r "${include_list}" ]
1095 [ "${DEBUG}" = "Yes" ] && cp ${include_list} ${persistent_backing}/${persistence_list}.${device_name}
1096 while read source dest options # < ${include_list}
1098 if echo ${source} | grep -qe "^[[:space:]]*\(#.*\)\?$"
1100 # skipping empty or commented lines
1104 if echo ${dest} | grep -qe "^[^/]"
1108 elif [ -z "${dest}" ]
1113 if echo ${dest} | grep -qe "^/\+$\|^/\+live\(/.*\)\?$"
1115 # mounting on / or /live could cause trouble
1116 log_warning_msg "Skipping unsafe custom mount on ${dest}"
1120 for opt in $(echo ${options} | tr ',' ' ');
1126 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
1132 # FIXME: handle case: we already have /a/b in
1133 # $bindings added from current $device, but
1134 # now we find /a -- /a should replace /a/b in
1137 # FIXME: handle case: we have /a in $bindings
1138 # from current $device, now we find /a/b, so
1141 # ensure that no multiple-/ occur in paths
1142 local full_source="$(echo ${backing}/${source}/ | sed -e 's|/\+|/|g')"
1143 local full_dest="$(echo ${rootmnt}/${dest}/ | sed -e 's|/\+|/|g')"
1145 if echo ${options} | grep -qe "\<linkfiles\>";
1147 echo "${full_source} ${full_dest} ${options}" >> ${links}
1149 echo "${full_source} ${full_dest} ${options}" >> ${bindings}
1151 done < ${include_list}
1153 if [ -z "${device_used}" ]
1155 # this device was not used for / earlier, or
1156 # custom mount point now, so it's useless
1162 # We sort the list according to destination so we're sure that
1163 # we won't hide a previous mount. We also ignore duplicate
1164 # destinations in a more or less arbitrary way.
1165 [ -e "${bindings}" ] && sort -k2 -sbu ${bindings} >> ${custom_mounts}
1168 # After all mounts are considered we add symlinks so they
1169 # won't be hidden by some mount.
1170 [ -e "${links}" ] && sort -k2 -sbu ${links} >> ${custom_mounts}
1173 rm -f ${bindings} ${links} 2> /dev/null
1174 echo ${custom_mounts}
1177 do_custom_mounts () {
1178 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1179 local rootmnt="${2}" # should be set empty post-live-boot
1181 while read source dest options # < ${custom_mounts}
1183 local opt_linkfiles=""
1185 for opt in $(echo ${options} | tr ',' ' ');
1197 if mountpoint -q "${dest}";
1199 log_warning_msg "Skipping custom mount ${source} on ${dest}: destination is already a mount point"
1203 # FIXME: we don't handle already existing
1204 # non-directory files in the paths of both $source and
1207 if [ ! -d "${dest}" ]
1209 # if ${dest} is in /home/$user, try fixing
1211 # FIXME: this should really be handled by
1212 # live-config since we don't know for sure
1213 # which uid a certain user has until then
1214 if echo ${dest} | grep -qe "^${rootmnt}/*home/\+[^/]\+"
1217 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1223 # assume that the intended user is the first, which is usually the case
1224 chown 1000:1000 ${path}
1232 # if ${source} doesn't exist on our persistent media
1233 # we bootstrap it with $dest from the live filesystem.
1234 # this both makes sense and is critical if we're
1235 # dealing with /etc or other system dir.
1236 if [ ! -d "${source}" ]
1238 if [ -n "${PERSISTENT_READONLY}" ] || [ -n "${opt_linkfiles}" ]
1241 elif [ -n "${opt_union}" ]
1243 # union's don't need to be bootstrapped
1246 # ensure that $dest is not copied *into* $source
1247 mkdir -p "$(dirname ${source})"
1248 cp -a "${dest}" "${source}"
1252 rofs_dest_backing=""
1253 for d in ${rootmnt}/live/rofs/*
1255 if [ -n "${rootmnt}" ]
1257 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1259 rofs_dest_backing="${d}/${dest}"
1262 if [ -d "${rofs_dest_backing}" ]
1266 rofs_dest_backing=""
1270 if [ -z "${PERSISTENT_READONLY}" ]
1272 if [ -n "${opt_linkfiles}" ]
1274 links_source="${source}"
1275 links_dest="${dest}"
1276 elif [ -n "${opt_union}" ]
1278 do_union ${dest} ${source} ${rofs_dest_backing}
1280 mount --bind "${source}" "${dest}"
1283 if [ -n "${opt_linkfiles}" ]
1285 links_dest="${dest}"
1286 dest="$(mktemp -d ${persistent_backing}/links_source-XXXXXX)"
1287 links_source="${dest}"
1289 if [ -n "${rootmnt}" ]
1291 cow_dir="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
1293 cow_dir="/live/cow/${dest}"
1296 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1299 if [ -n "${opt_linkfiles}" ]
1301 link_files "${links_source}" "${links_dest}" "${rootmnt}"
1304 PERSISTENCE_IS_ON="1"
1305 export PERSISTENCE_IS_ON
1306 done < ${custom_mounts}