X-Git-Url: http://git.grml.org/?p=live-boot-grml.git;a=blobdiff_plain;f=components%2F9990-misc-helpers.sh;h=1267a6709080bf4e1bafa91246480e51490c1c78;hp=87c49309721ad79d14b2a4b1d05e334d64295b0e;hb=a70800ee4b64f8566344587935642d55feb51777;hpb=f2dcec3f21086a557db86ae928295474be79d35b diff --git a/components/9990-misc-helpers.sh b/components/9990-misc-helpers.sh index 87c4930..1267a67 100755 --- a/components/9990-misc-helpers.sh +++ b/components/9990-misc-helpers.sh @@ -15,6 +15,42 @@ is_live_path() return 1 } +grml_match_bootid() +{ + path="$1" + + if [ -n "$IGNORE_BOOTID" ] ; then + echo " * Ignoring verification of bootid.txt as requested via ignore_bootid.">>/boot.log + return 0 + fi + + if [ -n "$BOOTID" ] && ! [ -r "${path}/conf/bootid.txt" ] ; then + echo " * Warning: bootid=... specified but no bootid.txt found on currently requested device.">>/boot.log + return 1 + fi + + [ -r "${path}/conf/bootid.txt" ] || return 0 + + bootid_conf=$(cat "${path}/conf/bootid.txt") + + if [ -z "$BOOTID" -a -z "$IGNORE_BOOTID" ] + then + echo " * Warning: bootid.txt found but ignore_bootid / bootid=.. bootoption missing...">>/boot.log + return 1 + fi + + if [ "$BOOTID" = "$bootid_conf" ] + then + echo " * Successfully verified /conf/bootid.txt from ISO, continuing... ">>/boot.log + else + echo " * Warning: BOOTID of ISO does not match. Retrying and continuing search...">>/boot.log + return 1 + fi + + return 0 +} + + matches_uuid () { if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ] @@ -95,6 +131,7 @@ is_nice_device () check_dev () { + local force fix sysdev="${1}" devname="${2}" skip_uuid_check="${3}" @@ -102,7 +139,20 @@ check_dev () # support for fromiso=.../isofrom=.... if [ -n "$FROMISO" ] then - ISO_DEVICE=$(dirname $FROMISO) + fs_type="${FROMISO%%:*}" + fs_type_auto='1' + ISO_DEVICE="${FROMISO}" + if echo "${fs_type}" | grep -q '[^[:alnum:]_-]'; then + # Not a valid file system name. Treat as part of the + # path, and, especially, use autodetection. + fs_type='' + else + # Looks like a file system specification, treat it + # like that. + fs_type_auto='0' + ISO_DEVICE="${ISO_DEVICE#*:}" + fi + ISO_DEVICE=$(dirname "${ISO_DEVICE}") if ! [ -b $ISO_DEVICE ] then # to support unusual device names like /dev/cciss/c0d0p1 @@ -114,23 +164,57 @@ check_dev () ISO_DEVICE=$(dirname ${ISO_DEVICE}) [ -b "$ISO_DEVICE" ] && break i=$(($i -1)) - done + done fi if [ "$ISO_DEVICE" = "/" ] then - echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log + # not a block device, check if it's an iso file, for + # example an ISO when booting on an ONIE system + if echo "${FROMISO}" | grep -q "\.iso$" + then + if [ '0' -ne "${fs_type_auto}" ]; then + # Autodetect fs type if not overridden. + fs_type=$(get_fstype "${FROMISO}") + fi + if is_supported_fs ${fs_type} + then + mkdir /run/live/fromiso + mount -t "${fs_type}" -o 'ro' "${FROMISO}" '/run/live/fromiso' + if [ "$?" != 0 ] + then + echo "Warning: unable to mount ${FROMISO} (type ${fs_type})." >>/boot.log + fi + devname="/run/live/fromiso" + fi + else + echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log + fi else - fs_type=$(get_fstype "${ISO_DEVICE}") + # Need to extract actual ISO file path later on, + # initialize first. + iso_name="${FROMISO}" + + if [ '0' -ne "${fs_type_auto}" ]; then + # Try to auto-detect file system if not + # explicitly provided. + fs_type=$(get_fstype "${ISO_DEVICE}") + else + # Delete file system type override. + iso_name="${iso_name#*:}" + fi + # At this point, the backing device should always be + # at the very front, so remove that - leaving only the + # ISO file path. + iso_name="$(echo "${iso_name}" | sed "s|^${ISO_DEVICE}||")" if is_supported_fs ${fs_type} then - mkdir /live/fromiso - mount -t $fs_type "$ISO_DEVICE" /live/fromiso - ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")" - loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '') + mkdir /run/live/fromiso + mount -t "${fs_type}" -o 'ro' "$ISO_DEVICE" '/run/live/fromiso' + loopdevname=$(setup_loop "/run/live/fromiso/${iso_name}" "loop" "/sys/block/loop*" "" '') devname="${loopdevname}" else - echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log + echo "Warning: unable to mount $ISO_DEVICE (type ${fs_type})." >>/boot.log fi fi fi @@ -167,12 +251,13 @@ check_dev () /dev/md*) # Adding raid support - if [ -x /scripts/local-top/mdadm ] + if [ -x /scripts/local-block/mdadm ] then - [ -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 >>/boot.log - [ -r /conf/conf.d/md.orig ] && mv /conf/conf.d/md.orig /conf/conf.d/md + # Back in the day, when there was still a local-top mdadm script, we + # used to select specific devices to be auto-assembled. + # This functionality was dropped in the local-block script, so just + # scan and assemble all RAID devices. + /scripts/local-block/mdadm >>/boot.log fi ;; esac @@ -195,6 +280,33 @@ check_dev () then devuid=$(blkid -o value -s UUID "$devname") [ -n "$devuid" ] && grep -qs "\<$devuid\>" /var/lib/live/boot/devices-already-tried-to-mount && continue + + for _PARAMETER in ${LIVE_BOOT_CMDLINE} + do + case "${_PARAMETER}" in + forcefsck) + FORCEFSCK="true" + ;; + esac + done + + if [ "${PERSISTENCE_FSCK}" = "true" ] || [ "${PERSISTENCE_FSCK}" = "yes" ] || [ "${FORCEFSCK}" = "true" ] + then + force="" + if [ "$FORCEFSCK" = "true" ] + then + force="-f" + fi + + fix="-a" + if [ "$FSCKFIX" = "true" ] || [ "$FSCKFIX" = "yes" ] + then + fix="-y" + fi + + fsck $fix $force ${devname} >> fsck.log 2>&1 + fi + mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue [ -n "$devuid" ] && echo "$devuid" >> /var/lib/live/boot/devices-already-tried-to-mount @@ -203,9 +315,9 @@ check_dev () if [ -f ${mountpoint}/${FINDISO} ] then umount ${mountpoint} - mkdir -p /live/findiso - mount -t ${fstype} -o ro,noatime "${devname}" /live/findiso - loopdevname=$(setup_loop "/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "") + mkdir -p /run/live/findiso + mount -t ${fstype} -o ro,noatime "${devname}" /run/live/findiso + loopdevname=$(setup_loop "/run/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "") devname="${loopdevname}" mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint} else @@ -214,7 +326,7 @@ check_dev () fi if is_live_path ${mountpoint} && \ - ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint}) + ([ "${skip_uuid_check}" ] || grml_match_bootid ${mountpoint}) then echo ${mountpoint} return 0 @@ -310,19 +422,6 @@ find_livefs () return 0 fi done - elif [ "${fstype}" = "squashfs" -o \ - "${fstype}" = "btrfs" -o \ - "${fstype}" = "ext2" -o \ - "${fstype}" = "ext3" -o \ - "${fstype}" = "ext4" -o \ - "${fstype}" = "jffs2" ] - then - # This is an ugly hack situation, the block device has - # an image directly on it. It's hopefully - # live-boot, so take it and run with it. - ln -s "${devname}" "${devname}.${fstype}" - echo "${devname}.${fstype}" - return 0 fi done @@ -420,7 +519,21 @@ is_supported_fs () 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 + # For ntfs, since user space program ntfs-3g will be used. Check ntfs-3g instead of kernel module. + if [ "${fstype}" = "ntfs" ]; then + if type ntfs-3g >/dev/null 2>&1; then + return 0 + else + return 1 + fi + fi if grep -q ${fstype} /proc/filesystems then return 0 @@ -449,7 +562,7 @@ is_supported_fs () get_fstype () { - /sbin/blkid -s TYPE -o value $1 2>/dev/null + blkid -s TYPE -o value $1 2>/dev/null } where_is_mounted () @@ -507,7 +620,7 @@ base_path () { testpath="${1}" mounts="$(awk '{print $2}' /proc/mounts)" - testpath="$(busybox realpath ${testpath})" + testpath="$(realpath ${testpath})" while true do @@ -625,7 +738,7 @@ setup_loop () echo "${passphrase}" > /tmp/passphrase unset passphrase exec 9 boot.log && return 0 ) + ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" >> boot.log && return 0 ) fi } @@ -697,7 +810,7 @@ mount_persistence_media () # 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 + # underneath /run/live/persistence, so we're done if [ -d "${device}" ] then echo "${device}" @@ -709,7 +822,7 @@ mount_persistence_media () return 1 fi - backing="/live/persistence/$(basename ${device})" + backing="/run/live/persistence/$(basename ${device})" mkdir -p "${backing}" old_backing="$(where_is_mounted ${device})" @@ -721,7 +834,7 @@ mount_persistence_media () then mount_opts="ro,noatime" fi - if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null + if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null 2>&1 then echo ${backing} return 0 @@ -732,7 +845,7 @@ mount_persistence_media () fi elif [ "${backing}" != "${old_backing}" ] then - if ! mount --move ${old_backing} ${backing} >/dev/null + if ! mount -o move ${old_backing} ${backing} >/dev/null then [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}" rmdir "${backing}" @@ -772,7 +885,7 @@ close_persistence_media () if is_active_luks_mapping ${device} then - /sbin/cryptsetup luksClose ${device} + cryptsetup luksClose ${device} fi } @@ -786,7 +899,7 @@ open_luks_device () 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|") @@ -827,7 +940,7 @@ open_luks_device () while true do $cryptkeyscript "$cryptkeyprompt" | \ - /sbin/cryptsetup -T 1 luksOpen ${dev} ${name} ${opts} + cryptsetup -T 1 luksOpen ${dev} ${name} ${opts} if [ 0 -eq ${?} ] then @@ -868,14 +981,14 @@ get_gpt_name () { 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 () @@ -915,7 +1028,7 @@ probe_for_fs_label () 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 @@ -1020,7 +1133,7 @@ find_persistence_media () # in one union together. # black_listed_devices="" - for d in /live/rootfs/* /live/findiso /live/fromiso + for d in /run/live/rootfs/* /run/live/findiso /run/live/fromiso do black_listed_devices="${black_listed_devices} $(what_is_mounted_on d)" done @@ -1074,18 +1187,18 @@ find_persistence_media () 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 @@ -1108,7 +1221,7 @@ find_persistence_media () # 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 @@ -1139,13 +1252,13 @@ get_mac () 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 () @@ -1163,6 +1276,10 @@ removable_dev () 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 @@ -1208,6 +1325,10 @@ non_removable_dev () 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 @@ -1301,31 +1422,33 @@ do_union () unionmountopts="${unionmountopts}:${rofs}=${ro_opt}" done fi - mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}" ;; overlay) - rw_opt="rw" - ro_opt="ro" - - # XXX: can multiple unionro be used? (overlay only handles two dirs, but perhaps they can be chained?) - # XXX: and can unionro be optional? i.e. can overlay skip lowerdir? - if echo ${unionro} | grep -q " " - then - panic "Multiple lower filesystems are currently not supported with overlay (unionro = ${unionro})." - elif [ -z "${unionro}" ] + # XXX: can unionro be optional? i.e. can overlay skip lowerdir? + if [ -z "${unionro}" ] then 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}" + # 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 -p "${unionrw}/rw" + mkdir -p "${unionrw}/work" + unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}/rw,workdir=${unionrw}/work" ;; esac + + mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}" } get_custom_mounts () { - # Side-effect: leaves $devices with persistence.conf mounted in /live/persistence + # Side-effect: leaves $devices with persistence.conf mounted in /run/live/persistence # Side-effect: prints info to file $custom_mounts local custom_mounts devices bindings links @@ -1356,7 +1479,7 @@ get_custom_mounts () if [ -n "${LIVE_BOOT_DEBUG}" ] && [ -e "${include_list}" ] then - cp ${include_list} /live/persistence/${persistence_list}.${device_name} + cp ${include_list} /run/live/persistence/${persistence_list}.${device_name} fi while read dir options # < ${include_list} @@ -1367,9 +1490,9 @@ get_custom_mounts () continue fi - if trim_path ${dir} | grep -q -e "^[^/]" -e "^/lib" -e "^/lib/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$" + if trim_path ${dir} | grep -q -e "^[^/]" -e "^/lib" -e "^/run/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$" then - 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." + log_warning_msg "Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/lib\", or \"/run/live\" or any of its sub-directories." continue fi @@ -1541,7 +1664,7 @@ activate_custom_mounts () rootfs_dest_backing="" if [ -n "${opt_link}" ] || [ -n "${opt_union}" ] then - for d in /live/rootfs/* + for d in /run/live/rootfs/* do if [ -n "${rootmnt}" ] then @@ -1559,11 +1682,11 @@ activate_custom_mounts () local cow_dir links_source if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ] then - link_files ${source} ${dest} "s|^/live/|/lib/live/mount/|" + link_files ${source} ${dest} "" elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ] then - mkdir -p ${rootmnt}/lib/live/mount/persistence - links_source=$(mktemp -d ${rootmnt}/lib/live/mount/persistence/links-source-XXXXXX) + mkdir -p /run/live/persistence + links_source=$(mktemp -d /run/live/persistence/links-source-XXXXXX) chown_ref ${source} ${links_source} chmod_ref ${source} ${links_source} # We put the cow dir in the below strange place to @@ -1571,7 +1694,7 @@ activate_custom_mounts () # has its own directory and isn't nested with some # other custom mount (if so that mount's files would # be linked, causing breakage. - cow_dir="/live/overlay/lib/live/mount/persistence/$(basename ${links_source})" + cow_dir="/run/live/overlay/run/live/persistence/$(basename ${links_source})" mkdir -p ${cow_dir} chown_ref "${source}" "${cow_dir}" chmod_ref "${source}" "${cow_dir}" @@ -1582,13 +1705,13 @@ activate_custom_mounts () 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 # in read-only mode, but note that rootfs_dest_backing # is non-empty (and necessary) only for unions - cow_dir="/live/overlay/${dest}" + cow_dir="/run/live/overlay/${dest}" if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ] then # If an earlier custom mount has files here @@ -1599,6 +1722,13 @@ activate_custom_mounts () mkdir -p ${cow_dir} chown_ref "${source}" "${cow_dir}" chmod_ref "${source}" "${cow_dir}" + if [ "${UNIONTYPE}" = "overlay" ] + then + # When we use overlay we add the "/rw" postfix to our source when using it + # as upper layer. Therefore we also have to add it here when using it as + # the lower layer. + source="${source}/rw" + fi do_union ${dest} ${cow_dir} ${source} ${rootfs_dest_backing} fi