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 grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
522 # remove all unnecessary /:s in the path, including last
523 echo ${1} | sed 's|//|/|g' | sed 's|/$||'
526 what_is_mounted_on ()
528 local dir="$(trim_path ${1})"
529 grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
545 mounts="$(awk '{print $2}' /proc/mounts)"
546 testpath="$(busybox realpath ${testpath})"
550 if echo "${mounts}" | grep -qs "^${testpath}"
552 set -- $(echo "${mounts}" | grep "^${testpath}" | lastline)
556 testpath=$(dirname $testpath)
563 # Returns used/free fs kbytes + 5% more
564 # You could pass a block device as ${1} or the mount point as ${2}
570 if [ -z "${mountp}" ]
572 mountp="$(where_is_mounted ${dev})"
574 if [ -z "${mountp}" ]
576 mountp="/mnt/tmp_fs_size"
579 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
585 if [ "${used}" = "used" ]
587 size=$(du -ks ${mountp} | cut -f1)
588 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
591 size="$(df -k | grep -s ${mountp} | awk '{print $4}')"
594 if [ -n "${doumount}" ]
596 umount "${mountp}" || log_warning_msg "cannot umount ${mountp}"
606 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
608 loadkeys /etc/boottime.kmap.gz
618 local encryption=${5}
621 # the output of setup_loop is evaluated in other functions,
622 # modprobe leaks kernel options like "libata.dma=0"
623 # as "options libata dma=0" on stdout, causing serious
624 # problems therefor, so instead always avoid output to stdout
625 modprobe -q -b "${module}" 1>/dev/null
629 for loopdev in ${pattern}
631 if [ "$(cat ${loopdev}/size)" -eq 0 ]
633 dev=$(sys2dev "${loopdev}")
636 if [ -n "${readonly}" ]
638 if losetup --help 2>&1 | grep -q -- "-r\b"
640 options="${options} -r"
644 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
646 options="${options} -o ${offset}"
649 if [ -z "${encryption}" ]
651 losetup ${options} "${dev}" "${fspath}"
653 # Loop AES encryption
658 echo -n "Enter passphrase for root filesystem: " >&6
660 echo "${passphrase}" > /tmp/passphrase
662 exec 9</tmp/passphrase
663 /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
666 rm -f /tmp/passphrase
668 if [ 0 -eq ${error} ]
675 echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&6
678 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
691 panic "No loop devices available"
701 old_mountp="$(where_is_mounted ${dev})"
703 if [ -n "${old_mountp}" ]
705 if [ "${opts}" != "ro" ]
707 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
710 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
712 if [ -z "${fstype}" ]
714 fstype=$(get_fstype "${dev}")
716 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
717 ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > live-boot.log && return 0 )
721 mount_persistent_media ()
726 # We can't mount into ${rootmnt}/live before ${rootmnt} has been
727 # mounted since that would cover our mountpoint.
728 if [ -n "${rootmnt}" ] && [ -z "$(what_is_mounted_on ${rootmnt})" ]
730 backing="/$(basename ${device})-backing"
732 backing="${rootmnt}/live/persistent/$(basename ${device})"
735 mkdir -p "${backing}"
736 local old_backing="$(where_is_mounted ${device})"
737 if [ -z "${old_backing}" ]
739 local fstype="$(get_fstype ${device})"
740 local mount_opts="rw,noatime"
741 if [ -n "${PERSISTENT_READONLY}" ]
743 mount_opts="ro,noatime"
745 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
750 log_warning_msg "Failed to mount persistent media ${device}"
753 elif [ "${backing}" != "${old_backing}" ]
755 if mount --move ${old_backing} ${backing} >/dev/null
760 log_warning_msg "Failed to move persistent media ${device}"
770 name="$(basename ${dev})"
772 if [ -n "${PERSISTENT_READONLY}" ]
774 opts="${opts} --readonly"
777 if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
779 re="^[[:space:]]*device:[[:space:]]*\([^[:space:]]*\)$"
780 opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
781 if [ "${opened_dev}" = "${dev}" ]
783 luks_device="/dev/mapper/${name}"
787 log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name"
796 /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
797 /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
801 luks_device="/dev/mapper/${name}"
807 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
810 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
820 /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
826 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
829 probe_for_gpt_name ()
831 local overlays="${1}"
832 local snapshots="${2}"
835 if ! is_gpt_device ${dev} || \
836 ( echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<luks\>" && \
837 /sbin/cryptsetup isLuks ${dev} > /dev/null 2>&1 )
841 for label in ${overlays} ${snapshots}
843 if [ "$(get_gpt_name ${dev})" = "${label}" ]
845 echo "${label}=${dev}"
850 probe_for_fs_label ()
852 local overlays="${1}"
853 local snapshots="${2}"
856 for label in ${overlays} ${snapshots}
858 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
860 echo "${label}=${dev}"
865 probe_for_file_name ()
867 local overlays="${1}"
868 local snapshots="${2}"
872 local backing="$(mount_persistent_media ${dev})"
873 if [ -z "${backing}" ]
878 for label in ${overlays}
880 path=${backing}/${PERSISTENT_PATH}${label}
883 local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
884 ret="${ret} ${label}=${loopdev}"
887 for label in ${snapshots}
889 for ext in squashfs cpio.gz ext2 ext3 ext4 jffs2
891 path="${PERSISTENT_PATH}${label}.${ext}"
892 if [ -f "${backing}/${path}" ]
894 ret="${ret} ${label}=${dev}:${backing}:${path}"
903 umount ${backing} > /dev/null 2>&1 || true
907 find_persistent_media ()
909 # Scans devices for overlays and snapshots, and returns a whitespace
910 # separated list of how to use them. Only overlays with a partition
911 # label or file name in ${overlays} are returned, and ditto for
912 # snapshots with labels in ${snapshots}.
914 # When scanning a LUKS device, the user will be asked to enter the
915 # passphrase; on failure to enter it, or if no persistent partitions
916 # or files were found, the LUKS device is closed.
918 # For a snapshot file the return value is ${label}=${snapdata}", where
919 # ${snapdata} is the parameter used for try_snap().
921 # For all other cases (overlay/snapshot partition and overlay file) the
922 # return value is "${label}=${device}", where ${device} a device that
923 # can mount the content. In the case of an overlay file, the device
924 # containing the file will remain mounted as a side-effect.
926 # No devices in ${black_listed_devices} will be scanned, and if
927 # ${white_list_devices} is non-empty, only devices in it will be
930 local overlays="${1}"
931 local snapshots="${2}"
932 local white_listed_devices="${3}"
935 for dev in $(storage_devices "" "${white_listed_devices}")
941 # Check if it's a luks device; we'll have to open the device
942 # in order to probe any filesystem it contains, like we do
943 # below. do_custom_mounts() also depends on that any luks
944 # device already has been opened.
945 if echo ${PERSISTENT_ENCRYPTION} | grep -qe "\<luks\>" && \
946 /sbin/cryptsetup isLuks ${dev} >/dev/null 2>&1
948 if luks_device=$(open_luks_device "${dev}")
953 # skip $dev since we failed/chose not to open it
956 elif echo ${PERSISTENT_ENCRYPTION} | grep -qve "\<none\>"
958 # skip $dev since we don't allow unencrypted storage
962 # Probe for matching GPT partition names or filesystem labels
963 if echo ${PERSISTENT_STORAGE} | grep -qe "\<filesystem\>"
965 local gpt_dev="${dev}"
966 if [ -n "${luks_device}" ]
968 # When we probe GPT partitions we need to look
969 # at the real device, not the virtual, opened
971 gpt_dev="${real_dev}"
973 result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${gpt_dev})
974 if [ -n "${result}" ]
976 ret="${ret} ${result}"
980 result=$(probe_for_fs_label "${overlays}" "${snapshots}" ${dev})
981 if [ -n "${result}" ]
983 ret="${ret} ${result}"
988 # Probe for files with matching name on mounted partition
989 if echo ${PERSISTENT_STORAGE} | grep -qe "\<file\>"
991 result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
992 if [ -n "${result}" ]
994 ret="${ret} ${result}"
999 # Close luks device if it isn't used
1000 if [ -z "${result}" ] && [ -n "${luks_device}" ] && \
1001 /sbin/cryptsetup status "${luks_device}" 1> /dev/null 2>&1
1003 /sbin/cryptsetup luksClose "${luks_device}"
1017 for adaptor in /sys/class/net/*
1019 status="$(cat ${adaptor}/iflink)"
1021 if [ "${status}" -eq 2 ]
1023 mac="$(cat ${adaptor}/address)"
1024 mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
1034 if [ -x /sbin/cryptsetup ]
1036 /sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}
1046 output_format="${1}"
1050 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1053 if [ "$(cat ${sysblock}/removable)" = "1" ]
1055 if [ -z "${want_usb}" ]
1059 if readlink ${sysblock} | grep -q usb
1066 if [ "${dev_ok}" = "yes" ]
1068 case "${output_format}" in
1070 ret="${ret} ${sysblock}"
1073 devname=$(sys2dev "${sysblock}")
1074 ret="${ret} ${devname}"
1083 removable_usb_dev ()
1085 output_format="${1}"
1087 removable_dev "${output_format}" "want_usb"
1090 non_removable_dev ()
1092 output_format="${1}"
1095 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1097 if [ "$(cat ${sysblock}/removable)" = "0" ]
1099 case "${output_format}" in
1101 ret="${ret} ${sysblock}"
1104 devname=$(sys2dev "${sysblock}")
1105 ret="${ret} ${devname}"
1116 # create source's directory structure in dest, and recursively
1117 # create symlinks in dest to to all files in source. if mask
1118 # is non-empty, remove mask from all source paths when
1119 # creating links (will be necessary if we change root, which
1120 # live-boot normally does (into $rootmnt)).
1122 # remove multiple /:s and ensure ending on /
1123 local src_dir="$(echo "${1}"/ | sed -e 's|/\+|/|g')"
1124 local dest_dir="$(echo "${2}"/ | sed -e 's|/\+|/|g')"
1125 local src_mask="${3}"
1127 # This check can only trigger on the inital, non-recursive call since
1128 # we create the destination before recursive calls
1129 if [ ! -d "${dest_dir}" ]
1131 log_warning_msg "Must link_files into a directory"
1135 find "${src_dir}" -mindepth 1 -maxdepth 1 | while read src; do
1136 local dest="${dest_dir}$(basename "${src}")"
1139 if [ -z "$(ls -A "${src}")" ]
1143 if [ ! -d "${dest}" ]
1146 prev="$(dirname "${dest}")"
1147 chown --reference "${prev}" "${dest}"
1148 chmod --reference "${prev}" "${dest}"
1150 link_files "${src}" "${dest}" "${src_mask}"
1152 if [ -n "${src_mask}" ]
1154 src="$(echo ${src} | sed "s|^${src_mask}||")"
1156 rm -rf "${dest}" 2> /dev/null
1157 ln -s "${src}" "${dest}"
1164 local unionmountpoint="${1}" # directory where the union is mounted
1165 local unionrw="${2}" # branch where the union changes are stored
1166 local unionro1="${3}" # first underlying read-only branch (optional)
1167 local unionro2="${4}" # second underlying read-only branch (optional)
1169 if [ "${UNIONTYPE}" = "aufs" ]
1174 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1183 case "${UNIONTYPE}" in
1185 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1186 unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
1187 if [ -n "${unionro1}" ]
1189 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1191 if [ -n "${unionro2}" ]
1193 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1195 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1196 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1197 ( mkdir -p /run/sendsigs.omit.d
1198 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1202 # XXX: can unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1203 # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir?
1204 unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}"
1205 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1209 unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1210 if [ -n "${unionro1}" ]
1212 unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}"
1214 if [ -n "${unionro2}" ]
1216 unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}"
1218 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1223 get_custom_mounts ()
1225 # Side-effect: leaves $devices with live.persist mounted in ${rootmnt}/live/persistent
1226 # Side-effect: prints info to file $custom_mounts
1228 local devices="${1}"
1229 local custom_mounts="${2}" # print result to this file
1231 local bindings="/tmp/bindings.list"
1232 local links="/tmp/links.list"
1233 rm -rf ${bindings} ${links} 2> /dev/null
1235 for device in ${devices}
1237 if [ ! -b "${device}" ]
1242 local device_name="$(basename ${device})"
1243 local device_used=""
1244 local backing=$(mount_persistent_media ${device})
1245 if [ -z "${backing}" ]
1250 local include_list="${backing}/${persistence_list}"
1251 if [ ! -r "${include_list}" ]
1253 umount "${backing}" >/dev/null 2>&1
1254 rmdir "${backing}" >/dev/null 2>&1
1255 if /sbin/cryptsetup status ${device_name} >/dev/null 2>&1
1257 /sbin/cryptsetup luksClose "${device_name}"
1262 if [ -n "${DEBUG}" ] && [ -e "${include_list}" ]
1264 cp ${include_list} ${rootmnt}/live/persistent/${persistence_list}.${device_name}
1267 while read source dest options # < ${include_list}
1269 if echo ${source} | grep -qe "^[[:space:]]*\(#.*\)\?$"
1271 # skipping empty or commented lines
1275 if echo ${dest} | grep -qe "^[^/]"
1279 elif [ -z "${dest}" ]
1284 if echo ${dest} | grep -qe "^/\+$\|^/\+live\(/.*\)\?$"
1286 # mounting on / or /live could cause trouble
1287 log_warning_msg "Skipping unsafe custom mount on ${dest}"
1291 for opt in $(echo ${options} | tr ',' ' ');
1297 log_warning_msg "Skipping custom mount with unkown option: ${opt}"
1303 # ensure that no multiple-/ occur in paths
1304 local full_source="$(echo ${backing}/${source}/ | sed -e 's|/\+|/|g')"
1305 local full_dest="$(echo ${rootmnt}/${dest}/ | sed -e 's|/\+|/|g')"
1307 if echo ${options} | grep -qe "\<linkfiles\>";
1309 echo "${full_source} ${full_dest} ${options}" >> ${links}
1311 echo "${full_source} ${full_dest} ${options}" >> ${bindings}
1313 done < ${include_list}
1315 if [ -z "${device_used}" ]
1317 # this device was not used for / earlier, or
1318 # custom mount point now, so it's useless
1324 # We sort the list according to destination so we're sure that
1325 # we won't hide a previous mount. We also ignore duplicate
1326 # destinations in a more or less arbitrary way.
1327 [ -e "${bindings}" ] && sort -k2 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
1329 # After all mounts are considered we add symlinks so they
1330 # won't be hidden by some mount.
1331 [ -e "${links}" ] && sort -k2 -sbu ${links} >> ${custom_mounts} && rm ${links}
1336 local custom_mounts="${1}" # the ouput from get_custom_mounts()
1338 while read source dest options # < ${custom_mounts}
1340 local opt_linkfiles=""
1342 for opt in $(echo ${options} | tr ',' ' ');
1354 if [ -n "$(what_is_mounted_on "${dest}")" ]
1356 log_warning_msg "Skipping custom mount ${source} on ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1360 # FIXME: we don't handle already existing
1361 # non-directory files in the paths of both $source and
1364 if [ ! -d "${dest}" ]
1366 # if ${dest} is in /home/$user, try fixing
1368 # FIXME: this should really be handled by
1369 # live-config since we don't know for sure
1370 # which uid a certain user has until then
1371 if echo ${dest} | grep -qe "^${rootmnt}/*home/\+[^/]\+"
1374 for dir in $(echo ${dest} | sed -e 's|/\+| |g')
1380 # assume that the intended user is the first, which is usually the case
1381 chown 1000:1000 ${path}
1389 # if ${source} doesn't exist on our persistent media
1390 # we bootstrap it with $dest from the live filesystem.
1391 # this both makes sense and is critical if we're
1392 # dealing with /etc or other system dir.
1393 if [ ! -d "${source}" ]
1395 if [ -n "${PERSISTENT_READONLY}" ] || [ -n "${opt_linkfiles}" ]
1398 elif [ -n "${opt_union}" ]
1400 # union's don't need to be bootstrapped
1403 # ensure that $dest is not copied *into* $source
1404 mkdir -p "$(dirname ${source})"
1405 cp -a "${dest}" "${source}"
1409 rofs_dest_backing=""
1410 for d in ${rootmnt}/live/rofs/*
1412 if [ -n "${rootmnt}" ]
1414 rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1416 rofs_dest_backing="${d}/${dest}"
1418 if [ -d "${rofs_dest_backing}" ]
1422 rofs_dest_backing=""
1426 if [ -z "${PERSISTENT_READONLY}" ]
1428 if [ -n "${opt_linkfiles}" ]
1430 links_source="${source}"
1431 links_dest="${dest}"
1432 elif [ -n "${opt_union}" ]
1434 do_union ${dest} ${source} ${rofs_dest_backing}
1436 mount --bind "${source}" "${dest}"
1439 if [ -n "${opt_linkfiles}" ]
1441 links_dest="${dest}"
1442 dest="$(mktemp -d ${persistent_backing}/links_source-XXXXXX)"
1443 links_source="${dest}"
1445 if [ -n "${rootmnt}" ]
1447 cow_dir="$(echo ${dest} | sed -e "s|${rootmnt}|/cow/|")"
1449 cow_dir="/live/cow/${dest}"
1452 do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing}
1455 if [ -n "${opt_linkfiles}" ]
1457 link_files "${links_source}" "${links_dest}" "${rootmnt}"
1460 PERSISTENCE_IS_ON="1"
1461 export PERSISTENCE_IS_ON
1462 done < ${custom_mounts}
1465 fix_home_rw_compatibility ()
1469 if [ -n "${PERSISTENT_READONLY}" ]
1474 local backing="$(mount_persistent_media ${device})"
1475 if [ -z "${backing}" ]
1480 local include_list="${backing}/${persistence_list}"
1481 if [ ! -r "${include_list}" ]
1483 echo "# home-rw backwards compatibility:
1484 . /home" > "${include_list}"