{
sysfs_path="${1#/sys}"
- if 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)"
+ if udevadm info --query=all --path="${sysfs_path}" | egrep -q "DEVTYPE=disk"
then
return 0
elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
ISO_DEVICE=$(dirname ${ISO_DEVICE})
[ -b "$ISO_DEVICE" ] && break
i=$(($i -1))
- done
+ done
fi
if [ "$ISO_DEVICE" = "/" ]
# Adding lvm support
if [ -x /scripts/local-top/lvm2 ]
then
- ROOT="$device" resume="" /scripts/local-top/lvm2
+ ROOT="$device" resume="" /scripts/local-top/lvm2 >>/boot.log
fi
;;
# Adding raid support
if [ -x /scripts/local-top/mdadm ]
then
- cp /conf/conf.d/md /conf/conf.d/md.orig
+ [ -r /conf/conf.d/md ] && cp /conf/conf.d/md /conf/conf.d/md.orig
echo "MD_DEVS=$device " >> /conf/conf.d/md
- /scripts/local-top/mdadm
- mv /conf/conf.d/md.orig /conf/conf.d/md
+ /scripts/local-top/mdadm >>/boot.log
+ [ -r /conf/conf.d/md.orig ] && mv /conf/conf.d/md.orig /conf/conf.d/md
fi
;;
esac
return 1
fi
+ # get_fstype might report "unknown" or "swap", ignore it as no such kernel module exists
+ if [ "${fstype}" = "unknown" ] || [ "${fstype}" = "swap" ]
+ then
+ return 1
+ fi
+
# Try to look if it is already supported by the kernel
if grep -q ${fstype} /proc/filesystems
then
return 0
else
# Then try to add support for it the gentle way using the initramfs capabilities
- modprobe ${fstype}
+ modprobe -q -b ${fstype}
if grep -q ${fstype} /proc/filesystems
then
return 0
get_fstype ()
{
- /sbin/blkid -s TYPE -o value $1 2>/dev/null
+ blkid -s TYPE -o value $1 2>/dev/null
}
where_is_mounted ()
{
testpath="${1}"
mounts="$(awk '{print $2}' /proc/mounts)"
- testpath="$(busybox realpath ${testpath})"
+ testpath="$(realpath ${testpath})"
while true
do
echo "${passphrase}" > /tmp/passphrase
unset passphrase
exec 9</tmp/passphrase
- /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
+ losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
error=${?}
exec 9<&-
rm -f /tmp/passphrase
}
# Try to mount $device to the place expected by live-boot. If $device
-# is already mounted somewhere, move it to the expected place. If
-# we're only probing $device (to check if it has custom persistence)
+# is already mounted somewhere, move it to the expected place. If $device
+# ends with a "/" this is a directory path.
+# If we're only probing $device (to check if it has custom persistence)
# $probe should be set, which suppresses warnings upon failure. On
# success, print the mount point for $device.
mount_persistence_media ()
device=${1}
probe=${2}
+ # get_custom_mounts() might call this with a directory path instead
+ # of a block device path. This means we have found sub-directory path
+ # underneath /lib/live/mounts/persistence, so we're done
+ if [ -d "${device}" ]
+ then
+ echo "${device}"
+ return 0
+ fi
+
if [ ! -b "${device}" ]
then
return 1
fi
elif [ "${backing}" != "${old_backing}" ]
then
- if mount --move ${old_backing} ${backing} >/dev/null
+ if ! mount -o move ${old_backing} ${backing} >/dev/null
then
- echo ${backing}
- return 0
- else
[ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
rmdir "${backing}"
return 1
fi
+ mount_opts="rw,noatime"
+ if [ -n "${PERSISTENCE_READONLY}" ]
+ then
+ mount_opts="ro,noatime"
+ fi
+ if ! mount -o "remount,${mount_opts}" "${backing}" >/dev/null
+ then
+ log_warning_msg "Failed to remount persistence media ${device} writable"
+ # Don't unmount or rmdir the new mountpoint in this case
+ fi
+ echo ${backing}
+ return 0
else
# This means that $device has already been mounted on
# the place expected by live-boot, so we're done.
if is_active_luks_mapping ${device}
then
- /sbin/cryptsetup luksClose ${device}
+ cryptsetup luksClose ${device}
fi
}
opts="${opts} --readonly"
fi
- if /sbin/cryptsetup status "${name}" >/dev/null 2>&1
+ if cryptsetup status "${name}" >/dev/null 2>&1
then
re="^[[:space:]]*device:[[:space:]]*\([^[:space:]]*\)$"
opened_dev=$(cryptsetup status ${name} 2>/dev/null | grep "${re}" | sed "s|${re}|\1|")
load_keymap
+ # check for plymouth
+ if [ -x /bin/plymouth ]
+ then
+ _PLYMOUTH="true"
+ fi
+
+ case "${_PLYMOUTH}" in
+ true)
+ plymouth --ping
+
+ cryptkeyscript="plymouth ask-for-password --prompt"
+ # Plymouth will add a : if it is a non-graphical prompt
+ cryptkeyprompt="Please unlock disk ${dev}"
+ ;;
+
+ *)
+ cryptkeyscript="/lib/cryptsetup/askpass"
+ cryptkeyprompt="Please unlock disk ${dev}: "
+ ;;
+ esac
+
while true
do
- /lib/cryptsetup/askpass "Enter passphrase for ${dev}: " | \
- /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
+ $cryptkeyscript "$cryptkeyprompt" | \
+ cryptsetup -T 1 luksOpen ${dev} ${name} ${opts}
if [ 0 -eq ${?} ]
then
fi
echo >&6
- echo -n "There was an error decrypting ${dev} ... Retry? [Y/n] " >&6
- read answer
+ retryprompt="There was an error decrypting ${dev} ... Retry? [Y/n]"
+
+ case "${_PLYMOUTH}" in
+ true)
+ plymouth display-message --text "${retryprompt}"
+ answer=$(plymouth watch-keystroke --keys="YNyn")
+ ;;
+
+ *)
+ echo -n "${retryprompt} " >&6
+ read answer
+ ;;
+ esac
if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
then
+ case "${_PLYMOUTH}" in
+ true)
+ plymouth display-message --text ""
+ ;;
+ esac
+
return 2
fi
done
{
local dev
dev="${1}"
- /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
+ blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
}
is_gpt_device ()
{
local dev
dev="${1}"
- [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
+ [ "$(blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
}
probe_for_gpt_name ()
for label in ${overlays}
do
- if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
+ if [ "$(blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ]
then
echo "${label}=${dev}"
fi
fi
}
+probe_for_directory_name ()
+{
+ local overlays dev ret backing
+ overlays="${1}"
+ dev="${2}"
+
+ ret=""
+ backing="$(mount_persistence_media ${dev} probe)"
+ if [ -z "${backing}" ]
+ then
+ return
+ fi
+
+ for label in ${overlays}
+ do
+ path=${backing}/${PERSISTENCE_PATH}/${label}
+ if [ -d "${path}" ]
+ then
+ # in this case the "device" ends with a "/"
+ ret="${ret} ${label}=${backing}/${PERSISTENCE_PATH}/${label%%/}/"
+ fi
+ done
+
+ if [ -n "${ret}" ]
+ then
+ echo ${ret}
+ else
+ # unmount and remove mountpoint
+ umount ${backing} > /dev/null 2>&1 || true
+ rmdir ${backing} > /dev/null 2>&1 || true
+ fi
+}
+
find_persistence_media ()
{
# Scans devices for overlays, and returns a whitespace
white_listed_devices="${2}"
ret=""
- black_listed_devices="$(what_is_mounted_on /live/medium) $(what_is_mounted_on /live/findiso) $(what_is_mounted_on /live/fromiso)"
+ #
+ # The devices that are hosting the actual live rootfs should not be
+ # used for persistence storage since otherwise you might mount a
+ # parent directory on top of a sub-directory of the same filesystem
+ # in one union together.
+ #
+ black_listed_devices=""
+ for d in /live/rootfs/* /live/findiso /live/fromiso
+ do
+ black_listed_devices="${black_listed_devices} $(what_is_mounted_on d)"
+ done
for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
do
result=$(probe_for_file_name "${overlays}" ${dev})
if [ -n "${result}" ]
then
- local loopdevice
+ local loopdevice
loopdevice=${result##*=}
- if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${loopdevice}
+ if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${loopdevice}
then
- local luksfile
+ local luksfile
luksfile=""
if luksfile=$(open_luks_device "${loopdevice}")
then
- result=${result%%=*}
+ result=${result%%=*}
result="${result}=${luksfile}"
else
- losetup -d $loopdevice
+ losetup -d $loopdevice
result=""
fi
fi
fi
fi
+ # Probe for directory with matching name on mounted partition
+ if is_in_comma_sep_list directory ${PERSISTENCE_STORAGE}
+ then
+ result=$(probe_for_directory_name "${overlays}" ${dev})
+ if [ -n "${result}" ]
+ then
+ ret="${ret} ${result}"
+ continue
+ fi
+ fi
+
# Close luks device if it isn't used
if [ -z "${result}" ] && [ -n "${luks_device}" ] && is_active_luks_mapping "${luks_device}"
then
- /sbin/cryptsetup luksClose "${luks_device}"
+ cryptsetup luksClose "${luks_device}"
fi
done
is_luks_partition ()
{
device="${1}"
- /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1
+ cryptsetup isLuks "${device}" 1>/dev/null 2>&1
}
is_active_luks_mapping ()
{
device="${1}"
- /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1
+ cryptsetup status "${device}" 1>/dev/null 2>&1
}
get_luks_backing_device ()
for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
do
+ if [ ! -d "${sysblock}" ]; then
+ continue
+ fi
+
dev_ok=
if [ "$(cat ${sysblock}/removable)" = "1" ]
then
for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
do
+ if [ ! -d "${sysblock}" ]; then
+ continue
+ fi
+
if [ "$(cat ${sysblock}/removable)" = "0" ]
then
case "${output_format}" in
rw_opt="rw"
ro_opt="rr+wh"
noxino_opt="noxino"
- ;;
-
- unionfs-fuse)
- rw_opt="RW"
- ro_opt="RO"
- ;;
- *)
- rw_opt="rw"
- ro_opt="ro"
- ;;
- esac
-
- case "${UNIONTYPE}" in
- unionfs-fuse)
- unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
- unionmountopts="${unionmountopts} ${unionrw}=${rw_opt}"
+ unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
if [ -n "${unionro}" ]
then
for rofs in ${unionro}
unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
done
fi
- ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
- unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
- ( mkdir -p /run/sendsigs.omit.d
- pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
;;
- overlayfs)
- # XXX: can multiple unionro be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
- # XXX: and can unionro be optional? i.e. can overlayfs skip lowerdir?
- if echo ${unionro} | grep -q " "
+ overlay)
+ # XXX: can unionro be optional? i.e. can overlay skip lowerdir?
+ if [ -z "${unionro}" ]
then
- panic "Multiple lower filesystems are currently not supported with overlayfs (unionro = ${unionro})."
- elif [ -z "${unionro}" ]
- then
- panic "Overlayfs needs at least one lower filesystem (read-only branch)."
+ panic "overlay needs at least one lower filesystem (read-only branch)."
fi
- unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}"
- mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
- ;;
-
- *)
- unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
- if [ -n "${unionro}" ]
- then
- for rofs in ${unionro}
- do
- unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
- done
- fi
- mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
+ # Multiple lower layers can now be given using the the colon (":") as a
+ # separator character between the directory names.
+ unionro="$(echo ${unionro} | sed -e 's| |:|g')"
+ # overlayfs requires:
+ # + a workdir to become mounted
+ # + workdir and upperdir to reside under the same mount
+ # + workdir and upperdir to be in separate directories
+ mkdir "${unionrw}/rw"
+ mkdir "${unionrw}/work"
+ unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}/rw,workdir=${unionrw}/work"
;;
esac
+
+ mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
}
get_custom_mounts ()
union|bind)
;;
*)
- log_warning_msg "Skipping custom mount with unkown option: ${opt}"
+ log_warning_msg "Skipping custom mount with unknown option: ${opt}"
continue 2
;;
esac
prev_dest=""
# This sort will ensure that a source /a comes right before a source
# /a/b so we only need to look at the previous source
- sort -k2 -b ${custom_mounts} |
+ [ -e ${custom_mounts} ] && sort -k2 -b ${custom_mounts} |
while read device source dest options
do
if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$"
do_union ${dest} ${source} ${rootfs_dest_backing}
elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ]
then
- mount --bind "${source}" "${dest}"
+ mount -o bind "${source}" "${dest}"
elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
then
# bind-mount and union mount are handled the same