9 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
11 for FILESYSTEM
in squashfs ext2 ext3 ext4 xfs dir jffs2
13 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
25 if [ "${IGNORE_UUID}" ] ||
[ ! -e /conf
/uuid.conf
]
31 uuid
="$(cat /conf/uuid.conf)"
33 for try_uuid_file
in "${path}/.disk/live-uuid"*
35 [ -e "${try_uuid_file}" ] ||
continue
37 try_uuid
="$(cat "${try_uuid_file}")"
39 if [ "${uuid}" = "${try_uuid}" ]
51 *.squashfs|
*.ext2|
*.ext3|
*.ext4|
*.jffs2
)
52 echo $
(setup_loop
"${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
60 panic
"Unrecognized live filesystem: ${1}"
67 # Does any files match pattern ${1} ?
71 if [ "$(echo ${pattern})" != "${pattern}" ]
79 mount_images_in_directory
()
85 if match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
86 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
87 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
88 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
89 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
90 match_files_in_dir
"${directory}/${LIVE_MEDIA_PATH}/*.dir"
92 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
93 setup_unionfs
"${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
95 panic
"No supported filesystem images found at /${LIVE_MEDIA_PATH}."
101 sysfs_path
="${1#/sys}"
103 if /sbin
/udevadm test-builtin path_id
"${sysfs_path}" |
egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)"
106 elif echo "${sysfs_path}" |
grep -q '^/block/vd[a-z]$'
109 elif echo ${sysfs_path} |
grep -q "^/block/dm-"
112 elif echo ${sysfs_path} |
grep -q "^/block/mtdblock"
124 skip_uuid_check
="${3}"
126 # support for fromiso=.../isofrom=....
129 ISO_DEVICE
=$
(dirname $FROMISO)
130 if ! [ -b $ISO_DEVICE ]
132 # to support unusual device names like /dev/cciss/c0d0p1
133 # as well we have to identify the block device name, let's
134 # do that for up to 15 levels
136 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
138 ISO_DEVICE
=$
(dirname ${ISO_DEVICE})
139 [ -b "$ISO_DEVICE" ] && break
144 if [ "$ISO_DEVICE" = "/" ]
146 echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
148 fs_type
=$
(get_fstype
"${ISO_DEVICE}")
149 if is_supported_fs
${fs_type}
152 mount
-t $fs_type "$ISO_DEVICE" /live
/fromiso
153 ISO_NAME
="$(echo $FROMISO | sed "s|
$ISO_DEVICE||
")"
154 loopdevname
=$
(setup_loop
"/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
155 devname
="${loopdevname}"
157 echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
162 if [ -z "${devname}" ]
164 devname
=$
(sys2dev
"${sysdev}")
167 if [ -d "${devname}" ]
169 mount
-o bind "${devname}" $mountpoint ||
continue
171 if is_live_path
$mountpoint
181 for device
in ${devname}
186 if [ -x /scripts
/local-top
/lvm2
]
188 ROOT
="$device" resume
="" /scripts
/local-top
/lvm2
193 # Adding raid support
194 if [ -x /scripts
/local-top
/mdadm
]
196 cp /conf
/conf.d
/md
/conf
/conf.d
/md.orig
197 echo "MD_DEVS=$device " >> /conf
/conf.d
/md
198 /scripts
/local-top
/mdadm
199 mv /conf
/conf.d
/md.orig
/conf
/conf.d
/md
206 [ -n "$device" ] && devname
="$device"
208 [ -e "$devname" ] ||
continue
210 if [ -n "${LIVE_MEDIA_OFFSET}" ]
212 loopdevname
=$
(setup_loop
"${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
213 devname
="${loopdevname}"
216 fstype
=$
(get_fstype
"${devname}")
218 if is_supported_fs
${fstype}
220 devuid
=$
(blkid
-o value
-s UUID
"$devname")
221 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
222 mount
-t ${fstype} -o ro,noatime "${devname}" ${mountpoint} ||
continue
223 [ -n "$devuid" ] && echo "$devuid" >> $tried
225 if [ -n "${FINDISO}" ]
227 if [ -f ${mountpoint}/${FINDISO} ]
230 mkdir
-p /live
/findiso
231 mount
-t ${fstype} -o ro
,noatime
"${devname}" /live
/findiso
232 loopdevname
=$
(setup_loop
"/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
233 devname
="${loopdevname}"
234 mount
-t iso9660
-o ro
,noatime
"${devname}" ${mountpoint}
240 if is_live_path
${mountpoint} && \
241 ([ "${skip_uuid_check}" ] || matches_uuid
${mountpoint})
246 umount
${mountpoint} 2>/dev
/null
250 if [ -n "${LIVE_MEDIA_OFFSET}" ]
252 losetup
-d "${loopdevname}"
262 # don't start autodetection before timeout has expired
263 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
265 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
271 # first look at the one specified in the command line
272 case "${LIVE_MEDIA}" in
274 for sysblock
in $
(removable_usb_dev
"sys")
276 for dev
in $
(subdevices
"${sysblock}")
278 if check_dev
"${dev}"
288 for sysblock
in $
(removable_dev
"sys")
290 for dev
in $
(subdevices
"${sysblock}")
292 if check_dev
"${dev}"
302 if [ ! -z "${LIVE_MEDIA}" ]
304 if check_dev
"null" "${LIVE_MEDIA}" "skip_uuid_check"
312 # or do the scan of block devices
313 # prefer removable devices over non-removable devices, so scan them first
314 devices_to_scan
="$(removable_dev 'sys') $(non_removable_dev 'sys')"
316 for sysblock
in $devices_to_scan
318 devname
=$
(sys2dev
"${sysblock}")
319 [ -e "$devname" ] ||
continue
320 fstype
=$
(get_fstype
"${devname}")
322 if /lib
/udev
/cdrom_id
${devname} > /dev
/null
324 if check_dev
"null" "${devname}"
328 elif is_nice_device
"${sysblock}"
330 for dev
in $
(subdevices
"${sysblock}")
332 if check_dev
"${dev}"
337 elif [ "${fstype}" = "squashfs" -o \
338 "${fstype}" = "btrfs" -o \
339 "${fstype}" = "ext2" -o \
340 "${fstype}" = "ext3" -o \
341 "${fstype}" = "ext4" -o \
342 "${fstype}" = "jffs2" ]
344 # This is an ugly hack situation, the block device has
345 # an image directly on it. It's hopefully
346 # live-boot, so take it and run with it.
347 ln -s "${devname}" "${devname}.${fstype}"
348 echo "${devname}.${fstype}"
359 VALUE
="$(eval echo -n \${$STRING})"
361 if [ -f /live.vars
] && grep -sq "export ${STRING}" /live.vars
363 sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars
365 echo "export ${STRING}=\"${VALUE}\"" >> /live.vars
368 eval export "${STRING}"="${VALUE}"
371 is_in_list_separator_helper
()
373 local sep element list
379 echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.
*\
)\?$
"
382 is_in_space_sep_list ()
387 is_in_list_separator_helper "[[:space
:]]" "${element}" "${*}"
390 is_in_comma_sep_list ()
395 is_in_list_separator_helper "," "${element}" "${*}"
401 echo "/dev
/$
($udevinfo -q name
-p ${sysdev} 2>/dev
/null||
echo ${sysdev##*/})"
409 for dev in "${sysblock}"/* "${sysblock}"
411 if [ -e "${dev}/dev
" ]
422 black_listed_devices="${1}"
423 white_listed_devices="${2}"
425 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd
")
427 fulldevname=$(sys2dev "${sysblock}")
429 if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
430 [ -n "${white_listed_devices}" ] && \
431 ! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
433 # skip this device entirely
437 for dev in $(subdevices "${sysblock}")
439 devname=$(sys2dev "${dev}")
441 if is_in_space_sep_list ${devname} ${black_listed_devices}
443 # skip this subdevice
456 # Validate input first
457 if [ -z "${fstype}" ]
462 # Try to look if it is already supported by the kernel
463 if grep -q ${fstype} /proc/filesystems
467 # Then try to add support for it the gentle way using the initramfs capabilities
469 if grep -q ${fstype} /proc/filesystems
472 # Then try the hard way if /root is already reachable
474 kmodule="/root
/lib
/modules
/`uname -r`/${fstype}/${fstype}.ko
"
475 if [ -e "${kmodule}" ]
478 if grep -q ${fstype} /proc/filesystems
491 /sbin/blkid -s TYPE -o value $1 2>/dev/null
498 grep -m1 "^
${device} " /proc/mounts | cut -f2 -d ' '
503 # remove all unnecessary /:s in the path, including last one (except
504 # if path is just "/")
505 echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|'
508 what_is_mounted_on ()
511 dir="$
(trim_path
${1})"
512 grep -m1 "^
[^
]\
+ ${dir} " /proc/mounts | cut -d' ' -f1
517 local reference targets owner
521 owner=$(stat -c %u:%g "${reference}")
522 chown -h ${owner} ${targets}
527 local reference targets rights
531 rights=$(stat -c %a "${reference}")
532 chmod ${rights} ${targets}
548 mounts="$
(awk '{print $2}' /proc
/mounts
)"
549 testpath="$
(busybox realpath
${testpath})"
553 if echo "${mounts}" | grep -qs "^
${testpath}"
555 set -- $(echo "${mounts}" | grep "^
${testpath}" | lastline)
559 testpath=$(dirname $testpath)
566 # Returns used/free fs kbytes + 5% more
567 # You could pass a block device as ${1} or the mount point as ${2}
573 if [ -z "${mountp}" ]
575 mountp="$
(where_is_mounted
${dev})"
577 if [ -z "${mountp}" ]
579 mountp="/mnt
/tmp_fs_size
"
582 mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}"
588 if [ "${used}" = "used
" ]
590 size=$(du -ks ${mountp} | cut -f1)
591 size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure
594 size="$
(df
-kP |
grep -s ${mountp} |
awk '{print $4}')"
597 if [ -n "${doumount}" ]
599 umount "${mountp}" || log_warning_msg "cannot umount
${mountp}"
609 if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]
611 loadkeys /etc/boottime.kmap.gz
617 local fspath module pattern offset encryption readonly
625 # the output of setup_loop is evaluated in other functions,
626 # modprobe leaks kernel options like "libata.dma
=0"
627 # as "options libata dma
=0" on stdout, causing serious
628 # problems therefor, so instead always avoid output to stdout
629 modprobe -q -b "${module}" 1>/dev/null
633 for loopdev in ${pattern}
635 if [ "$
(cat ${loopdev}/size
)" -eq 0 ]
637 dev=$(sys2dev "${loopdev}")
640 if [ -n "${readonly}" ]
642 if losetup --help 2>&1 | grep -q -- "-r\b"
644 options="${options} -r"
648 if [ -n "${offset}" ] && [ 0 -lt "${offset}" ]
650 options="${options} -o ${offset}"
653 if [ -z "${encryption}" ]
655 losetup ${options} "${dev}" "${fspath}"
657 # Loop AES encryption
662 echo -n "Enter passphrase for root filesystem: " >&6
664 echo "${passphrase}" > /tmp
/passphrase
666 exec 9</tmp
/passphrase
667 /sbin
/losetup
${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
670 rm -f /tmp/passphrase
672 if [ 0 -eq ${error} ]
679 echo -n "There was an error decrypting the root filesystem ... Retry?
[Y
/n
] " >&6
682 if [ "$
(echo "${answer}" | cut
-b1 |
tr A-Z a-z
)" = "n
" ]
695 panic "No loop devices available
"
705 old_mountp="$
(where_is_mounted
${dev})"
707 if [ -n "${old_mountp}" ]
709 if [ "${opts}" != "ro
" ]
711 mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed
"
714 mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
716 if [ -z "${fstype}" ]
718 fstype=$(get_fstype "${dev}")
720 mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
721 ( echo "SKIPPING
: Cannot mount
${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > boot.log && return 0 )
725 # Try to mount $device to the place expected by live-boot. If $device
726 # is already mounted somewhere, move it to the expected place. If
727 # we're only probing $device (to check if it has custom persistence)
728 # $probe should be set, which suppresses warnings upon failure. On
729 # success, print the mount point for $device.
730 mount_persistence_media ()
732 local device probe backing old_backing fstype mount_opts
736 backing="/live
/persistence
/$
(basename ${device})"
738 mkdir -p "${backing}"
739 old_backing="$
(where_is_mounted
${device})"
740 if [ -z "${old_backing}" ]
742 fstype="$
(get_fstype
${device})"
743 mount_opts="rw
,noatime
"
744 if [ -n "${PERSISTENCE_READONLY}" ]
746 mount_opts="ro
,noatime
"
748 if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null
753 [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media
${device}"
757 elif [ "${backing}" != "${old_backing}" ]
759 if mount --move ${old_backing} ${backing} >/dev/null
764 [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media
${device}"
769 # This means that $device has already been mounted on
770 # the place expected by live-boot, so we're done.
776 close_persistence_media ()
780 backing="$
(where_is_mounted
${device})"
782 if [ -d "${backing}" ]
784 umount "${backing}" >/dev/null 2>&1
785 rmdir "${backing}" >/dev/null 2>&1
788 if is_active_luks_mapping ${device}
790 /sbin/cryptsetup luksClose ${device}
797 name="$
(basename ${dev})"
799 if [ -n "${PERSISTENCE_READONLY}" ]
801 opts="${opts} --readonly"
804 if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
806 re="^
[[:space
:]]*device
:[[:space
:]]*\
([^
[:space
:]]*\
)$
"
807 opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
808 if [ "${opened_dev}" = "${dev}" ]
810 luks_device
="/dev/mapper/${name}"
814 log_warning_msg
"Cannot open luks device ${dev} since ${opened_dev} already is opened with its name"
823 /lib
/cryptsetup
/askpass
"Enter passphrase for ${dev}: " | \
824 /sbin
/cryptsetup
-T 1 luksOpen
${dev} ${name} ${opts}
828 luks_device
="/dev/mapper/${name}"
834 echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
837 if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
848 /sbin
/blkid
-s PART_ENTRY_NAME
-p -o value
${dev} 2>/dev
/null
855 [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
858 probe_for_gpt_name
()
860 local overlays dev gpt_dev gpt_name
865 if is_active_luks_mapping
${dev}
867 # if $dev is an opened luks device, we need to check
868 # GPT stuff on the backing device
869 gpt_dev
=$
(get_luks_backing_device
"${dev}")
872 if ! is_gpt_device
${gpt_dev}
877 gpt_name
=$
(get_gpt_name
${gpt_dev})
878 for label
in ${overlays}
880 if [ "${gpt_name}" = "${label}" ]
882 echo "${label}=${dev}"
887 probe_for_fs_label
()
893 for label
in ${overlays}
895 if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
897 echo "${label}=${dev}"
902 probe_for_file_name
()
904 local overlays dev ret backing
909 backing
="$(mount_persistence_media ${dev} probe)"
910 if [ -z "${backing}" ]
915 for label
in ${overlays}
917 path
=${backing}/${PERSISTENCE_PATH}${label}
921 loopdev
=$
(setup_loop
"${path}" "loop" "/sys/block/loop*")
922 ret
="${ret} ${label}=${loopdev}"
930 # unmount and remove mountpoint
931 umount
${backing} > /dev
/null
2>&1 || true
932 rmdir ${backing} > /dev
/null
2>&1 || true
936 find_persistence_media
()
938 # Scans devices for overlays, and returns a whitespace
939 # separated list of how to use them. Only overlays with a partition
940 # label or file name in ${overlays} are returned.
942 # When scanning a LUKS device, the user will be asked to enter the
943 # passphrase; on failure to enter it, or if no persistence partitions
944 # or files were found, the LUKS device is closed.
946 # For all other cases (overlay partition and overlay file) the
947 # return value is "${label}=${device}", where ${device} a device that
948 # can mount the content. In the case of an overlay file, the device
949 # containing the file will remain mounted as a side-effect.
951 # No devices in ${black_listed_devices} will be scanned, and if
952 # ${white_list_devices} is non-empty, only devices in it will be
955 local overlays white_listed_devices ret black_listed_devices
957 white_listed_devices
="${2}"
960 black_listed_devices
="$(what_is_mounted_on /live/medium)"
962 for dev
in $
(storage_devices
"${black_listed_devices}" "${white_listed_devices}")
964 local result luks_device
968 # Check if it's a luks device; we'll have to open the device
969 # in order to probe any filesystem it contains, like we do
970 # below. activate_custom_mounts() also depends on that any luks
971 # device already has been opened.
972 if is_in_comma_sep_list luks
${PERSISTENCE_ENCRYPTION} && is_luks_partition
${dev}
974 if luks_device
=$
(open_luks_device
"${dev}")
978 # skip $dev since we failed/chose not to open it
981 elif ! is_in_comma_sep_list none
${PERSISTENCE_ENCRYPTION}
983 # skip $dev since we don't allow unencrypted storage
987 # Probe for matching GPT partition names or filesystem labels
988 if is_in_comma_sep_list filesystem
${PERSISTENCE_STORAGE}
990 result
=$
(probe_for_gpt_name
"${overlays}" ${dev})
991 if [ -n "${result}" ]
993 ret
="${ret} ${result}"
997 result
=$
(probe_for_fs_label
"${overlays}" ${dev})
998 if [ -n "${result}" ]
1000 ret
="${ret} ${result}"
1005 # Probe for files with matching name on mounted partition
1006 if is_in_comma_sep_list
file ${PERSISTENCE_STORAGE}
1008 result
=$
(probe_for_file_name
"${overlays}" ${dev})
1009 if [ -n "${result}" ]
1011 ret
="${ret} ${result}"
1016 # Close luks device if it isn't used
1017 if [ -z "${result}" ] && [ -n "${luks_device}" ] && is_active_luks_mapping "${luks_device}"
1019 /sbin
/cryptsetup luksClose
"${luks_device}"
1033 for adaptor
in /sys
/class
/net
/*
1035 status
="$(cat ${adaptor}/iflink)"
1037 if [ "${status}" -eq 2 ]
1039 mac
="$(cat ${adaptor}/address)"
1040 mac
="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
1047 is_luks_partition
()
1050 /sbin
/cryptsetup isLuks
"${device}" 1>/dev
/null
2>&1
1053 is_active_luks_mapping
()
1056 /sbin
/cryptsetup status
"${device}" 1>/dev
/null
2>&1
1059 get_luks_backing_device
()
1062 cryptsetup status
${device} 2> /dev
/null | \
1063 awk '{if ($1 == "device:") print $2}'
1068 output_format
="${1}"
1072 for sysblock
in $
(echo /sys
/block
/* |
tr ' ' '\n' |
grep -vE "/(loop|ram|dm-|fd)")
1075 if [ "$(cat ${sysblock}/removable)" = "1" ]
1077 if [ -z "${want_usb}" ]
1081 if readlink
${sysblock} |
grep -q usb
1088 if [ "${dev_ok}" = "true" ]
1090 case "${output_format}" in
1092 ret
="${ret} ${sysblock}"
1095 devname
=$
(sys2dev
"${sysblock}")
1096 ret
="${ret} ${devname}"
1105 removable_usb_dev
()
1107 output_format
="${1}"
1109 removable_dev
"${output_format}" "want_usb"
1112 non_removable_dev
()
1114 output_format
="${1}"
1117 for sysblock
in $
(echo /sys
/block
/* |
tr ' ' '\n' |
grep -vE "/(loop|ram|dm-|fd)")
1119 if [ "$(cat ${sysblock}/removable)" = "0" ]
1121 case "${output_format}" in
1123 ret
="${ret} ${sysblock}"
1126 devname
=$
(sys2dev
"${sysblock}")
1127 ret
="${ret} ${devname}"
1138 # create source's directory structure in dest, and recursively
1139 # create symlinks in dest to to all files in source. if mask
1140 # is non-empty, remove mask from all source paths when
1141 # creating links (will be necessary if we change root, which
1142 # live-boot normally does (into $rootmnt)).
1143 local src_dir dest_dir src_mask
1145 # remove multiple /:s and ensure ending on /
1146 src_dir
="$(trim_path ${1})/"
1147 dest_dir
="$(trim_path ${2})/"
1150 # This check can only trigger on the inital, non-recursive call since
1151 # we create the destination before recursive calls
1152 if [ ! -d "${dest_dir}" ]
1154 log_warning_msg
"Must link_files into a directory"
1158 find "${src_dir}" -mindepth 1 -maxdepth 1 | \
1161 local dest final_src
1162 dest
="${dest_dir}$(basename "${src}")"
1165 if [ -z "$(ls -A "${src}")" ]
1169 if [ ! -d "${dest}" ]
1172 chown_ref
"${src}" "${dest}"
1173 chmod_ref
"${src}" "${dest}"
1175 link_files
"${src}" "${dest}" "${src_mask}"
1178 if [ -n "${src_mask}" ]
1180 final_src
="$(echo ${final_src} | sed "s|^
${src_mask}||
")"
1182 rm -rf "${dest}" 2> /dev
/null
1183 ln -s "${final_src}" "${dest}"
1184 chown_ref
"${src}" "${dest}"
1191 local unionmountpoint unionrw unionro
1192 unionmountpoint
="${1}" # directory where the union is mounted
1194 unionrw
="${1}" # branch where the union changes are stored
1196 unionro
="${*}" # space separated list of read-only branches (optional)
1198 case "${UNIONTYPE}" in
1216 case "${UNIONTYPE}" in
1218 unionmountopts
="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1219 unionmountopts
="${unionmountopts} ${unionrw}=${rw_opt}"
1220 if [ -n "${unionro}" ]
1222 for rofs
in ${unionro}
1224 unionmountopts
="${unionmountopts}:${rofs}=${ro_opt}"
1227 ( sysctl
-w fs.file-max
=391524 ; ulimit -HSn 16384
1228 unionfs-fuse
${unionmountopts} "${unionmountpoint}" ) && \
1229 ( mkdir
-p /run
/sendsigs.omit.d
1230 pidof unionfs-fuse
>> /run
/sendsigs.omit.d
/unionfs-fuse || true
)
1234 # XXX: can multiple unionro be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
1235 # XXX: and can unionro be optional? i.e. can overlayfs skip lowerdir?
1236 if echo ${unionro} |
grep -q " "
1238 panic
"Multiple lower filesystems are currently not supported with overlayfs (unionro = ${unionro})."
1239 elif [ -z "${unionro}" ]
1241 panic
"Overlayfs needs at least one lower filesystem (read-only branch)."
1243 unionmountopts
="-o noatime,lowerdir=${unionro},upperdir=${unionrw}"
1244 mount
-t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1248 unionmountopts="-o noatime
,${noxino_opt},dirs=${unionrw}=${rw_opt}"
1249 if [ -n "${unionro}" ]
1251 for rofs in ${unionro}
1253 unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
1256 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1261 get_custom_mounts
()
1263 # Side-effect: leaves $devices with persistence.conf mounted in /live/persistence
1264 # Side-effect: prints info to file $custom_mounts
1266 local custom_mounts devices bindings links
1271 bindings
="/tmp/bindings.list"
1272 links
="/tmp/links.list"
1273 rm -rf ${bindings} ${links} 2> /dev
/null
1275 for device
in ${devices}
1277 if [ ! -b "${device}" ]
1282 local device_name backing include_list
1283 device_name
="$(basename ${device})"
1284 backing
=$
(mount_persistence_media
${device})
1285 if [ -z "${backing}" ]
1290 if [ -r "${backing}/${persistence_list}" ]
1292 include_list
="${backing}/${persistence_list}"
1293 elif [ -r "${backing}/${old_persistence_list}" ]
1295 include_list
="${backing}/${old_persistence_list}"
1300 if [ -n "${DEBUG}" ] && [ -e "${include_list}" ]
1302 cp ${include_list} /live/persistence/${persistence_list}.${device_name}
1305 while read dir options
# < ${include_list}
1307 if echo ${dir} |
grep -qe "^[[:space:]]*\(#.*\)\?$"
1309 # skipping empty or commented lines
1313 if trim_path
${dir} |
grep -q -e "^[^/]" -e "^/lib" -e "^/lib/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
1315 log_warning_msg
"Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/lib\", or \"/lib/live\" or any of its sub-directories."
1319 local opt_source opt_link
source full_source full_dest
1322 for opt
in $
(echo ${options} |
tr ',' ' ');
1326 opt_source
=${opt#source=}
1334 log_warning_msg
"Skipping custom mount with unkown option: ${opt}"
1341 if [ -n "${opt_source}" ]
1343 if echo ${opt_source} |
grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${opt_source}" != "." ]
1345 log_warning_msg
"Skipping unsafe custom mount with option source=${opt_source}: must be either \".\" (the media root) or a relative path w.r.t. the media root that contains neither comas, nor the special \".\" and \"..\" path components"
1348 source="${opt_source}"
1352 full_source
="$(trim_path ${backing}/${source})"
1353 full_dest
="$(trim_path ${rootmnt}/${dir})"
1354 if [ -n "${opt_link}" ]
1356 echo "${device} ${full_source} ${full_dest} ${options}" >> ${links}
1358 echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings}
1360 done < ${include_list}
1363 # We sort the list according to destination so we're sure that
1364 # we won't hide a previous mount. We also ignore duplicate
1365 # destinations in a more or less arbitrary way.
1366 [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings}
1368 # After all mounts are considered we add symlinks so they
1369 # won't be hidden by some mount.
1370 [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links}
1372 # We need to make sure that no two custom mounts have the same sources
1373 # or are nested; if that is the case, too much weird stuff can happen.
1374 local prev_source prev_dest
1375 prev_source
="impossible source" # first iteration must not match
1377 # This sort will ensure that a source /a comes right before a source
1378 # /a/b so we only need to look at the previous source
1379 sort -k2 -b ${custom_mounts} |
1380 while read device
source dest options
1382 if echo ${source} |
grep -qe "^${prev_source}\(/.*\)\?$"
1384 panic
"Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}"
1386 prev_source
=${source}
1391 activate_custom_mounts
()
1393 local custom_mounts used_devices
1394 custom_mounts
="${1}" # the ouput from get_custom_mounts()
1397 while read device
source dest options
# < ${custom_mounts}
1399 local opt_bind opt_link opt_union
1403 for opt
in $
(echo ${options} |
tr ',' ' ');
1408 unset opt_link opt_union
1412 unset opt_bind opt_union
1416 unset opt_bind opt_link
1421 if [ -n "$(what_is_mounted_on "${dest}")" ]
1423 if [ "${dest}" = "${rootmnt}" ]
1427 log_warning_msg
"Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there"
1432 if [ ! -d "${dest}" ]
1434 # create the destination and delete existing files in
1435 # its path that are in the way
1437 for dir
in $
(echo ${dest} |
sed -e 's|/\+| |g')
1439 path
=$
(trim_path
${path}/${dir})
1447 if echo ${path} |
grep -qe "^${rootmnt}/*home/[^/]\+"
1449 # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case
1450 # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then
1451 chown
1000:1000 ${path}
1457 # if ${source} doesn't exist on our persistence media
1458 # we bootstrap it with $dest from the live filesystem.
1459 # this both makes sense and is critical if we're
1460 # dealing with /etc or other system dir.
1461 if [ ! -d "${source}" ]
1463 if [ -n "${PERSISTENCE_READONLY}" ]
1466 elif [ -n "${opt_union}" ] ||
[ -n "${opt_link}" ]
1468 # unions and don't need to be bootstrapped
1469 # link dirs can't be bootstrapped in a sensible way
1470 mkdir
-p "${source}"
1471 chown_ref
"${dest}" "${source}"
1472 chmod_ref
"${dest}" "${source}"
1473 elif [ -n "${opt_bind}" ]
1475 # ensure that $dest is not copied *into* $source
1476 mkdir
-p "$(dirname ${source})"
1477 cp -a "${dest}" "${source}"
1481 # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can
1482 # ignore the loop below and set rootfs_dest_backing=$dest
1483 local rootfs_dest_backing
1484 rootfs_dest_backing
=""
1485 if [ -n "${opt_link}"]
1487 for d
in /live
/rootfs
/*
1489 if [ -n "${rootmnt}" ]
1491 fs
="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
1497 rootfs_dest_backing="${rootfs_dest_backing} ${fs}"
1502 local cow_dir links_source
1503 if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1505 link_files ${source} ${dest} ${rootmnt}
1506 elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1508 mkdir -p ${rootmnt}/lib/live/mount/persistence
1509 links_source=$(mktemp -d ${rootmnt}/lib/live/mount/persistence/links-source-XXXXXX)
1510 chown_ref ${source} ${links_source}
1511 chmod_ref ${source} ${links_source}
1512 # We put the cow dir in the below strange place to
1513 # make it absolutely certain that the link source
1514 # has its own directory and isn't nested with some
1515 # other custom mount (if so that mount's files would
1516 # be linked, causing breakage.
1517 cow_dir="/live
/overlay
/lib
/live
/mount
/persistence
/$
(basename ${links_source})"
1519 chown_ref "${source}" "${cow_dir}"
1520 chmod_ref "${source}" "${cow_dir}"
1521 do_union ${links_source} ${cow_dir} ${source} ${rootfs_dest_backing}
1522 link_files ${links_source} ${dest} ${rootmnt}
1523 elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1525 do_union ${dest} ${source} ${rootfs_dest_backing}
1526 elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
1528 mount --bind "${source}" "${dest}"
1529 elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
1531 # bind-mount and union mount are handled the same
1532 # in read-only mode, but note that rootfs_dest_backing
1533 # is non-empty (and necessary) only for unions
1534 cow_dir="/live
/overlay
/${dest}"
1535 if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
1537 # If an earlier custom mount has files here
1538 # it will "block
" the current mount's files
1539 # which is undesirable
1543 chown_ref "${source}" "${cow_dir}"
1544 chmod_ref "${source}" "${cow_dir}"
1545 do_union ${dest} ${cow_dir} ${source} ${rootfs_dest_backing}
1548 PERSISTENCE_IS_ON="1"
1549 export PERSISTENCE_IS_ON
1551 if echo ${used_devices} | grep -qve "^\
(.
* \
)\?${device}\
( .
*\
)\?$
"
1553 used_devices="${used_devices} ${device}"
1555 done < ${custom_mounts}
1557 echo ${used_devices}
1564 [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..
") ]