+ dev="${1}"
+ mountp="${2}"
+ opts="${3}"
+ fstype="${4}"
+
+ old_mountp="$(where_is_mounted ${dev})"
+
+ if [ -n "${old_mountp}" ]
+ then
+ if [ "${opts}" != "ro" ]
+ then
+ mount -o remount,"${opts}" "${dev}" "${old_mountp}" || panic "Remounting ${dev} ${opts} on ${old_mountp} failed"
+ fi
+
+ mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
+ else
+ if [ -z "${fstype}" ]
+ then
+ fstype=$(get_fstype "${dev}")
+ fi
+ mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
+ ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > live-boot.log && return 0 )
+ fi
+}
+
+open_luks_device ()
+{
+ dev="${1}"
+ name="$(basename ${dev})"
+ opts="--key-file=-"
+ if [ -n "${PERSISTENT_READONLY}" ]
+ then
+ opts="${opts} --readonly"
+ fi
+
+ load_keymap
+
+ while true
+ do
+ /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
+ /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
+
+ if [ 0 -eq ${?} ]
+ then
+ luks_device="/dev/mapper/${name}"
+ echo ${luks_device}
+ return 0
+ fi
+
+ echo >&6
+ echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
+ read answer
+
+ if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
+ then
+ return 2
+ fi
+ done
+}
+
+find_persistent_media ()
+{
+ # Scans devices for overlays and snapshots, and returns a whitespace
+ # separated list of how to use them. Only overlays with a partition
+ # label or file name in ${overlays} are returned, and ditto for
+ # snapshots with labels in ${snapshots}.
+ #
+ # When scanning a LUKS device, the user will be asked to enter the
+ # passphrase; on failure to enter it, or if no persistent partitions
+ # or files were found, the LUKS device is closed.
+ #
+ # For a snapshot file the return value is ${label}=${snapdata}", where
+ # ${snapdata} is the parameter used for try_snap().
+ #
+ # For all other cases (overlay/snapshot partition and overlay file) the
+ # return value is "${label}=${device}", where ${device} a device that
+ # can mount the content. In the case of an overlay file, the device
+ # containing the file will remain mounted as a side-effect.
+ #
+ # No devices in ${black_listed_devices} will be scanned, and if
+ # ${white_list_devices} is non-empty, only devices in it will be
+ # scanned.
+
+ overlays="${1}"
+ snapshots="${2}"
+ black_listed_devices="${3}"
+ white_listed_devices="${4}"
+
+ for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
+ do
+ luks_device=""