From 2e70d7be610c9e45787c37352d36241de3c155d7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 2 Jul 2012 17:40:11 +0200 Subject: Renaming boot scripts for refactoring them into numbered plugins. --- scripts/boot.sh | 58 +- scripts/boot/9990-aaa-fixme.sh | 57 ++ scripts/boot/9990-cmdline.sh | 331 +++++++ scripts/boot/9990-fstab.sh | 38 + scripts/boot/9990-initramfs-tools.sh | 67 ++ scripts/boot/9990-misc-helpers.sh | 1558 ++++++++++++++++++++++++++++++++ scripts/boot/9990-mount-cifs.sh | 28 + scripts/boot/9990-mount-http.sh | 88 ++ scripts/boot/9990-mount-iscsi.sh | 51 ++ scripts/boot/9990-mount-nfs.sh | 28 + scripts/boot/9990-mountroot.sh | 221 +++++ scripts/boot/9990-netbase.sh | 141 +++ scripts/boot/9990-netboot.sh | 41 + scripts/boot/9990-networking.sh | 163 ++++ scripts/boot/9990-overlay.sh | 410 +++++++++ scripts/boot/9990-read-only.sh | 33 + scripts/boot/9990-select-eth-device.sh | 95 ++ scripts/boot/9990-swapon.sh | 48 + scripts/boot/9990-toram-todisk.sh | 104 +++ scripts/boot/9990-verify-checksums.sh | 63 ++ scripts/boot/cmdline.sh | 331 ------- scripts/boot/fstab.sh | 38 - scripts/boot/initramfs-tools.sh | 67 -- scripts/boot/misc-helpers.sh | 1558 -------------------------------- scripts/boot/mount-cifs.sh | 28 - scripts/boot/mount-http.sh | 88 -- scripts/boot/mount-iscsi.sh | 51 -- scripts/boot/mount-nfs.sh | 28 - scripts/boot/mountroot.sh | 221 ----- scripts/boot/netbase.sh | 141 --- scripts/boot/netboot.sh | 41 - scripts/boot/networking.sh | 163 ---- scripts/boot/overlay.sh | 410 --------- scripts/boot/read-only.sh | 33 - scripts/boot/select-eth-device.sh | 95 -- scripts/boot/swapon.sh | 48 - scripts/boot/toram-todisk.sh | 104 --- scripts/boot/verify-checksums.sh | 63 -- 38 files changed, 3566 insertions(+), 3565 deletions(-) create mode 100755 scripts/boot/9990-aaa-fixme.sh create mode 100755 scripts/boot/9990-cmdline.sh create mode 100755 scripts/boot/9990-fstab.sh create mode 100755 scripts/boot/9990-initramfs-tools.sh create mode 100755 scripts/boot/9990-misc-helpers.sh create mode 100755 scripts/boot/9990-mount-cifs.sh create mode 100755 scripts/boot/9990-mount-http.sh create mode 100755 scripts/boot/9990-mount-iscsi.sh create mode 100755 scripts/boot/9990-mount-nfs.sh create mode 100755 scripts/boot/9990-mountroot.sh create mode 100755 scripts/boot/9990-netbase.sh create mode 100755 scripts/boot/9990-netboot.sh create mode 100755 scripts/boot/9990-networking.sh create mode 100755 scripts/boot/9990-overlay.sh create mode 100755 scripts/boot/9990-read-only.sh create mode 100755 scripts/boot/9990-select-eth-device.sh create mode 100755 scripts/boot/9990-swapon.sh create mode 100755 scripts/boot/9990-toram-todisk.sh create mode 100755 scripts/boot/9990-verify-checksums.sh delete mode 100755 scripts/boot/cmdline.sh delete mode 100755 scripts/boot/fstab.sh delete mode 100755 scripts/boot/initramfs-tools.sh delete mode 100755 scripts/boot/misc-helpers.sh delete mode 100755 scripts/boot/mount-cifs.sh delete mode 100755 scripts/boot/mount-http.sh delete mode 100755 scripts/boot/mount-iscsi.sh delete mode 100755 scripts/boot/mount-nfs.sh delete mode 100755 scripts/boot/mountroot.sh delete mode 100755 scripts/boot/netbase.sh delete mode 100755 scripts/boot/netboot.sh delete mode 100755 scripts/boot/networking.sh delete mode 100755 scripts/boot/overlay.sh delete mode 100755 scripts/boot/read-only.sh delete mode 100755 scripts/boot/select-eth-device.sh delete mode 100755 scripts/boot/swapon.sh delete mode 100755 scripts/boot/toram-todisk.sh delete mode 100755 scripts/boot/verify-checksums.sh (limited to 'scripts') diff --git a/scripts/boot.sh b/scripts/boot.sh index 9539496..c031f00 100755 --- a/scripts/boot.sh +++ b/scripts/boot.sh @@ -2,66 +2,10 @@ # set -e -if [ -e /scripts/functions ] -then - # initramfs-tools specific (FIXME) - . /scripts/functions -fi - -for _SCRIPT in /lib/live/boot/* +for _SCRIPT in /lib/live/boot/????-* do if [ -e "${_SCRIPT}" ] then . ${_SCRIPT} fi done - -export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin" - -echo "/root/lib" >> /etc/ld.so.conf -echo "/root/usr/lib" >> /etc/ld.so.conf - -mountpoint="/live/image" -alt_mountpoint="/media" -LIVE_MEDIA_PATH="live" - -HOSTNAME="host" - -mkdir -p "${mountpoint}" -tried="/tmp/tried" - -# Create /etc/mtab for debug purpose and future syncs -if [ ! -d /etc ] -then - mkdir /etc/ -fi - -if [ ! -f /etc/mtab ] -then - touch /etc/mtab -fi - -if [ ! -x "/bin/fstype" ] -then - # klibc not in path -> not in initramfs - export PATH="${PATH}:/usr/lib/klibc/bin" -fi - -# handle upgrade path from old udev (using udevinfo) to -# recent versions of udev (using udevadm info) -if [ -x /sbin/udevadm ] -then - udevinfo='/sbin/udevadm info' -else - udevinfo='udevinfo' -fi - -old_root_overlay_label="live-rw" -old_home_overlay_label="home-rw" -custom_overlay_label="persistence" -persistence_list="live-persistence.conf" - -if [ ! -f /live.vars ] -then - touch /live.vars -fi diff --git a/scripts/boot/9990-aaa-fixme.sh b/scripts/boot/9990-aaa-fixme.sh new file mode 100755 index 0000000..77a291a --- /dev/null +++ b/scripts/boot/9990-aaa-fixme.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +if [ -e /scripts/functions ] +then + # initramfs-tools specific (FIXME) + . /scripts/functions +fi + +export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin" + +echo "/root/lib" >> /etc/ld.so.conf +echo "/root/usr/lib" >> /etc/ld.so.conf + +mountpoint="/live/image" +alt_mountpoint="/media" +LIVE_MEDIA_PATH="live" + +HOSTNAME="host" + +mkdir -p "${mountpoint}" +tried="/tmp/tried" + +# Create /etc/mtab for debug purpose and future syncs +if [ ! -d /etc ] +then + mkdir /etc/ +fi + +if [ ! -f /etc/mtab ] +then + touch /etc/mtab +fi + +if [ ! -x "/bin/fstype" ] +then + # klibc not in path -> not in initramfs + export PATH="${PATH}:/usr/lib/klibc/bin" +fi + +# handle upgrade path from old udev (using udevinfo) to +# recent versions of udev (using udevadm info) +if [ -x /sbin/udevadm ] +then + udevinfo='/sbin/udevadm info' +else + udevinfo='udevinfo' +fi + +old_root_overlay_label="live-rw" +old_home_overlay_label="home-rw" +custom_overlay_label="persistence" +persistence_list="live-persistence.conf" + +if [ ! -f /live.vars ] +then + touch /live.vars +fi diff --git a/scripts/boot/9990-cmdline.sh b/scripts/boot/9990-cmdline.sh new file mode 100755 index 0000000..a3781da --- /dev/null +++ b/scripts/boot/9990-cmdline.sh @@ -0,0 +1,331 @@ +#!/bin/sh + +#set -e + +Cmdline () +{ + for _PARAMETER in ${_CMDLINE} + do + case "${_PARAMETER}" in + live-boot.read-only|read-only) + LIVE_READ_ONLY="true" + ;; + + live-boot.swapon) + LIVE_SWAPON="true" + ;; + + live-boot.verify-checksums|verify-checksums) + LIVE_VERIFY_CHECKSUMS="true" + ;; + + # Special options + live-boot.debug|debug) + LIVE_DEBUG="true" + ;; + + + # parameters below need review (FIXME) + skipconfig) + NOFSTAB="true" + NONETWORKING="true" + + export NOFSTAB NONETWORKING + ;; + + BOOTIF=*) + BOOTIF="${x#BOOTIF=}" + ;; + + dhcp) + # Force dhcp even while netbooting + # Use for debugging in case somebody works on fixing dhclient + DHCP="true"; + export DHCP + ;; + + nodhcp) + DHCP="" + export DHCP + ;; + + ethdevice=*) + DEVICE="${_PARAMETER#ethdevice=}" + ETHDEVICE="${DEVICE}" + export DEVICE ETHDEVICE + ;; + + ethdevice-timeout=*) + ETHDEV_TIMEOUT="${_PARAMETER#ethdevice-timeout=}" + export ETHDEV_TIMEOUT + ;; + + fetch=*) + FETCH="${_PARAMETER#fetch=}" + export FETCH + ;; + + findiso=*) + FINDISO="${_PARAMETER#findiso=}" + export FINDISO + ;; + + ftpfs=*) + FTPFS="${_PARAMETER#ftpfs=}" + export FTPFS + ;; + + httpfs=*) + HTTPFS="${_PARAMETER#httpfs=}" + export HTTPFS + ;; + + iscsi=*) + ISCSI="${_PARAMETER#iscsi=}" + #ip:port - separated by ; + ISCSI_PORTAL="${ISCSI%;*}" + if echo "${ISCSI_PORTAL}" | grep -q , ; then + ISCSI_SERVER="${ISCSI_PORTAL%,*}" + ISCSI_PORT="${ISCSI_PORTAL#*,}" + fi + #target name + ISCSI_TARGET="${ISCSI#*;}" + export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT + ;; + + isofrom=*|fromiso=*) + FROMISO="${_PARAMETER#*=}" + export FROMISO + ;; + + ignore_uuid) + IGNORE_UUID="true" + export IGNORE_UUID + ;; + + ip=*) + STATICIP="${_PARAMETER#ip=}" + + if [ -z "${STATICIP}" ] + then + STATICIP="frommedia" + fi + + export STATICIP + ;; + + live-media=*|bootfrom=*) + LIVE_MEDIA="${_PARAMETER#*=}" + export LIVE_MEDIA + ;; + + live-media-encryption=*|encryption=*) + LIVE_MEDIA_ENCRYPTION="${_PARAMETER#*=}" + export LIVE_MEDIA_ENCRYPTION + ;; + + live-media-offset=*) + LIVE_MEDIA_OFFSET="${_PARAMETER#live-media-offset=}" + export LIVE_MEDIA_OFFSET + ;; + + live-media-path=*) + LIVE_MEDIA_PATH="${_PARAMETER#live-media-path=}" + export LIVE_MEDIA_PATH + ;; + + live-media-timeout=*) + LIVE_MEDIA_TIMEOUT="${_PARAMETER#live-media-timeout=}" + export LIVE_MEDIA_TIMEOUT + ;; + + module=*) + MODULE="${_PARAMETER#module=}" + export MODULE + ;; + + netboot=*) + NETBOOT="${_PARAMETER#netboot=}" + export NETBOOT + ;; + + nfsopts=*) + NFSOPTS="${_PARAMETER#nfsopts=}" + export NFSOPTS + ;; + + nfsoverlay=*) + NFS_COW="${_PARAMETER#nfsoverlay=}" + export NFS_COW + ;; + + nofstab) + NOFSTAB="true" + export NOFSTAB + ;; + + nonetworking) + NONETWORKING="true" + export NONETWORKING + ;; + + ramdisk-size=*) + ramdisk_size="${_PARAMETER#ramdisk-size=}" + ;; + + persistence) + PERSISTENCE="true" + export PERSISTENCE + ;; + + persistence-encryption=*) + PERSISTENCE_ENCRYPTION="${_PARAMETER#*=}" + export PERSISTENCE_ENCRYPTION + ;; + + persistence-media=*) + PERSISTENCE_MEDIA="${_PARAMETER#*=}" + export PERSISTENCE_MEDIA + ;; + persistence-method=*) + PERSISTENCE_METHOD="${_PARAMETER#*=}" + export PERSISTENCE_METHOD + ;; + + persistence-path=*) + PERSISTENCE_PATH="${_PARAMETER#persistence-path=}" + export PERSISTENCE_PATH + ;; + persistence-read-only) + PERSISTENCE_READONLY="true" + export PERSISTENCE_READONLY + ;; + + persistence-storage=*) + PERSISTENCE_STORAGE="${_PARAMETER#persistence-storage=}" + export PERSISTENCE_STORAGE + ;; + + persistence-label=*) + old_root_overlay_label="${_PARAMETER#persistence-label=*}" + old_home_overlay_label="${_PARAMETER#persistence-label=*}" + custom_overlay_label="${_PARAMETER#persistence-label=*}" + ;; + + nopersistence) + NOPERSISTENCE="true" + export NOPERSISTENCE + ;; + + quickusbmodules) + QUICKUSBMODULES="true" + export QUICKUSBMODULES + ;; + + showmounts) + SHOWMOUNTS="true" + export SHOWMOUNTS + ;; + + todisk=*) + TODISK="${_PARAMETER#todisk=}" + export TODISK + ;; + + toram) + TORAM="true" + export TORAM + ;; + + toram=*) + TORAM="true" + MODULETORAM="${_PARAMETER#toram=}" + export TORAM MODULETORAM + ;; + + exposedroot) + EXPOSED_ROOT="true" + export EXPOSED_ROOT + ;; + + plainroot) + PLAIN_ROOT="true" + export PLAIN_ROOT + ;; + + skipunion) + SKIP_UNION_MOUNTS="true" + export SKIP_UNION_MOUNTS + ;; + + root=*) + ROOT="${_PARAMETER#root=}" + export ROOT + ;; + + union=*) + UNIONTYPE="${_PARAMETER#union=}" + export UNIONTYPE + ;; + esac + done + + # sort of compatibility with netboot.h from linux docs + if [ -z "${NETBOOT}" ] + then + if [ "${ROOT}" = "/dev/nfs" ] + then + NETBOOT="nfs" + export NETBOOT + elif [ "${ROOT}" = "/dev/cifs" ] + then + NETBOOT="cifs" + export NETBOOT + fi + fi + + if [ -z "${MODULE}" ] + then + MODULE="filesystem" + export MODULE + fi + + if [ -z "${UNIONTYPE}" ] + then + UNIONTYPE="aufs" + export UNIONTYPE + fi + + if [ -z "${PERSISTENCE_ENCRYPTION}" ] + then + PERSISTENCE_ENCRYPTION="none" + export PERSISTENCE_ENCRYPTION + elif is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} + then + if ! modprobe dm-crypt + then + log_warning_msg "Unable to load module dm-crypt" + PERSISTENCE_ENCRYPTION=$(echo ${PERSISTENCE_ENCRYPTION} | sed -e 's/\> "${_FSTAB}" + fi + + if ! grep -qs "^tmpfs /tmp" "${_FSTAB}" + then + echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> "${_FSTAB}" + fi + + log_end_msg +} diff --git a/scripts/boot/9990-initramfs-tools.sh b/scripts/boot/9990-initramfs-tools.sh new file mode 100755 index 0000000..37aa0c3 --- /dev/null +++ b/scripts/boot/9990-initramfs-tools.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +#set -e + +log_wait_msg () +{ + # Print a message and wait for enter + if [ -x /bin/plymouth ] && plymouth --ping + then + plymouth message --text="$@" + plymouth watch-keystroke | read nunya + fi + + _log_msg "Waiting: ${@} ... \n" +} + +# Override maybe_break from scripts/functions +maybe_break() +{ + if [ "${break}" = "$1" ]; then + # Call original panic + . /scripts/functions + panic "Spawning shell within the initramfs" + fi +} + +# Override panic from scripts/functions +panic() { + + DEB_1="\033[1;31m .''\`. \033[0m" + DEB_2="\033[1;31m: :' : \033[0m" + DEB_3="\033[1;31m\`. \`'\` \033[0m" + DEB_4="\033[1;31m \`- \033[0m" + + LIVELOG="\033[1;37m/boot.log\033[0m" + DEBUG="\033[1;37mdebug\033[0m" + + # Reset redirections to avoid buffering + exec 1>&6 6>&- + exec 2>&7 7>&- + kill ${tailpid} + + printf "\n\n" + printf " ${DEB_1}\n" + printf " ${DEB_2} \033[1;37mBOOT FAILED!\033[0m\n" + printf " ${DEB_3}\n" + printf " ${DEB_4} This Debian Live image failed to boot.\n\n" + + printf " Please file a bug against the 'live-boot' package or email the Debian\n" + printf " Live mailing list at , making sure to note the\n" + printf " exact version, name and distribution of the image you were attempting to boot.\n\n" + + printf " The file ${LIVELOG} contains some debugging information but booting with the\n" + printf " ${DEBUG} command-line parameter will greatly increase its verbosity which is\n" + printf " extremely useful when diagnosing issues.\n\n" + + if [ -n "${panic}" ]; then + printf " live-boot will now restart your system. " + else + printf " live-boot will now start a shell. " + fi + printf "The error message was:\n\n " + + # Call original panic + . /scripts/functions + panic "$@" +} diff --git a/scripts/boot/9990-misc-helpers.sh b/scripts/boot/9990-misc-helpers.sh new file mode 100755 index 0000000..cc39fcb --- /dev/null +++ b/scripts/boot/9990-misc-helpers.sh @@ -0,0 +1,1558 @@ +#!/bin/sh + +#set -e + +is_live_path () +{ + DIRECTORY="${1}" + + if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ] + then + for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2 + do + if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ] + then + return 0 + fi + done + fi + + return 1 +} + +matches_uuid () +{ + if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ] + then + return 0 + fi + + path="${1}" + uuid="$(cat /conf/uuid.conf)" + + for try_uuid_file in "${path}/.disk/live-uuid"* + do + [ -e "${try_uuid_file}" ] || continue + + try_uuid="$(cat "${try_uuid_file}")" + + if [ "${uuid}" = "${try_uuid}" ] + then + return 0 + fi + done + + return 1 +} + +get_backing_device () +{ + case "${1}" in + *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2) + echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}") + ;; + + *.dir) + echo "directory" + ;; + + *) + panic "Unrecognized live filesystem: ${1}" + ;; + esac +} + +match_files_in_dir () +{ + # Does any files match pattern ${1} ? + local pattern="${1}" + + if [ "$(echo ${pattern})" != "${pattern}" ] + then + return 0 + fi + + return 1 +} + +mount_images_in_directory () +{ + directory="${1}" + rootmnt="${2}" + mac="${3}" + + if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir" + then + [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}" + setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}" + else + panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}." + fi +} + +is_nice_device () +{ + sysfs_path="${1#/sys}" + + if [ -e /lib/udev/path_id ] + then + # squeeze + PATH_ID="/lib/udev/path_id" + else + # wheezy/sid (udev >= 174) + PATH_ID="/sbin/udevadm test-builtin path_id" + fi + + if ${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)" + then + return 0 + elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$' + then + return 0 + elif echo ${sysfs_path} | grep -q "^/block/dm-" + then + return 0 + elif echo ${sysfs_path} | grep -q "^/block/mtdblock" + then + return 0 + fi + + return 1 +} + +check_dev () +{ + sysdev="${1}" + devname="${2}" + skip_uuid_check="${3}" + + # support for fromiso=.../isofrom=.... + if [ -n "$FROMISO" ] + then + ISO_DEVICE=$(dirname $FROMISO) + if ! [ -b $ISO_DEVICE ] + then + # to support unusual device names like /dev/cciss/c0d0p1 + # as well we have to identify the block device name, let's + # do that for up to 15 levels + i=15 + while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ] + do + ISO_DEVICE=$(dirname ${ISO_DEVICE}) + [ -b "$ISO_DEVICE" ] && break + i=$(($i -1)) + done + fi + + if [ "$ISO_DEVICE" = "/" ] + then + echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log + else + fs_type=$(get_fstype "${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*" "" '') + devname="${loopdevname}" + else + echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log + fi + fi + fi + + if [ -z "${devname}" ] + then + devname=$(sys2dev "${sysdev}") + fi + + if [ -d "${devname}" ] + then + mount -o bind "${devname}" $mountpoint || continue + + if is_live_path $mountpoint + then + echo $mountpoint + return 0 + else + umount $mountpoint + fi + fi + + IFS="," + for device in ${devname} + do + case "$device" in + *mapper*) + # Adding lvm support + if [ -x /scripts/local-top/lvm2 ] + then + ROOT="$device" resume="" /scripts/local-top/lvm2 + fi + ;; + + /dev/md*) + # Adding raid support + if [ -x /scripts/local-top/mdadm ] + then + 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 + fi + ;; + esac + done + unset IFS + + [ -n "$device" ] && devname="$device" + + [ -e "$devname" ] || continue + + if [ -n "${LIVE_MEDIA_OFFSET}" ] + then + loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '') + devname="${loopdevname}" + fi + + fstype=$(get_fstype "${devname}") + + if is_supported_fs ${fstype} + then + devuid=$(blkid -o value -s UUID "$devname") + [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue + mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue + [ -n "$devuid" ] && echo "$devuid" >> $tried + + if [ -n "${FINDISO}" ] + then + 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 "") + devname="${loopdevname}" + mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint} + else + umount ${mountpoint} + fi + fi + + if is_live_path ${mountpoint} && \ + ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint}) + then + echo ${mountpoint} + return 0 + else + umount ${mountpoint} 2>/dev/null + fi + fi + + if [ -n "${LIVE_MEDIA_OFFSET}" ] + then + losetup -d "${loopdevname}" + fi + + return 1 +} + +find_livefs () +{ + timeout="${1}" + + # don't start autodetection before timeout has expired + if [ -n "${LIVE_MEDIA_TIMEOUT}" ] + then + if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ] + then + return 1 + fi + fi + + # first look at the one specified in the command line + case "${LIVE_MEDIA}" in + removable-usb) + for sysblock in $(removable_usb_dev "sys") + do + for dev in $(subdevices "${sysblock}") + do + if check_dev "${dev}" + then + return 0 + fi + done + done + return 1 + ;; + + removable) + for sysblock in $(removable_dev "sys") + do + for dev in $(subdevices "${sysblock}") + do + if check_dev "${dev}" + then + return 0 + fi + done + done + return 1 + ;; + + *) + if [ ! -z "${LIVE_MEDIA}" ] + then + if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check" + then + return 0 + fi + fi + ;; + esac + + # or do the scan of block devices + # prefer removable devices over non-removable devices, so scan them first + devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')" + + for sysblock in $devices_to_scan + do + devname=$(sys2dev "${sysblock}") + [ -e "$devname" ] || continue + fstype=$(get_fstype "${devname}") + + if /lib/udev/cdrom_id ${devname} > /dev/null + then + if check_dev "null" "${devname}" + then + return 0 + fi + elif is_nice_device "${sysblock}" + then + for dev in $(subdevices "${sysblock}") + do + if check_dev "${dev}" + then + 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 + + return 1 +} + +really_export () +{ + STRING="${1}" + VALUE="$(eval echo -n \${$STRING})" + + if [ -f /live.vars ] && grep -sq "export ${STRING}" /live.vars + then + sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars + else + echo "export ${STRING}=\"${VALUE}\"" >> /live.vars + fi + + eval export "${STRING}"="${VALUE}" +} + +is_in_list_separator_helper () +{ + local sep=${1} + shift + local element=${1} + shift + local list=${*} + echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$" +} + +is_in_space_sep_list () +{ + local element=${1} + shift + is_in_list_separator_helper "[[:space:]]" "${element}" "${*}" +} + +is_in_comma_sep_list () +{ + local element=${1} + shift + is_in_list_separator_helper "," "${element}" "${*}" +} + +sys2dev () +{ + sysdev=${1#/sys} + echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})" +} + +subdevices () +{ + sysblock=${1} + r="" + + for dev in "${sysblock}"/* "${sysblock}" + do + if [ -e "${dev}/dev" ] + then + r="${r} ${dev}" + fi + done + + echo ${r} +} + +storage_devices() +{ + black_listed_devices="${1}" + white_listed_devices="${2}" + + for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd") + do + fulldevname=$(sys2dev "${sysblock}") + + if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \ + [ -n "${white_listed_devices}" ] && \ + ! is_in_space_sep_list ${fulldevname} ${white_listed_devices} + then + # skip this device entirely + continue + fi + + for dev in $(subdevices "${sysblock}") + do + devname=$(sys2dev "${dev}") + + if is_in_space_sep_list ${devname} ${black_listed_devices} + then + # skip this subdevice + continue + else + echo "${devname}" + fi + done + done +} + +is_supported_fs () +{ + fstype="${1}" + + # Validate input first + if [ -z "${fstype}" ] + 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} + if grep -q ${fstype} /proc/filesystems + then + return 0 + # Then try the hard way if /root is already reachable + else + kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko" + if [ -e "${kmodule}" ] + then + insmod "${kmodule}" + if grep -q ${fstype} /proc/filesystems + then + return 0 + fi + fi + fi + fi + + return 1 +} + +get_fstype () +{ + /sbin/blkid -s TYPE -o value $1 2>/dev/null +} + +where_is_mounted () +{ + device=${1} + # return first found + grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' ' +} + +trim_path () +{ + # remove all unnecessary /:s in the path, including last one (except + # if path is just "/") + echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|' +} + +what_is_mounted_on () +{ + local dir="$(trim_path ${1})" + grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1 +} + +chown_ref () +{ + local reference="${1}" + shift + local targets=${@} + local owner=$(stat -c %u:%g "${reference}") + chown -h ${owner} ${targets} +} + +chmod_ref () +{ + local reference="${1}" + shift + local targets=${@} + local rights=$(stat -c %a "${reference}") + chmod ${rights} ${targets} +} + +lastline () +{ + while read lines + do + line=${lines} + done + + echo "${line}" +} + +base_path () +{ + testpath="${1}" + mounts="$(awk '{print $2}' /proc/mounts)" + testpath="$(busybox realpath ${testpath})" + + while true + do + if echo "${mounts}" | grep -qs "^${testpath}" + then + set -- $(echo "${mounts}" | grep "^${testpath}" | lastline) + echo ${1} + break + else + testpath=$(dirname $testpath) + fi + done +} + +fs_size () +{ + # Returns used/free fs kbytes + 5% more + # You could pass a block device as ${1} or the mount point as ${2} + + dev="${1}" + mountp="${2}" + used="${3}" + + if [ -z "${mountp}" ] + then + mountp="$(where_is_mounted ${dev})" + + if [ -z "${mountp}" ] + then + mountp="/mnt/tmp_fs_size" + + mkdir -p "${mountp}" + mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}" + + doumount=1 + fi + fi + + if [ "${used}" = "used" ] + then + size=$(du -ks ${mountp} | cut -f1) + size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure + else + # free space + size="$(df -k | grep -s ${mountp} | awk '{print $4}')" + fi + + if [ -n "${doumount}" ] + then + umount "${mountp}" || log_warning_msg "cannot umount ${mountp}" + rmdir "${mountp}" + fi + + echo "${size}" +} + +load_keymap () +{ + # Load custom keymap + if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ] + then + loadkeys /etc/boottime.kmap.gz + fi +} + +setup_loop () +{ + local fspath=${1} + local module=${2} + local pattern=${3} + local offset=${4} + local encryption=${5} + local readonly=${6} + + # the output of setup_loop is evaluated in other functions, + # modprobe leaks kernel options like "libata.dma=0" + # as "options libata dma=0" on stdout, causing serious + # problems therefor, so instead always avoid output to stdout + modprobe -q -b "${module}" 1>/dev/null + + udevadm settle + + for loopdev in ${pattern} + do + if [ "$(cat ${loopdev}/size)" -eq 0 ] + then + dev=$(sys2dev "${loopdev}") + options='' + + if [ -n "${readonly}" ] + then + if losetup --help 2>&1 | grep -q -- "-r\b" + then + options="${options} -r" + fi + fi + + if [ -n "${offset}" ] && [ 0 -lt "${offset}" ] + then + options="${options} -o ${offset}" + fi + + if [ -z "${encryption}" ] + then + losetup ${options} "${dev}" "${fspath}" + else + # Loop AES encryption + while true + do + load_keymap + + echo -n "Enter passphrase for root filesystem: " >&6 + read -s passphrase + echo "${passphrase}" > /tmp/passphrase + unset passphrase + exec 9&6 + read answer + + if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ] + then + unset answer + break + fi + done + fi + + echo "${dev}" + return 0 + fi + done + + panic "No loop devices available" +} + +try_mount () +{ + 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}" > boot.log && return 0 ) + fi +} + +mount_persistence_media () +{ + local device=${1} + local probe=${2} + + local backing="/live/persistence/$(basename ${device})" + + mkdir -p "${backing}" + local old_backing="$(where_is_mounted ${device})" + if [ -z "${old_backing}" ] + then + local fstype="$(get_fstype ${device})" + local mount_opts="rw,noatime" + if [ -n "${PERSISTENCE_READONLY}" ] + then + mount_opts="ro,noatime" + fi + if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null + then + echo ${backing} + return 0 + else + [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}" + rmdir "${backing}" + return 1 + fi + elif [ "${backing}" != "${old_backing}" ] + then + if mount --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 + fi + return 0 +} + +close_persistence_media () +{ + local device=${1} + local backing="$(where_is_mounted ${device})" + + if [ -d "${backing}" ] + then + umount "${backing}" >/dev/null 2>&1 + rmdir "${backing}" >/dev/null 2>&1 + fi + + if is_active_luks_mapping ${device} + then + /sbin/cryptsetup luksClose ${device} + fi +} + +open_luks_device () +{ + dev="${1}" + name="$(basename ${dev})" + opts="--key-file=-" + if [ -n "${PERSISTENCE_READONLY}" ] + then + opts="${opts} --readonly" + fi + + if /sbin/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|") + if [ "${opened_dev}" = "${dev}" ] + then + luks_device="/dev/mapper/${name}" + echo ${luks_device} + return 0 + else + log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name" + return 1 + fi + 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 +} + +get_gpt_name () +{ + local dev="${1}" + /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null +} + +is_gpt_device () +{ + local dev="${1}" + [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ] +} + +probe_for_gpt_name () +{ + local overlays="${1}" + local dev="${2}" + + local gpt_dev="${dev}" + if is_active_luks_mapping ${dev} + then + # if $dev is an opened luks device, we need to check + # GPT stuff on the backing device + gpt_dev=$(get_luks_backing_device "${dev}") + fi + + if ! is_gpt_device ${gpt_dev} + then + return + fi + + local gpt_name=$(get_gpt_name ${gpt_dev}) + for label in ${overlays} + do + if [ "${gpt_name}" = "${label}" ] + then + echo "${label}=${dev}" + fi + done +} + +probe_for_fs_label () +{ + local overlays="${1}" + local dev="${2}" + + for label in ${overlays} + do + if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ] + then + echo "${label}=${dev}" + fi + done +} + +probe_for_file_name () +{ + local overlays="${1}" + local dev="${2}" + + local ret="" + local backing="$(mount_persistence_media ${dev} probe)" + if [ -z "${backing}" ] + then + return + fi + + for label in ${overlays} + do + path=${backing}/${PERSISTENCE_PATH}${label} + if [ -f "${path}" ] + then + local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*") + ret="${ret} ${label}=${loopdev}" + fi + done + + if [ -n "${ret}" ] + then + echo ${ret} + else + umount ${backing} > /dev/null 2>&1 || true + fi +} + +find_persistence_media () +{ + # Scans devices for overlays, and returns a whitespace + # separated list of how to use them. Only overlays with a partition + # label or file name in ${overlays} are returned. + # + # When scanning a LUKS device, the user will be asked to enter the + # passphrase; on failure to enter it, or if no persistence partitions + # or files were found, the LUKS device is closed. + # + # For all other cases (overlay 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. + + local overlays="${1}" + local white_listed_devices="${2}" + local ret="" + + local black_listed_devices="$(what_is_mounted_on /live/image)" + + for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}") + do + local result="" + + local luks_device="" + # Check if it's a luks device; we'll have to open the device + # in order to probe any filesystem it contains, like we do + # below. activate_custom_mounts() also depends on that any luks + # device already has been opened. + if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${dev} + then + if luks_device=$(open_luks_device "${dev}") + then + dev="${luks_device}" + else + # skip $dev since we failed/chose not to open it + continue + fi + elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION} + then + # skip $dev since we don't allow unencrypted storage + continue + fi + + # Probe for matching GPT partition names or filesystem labels + if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE} + then + result=$(probe_for_gpt_name "${overlays}" ${dev}) + if [ -n "${result}" ] + then + ret="${ret} ${result}" + continue + fi + + result=$(probe_for_fs_label "${overlays}" ${dev}) + if [ -n "${result}" ] + then + ret="${ret} ${result}" + continue + fi + fi + + # Probe for files with matching name on mounted partition + if is_in_comma_sep_list file ${PERSISTENCE_STORAGE} + then + result=$(probe_for_file_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}" + fi + done + + if [ -n "${ret}" ] + then + echo ${ret} + fi +} + +get_mac () +{ + mac="" + + for adaptor in /sys/class/net/* + do + status="$(cat ${adaptor}/iflink)" + + if [ "${status}" -eq 2 ] + then + mac="$(cat ${adaptor}/address)" + mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')" + fi + done + + echo ${mac} +} + +is_luks_partition () +{ + device="${1}" + /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1 +} + +is_active_luks_mapping () +{ + device="${1}" + /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1 +} + +get_luks_backing_device () +{ + device=${1} + cryptsetup status ${device} 2> /dev/null | \ + awk '{if ($1 == "device:") print $2}' +} + +removable_dev () +{ + output_format="${1}" + want_usb="${2}" + ret= + + for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") + do + dev_ok= + if [ "$(cat ${sysblock}/removable)" = "1" ] + then + if [ -z "${want_usb}" ] + then + dev_ok="true" + else + if readlink ${sysblock} | grep -q usb + then + dev_ok="true" + fi + fi + fi + + if [ "${dev_ok}" = "true" ] + then + case "${output_format}" in + sys) + ret="${ret} ${sysblock}" + ;; + *) + devname=$(sys2dev "${sysblock}") + ret="${ret} ${devname}" + ;; + esac + fi + done + + echo "${ret}" +} + +removable_usb_dev () +{ + output_format="${1}" + + removable_dev "${output_format}" "want_usb" +} + +non_removable_dev () +{ + output_format="${1}" + ret= + + for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") + do + if [ "$(cat ${sysblock}/removable)" = "0" ] + then + case "${output_format}" in + sys) + ret="${ret} ${sysblock}" + ;; + *) + devname=$(sys2dev "${sysblock}") + ret="${ret} ${devname}" + ;; + esac + fi + done + + echo "${ret}" +} + +link_files () +{ + # create source's directory structure in dest, and recursively + # create symlinks in dest to to all files in source. if mask + # is non-empty, remove mask from all source paths when + # creating links (will be necessary if we change root, which + # live-boot normally does (into $rootmnt)). + + # remove multiple /:s and ensure ending on / + local src_dir="$(trim_path ${1})/" + local dest_dir="$(trim_path ${2})/" + local src_mask="${3}" + + # This check can only trigger on the inital, non-recursive call since + # we create the destination before recursive calls + if [ ! -d "${dest_dir}" ] + then + log_warning_msg "Must link_files into a directory" + return + fi + + find "${src_dir}" -mindepth 1 -maxdepth 1 | \ + while read src + do + local dest="${dest_dir}$(basename "${src}")" + if [ -d "${src}" ] + then + if [ -z "$(ls -A "${src}")" ] + then + continue + fi + if [ ! -d "${dest}" ] + then + mkdir -p "${dest}" + chown_ref "${src}" "${dest}" + chmod_ref "${src}" "${dest}" + fi + link_files "${src}" "${dest}" "${src_mask}" + else + local final_src=${src} + if [ -n "${src_mask}" ] + then + final_src="$(echo ${final_src} | sed "s|^${src_mask}||")" + fi + rm -rf "${dest}" 2> /dev/null + ln -s "${final_src}" "${dest}" + chown_ref "${src}" "${dest}" + fi + done +} + +do_union () +{ + local unionmountpoint="${1}" # directory where the union is mounted + local unionrw="${2}" # branch where the union changes are stored + local unionro1="${3}" # first underlying read-only branch (optional) + local unionro2="${4}" # second underlying read-only branch (optional) + + case "${UNIONTYPE}" in + aufs) + 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}" + if [ -n "${unionro1}" ] + then + unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}" + fi + if [ -n "${unionro2}" ] + then + unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}" + 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 unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?) + # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir? + unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}" + mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}" + ;; + + *) + unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}" + if [ -n "${unionro1}" ] + then + unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}" + fi + if [ -n "${unionro2}" ] + then + unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}" + fi + mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}" + ;; + esac +} + +get_custom_mounts () +{ + # Side-effect: leaves $devices with live-persistence.conf mounted in /live/persistence + # Side-effect: prints info to file $custom_mounts + + local custom_mounts=${1} + shift + local devices=${@} + + local bindings="/tmp/bindings.list" + local links="/tmp/links.list" + rm -rf ${bindings} ${links} 2> /dev/null + + for device in ${devices} + do + if [ ! -b "${device}" ] + then + continue + fi + + local device_name="$(basename ${device})" + local backing=$(mount_persistence_media ${device}) + if [ -z "${backing}" ] + then + continue + fi + + local include_list="${backing}/${persistence_list}" + if [ ! -r "${include_list}" ] + then + continue + fi + + if [ -n "${DEBUG}" ] && [ -e "${include_list}" ] + then + cp ${include_list} /live/persistence/${persistence_list}.${device_name} + fi + + while read dir options # < ${include_list} + do + if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$" + then + # skipping empty or commented lines + continue + fi + + if trim_path ${dir} | grep -q -e "^[^/]" -e "^/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 \"/live\" or any sub-directory therein." + continue + fi + + local opt_source="" + local opt_link="" + for opt in $(echo ${options} | tr ',' ' '); + do + case "${opt}" in + source=*) + opt_source=${opt#source=} + ;; + link) + opt_link="true" + ;; + union|bind) + ;; + *) + log_warning_msg "Skipping custom mount with unkown option: ${opt}" + continue 2 + ;; + esac + done + + local source="${dir}" + if [ -n "${opt_source}" ] + then + if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${source}" != "." ] + then + 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" + continue + else + source="${opt_source}" + fi + fi + + local full_source="$(trim_path ${backing}/${source})" + local full_dest="$(trim_path ${rootmnt}/${dir})" + if [ -n "${opt_link}" ] + then + echo "${device} ${full_source} ${full_dest} ${options}" >> ${links} + else + echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings} + fi + done < ${include_list} + done + + # We sort the list according to destination so we're sure that + # we won't hide a previous mount. We also ignore duplicate + # destinations in a more or less arbitrary way. + [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings} + + # After all mounts are considered we add symlinks so they + # won't be hidden by some mount. + [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links} + + # We need to make sure that no two custom mounts have the same sources + # or are nested; if that is the case, too much weird stuff can happen. + local prev_source="impossible source" # first iteration must not match + local 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} | + while read device source dest options + do + if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$" + then + panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}" + fi + prev_source=${source} + prev_dest=${dest} + done +} + +activate_custom_mounts () +{ + local custom_mounts="${1}" # the ouput from get_custom_mounts() + local used_devices="" + + while read device source dest options # < ${custom_mounts} + do + local opt_bind="true" + local opt_link="" + local opt_union="" + for opt in $(echo ${options} | tr ',' ' '); + do + case "${opt}" in + bind) + opt_bind="true" + unset opt_link opt_union + ;; + link) + opt_link="true" + unset opt_bind opt_union + ;; + union) + opt_union="true" + unset opt_bind opt_link + ;; + esac + done + + if [ -n "$(what_is_mounted_on "${dest}")" ] + then + if [ "${dest}" = "${rootmnt}" ] + then + umount "${dest}" + else + log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there" + continue + fi + fi + + if [ ! -d "${dest}" ] + then + # create the destination and delete existing files in + # its path that are in the way + path="/" + for dir in $(echo ${dest} | sed -e 's|/\+| |g') + do + path=$(trim_path ${path}/${dir}) + if [ -f ${path} ] + then + rm -f ${path} + fi + if [ ! -e ${path} ] + then + mkdir -p ${path} + if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+" + then + # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case + # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then + chown 1000:1000 ${path} + fi + fi + done + fi + + # if ${source} doesn't exist on our persistence media + # we bootstrap it with $dest from the live filesystem. + # this both makes sense and is critical if we're + # dealing with /etc or other system dir. + if [ ! -d "${source}" ] + then + if [ -n "${PERSISTENCE_READONLY}" ] + then + continue + elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ] + then + # unions and don't need to be bootstrapped + # link dirs can't be bootstrapped in a sensible way + mkdir -p "${source}" + chown_ref "${dest}" "${source}" + chmod_ref "${dest}" "${source}" + elif [ -n "${opt_bind}" ] + then + # ensure that $dest is not copied *into* $source + mkdir -p "$(dirname ${source})" + cp -a "${dest}" "${source}" + fi + fi + + # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can + # ignore the loop below and set rofs_dest_backing=$dest + local rofs_dest_backing="" + if [ -n "${opt_link}"] + then + for d in /live/rofs/* + do + if [ -n "${rootmnt}" ] + then + rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")" + else + rofs_dest_backing="${d}/${dest}" + fi + if [ -d "${rofs_dest_backing}" ] + then + break + else + rofs_dest_backing="" + fi + done + fi + + if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ] + then + link_files ${source} ${dest} ${rootmnt} + elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ] + then + mkdir -p /live/persistence + local links_source=$(mktemp -d /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 + # make it absolutely certain that the link source + # has its own directory and isn't nested with some + # other custom mount (if so that mount's files would + # be linked, causing breakage. + local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})" + mkdir -p ${cow_dir} + chown_ref "${source}" "${cow_dir}" + chmod_ref "${source}" "${cow_dir}" + do_union ${links_source} ${cow_dir} ${source} ${rofs_dest_backing} + link_files ${links_source} ${dest} ${rootmnt} + elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ] + then + do_union ${dest} ${source} ${rofs_dest_backing} + elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ] + then + mount --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 rofs_dest_backing + # is non-empty (and necessary) only for unions + if [ -n "${rootmnt}" ] + then + local cow_dir="$(echo ${dest} | sed -e "s|^${rootmnt}|/live/overlay/|")" + else + # This is happens if persistence is activated + # post boot + local cow_dir="/live/overlay/${dest}" + fi + if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ] + then + # If an earlier custom mount has files here + # it will "block" the current mount's files + # which is undesirable + rm -rf "${cow_dir}" + fi + mkdir -p ${cow_dir} + chown_ref "${source}" "${cow_dir}" + chmod_ref "${source}" "${cow_dir}" + do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing} + fi + + PERSISTENCE_IS_ON="1" + export PERSISTENCE_IS_ON + + if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$" + then + used_devices="${used_devices} ${device}" + fi + done < ${custom_mounts} + + echo ${used_devices} +} + +fix_backwards_compatibility () +{ + local device=${1} + local dir=${2} + local opt=${3} + + if [ -n "${PERSISTENCE_READONLY}" ] + then + return + fi + + local backing="$(mount_persistence_media ${device})" + if [ -z "${backing}" ] + then + return + fi + + local include_list="${backing}/${persistence_list}" + if [ ! -r "${include_list}" ] + then + echo "# persistence backwards compatibility: +${dir} ${opt},source=." > "${include_list}" + fi +} + +is_mountpoint () +{ + directory="$1" + + [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ] +} diff --git a/scripts/boot/9990-mount-cifs.sh b/scripts/boot/9990-mount-cifs.sh new file mode 100755 index 0000000..a8ef3f4 --- /dev/null +++ b/scripts/boot/9990-mount-cifs.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +#set -e + +do_cifsmount () +{ + rc=1 + + if [ -x "/sbin/mount.cifs" ] + then + if [ -z "${NFSOPTS}" ] + then + CIFSOPTS="-ouser=root,password=" + else + CIFSOPTS="-o ${NFSOPTS}" + fi + + log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}" + modprobe -q cifs + + if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" + then + rc=0 + fi + fi + + return ${rc} +} diff --git a/scripts/boot/9990-mount-http.sh b/scripts/boot/9990-mount-http.sh new file mode 100755 index 0000000..1b718c0 --- /dev/null +++ b/scripts/boot/9990-mount-http.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +#set -e + +do_httpmount () +{ + rc=1 + + for webfile in HTTPFS FTPFS FETCH + do + local url="$(eval echo \"\$\{${webfile}\}\")" + local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')" + + if [ -n "$url" ] + then + case "${extension}" in + iso|squashfs|tgz|tar) + if [ "${extension}" = "iso" ] + then + mkdir -p "${alt_mountpoint}" + dest="${alt_mountpoint}" + else + local dest="${mountpoint}/${LIVE_MEDIA_PATH}" + mount -t ramfs ram "${mountpoint}" + mkdir -p "${dest}" + fi + if [ "${webfile}" = "FETCH" ] + then + case "$url" in + tftp*) + ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')" + rfile="$(echo $url | sed -e "s|tftp://$ip||g")" + lfile="$(basename $url)" + log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip" + tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip + ;; + + *) + log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})" + wget "${url}" -O "${dest}/$(basename ${url})" + ;; + esac + else + log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})" + if [ "${webfile}" = "FTPFS" ] + then + FUSE_MOUNT="curlftpfs" + url="$(dirname ${url})" + else + FUSE_MOUNT="httpfs" + fi + modprobe fuse + $FUSE_MOUNT "${url}" "${dest}" + ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )" + fi + [ ${?} -eq 0 ] && rc=0 + [ "${extension}" = "tgz" ] && live_dest="ram" + if [ "${extension}" = "iso" ] + then + isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '') + mount -t iso9660 "${isoloop}" "${mountpoint}" + rc=${?} + fi + break + ;; + + *) + log_begin_msg "Unrecognized archive extension for ${url}" + ;; + esac + fi + done + + if [ ${rc} != 0 ] + then + if [ -d "${alt_mountpoint}" ] + then + umount "${alt_mountpoint}" + rmdir "${alt_mountpoint}" + fi + umount "${mountpoint}" + elif [ "${webfile}" != "FETCH" ] ; then + NETBOOT="${webfile}" + export NETBOOT + fi + + return ${rc} +} diff --git a/scripts/boot/9990-mount-iscsi.sh b/scripts/boot/9990-mount-iscsi.sh new file mode 100755 index 0000000..fd29d91 --- /dev/null +++ b/scripts/boot/9990-mount-iscsi.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +#set -e + +do_iscsi() +{ + do_netsetup + #modprobe ib_iser + modprobe iscsi_tcp + local debugopt="" + [ "${DEBUG}" = "true" ] && debugopt="-d 8" + #FIXME this name is supposed to be unique - some date + ifconfig hash? + ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)" + export ISCSI_INITIATORNAME + if [ -n "${ISCSI_SERVER}" ] ; then + iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}" + else + iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260 + fi + if [ $? != 0 ] + then + panic "Failed to log into iscsi target" + fi + local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \ + /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')" + if [ -n "${host}" ] + then + local devices="" + local i=0 + while [ -z "${devices}" -a $i -lt 60 ] + do + sleep 1 + devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \ + /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')" + i=$(expr $i + 1) + echo -ne $i\\r + done + for dev in $devices + do + if check_dev "null" "/dev/$dev" + then + NETBOOT="iscsi" + export NETBOOT + return 0; + fi + done + panic "Failed to locate a live device on iSCSI devices (tried: $devices)." + else + panic "Failed to locate iSCSI host in /sys" + fi +} diff --git a/scripts/boot/9990-mount-nfs.sh b/scripts/boot/9990-mount-nfs.sh new file mode 100755 index 0000000..6a3ae55 --- /dev/null +++ b/scripts/boot/9990-mount-nfs.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +#set -e + +do_nfsmount () +{ + rc=1 + + modprobe -q nfs + + if [ -n "${NFSOPTS}" ] + then + NFSOPTS="-o ${NFSOPTS}" + fi + + log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}" + + # FIXME: This while loop is an ugly HACK round an nfs bug + i=0 + while [ "$i" -lt 60 ] + do + nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break + sleep 1 + i="$(($i + 1))" + done + + return ${rc} +} diff --git a/scripts/boot/9990-mountroot.sh b/scripts/boot/9990-mountroot.sh new file mode 100755 index 0000000..2d14e4d --- /dev/null +++ b/scripts/boot/9990-mountroot.sh @@ -0,0 +1,221 @@ +#!/bin/sh + +# set -e + +mountroot () +{ + if [ -x /scripts/local-top/cryptroot ] + then + /scripts/local-top/cryptroot + fi + + exec 6>&1 + exec 7>&2 + exec > boot.log + exec 2>&1 + tail -f boot.log >&7 & + tailpid="${!}" + + . /live.vars + + _CMDLINE="$(cat /proc/cmdline)" + Cmdline + + case "${LIVE_DEBUG}" in + true) + set -x + ;; + esac + + case "${LIVE_READ_ONLY}" in + true) + Read_only + ;; + esac + + Select_eth_device + + # Needed here too because some things (*cough* udev *cough*) + # changes the timeout + + if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ] + then + if do_netmount + then + livefs_root="${mountpoint}" + else + panic "Unable to find a live file system on the network" + fi + else + if [ -n "${ISCSI_PORTAL}" ] + then + do_iscsi && livefs_root="${mountpoint}" + elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ] + then + # Do a local boot from hd + livefs_root=${ROOT} + else + if [ -x /usr/bin/memdiskfind ] + then + MEMDISK=$(/usr/bin/memdiskfind) + + if [ $? -eq 0 ] + then + # We found a memdisk, set up phram + modprobe phram phram=memdisk,${MEMDISK} + + # Load mtdblock, the memdisk will be /dev/mtdblock0 + modprobe mtdblock + fi + fi + + # Scan local devices for the image + i=0 + while [ "$i" -lt 60 ] + do + livefs_root=$(find_livefs ${i}) + + if [ -n "${livefs_root}" ] + then + break + fi + + sleep 1 + i="$(($i + 1))" + done + fi + fi + + if [ -z "${livefs_root}" ] + then + panic "Unable to find a medium containing a live file system" + fi + + case "${LIVE_VERIFY_CHECKSUMS}" in + true) + Verify_checksums "${livefs_root}" + ;; + esac + + if [ "${TORAM}" ] + then + live_dest="ram" + elif [ "${TODISK}" ] + then + live_dest="${TODISK}" + fi + + if [ "${live_dest}" ] + then + log_begin_msg "Copying live media to ${live_dest}" + copy_live_to "${livefs_root}" "${live_dest}" + log_end_msg + fi + + # if we do not unmount the ISO we can't run "fsck /dev/ice" later on + # because the mountpoint is left behind in /proc/mounts, so let's get + # rid of it when running from RAM + if [ -n "$FROMISO" ] && [ "${TORAM}" ] + then + losetup -d /dev/loop0 + + if is_mountpoint /live/fromiso + then + umount /live/fromiso + rmdir --ignore-fail-on-non-empty /live/fromiso \ + >/dev/null 2>&1 || true + fi + fi + + if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ] + then + setup_unionfs "${livefs_root}" "${rootmnt}" + else + mac="$(get_mac)" + mac="$(echo ${mac} | sed 's/-//g')" + mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}" + fi + + + if [ -n "${ROOT_PID}" ] + then + echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid + fi + + log_end_msg + + # unionfs-fuse needs /dev to be bind-mounted for the duration of + # live-bottom; udev's init script will take care of things after that + case "${UNIONTYPE}" in + unionfs-fuse) + mount -n -o bind /dev "${rootmnt}/dev" + ;; + esac + + # Move to the new root filesystem so that programs there can get at it. + if [ ! -d /root/live/image ] + then + mkdir -p /root/live/image + mount --move /live/image /root/live/image + fi + + # aufs2 in kernel versions around 2.6.33 has a regression: + # directories can't be accessed when read for the first the time, + # causing a failure for example when accessing /var/lib/fai + # when booting FAI, this simple workaround solves it + ls /root/* >/dev/null 2>&1 + + # Move findiso directory to the new root filesystem so that programs there can get at it. + if [ -d /live/findiso ] && [ ! -d /root/live/findiso ] + then + mkdir -p /root/live/findiso + mount -n --move /live/findiso /root/live/findiso + fi + + # if we do not unmount the ISO we can't run "fsck /dev/ice" later on + # because the mountpoint is left behind in /proc/mounts, so let's get + # rid of it when running from RAM + if [ -n "$FINDISO" ] && [ "${TORAM}" ] + then + losetup -d /dev/loop0 + + if is_mountpoint /root/live/findiso + then + umount /root/live/findiso + rmdir --ignore-fail-on-non-empty /root/live/findiso \ + >/dev/null 2>&1 || true + fi + fi + + if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ] + then + log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf" + cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf + log_end_msg + fi + + if ! [ -d "/lib/live/boot" ] + then + panic "A wrong rootfs was mounted." + fi + + Fstab + Netbase + + case "${LIVE_SWAPON}" in + true) + Swapon + ;; + esac + + case "${UNIONFS}" in + unionfs-fuse) + umount "${rootmnt}/dev" + ;; + esac + + exec 1>&6 6>&- + exec 2>&7 7>&- + kill ${tailpid} + [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null +} diff --git a/scripts/boot/9990-netbase.sh b/scripts/boot/9990-netbase.sh new file mode 100755 index 0000000..3f5f7af --- /dev/null +++ b/scripts/boot/9990-netbase.sh @@ -0,0 +1,141 @@ +#!/bin/sh + +#set -e + +Netbase () +{ + if [ -n "${NONETWORKING}" ] + then + return + fi + + # FIXME: stop hardcoding overloading of initramfs-tools functions + . /scripts/functions + . /lib/live/boot/initramfs-tools.sh + + log_begin_msg "Preconfiguring networking" + + IFFILE="/root/etc/network/interfaces" + + if [ "${STATICIP}" = "frommedia" ] && [ -e "${IFFILE}" ] + then + # will use existent /etc/network/interfaces + log_end_msg + return + fi + +cat > "${IFFILE}" << EOF +auto lo +iface lo inet loopback + +EOF + + udevadm trigger + udevadm settle + + if [ -z "${NETBOOT}" ] && [ -n "${STATICIP}" ] && [ "${STATICIP}" != "frommedia" ] + then + parsed=$(echo "${STATICIP}" | sed -e 's|,| |g') + + for ifline in ${parsed} + do + ifname="$(echo ${ifline} | cut -f1 -d ':')" + ifaddress="$(echo ${ifline} | cut -f2 -d ':')" + ifnetmask="$(echo ${ifline} | cut -f3 -d ':')" + ifgateway="$(echo ${ifline} | cut -f4 -d ':')" + +cat >> "${IFFILE}" << EOF +allow-hotplug ${ifname} +iface ${ifname} inet static + address ${ifaddress} + netmask ${ifnetmask} +EOF + + if [ -n "${ifgateway}" ] + then + +cat >> "${IFFILE}" << EOF + gateway ${ifgateway} + +EOF + + fi + done + else + if [ -z "${NETBOOT}" ] || [ -n "${DHCP}" ] + then + # default, dhcp assigned + method="dhcp" + else + # make sure that the preconfigured interface would not get reassigned by dhcp + # on startup by ifup script - otherwise our root fs might be disconnected! + method="manual" + fi + + # iterate the physical interfaces and add them to the interfaces list and also add when ethdevice= called on cmdline + if [ "${method}" != dhcp ] || ([ ! -x /root/usr/sbin/NetworkManager ] && [ ! -x /root/usr/sbin/wicd ]) || [ ! -z "${ETHDEVICE}" ] + then + for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan* + do + [ -e ${interface} ] || continue + i="$(basename ${interface})" + +cat >> "${IFFILE}" << EOF +allow-hotplug ${i} +iface ${i} inet ${method} + +EOF + + done + fi + + if [ ! -f /root/etc/resolv.conf ] || [ -z "$(cat /root/etc/resolv.conf)" ] + then + if [ -f /netboot.config ] + then + # create a resolv.conf if it is not present or empty + cp /netboot.config /root/var/log/netboot.config + + rc_search=$(cat netboot.config | awk '/domain/{print $3}') + rc_server0=$(cat netboot.config | awk '/dns0/{print $5}') + rc_server1=$(cat netboot.config | awk '/dns0/{print $8}') + rc_server0="nameserver ${rc_server0}" + + if [ "${rc_server1}" = "0.0.0.0" ] + then + rc_server1="" + else + rc_server1="nameserver ${rc_server1}" + fi + +cat > /root/etc/resolv.conf << EOF +# /etc/resolv.conf +# Autogenerated by live-boot +search ${rc_search} +domain ${rc_search} +${rc_server0} +${rc_server1} +EOF + + cat /root/etc/resolv.conf >> /root/var/log/netboot.config + fi + fi + fi + + #if [ ! -x /root/usr/sbin/NetworkManager ] + #then + # for i in eth0 eth1 eth2 ath0 wlan0 + # do + # grep -q "iface ${i}" ${IFFILE} && continue + # + #cat >> "${IFFILE}" << EOF + #allow-hotplug ${i} + #iface ${i} inet dhcp + # + #EOF + # + # done + #fi + + log_end_msg +} diff --git a/scripts/boot/9990-netboot.sh b/scripts/boot/9990-netboot.sh new file mode 100755 index 0000000..5054fb8 --- /dev/null +++ b/scripts/boot/9990-netboot.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +#set -e + +do_netmount() +{ + do_netsetup + + if [ "${NFSROOT}" = "auto" ] + then + NFSROOT=${ROOTSERVER}:${ROOTPATH} + fi + + rc=1 + + if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) + then + do_httpmount + return $? + fi + + if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ] + then + NFSROOT=${ROOTSERVER}:${NFSROOT} + fi + + log_begin_msg "Trying netboot from ${NFSROOT}" + + if [ "${NETBOOT}" != "nfs" ] && do_cifsmount + then + rc=0 + elif do_nfsmount + then + NETBOOT="nfs" + export NETBOOT + rc=0 + fi + + log_end_msg + return ${rc} +} diff --git a/scripts/boot/9990-networking.sh b/scripts/boot/9990-networking.sh new file mode 100755 index 0000000..8c8d840 --- /dev/null +++ b/scripts/boot/9990-networking.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +#set -e + +do_netsetup () +{ + modprobe -q af_packet # For DHCP + + udevadm trigger + udevadm settle + + [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15 + echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration." + + if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ] + then + # support for Syslinux IPAPPEND parameter + # it sets the BOOTIF variable on the kernel parameter + + if [ -n "${BOOTIF}" ] + then + # pxelinux sets BOOTIF to a value based on the mac address of the + # network card used to PXE boot, so use this value for DEVICE rather + # than a hard-coded device name from initramfs.conf. this facilitates + # network booting when machines may have multiple network cards. + # pxelinux sets BOOTIF to 01-$mac_address + + # strip off the leading "01-", which isn't part of the mac + # address + temp_mac=${BOOTIF#*-} + + # convert to typical mac address format by replacing "-" with ":" + bootif_mac="" + IFS='-' + for x in $temp_mac + do + if [ -z "$bootif_mac" ] + then + bootif_mac="$x" + else + bootif_mac="$bootif_mac:$x" + fi + done + unset IFS + + # look for devices with matching mac address, and set DEVICE to + # appropriate value if match is found. + + for device in /sys/class/net/* + do + if [ -f "$device/address" ] + then + current_mac=$(cat "$device/address") + + if [ "$bootif_mac" = "$current_mac" ] + then + DEVICE=${device##*/} + break + fi + fi + done + fi + + # if ethdevice was not specified on the kernel command line + # make sure we try to get a working network configuration + # for *every* present network device (except for loopback of course) + if [ -z "$ETHDEVICE" ] + then + echo "If you want to boot from a specific device use bootoption ethdevice=..." + for device in /sys/class/net/* + do + dev=${device##*/} + if [ "$dev" != "lo" ] + then + ETHDEVICE="$ETHDEVICE $dev" + fi + done + fi + + # split args of ethdevice=eth0,eth1 into "eth0 eth1" + for device in $(echo $ETHDEVICE | sed 's/,/ /g') + do + devlist="$devlist $device" + done + + # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into + # an endless loop; if execution fails give it two further tries, that's + # why we use '$devlist $devlist $devlist' for the other for loop + for dev in $devlist $devlist $devlist + do + echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev" + ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config & + jobid=$! + sleep "$ETHDEV_TIMEOUT" ; sleep 1 + if [ -r /proc/"$jobid"/status ] + then + echo "Killing job $jobid for device $dev as ipconfig ran into recursion..." + kill -9 $jobid + fi + + # if configuration of device worked we should have an assigned + # IP address, if so let's use the device as $DEVICE for later usage. + # simple and primitive approach which seems to work fine + if ifconfig $dev | grep -q 'inet.*addr:' + then + export DEVICE="$dev" + break + fi + done + else + for interface in ${DEVICE}; do + ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config + [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf + if [ "$IPV4ADDR" != "0.0.0.0" ] + then + break + fi + done + fi + + for interface in ${DEVICE} + do + # source relevant ipconfig output + OLDHOSTNAME=${HOSTNAME} + [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf + [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME} + export HOSTNAME + + if [ -n "${interface}" ] + then + HWADDR="$(cat /sys/class/net/${interface}/address)" + fi + + if [ ! -e "/etc/resolv.conf" ] + then + echo "Creating /etc/resolv.conf" + + if [ -n "${DNSDOMAIN}" ] + then + echo "domain ${DNSDOMAIN}" > /etc/resolv.conf + echo "search ${DNSDOMAIN}" >> /etc/resolv.conf + fi + + for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1} + do + if [ -n "$i" ] && [ "$i" != 0.0.0.0 ] + then + echo "nameserver $i" >> /etc/resolv.conf + fi + done + fi + + # Check if we have a network device at all + if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \ + ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \ + ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \ + ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \ + ! ls /sys/class/net/ra0 > /dev/null 2>&1 + then + panic "No supported network device found, maybe a non-mainline driver is required." + fi + done +} diff --git a/scripts/boot/9990-overlay.sh b/scripts/boot/9990-overlay.sh new file mode 100755 index 0000000..cb12c4b --- /dev/null +++ b/scripts/boot/9990-overlay.sh @@ -0,0 +1,410 @@ +#!/bin/sh + +#set -e + +setup_unionfs () +{ + image_directory="${1}" + rootmnt="${2}" + addimage_directory="${3}" + + case ${UNIONTYPE} in + aufs|unionfs|overlayfs) + modprobe -q -b ${UNIONTYPE} + + if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ] + then + echo "${UNIONTYPE} not available, falling back to unionfs-fuse." + echo "This might be really slow." + + UNIONTYPE="unionfs-fuse" + fi + ;; + esac + + case "${UNIONTYPE}" in + unionfs-fuse) + modprobe fuse + ;; + esac + + # run-init can't deal with images in a subdir, but we're going to + # move all of these away before it runs anyway. No, we're not, + # put them in / since move-mounting them into / breaks mono and + # some other apps. + + croot="/" + + # Let's just mount the read-only file systems first + rofslist="" + + if [ -z "${PLAIN_ROOT}" ] + then + # Read image names from ${MODULE}.module if it exists + if [ -e "${image_directory}/filesystem.${MODULE}.module" ] + then + for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module) + do + image_string="${image_string} ${image_directory}/${IMAGE}" + done + elif [ -e "${image_directory}/${MODULE}.module" ] + then + for IMAGE in $(cat ${image_directory}/${MODULE}.module) + do + image_string="${image_string} ${image_directory}/${IMAGE}" + done + else + # ${MODULE}.module does not exist, create a list of images + for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir + do + for IMAGE in "${image_directory}"/*."${FILESYSTEM}" + do + if [ -e "${IMAGE}" ] + then + image_string="${image_string} ${IMAGE}" + fi + done + done + + if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ] + then + for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir + do + for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}" + do + if [ -e "${IMAGE}" ] + then + image_string="${image_string} ${IMAGE}" + fi + done + done + fi + + # Now sort the list + image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )" + fi + + [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})" + + mkdir -p "${croot}" + + for image in ${image_string} + do + imagename=$(basename "${image}") + + export image devname + maybe_break live-realpremount + log_begin_msg "Running /scripts/live-realpremount" + run_scripts /scripts/live-realpremount + log_end_msg + + if [ -d "${image}" ] + then + # it is a plain directory: do nothing + rofslist="${image} ${rofslist}" + elif [ -f "${image}" ] + then + if losetup --help 2>&1 | grep -q -- "-r\b" + then + backdev=$(get_backing_device "${image}" "-r") + else + backdev=$(get_backing_device "${image}") + fi + fstype=$(get_fstype "${backdev}") + + case "${fstype}" in + unknown) + panic "Unknown file system type on ${backdev} (${image})" + ;; + + "") + fstype="${imagename##*.}" + log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}." + ;; + esac + + case "${UNIONTYPE}" in + unionmount) + mpoint="${rootmnt}" + rofslist="${rootmnt} ${rofslist}" + ;; + + *) + mpoint="${croot}/${imagename}" + rofslist="${mpoint} ${rofslist}" + ;; + esac + + mkdir -p "${mpoint}" + log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\"" + mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}" + log_end_msg + fi + done + else + # we have a plain root system + mkdir -p "${croot}/filesystem" + log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\"" + mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \ + panic "Can not mount ${image_directory} on ${croot}/filesystem" && \ + rofslist="${croot}/filesystem ${rofslist}" + # probably broken: + mount -o bind ${croot}/filesystem $mountpoint + log_end_msg + fi + + # tmpfs file systems + touch /etc/fstab + mkdir -p /live + mount -t tmpfs tmpfs /live + mkdir -p /live/overlay + + # Looking for persistence devices or files + if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] + then + + if [ -z "${QUICKUSBMODULES}" ] + then + # Load USB modules + num_block=$(ls -l /sys/block | wc -l) + for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage + do + modprobe -q -b ${module} + done + + udevadm trigger + udevadm settle + + # For some reason, udevsettle does not block in this scenario, + # so we sleep for a little while. + # + # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591 + for timeout in 5 4 3 2 1 + do + sleep 1 + + if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ] + then + break + fi + done + fi + + case "${PERSISTENCE_MEDIA}" in + removable) + whitelistdev="$(removable_dev)" + ;; + + removable-usb) + whitelistdev="$(removable_usb_dev)" + ;; + + *) + whitelistdev="" + ;; + esac + + if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD} + then + overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}" + fi + + local overlay_devices="" + for media in $(find_persistence_media "${overlays}" "${whitelistdev}") + do + media="$(echo ${media} | tr ":" " ")" + + case ${media} in + ${old_root_overlay_label}=*) + device="${media#*=}" + fix_backwards_compatibility ${device} / union + overlay_devices="${overlay_devices} ${device}" + ;; + + ${old_home_overlay_label}=*) + device="${media#*=}" + fix_backwards_compatibility ${device} /home bind + overlay_devices="${overlay_devices} ${device}" + ;; + + ${custom_overlay_label}=*) + device="${media#*=}" + overlay_devices="${overlay_devices} ${device}" + ;; + esac + done + elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ] + then + # check if there are any nfs options + if echo ${NFS_COW} | grep -q ',' + then + nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)" + nfs_cow=$(echo ${NFS_COW}|cut -d, -f1) + else + nfs_cow_opts="-o nolock" + nfs_cow=${NFS_COW} + fi + + if [ -n "${PERSISTENCE_READONLY}" ] + then + nfs_cow_opts="${nfs_cow_opts},nocto,ro" + fi + + mac="$(get_mac)" + if [ -n "${mac}" ] + then + cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/") + cow_fstype="nfs" + else + panic "unable to determine mac address" + fi + fi + + if [ -z "${cowdevice}" ] + then + cowdevice="tmpfs" + cow_fstype="tmpfs" + cow_mountopt="rw,noatime,mode=755" + fi + + if [ "${UNIONTYPE}" != "unionmount" ] + then + if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ] + then + mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay" + root_backing="/live/persistence/$(basename ${cowdevice})-root" + mkdir -p ${root_backing} + else + root_backing="/live/overlay" + fi + + if [ "${cow_fstype}" = "nfs" ] + then + log_begin_msg \ + "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}" + nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \ + panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}" + else + mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \ + panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}" + fi + fi + + rofscount=$(echo ${rofslist} |wc -w) + + rofs=${rofslist%% } + + if [ -n "${EXPOSED_ROOT}" ] + then + if [ ${rofscount} -ne 1 ] + then + panic "only one RO file system supported with exposedroot: ${rofslist}" + fi + + mount --bind ${rofs} ${rootmnt} || \ + panic "bind mount of ${rofs} failed" + + if [ -z "${SKIP_UNION_MOUNTS}" ] + then + cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live' + else + cow_dirs='' + fi + else + cow_dirs="/" + fi + + if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ] + then + true # FIXME: Maybe it does, I don't really know. + #panic "unionmount does not support subunions (${cow_dirs})." + fi + + for dir in ${cow_dirs}; do + unionmountpoint="${rootmnt}${dir}" + mkdir -p ${unionmountpoint} + if [ "${UNIONTYPE}" = "unionmount" ] + then + # FIXME: handle PERSISTENCE_READONLY + unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}" + mount_full $unionmountopts "${unionmountpoint}" + else + cow_dir="/live/overlay${dir}" + rofs_dir="${rofs}${dir}" + mkdir -p ${cow_dir} + if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ] + then + do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir} + else + do_union ${unionmountpoint} ${cow_dir} ${rofs_dir} + fi + fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}" + done + + # Correct the permissions of /: + chmod 0755 "${rootmnt}" + + live_rofs_list="" + # SHOWMOUNTS is necessary for custom mounts with the union option + # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS + if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] 1) + then + # XXX: is the for loop really necessary? rofslist can only contain one item (see above XXX about EXPOSEDROOT) and this is also assumed elsewhere above (see use of $rofs above). + for d in ${rofslist} + do + live_rofs="/live/rofs/${d##*/}" + live_rofs_list="${live_rofs_list} ${live_rofs}" + mkdir -p "${live_rofs}" + case d in + *.dir) + # do nothing # mount -o bind "${d}" "${live_rofs}" + ;; + *) + case "${UNIONTYPE}" in + unionfs-fuse) + mount -o bind "${d}" "${live_rofs}" + ;; + + *) + mount -o move "${d}" "${live_rofs}" + ;; + esac + ;; + esac + done + fi + + # Adding custom persistence + if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] + then + local custom_mounts="/tmp/custom_mounts.list" + rm -rf ${custom_mounts} 2> /dev/null + + # Gather information about custom mounts from devies detected as overlays + get_custom_mounts ${custom_mounts} ${overlay_devices} + + [ -n "${DEBUG}" ] && cp ${custom_mounts} "/live/persistence" + + # Now we do the actual mounting (and symlinking) + local used_overlays="" + used_overlays=$(activate_custom_mounts ${custom_mounts}) + rm ${custom_mounts} + + # Close unused overlays (e.g. due to missing $persistence_list) + for overlay in ${overlay_devices} + do + if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$" + then + close_persistence_media ${overlay} + fi + done + fi + + mkdir -p "${rootmnt}/live" + mount -o move /live "${rootmnt}/live" >/dev/null 2>&1 || mount -o bind /live "${rootmnt}/live" || log_warning_msg "Unable to move or bind /live to ${rootmnt}/live" + + # shows cow fs on /overlay (FIXME: do we still need/want this? probably yes) + mkdir -p "${rootmnt}/live/overlay" + mount -o move /live/overlay "${rootmnt}/live/overlay" >/dev/null 2>&1 || mount -o bind /overlay "${rootmnt}/live/overlay" || log_warning_msg "Unable to move or bind /overlay to ${rootmnt}/live/overlay" + +} diff --git a/scripts/boot/9990-read-only.sh b/scripts/boot/9990-read-only.sh new file mode 100755 index 0000000..48aa06c --- /dev/null +++ b/scripts/boot/9990-read-only.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +#set -e + +Read_only () +{ + # Marking some block devices as read-only to ensure that nothing + # gets written as linux still writes to 'only' read-only mounted filesystems. + _DEVICES="/dev/sd* /dev/vd*" + + for _DEVICE in ${_DEVICES} + do + if [ ! -b "${_DEVICE}" ] + then + continue + fi + + echo -n "Setting ${_DEVICE} read-only..." > /dev/console + + blockdev --setro ${_DEVICE} + _RETURN="${?}" + + case "${_RETURN}" in + 0) + echo " done, use 'blockdev --setrw ${_DEVICE}' to set read-write." > /dev/console + ;; + + *) + echo " failed." > /dev/console + ;; + esac + done +} diff --git a/scripts/boot/9990-select-eth-device.sh b/scripts/boot/9990-select-eth-device.sh new file mode 100755 index 0000000..ed1da6f --- /dev/null +++ b/scripts/boot/9990-select-eth-device.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +Select_eth_device () +{ + # Boot type in initramfs's config + bootconf=$(egrep '^BOOT=' /conf/initramfs.conf | tail -1) + + # can be superseded by command line (used by Debian-Live's netboot for example) + for ARGUMENT in $(cat /proc/cmdline) + do + case "${ARGUMENT}" in + netboot=*) + NETBOOT="${ARGUMENT#netboot=}" + ;; + esac + done + + if [ "$bootconf" != "BOOT=nfs" ] && [ -z "$NETBOOT" ] && [ -z "$FETCH" ] && [ -z "$FTPFS" ] && [ -z "$HTTPFS" ] + then + # Not a net boot : nothing to do + return + fi + + # we want to do some basic IP + modprobe -q af_packet + + # Available Ethernet interfaces ? + l_interfaces="" + echo "Waiting for ethernet card(s) up... If this fails, maybe the ethernet card is not supported by the kernel `uname -r`?" + while [ -z "$l_interfaces" ] + do + l_interfaces="$(cd /sys/class/net/ && ls -d eth* 2>/dev/null)" + done + + if [ $(echo $l_interfaces | wc -w) -lt 2 ] + then + # only one interface : no choice + echo "DEVICE=$l_interfaces" >> /conf/param.conf + return + fi + + # If user force to use specific device, write it + for ARGUMENT in $(cat /proc/cmdline) + do + case "${ARGUMENT}" in + live-netdev=*) + NETDEV="${ARGUMENT#live-netdev=}" + echo "DEVICE=$NETDEV" >> /conf/param.conf + echo "Found live-netdev parameter in /proc/cmdline. Force to use network device $NETDEV." + return + ;; + esac + done + + found_eth_dev="" + while true + do + echo -n "Looking for a connected Ethernet interface ..." + + for interface in $l_interfaces + do + # ATTR{carrier} is not set if this is not done + echo -n " $interface ?" + ipconfig -c none -d $interface -t 1 >/dev/null 2>&1 + done + + echo '' + + for step in 1 2 3 4 5 + do + for interface in $l_interfaces + do + carrier=$(cat /sys/class/net/$interface/carrier \ + 2>/dev/null) + # link detected + + case "${carrier}" in + 1) + echo "Connected $interface found" + # inform initrd's init script : + found_eth_dev="$found_eth_dev $interface" + ;; + esac + done + if [ -n "$found_eth_dev" ] + then + echo "DEVICE='$found_eth_dev'" >> /conf/param.conf + return + else + # wait a bit + sleep 1 + fi + done + done +} diff --git a/scripts/boot/9990-swapon.sh b/scripts/boot/9990-swapon.sh new file mode 100755 index 0000000..158d81b --- /dev/null +++ b/scripts/boot/9990-swapon.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +#set -e + +Swapon () +{ + _DEVICES="/dev/sd* /dev/vd*" + + if [ -e /run ] + then + # wheezy + _FSTAB="/root/etc/fstab.d/swap" + else + # squeeze + _FSTAB="/root/etc/fstab" + fi + + for _DEVICE in ${_DEVICES} + do + if [ ! -b "${_DEVICE}" ] + then + continue + fi + + blkid -o udev -p ${_DEVICE%%[0-9]*} | grep -q "^ID_FS_USAGE=raid" && continue + + _MAGIC="$(/bin/dd if=${_DEVICE} bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null)" || continue + + case "${_MAGIC}" in + SWAPSPACE2|SWAP-SPACE) + _SWAP_DEVICES="${_SWAP_DEVICES} ${_DEVICE}" + ;; + esac + done + + # Remove all auto swap entries + if grep -qs "swap swap" "${_FSTAB}" + then + grep -v "swap swap" "${_FSTAB}" > "${_FSTAB}".tmp + mv "${_FSTAB}".tmp "${_FSTAB}" + fi + + # Add new swap entries + for _DEVICE in _SWAP_DEVICES + do + echo "${_DEVICE} swap swap defaults 0 0" >> "${_FSTAB}" + done +} diff --git a/scripts/boot/9990-toram-todisk.sh b/scripts/boot/9990-toram-todisk.sh new file mode 100755 index 0000000..2643eb8 --- /dev/null +++ b/scripts/boot/9990-toram-todisk.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +#set -e + +copy_live_to () +{ + copyfrom="${1}" + copytodev="${2}" + copyto="${copyfrom}_swap" + + if [ -z "${MODULETORAM}" ] + then + size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used") + else + MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}" + + if [ -f "${MODULETORAMFILE}" ] + then + size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 ) + else + log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read." + return 1 + fi + fi + + if [ "${copytodev}" = "ram" ] + then + # copying to ram: + freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo) + mount_options="-o size=${size}k" + free_string="memory" + fstype="tmpfs" + dev="/dev/shm" + else + # it should be a writable block device + if [ -b "${copytodev}" ] + then + dev="${copytodev}" + free_string="space" + fstype=$(get_fstype "${dev}") + freespace=$(fs_size "${dev}") + else + log_warning_msg "${copytodev} is not a block device." + return 1 + fi + fi + + if [ "${freespace}" -lt "${size}" ] + then + log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}." + return 1 + fi + + # Custom ramdisk size + if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ] + then + # FIXME: should check for wrong values + mount_options="-o size=${ramdisk_size}" + fi + + # begin copying (or uncompressing) + mkdir "${copyto}" + log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}" + mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}" + + if [ "${extension}" = "tgz" ] + then + cd "${copyto}" + tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})" + rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})" + mount -r -o move "${copyto}" "${rootmnt}" + cd "${OLDPWD}" + else + if [ -n "${MODULETORAMFILE}" ] + then + if [ -x /bin/rsync ] + then + echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console + rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module + else + cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module + fi + else + if [ -x /bin/rsync ] + then + echo " * Copying whole medium to RAM" 1>/dev/console + rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files + else + mkdir -p ${copyto}/${LIVE_MEDIA_PATH} + cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} + if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ] + then + cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto} + fi + fi + fi + + umount ${copyfrom} + mount -r -o move ${copyto} ${copyfrom} + fi + + rmdir ${copyto} + return 0 +} diff --git a/scripts/boot/9990-verify-checksums.sh b/scripts/boot/9990-verify-checksums.sh new file mode 100755 index 0000000..7dd5da3 --- /dev/null +++ b/scripts/boot/9990-verify-checksums.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +#set -e + +Verify_checksums () +{ + _MOUNTPOINT="${1}" + + _DIGESTS="sha512 sha384 sha256 sha224 sha1 md5" + _TTY="/dev/tty8" + + log_begin_msg "Verifying checksums" + + cd "${_MOUNTPOINT}" + + for _DIGEST in ${_DIGESTS} + do + _CHECKSUMS="$(echo ${_DIGEST} | tr [a-z] [A-Z])SUMS" + + if [ -e "${_CHECKSUMS}" ] + then + echo "Found ${_CHECKSUMS}..." > "${_TTY}" + + if [ -e "/bin/${_DIGEST}sum" ] + then + echo "Checking ${_CHECKSUMS}..." > "${_TTY}" + + # Verify checksums + /bin/${_DIGEST}sum -c "${_CHECKSUMS}" < "${_TTY}" > "${_TTY}" + _RETURN="${?}" + + # Stop after first verification + break + else + echo "Not found /bin/${_DIGEST}sum..." > "${_TTY}" + fi + fi + done + + log_end_msg + + case "${_RETURN}" in + 0) + log_success_msg "Verification successfull, rebooting in 10 seconds." + sleep 10 + + # Unmount live-media + cd / + umount -f ${_MOUNTPOINT} > /dev/null 2>&1 + sync + + # Attempt to remount all mounted filesystems read-only + echo u > /proc/sysrq-trigger + + # Immediately reboot the system without syncing or unmounting filesystems + echo b > /proc/sysrq-trigger + ;; + + *) + panic "Verification failed, $(basename ${_TTY}) for more information." + ;; + esac +} diff --git a/scripts/boot/cmdline.sh b/scripts/boot/cmdline.sh deleted file mode 100755 index a3781da..0000000 --- a/scripts/boot/cmdline.sh +++ /dev/null @@ -1,331 +0,0 @@ -#!/bin/sh - -#set -e - -Cmdline () -{ - for _PARAMETER in ${_CMDLINE} - do - case "${_PARAMETER}" in - live-boot.read-only|read-only) - LIVE_READ_ONLY="true" - ;; - - live-boot.swapon) - LIVE_SWAPON="true" - ;; - - live-boot.verify-checksums|verify-checksums) - LIVE_VERIFY_CHECKSUMS="true" - ;; - - # Special options - live-boot.debug|debug) - LIVE_DEBUG="true" - ;; - - - # parameters below need review (FIXME) - skipconfig) - NOFSTAB="true" - NONETWORKING="true" - - export NOFSTAB NONETWORKING - ;; - - BOOTIF=*) - BOOTIF="${x#BOOTIF=}" - ;; - - dhcp) - # Force dhcp even while netbooting - # Use for debugging in case somebody works on fixing dhclient - DHCP="true"; - export DHCP - ;; - - nodhcp) - DHCP="" - export DHCP - ;; - - ethdevice=*) - DEVICE="${_PARAMETER#ethdevice=}" - ETHDEVICE="${DEVICE}" - export DEVICE ETHDEVICE - ;; - - ethdevice-timeout=*) - ETHDEV_TIMEOUT="${_PARAMETER#ethdevice-timeout=}" - export ETHDEV_TIMEOUT - ;; - - fetch=*) - FETCH="${_PARAMETER#fetch=}" - export FETCH - ;; - - findiso=*) - FINDISO="${_PARAMETER#findiso=}" - export FINDISO - ;; - - ftpfs=*) - FTPFS="${_PARAMETER#ftpfs=}" - export FTPFS - ;; - - httpfs=*) - HTTPFS="${_PARAMETER#httpfs=}" - export HTTPFS - ;; - - iscsi=*) - ISCSI="${_PARAMETER#iscsi=}" - #ip:port - separated by ; - ISCSI_PORTAL="${ISCSI%;*}" - if echo "${ISCSI_PORTAL}" | grep -q , ; then - ISCSI_SERVER="${ISCSI_PORTAL%,*}" - ISCSI_PORT="${ISCSI_PORTAL#*,}" - fi - #target name - ISCSI_TARGET="${ISCSI#*;}" - export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT - ;; - - isofrom=*|fromiso=*) - FROMISO="${_PARAMETER#*=}" - export FROMISO - ;; - - ignore_uuid) - IGNORE_UUID="true" - export IGNORE_UUID - ;; - - ip=*) - STATICIP="${_PARAMETER#ip=}" - - if [ -z "${STATICIP}" ] - then - STATICIP="frommedia" - fi - - export STATICIP - ;; - - live-media=*|bootfrom=*) - LIVE_MEDIA="${_PARAMETER#*=}" - export LIVE_MEDIA - ;; - - live-media-encryption=*|encryption=*) - LIVE_MEDIA_ENCRYPTION="${_PARAMETER#*=}" - export LIVE_MEDIA_ENCRYPTION - ;; - - live-media-offset=*) - LIVE_MEDIA_OFFSET="${_PARAMETER#live-media-offset=}" - export LIVE_MEDIA_OFFSET - ;; - - live-media-path=*) - LIVE_MEDIA_PATH="${_PARAMETER#live-media-path=}" - export LIVE_MEDIA_PATH - ;; - - live-media-timeout=*) - LIVE_MEDIA_TIMEOUT="${_PARAMETER#live-media-timeout=}" - export LIVE_MEDIA_TIMEOUT - ;; - - module=*) - MODULE="${_PARAMETER#module=}" - export MODULE - ;; - - netboot=*) - NETBOOT="${_PARAMETER#netboot=}" - export NETBOOT - ;; - - nfsopts=*) - NFSOPTS="${_PARAMETER#nfsopts=}" - export NFSOPTS - ;; - - nfsoverlay=*) - NFS_COW="${_PARAMETER#nfsoverlay=}" - export NFS_COW - ;; - - nofstab) - NOFSTAB="true" - export NOFSTAB - ;; - - nonetworking) - NONETWORKING="true" - export NONETWORKING - ;; - - ramdisk-size=*) - ramdisk_size="${_PARAMETER#ramdisk-size=}" - ;; - - persistence) - PERSISTENCE="true" - export PERSISTENCE - ;; - - persistence-encryption=*) - PERSISTENCE_ENCRYPTION="${_PARAMETER#*=}" - export PERSISTENCE_ENCRYPTION - ;; - - persistence-media=*) - PERSISTENCE_MEDIA="${_PARAMETER#*=}" - export PERSISTENCE_MEDIA - ;; - persistence-method=*) - PERSISTENCE_METHOD="${_PARAMETER#*=}" - export PERSISTENCE_METHOD - ;; - - persistence-path=*) - PERSISTENCE_PATH="${_PARAMETER#persistence-path=}" - export PERSISTENCE_PATH - ;; - persistence-read-only) - PERSISTENCE_READONLY="true" - export PERSISTENCE_READONLY - ;; - - persistence-storage=*) - PERSISTENCE_STORAGE="${_PARAMETER#persistence-storage=}" - export PERSISTENCE_STORAGE - ;; - - persistence-label=*) - old_root_overlay_label="${_PARAMETER#persistence-label=*}" - old_home_overlay_label="${_PARAMETER#persistence-label=*}" - custom_overlay_label="${_PARAMETER#persistence-label=*}" - ;; - - nopersistence) - NOPERSISTENCE="true" - export NOPERSISTENCE - ;; - - quickusbmodules) - QUICKUSBMODULES="true" - export QUICKUSBMODULES - ;; - - showmounts) - SHOWMOUNTS="true" - export SHOWMOUNTS - ;; - - todisk=*) - TODISK="${_PARAMETER#todisk=}" - export TODISK - ;; - - toram) - TORAM="true" - export TORAM - ;; - - toram=*) - TORAM="true" - MODULETORAM="${_PARAMETER#toram=}" - export TORAM MODULETORAM - ;; - - exposedroot) - EXPOSED_ROOT="true" - export EXPOSED_ROOT - ;; - - plainroot) - PLAIN_ROOT="true" - export PLAIN_ROOT - ;; - - skipunion) - SKIP_UNION_MOUNTS="true" - export SKIP_UNION_MOUNTS - ;; - - root=*) - ROOT="${_PARAMETER#root=}" - export ROOT - ;; - - union=*) - UNIONTYPE="${_PARAMETER#union=}" - export UNIONTYPE - ;; - esac - done - - # sort of compatibility with netboot.h from linux docs - if [ -z "${NETBOOT}" ] - then - if [ "${ROOT}" = "/dev/nfs" ] - then - NETBOOT="nfs" - export NETBOOT - elif [ "${ROOT}" = "/dev/cifs" ] - then - NETBOOT="cifs" - export NETBOOT - fi - fi - - if [ -z "${MODULE}" ] - then - MODULE="filesystem" - export MODULE - fi - - if [ -z "${UNIONTYPE}" ] - then - UNIONTYPE="aufs" - export UNIONTYPE - fi - - if [ -z "${PERSISTENCE_ENCRYPTION}" ] - then - PERSISTENCE_ENCRYPTION="none" - export PERSISTENCE_ENCRYPTION - elif is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} - then - if ! modprobe dm-crypt - then - log_warning_msg "Unable to load module dm-crypt" - PERSISTENCE_ENCRYPTION=$(echo ${PERSISTENCE_ENCRYPTION} | sed -e 's/\> "${_FSTAB}" - fi - - if ! grep -qs "^tmpfs /tmp" "${_FSTAB}" - then - echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> "${_FSTAB}" - fi - - log_end_msg -} diff --git a/scripts/boot/initramfs-tools.sh b/scripts/boot/initramfs-tools.sh deleted file mode 100755 index 37aa0c3..0000000 --- a/scripts/boot/initramfs-tools.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh - -#set -e - -log_wait_msg () -{ - # Print a message and wait for enter - if [ -x /bin/plymouth ] && plymouth --ping - then - plymouth message --text="$@" - plymouth watch-keystroke | read nunya - fi - - _log_msg "Waiting: ${@} ... \n" -} - -# Override maybe_break from scripts/functions -maybe_break() -{ - if [ "${break}" = "$1" ]; then - # Call original panic - . /scripts/functions - panic "Spawning shell within the initramfs" - fi -} - -# Override panic from scripts/functions -panic() { - - DEB_1="\033[1;31m .''\`. \033[0m" - DEB_2="\033[1;31m: :' : \033[0m" - DEB_3="\033[1;31m\`. \`'\` \033[0m" - DEB_4="\033[1;31m \`- \033[0m" - - LIVELOG="\033[1;37m/boot.log\033[0m" - DEBUG="\033[1;37mdebug\033[0m" - - # Reset redirections to avoid buffering - exec 1>&6 6>&- - exec 2>&7 7>&- - kill ${tailpid} - - printf "\n\n" - printf " ${DEB_1}\n" - printf " ${DEB_2} \033[1;37mBOOT FAILED!\033[0m\n" - printf " ${DEB_3}\n" - printf " ${DEB_4} This Debian Live image failed to boot.\n\n" - - printf " Please file a bug against the 'live-boot' package or email the Debian\n" - printf " Live mailing list at , making sure to note the\n" - printf " exact version, name and distribution of the image you were attempting to boot.\n\n" - - printf " The file ${LIVELOG} contains some debugging information but booting with the\n" - printf " ${DEBUG} command-line parameter will greatly increase its verbosity which is\n" - printf " extremely useful when diagnosing issues.\n\n" - - if [ -n "${panic}" ]; then - printf " live-boot will now restart your system. " - else - printf " live-boot will now start a shell. " - fi - printf "The error message was:\n\n " - - # Call original panic - . /scripts/functions - panic "$@" -} diff --git a/scripts/boot/misc-helpers.sh b/scripts/boot/misc-helpers.sh deleted file mode 100755 index cc39fcb..0000000 --- a/scripts/boot/misc-helpers.sh +++ /dev/null @@ -1,1558 +0,0 @@ -#!/bin/sh - -#set -e - -is_live_path () -{ - DIRECTORY="${1}" - - if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ] - then - for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2 - do - if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ] - then - return 0 - fi - done - fi - - return 1 -} - -matches_uuid () -{ - if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ] - then - return 0 - fi - - path="${1}" - uuid="$(cat /conf/uuid.conf)" - - for try_uuid_file in "${path}/.disk/live-uuid"* - do - [ -e "${try_uuid_file}" ] || continue - - try_uuid="$(cat "${try_uuid_file}")" - - if [ "${uuid}" = "${try_uuid}" ] - then - return 0 - fi - done - - return 1 -} - -get_backing_device () -{ - case "${1}" in - *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2) - echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}") - ;; - - *.dir) - echo "directory" - ;; - - *) - panic "Unrecognized live filesystem: ${1}" - ;; - esac -} - -match_files_in_dir () -{ - # Does any files match pattern ${1} ? - local pattern="${1}" - - if [ "$(echo ${pattern})" != "${pattern}" ] - then - return 0 - fi - - return 1 -} - -mount_images_in_directory () -{ - directory="${1}" - rootmnt="${2}" - mac="${3}" - - if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" || - match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" || - match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" || - match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" || - match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" || - match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir" - then - [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}" - setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}" - else - panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}." - fi -} - -is_nice_device () -{ - sysfs_path="${1#/sys}" - - if [ -e /lib/udev/path_id ] - then - # squeeze - PATH_ID="/lib/udev/path_id" - else - # wheezy/sid (udev >= 174) - PATH_ID="/sbin/udevadm test-builtin path_id" - fi - - if ${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)" - then - return 0 - elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$' - then - return 0 - elif echo ${sysfs_path} | grep -q "^/block/dm-" - then - return 0 - elif echo ${sysfs_path} | grep -q "^/block/mtdblock" - then - return 0 - fi - - return 1 -} - -check_dev () -{ - sysdev="${1}" - devname="${2}" - skip_uuid_check="${3}" - - # support for fromiso=.../isofrom=.... - if [ -n "$FROMISO" ] - then - ISO_DEVICE=$(dirname $FROMISO) - if ! [ -b $ISO_DEVICE ] - then - # to support unusual device names like /dev/cciss/c0d0p1 - # as well we have to identify the block device name, let's - # do that for up to 15 levels - i=15 - while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ] - do - ISO_DEVICE=$(dirname ${ISO_DEVICE}) - [ -b "$ISO_DEVICE" ] && break - i=$(($i -1)) - done - fi - - if [ "$ISO_DEVICE" = "/" ] - then - echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log - else - fs_type=$(get_fstype "${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*" "" '') - devname="${loopdevname}" - else - echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log - fi - fi - fi - - if [ -z "${devname}" ] - then - devname=$(sys2dev "${sysdev}") - fi - - if [ -d "${devname}" ] - then - mount -o bind "${devname}" $mountpoint || continue - - if is_live_path $mountpoint - then - echo $mountpoint - return 0 - else - umount $mountpoint - fi - fi - - IFS="," - for device in ${devname} - do - case "$device" in - *mapper*) - # Adding lvm support - if [ -x /scripts/local-top/lvm2 ] - then - ROOT="$device" resume="" /scripts/local-top/lvm2 - fi - ;; - - /dev/md*) - # Adding raid support - if [ -x /scripts/local-top/mdadm ] - then - 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 - fi - ;; - esac - done - unset IFS - - [ -n "$device" ] && devname="$device" - - [ -e "$devname" ] || continue - - if [ -n "${LIVE_MEDIA_OFFSET}" ] - then - loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '') - devname="${loopdevname}" - fi - - fstype=$(get_fstype "${devname}") - - if is_supported_fs ${fstype} - then - devuid=$(blkid -o value -s UUID "$devname") - [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue - mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue - [ -n "$devuid" ] && echo "$devuid" >> $tried - - if [ -n "${FINDISO}" ] - then - 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 "") - devname="${loopdevname}" - mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint} - else - umount ${mountpoint} - fi - fi - - if is_live_path ${mountpoint} && \ - ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint}) - then - echo ${mountpoint} - return 0 - else - umount ${mountpoint} 2>/dev/null - fi - fi - - if [ -n "${LIVE_MEDIA_OFFSET}" ] - then - losetup -d "${loopdevname}" - fi - - return 1 -} - -find_livefs () -{ - timeout="${1}" - - # don't start autodetection before timeout has expired - if [ -n "${LIVE_MEDIA_TIMEOUT}" ] - then - if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ] - then - return 1 - fi - fi - - # first look at the one specified in the command line - case "${LIVE_MEDIA}" in - removable-usb) - for sysblock in $(removable_usb_dev "sys") - do - for dev in $(subdevices "${sysblock}") - do - if check_dev "${dev}" - then - return 0 - fi - done - done - return 1 - ;; - - removable) - for sysblock in $(removable_dev "sys") - do - for dev in $(subdevices "${sysblock}") - do - if check_dev "${dev}" - then - return 0 - fi - done - done - return 1 - ;; - - *) - if [ ! -z "${LIVE_MEDIA}" ] - then - if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check" - then - return 0 - fi - fi - ;; - esac - - # or do the scan of block devices - # prefer removable devices over non-removable devices, so scan them first - devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')" - - for sysblock in $devices_to_scan - do - devname=$(sys2dev "${sysblock}") - [ -e "$devname" ] || continue - fstype=$(get_fstype "${devname}") - - if /lib/udev/cdrom_id ${devname} > /dev/null - then - if check_dev "null" "${devname}" - then - return 0 - fi - elif is_nice_device "${sysblock}" - then - for dev in $(subdevices "${sysblock}") - do - if check_dev "${dev}" - then - 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 - - return 1 -} - -really_export () -{ - STRING="${1}" - VALUE="$(eval echo -n \${$STRING})" - - if [ -f /live.vars ] && grep -sq "export ${STRING}" /live.vars - then - sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars - else - echo "export ${STRING}=\"${VALUE}\"" >> /live.vars - fi - - eval export "${STRING}"="${VALUE}" -} - -is_in_list_separator_helper () -{ - local sep=${1} - shift - local element=${1} - shift - local list=${*} - echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$" -} - -is_in_space_sep_list () -{ - local element=${1} - shift - is_in_list_separator_helper "[[:space:]]" "${element}" "${*}" -} - -is_in_comma_sep_list () -{ - local element=${1} - shift - is_in_list_separator_helper "," "${element}" "${*}" -} - -sys2dev () -{ - sysdev=${1#/sys} - echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})" -} - -subdevices () -{ - sysblock=${1} - r="" - - for dev in "${sysblock}"/* "${sysblock}" - do - if [ -e "${dev}/dev" ] - then - r="${r} ${dev}" - fi - done - - echo ${r} -} - -storage_devices() -{ - black_listed_devices="${1}" - white_listed_devices="${2}" - - for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "loop|ram|fd") - do - fulldevname=$(sys2dev "${sysblock}") - - if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \ - [ -n "${white_listed_devices}" ] && \ - ! is_in_space_sep_list ${fulldevname} ${white_listed_devices} - then - # skip this device entirely - continue - fi - - for dev in $(subdevices "${sysblock}") - do - devname=$(sys2dev "${dev}") - - if is_in_space_sep_list ${devname} ${black_listed_devices} - then - # skip this subdevice - continue - else - echo "${devname}" - fi - done - done -} - -is_supported_fs () -{ - fstype="${1}" - - # Validate input first - if [ -z "${fstype}" ] - 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} - if grep -q ${fstype} /proc/filesystems - then - return 0 - # Then try the hard way if /root is already reachable - else - kmodule="/root/lib/modules/`uname -r`/${fstype}/${fstype}.ko" - if [ -e "${kmodule}" ] - then - insmod "${kmodule}" - if grep -q ${fstype} /proc/filesystems - then - return 0 - fi - fi - fi - fi - - return 1 -} - -get_fstype () -{ - /sbin/blkid -s TYPE -o value $1 2>/dev/null -} - -where_is_mounted () -{ - device=${1} - # return first found - grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' ' -} - -trim_path () -{ - # remove all unnecessary /:s in the path, including last one (except - # if path is just "/") - echo ${1} | sed 's|//\+|/|g' | sed 's|^\(.*[^/]\)/$|\1|' -} - -what_is_mounted_on () -{ - local dir="$(trim_path ${1})" - grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1 -} - -chown_ref () -{ - local reference="${1}" - shift - local targets=${@} - local owner=$(stat -c %u:%g "${reference}") - chown -h ${owner} ${targets} -} - -chmod_ref () -{ - local reference="${1}" - shift - local targets=${@} - local rights=$(stat -c %a "${reference}") - chmod ${rights} ${targets} -} - -lastline () -{ - while read lines - do - line=${lines} - done - - echo "${line}" -} - -base_path () -{ - testpath="${1}" - mounts="$(awk '{print $2}' /proc/mounts)" - testpath="$(busybox realpath ${testpath})" - - while true - do - if echo "${mounts}" | grep -qs "^${testpath}" - then - set -- $(echo "${mounts}" | grep "^${testpath}" | lastline) - echo ${1} - break - else - testpath=$(dirname $testpath) - fi - done -} - -fs_size () -{ - # Returns used/free fs kbytes + 5% more - # You could pass a block device as ${1} or the mount point as ${2} - - dev="${1}" - mountp="${2}" - used="${3}" - - if [ -z "${mountp}" ] - then - mountp="$(where_is_mounted ${dev})" - - if [ -z "${mountp}" ] - then - mountp="/mnt/tmp_fs_size" - - mkdir -p "${mountp}" - mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" || log_warning_msg "cannot mount -t $(get_fstype ${dev}) -o ro ${dev} ${mountp}" - - doumount=1 - fi - fi - - if [ "${used}" = "used" ] - then - size=$(du -ks ${mountp} | cut -f1) - size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure - else - # free space - size="$(df -k | grep -s ${mountp} | awk '{print $4}')" - fi - - if [ -n "${doumount}" ] - then - umount "${mountp}" || log_warning_msg "cannot umount ${mountp}" - rmdir "${mountp}" - fi - - echo "${size}" -} - -load_keymap () -{ - # Load custom keymap - if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ] - then - loadkeys /etc/boottime.kmap.gz - fi -} - -setup_loop () -{ - local fspath=${1} - local module=${2} - local pattern=${3} - local offset=${4} - local encryption=${5} - local readonly=${6} - - # the output of setup_loop is evaluated in other functions, - # modprobe leaks kernel options like "libata.dma=0" - # as "options libata dma=0" on stdout, causing serious - # problems therefor, so instead always avoid output to stdout - modprobe -q -b "${module}" 1>/dev/null - - udevadm settle - - for loopdev in ${pattern} - do - if [ "$(cat ${loopdev}/size)" -eq 0 ] - then - dev=$(sys2dev "${loopdev}") - options='' - - if [ -n "${readonly}" ] - then - if losetup --help 2>&1 | grep -q -- "-r\b" - then - options="${options} -r" - fi - fi - - if [ -n "${offset}" ] && [ 0 -lt "${offset}" ] - then - options="${options} -o ${offset}" - fi - - if [ -z "${encryption}" ] - then - losetup ${options} "${dev}" "${fspath}" - else - # Loop AES encryption - while true - do - load_keymap - - echo -n "Enter passphrase for root filesystem: " >&6 - read -s passphrase - echo "${passphrase}" > /tmp/passphrase - unset passphrase - exec 9&6 - read answer - - if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ] - then - unset answer - break - fi - done - fi - - echo "${dev}" - return 0 - fi - done - - panic "No loop devices available" -} - -try_mount () -{ - 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}" > boot.log && return 0 ) - fi -} - -mount_persistence_media () -{ - local device=${1} - local probe=${2} - - local backing="/live/persistence/$(basename ${device})" - - mkdir -p "${backing}" - local old_backing="$(where_is_mounted ${device})" - if [ -z "${old_backing}" ] - then - local fstype="$(get_fstype ${device})" - local mount_opts="rw,noatime" - if [ -n "${PERSISTENCE_READONLY}" ] - then - mount_opts="ro,noatime" - fi - if mount -t "${fstype}" -o "${mount_opts}" "${device}" "${backing}" >/dev/null - then - echo ${backing} - return 0 - else - [ -z "${probe}" ] && log_warning_msg "Failed to mount persistence media ${device}" - rmdir "${backing}" - return 1 - fi - elif [ "${backing}" != "${old_backing}" ] - then - if mount --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 - fi - return 0 -} - -close_persistence_media () -{ - local device=${1} - local backing="$(where_is_mounted ${device})" - - if [ -d "${backing}" ] - then - umount "${backing}" >/dev/null 2>&1 - rmdir "${backing}" >/dev/null 2>&1 - fi - - if is_active_luks_mapping ${device} - then - /sbin/cryptsetup luksClose ${device} - fi -} - -open_luks_device () -{ - dev="${1}" - name="$(basename ${dev})" - opts="--key-file=-" - if [ -n "${PERSISTENCE_READONLY}" ] - then - opts="${opts} --readonly" - fi - - if /sbin/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|") - if [ "${opened_dev}" = "${dev}" ] - then - luks_device="/dev/mapper/${name}" - echo ${luks_device} - return 0 - else - log_warning_msg "Cannot open luks device ${dev} since ${opened_dev} already is opened with its name" - return 1 - fi - 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 -} - -get_gpt_name () -{ - local dev="${1}" - /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null -} - -is_gpt_device () -{ - local dev="${1}" - [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ] -} - -probe_for_gpt_name () -{ - local overlays="${1}" - local dev="${2}" - - local gpt_dev="${dev}" - if is_active_luks_mapping ${dev} - then - # if $dev is an opened luks device, we need to check - # GPT stuff on the backing device - gpt_dev=$(get_luks_backing_device "${dev}") - fi - - if ! is_gpt_device ${gpt_dev} - then - return - fi - - local gpt_name=$(get_gpt_name ${gpt_dev}) - for label in ${overlays} - do - if [ "${gpt_name}" = "${label}" ] - then - echo "${label}=${dev}" - fi - done -} - -probe_for_fs_label () -{ - local overlays="${1}" - local dev="${2}" - - for label in ${overlays} - do - if [ "$(/sbin/blkid -s LABEL -o value $dev 2>/dev/null)" = "${label}" ] - then - echo "${label}=${dev}" - fi - done -} - -probe_for_file_name () -{ - local overlays="${1}" - local dev="${2}" - - local ret="" - local backing="$(mount_persistence_media ${dev} probe)" - if [ -z "${backing}" ] - then - return - fi - - for label in ${overlays} - do - path=${backing}/${PERSISTENCE_PATH}${label} - if [ -f "${path}" ] - then - local loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*") - ret="${ret} ${label}=${loopdev}" - fi - done - - if [ -n "${ret}" ] - then - echo ${ret} - else - umount ${backing} > /dev/null 2>&1 || true - fi -} - -find_persistence_media () -{ - # Scans devices for overlays, and returns a whitespace - # separated list of how to use them. Only overlays with a partition - # label or file name in ${overlays} are returned. - # - # When scanning a LUKS device, the user will be asked to enter the - # passphrase; on failure to enter it, or if no persistence partitions - # or files were found, the LUKS device is closed. - # - # For all other cases (overlay 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. - - local overlays="${1}" - local white_listed_devices="${2}" - local ret="" - - local black_listed_devices="$(what_is_mounted_on /live/image)" - - for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}") - do - local result="" - - local luks_device="" - # Check if it's a luks device; we'll have to open the device - # in order to probe any filesystem it contains, like we do - # below. activate_custom_mounts() also depends on that any luks - # device already has been opened. - if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${dev} - then - if luks_device=$(open_luks_device "${dev}") - then - dev="${luks_device}" - else - # skip $dev since we failed/chose not to open it - continue - fi - elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION} - then - # skip $dev since we don't allow unencrypted storage - continue - fi - - # Probe for matching GPT partition names or filesystem labels - if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE} - then - result=$(probe_for_gpt_name "${overlays}" ${dev}) - if [ -n "${result}" ] - then - ret="${ret} ${result}" - continue - fi - - result=$(probe_for_fs_label "${overlays}" ${dev}) - if [ -n "${result}" ] - then - ret="${ret} ${result}" - continue - fi - fi - - # Probe for files with matching name on mounted partition - if is_in_comma_sep_list file ${PERSISTENCE_STORAGE} - then - result=$(probe_for_file_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}" - fi - done - - if [ -n "${ret}" ] - then - echo ${ret} - fi -} - -get_mac () -{ - mac="" - - for adaptor in /sys/class/net/* - do - status="$(cat ${adaptor}/iflink)" - - if [ "${status}" -eq 2 ] - then - mac="$(cat ${adaptor}/address)" - mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')" - fi - done - - echo ${mac} -} - -is_luks_partition () -{ - device="${1}" - /sbin/cryptsetup isLuks "${device}" 1>/dev/null 2>&1 -} - -is_active_luks_mapping () -{ - device="${1}" - /sbin/cryptsetup status "${device}" 1>/dev/null 2>&1 -} - -get_luks_backing_device () -{ - device=${1} - cryptsetup status ${device} 2> /dev/null | \ - awk '{if ($1 == "device:") print $2}' -} - -removable_dev () -{ - output_format="${1}" - want_usb="${2}" - ret= - - for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") - do - dev_ok= - if [ "$(cat ${sysblock}/removable)" = "1" ] - then - if [ -z "${want_usb}" ] - then - dev_ok="true" - else - if readlink ${sysblock} | grep -q usb - then - dev_ok="true" - fi - fi - fi - - if [ "${dev_ok}" = "true" ] - then - case "${output_format}" in - sys) - ret="${ret} ${sysblock}" - ;; - *) - devname=$(sys2dev "${sysblock}") - ret="${ret} ${devname}" - ;; - esac - fi - done - - echo "${ret}" -} - -removable_usb_dev () -{ - output_format="${1}" - - removable_dev "${output_format}" "want_usb" -} - -non_removable_dev () -{ - output_format="${1}" - ret= - - for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") - do - if [ "$(cat ${sysblock}/removable)" = "0" ] - then - case "${output_format}" in - sys) - ret="${ret} ${sysblock}" - ;; - *) - devname=$(sys2dev "${sysblock}") - ret="${ret} ${devname}" - ;; - esac - fi - done - - echo "${ret}" -} - -link_files () -{ - # create source's directory structure in dest, and recursively - # create symlinks in dest to to all files in source. if mask - # is non-empty, remove mask from all source paths when - # creating links (will be necessary if we change root, which - # live-boot normally does (into $rootmnt)). - - # remove multiple /:s and ensure ending on / - local src_dir="$(trim_path ${1})/" - local dest_dir="$(trim_path ${2})/" - local src_mask="${3}" - - # This check can only trigger on the inital, non-recursive call since - # we create the destination before recursive calls - if [ ! -d "${dest_dir}" ] - then - log_warning_msg "Must link_files into a directory" - return - fi - - find "${src_dir}" -mindepth 1 -maxdepth 1 | \ - while read src - do - local dest="${dest_dir}$(basename "${src}")" - if [ -d "${src}" ] - then - if [ -z "$(ls -A "${src}")" ] - then - continue - fi - if [ ! -d "${dest}" ] - then - mkdir -p "${dest}" - chown_ref "${src}" "${dest}" - chmod_ref "${src}" "${dest}" - fi - link_files "${src}" "${dest}" "${src_mask}" - else - local final_src=${src} - if [ -n "${src_mask}" ] - then - final_src="$(echo ${final_src} | sed "s|^${src_mask}||")" - fi - rm -rf "${dest}" 2> /dev/null - ln -s "${final_src}" "${dest}" - chown_ref "${src}" "${dest}" - fi - done -} - -do_union () -{ - local unionmountpoint="${1}" # directory where the union is mounted - local unionrw="${2}" # branch where the union changes are stored - local unionro1="${3}" # first underlying read-only branch (optional) - local unionro2="${4}" # second underlying read-only branch (optional) - - case "${UNIONTYPE}" in - aufs) - 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}" - if [ -n "${unionro1}" ] - then - unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}" - fi - if [ -n "${unionro2}" ] - then - unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}" - 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 unionro2 be used? (overlayfs only handles two dirs, but perhaps they can be chained?) - # XXX: and can unionro1 be optional? i.e. can overlayfs skip lowerdir? - unionmountopts="-o noatime,lowerdir=${unionro1},upperdir=${unionrw}" - mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}" - ;; - - *) - unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}" - if [ -n "${unionro1}" ] - then - unionmountopts="${unionmountopts}:${unionro1}=${ro_opt}" - fi - if [ -n "${unionro2}" ] - then - unionmountopts="${unionmountopts}:${unionro2}=${ro_opt}" - fi - mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}" - ;; - esac -} - -get_custom_mounts () -{ - # Side-effect: leaves $devices with live-persistence.conf mounted in /live/persistence - # Side-effect: prints info to file $custom_mounts - - local custom_mounts=${1} - shift - local devices=${@} - - local bindings="/tmp/bindings.list" - local links="/tmp/links.list" - rm -rf ${bindings} ${links} 2> /dev/null - - for device in ${devices} - do - if [ ! -b "${device}" ] - then - continue - fi - - local device_name="$(basename ${device})" - local backing=$(mount_persistence_media ${device}) - if [ -z "${backing}" ] - then - continue - fi - - local include_list="${backing}/${persistence_list}" - if [ ! -r "${include_list}" ] - then - continue - fi - - if [ -n "${DEBUG}" ] && [ -e "${include_list}" ] - then - cp ${include_list} /live/persistence/${persistence_list}.${device_name} - fi - - while read dir options # < ${include_list} - do - if echo ${dir} | grep -qe "^[[:space:]]*\(#.*\)\?$" - then - # skipping empty or commented lines - continue - fi - - if trim_path ${dir} | grep -q -e "^[^/]" -e "^/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 \"/live\" or any sub-directory therein." - continue - fi - - local opt_source="" - local opt_link="" - for opt in $(echo ${options} | tr ',' ' '); - do - case "${opt}" in - source=*) - opt_source=${opt#source=} - ;; - link) - opt_link="true" - ;; - union|bind) - ;; - *) - log_warning_msg "Skipping custom mount with unkown option: ${opt}" - continue 2 - ;; - esac - done - - local source="${dir}" - if [ -n "${opt_source}" ] - then - if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${source}" != "." ] - then - 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" - continue - else - source="${opt_source}" - fi - fi - - local full_source="$(trim_path ${backing}/${source})" - local full_dest="$(trim_path ${rootmnt}/${dir})" - if [ -n "${opt_link}" ] - then - echo "${device} ${full_source} ${full_dest} ${options}" >> ${links} - else - echo "${device} ${full_source} ${full_dest} ${options}" >> ${bindings} - fi - done < ${include_list} - done - - # We sort the list according to destination so we're sure that - # we won't hide a previous mount. We also ignore duplicate - # destinations in a more or less arbitrary way. - [ -e "${bindings}" ] && sort -k3 -sbu ${bindings} >> ${custom_mounts} && rm ${bindings} - - # After all mounts are considered we add symlinks so they - # won't be hidden by some mount. - [ -e "${links}" ] && cat ${links} >> ${custom_mounts} && rm ${links} - - # We need to make sure that no two custom mounts have the same sources - # or are nested; if that is the case, too much weird stuff can happen. - local prev_source="impossible source" # first iteration must not match - local 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} | - while read device source dest options - do - if echo ${source} | grep -qe "^${prev_source}\(/.*\)\?$" - then - panic "Two persistence mounts have the same or nested sources: ${source} on ${dest}, and ${prev_source} on ${prev_dest}" - fi - prev_source=${source} - prev_dest=${dest} - done -} - -activate_custom_mounts () -{ - local custom_mounts="${1}" # the ouput from get_custom_mounts() - local used_devices="" - - while read device source dest options # < ${custom_mounts} - do - local opt_bind="true" - local opt_link="" - local opt_union="" - for opt in $(echo ${options} | tr ',' ' '); - do - case "${opt}" in - bind) - opt_bind="true" - unset opt_link opt_union - ;; - link) - opt_link="true" - unset opt_bind opt_union - ;; - union) - opt_union="true" - unset opt_bind opt_link - ;; - esac - done - - if [ -n "$(what_is_mounted_on "${dest}")" ] - then - if [ "${dest}" = "${rootmnt}" ] - then - umount "${dest}" - else - log_warning_msg "Skipping custom mount ${dest}: $(what_is_mounted_on "${dest}") is already mounted there" - continue - fi - fi - - if [ ! -d "${dest}" ] - then - # create the destination and delete existing files in - # its path that are in the way - path="/" - for dir in $(echo ${dest} | sed -e 's|/\+| |g') - do - path=$(trim_path ${path}/${dir}) - if [ -f ${path} ] - then - rm -f ${path} - fi - if [ ! -e ${path} ] - then - mkdir -p ${path} - if echo ${path} | grep -qe "^${rootmnt}/*home/[^/]\+" - then - # if ${dest} is in /home try fixing proper ownership by assuming that the intended user is the first, which is usually the case - # FIXME: this should really be handled by live-config since we don't know for sure which uid a certain user has until then - chown 1000:1000 ${path} - fi - fi - done - fi - - # if ${source} doesn't exist on our persistence media - # we bootstrap it with $dest from the live filesystem. - # this both makes sense and is critical if we're - # dealing with /etc or other system dir. - if [ ! -d "${source}" ] - then - if [ -n "${PERSISTENCE_READONLY}" ] - then - continue - elif [ -n "${opt_union}" ] || [ -n "${opt_link}" ] - then - # unions and don't need to be bootstrapped - # link dirs can't be bootstrapped in a sensible way - mkdir -p "${source}" - chown_ref "${dest}" "${source}" - chmod_ref "${dest}" "${source}" - elif [ -n "${opt_bind}" ] - then - # ensure that $dest is not copied *into* $source - mkdir -p "$(dirname ${source})" - cp -a "${dest}" "${source}" - fi - fi - - # XXX: If CONFIG_AUFS_ROBR is added to the Debian kernel we can - # ignore the loop below and set rofs_dest_backing=$dest - local rofs_dest_backing="" - if [ -n "${opt_link}"] - then - for d in /live/rofs/* - do - if [ -n "${rootmnt}" ] - then - rofs_dest_backing="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")" - else - rofs_dest_backing="${d}/${dest}" - fi - if [ -d "${rofs_dest_backing}" ] - then - break - else - rofs_dest_backing="" - fi - done - fi - - if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ] - then - link_files ${source} ${dest} ${rootmnt} - elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ] - then - mkdir -p /live/persistence - local links_source=$(mktemp -d /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 - # make it absolutely certain that the link source - # has its own directory and isn't nested with some - # other custom mount (if so that mount's files would - # be linked, causing breakage. - local cow_dir="/live/overlay/live/persistence/$(basename ${links_source})" - mkdir -p ${cow_dir} - chown_ref "${source}" "${cow_dir}" - chmod_ref "${source}" "${cow_dir}" - do_union ${links_source} ${cow_dir} ${source} ${rofs_dest_backing} - link_files ${links_source} ${dest} ${rootmnt} - elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ] - then - do_union ${dest} ${source} ${rofs_dest_backing} - elif [ -n "${opt_bind}" ] && [ -z "${PERSISTENCE_READONLY}" ] - then - mount --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 rofs_dest_backing - # is non-empty (and necessary) only for unions - if [ -n "${rootmnt}" ] - then - local cow_dir="$(echo ${dest} | sed -e "s|^${rootmnt}|/live/overlay/|")" - else - # This is happens if persistence is activated - # post boot - local cow_dir="/live/overlay/${dest}" - fi - if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ] - then - # If an earlier custom mount has files here - # it will "block" the current mount's files - # which is undesirable - rm -rf "${cow_dir}" - fi - mkdir -p ${cow_dir} - chown_ref "${source}" "${cow_dir}" - chmod_ref "${source}" "${cow_dir}" - do_union ${dest} ${cow_dir} ${source} ${rofs_dest_backing} - fi - - PERSISTENCE_IS_ON="1" - export PERSISTENCE_IS_ON - - if echo ${used_devices} | grep -qve "^\(.* \)\?${device}\( .*\)\?$" - then - used_devices="${used_devices} ${device}" - fi - done < ${custom_mounts} - - echo ${used_devices} -} - -fix_backwards_compatibility () -{ - local device=${1} - local dir=${2} - local opt=${3} - - if [ -n "${PERSISTENCE_READONLY}" ] - then - return - fi - - local backing="$(mount_persistence_media ${device})" - if [ -z "${backing}" ] - then - return - fi - - local include_list="${backing}/${persistence_list}" - if [ ! -r "${include_list}" ] - then - echo "# persistence backwards compatibility: -${dir} ${opt},source=." > "${include_list}" - fi -} - -is_mountpoint () -{ - directory="$1" - - [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ] -} diff --git a/scripts/boot/mount-cifs.sh b/scripts/boot/mount-cifs.sh deleted file mode 100755 index a8ef3f4..0000000 --- a/scripts/boot/mount-cifs.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -#set -e - -do_cifsmount () -{ - rc=1 - - if [ -x "/sbin/mount.cifs" ] - then - if [ -z "${NFSOPTS}" ] - then - CIFSOPTS="-ouser=root,password=" - else - CIFSOPTS="-o ${NFSOPTS}" - fi - - log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}" - modprobe -q cifs - - if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" - then - rc=0 - fi - fi - - return ${rc} -} diff --git a/scripts/boot/mount-http.sh b/scripts/boot/mount-http.sh deleted file mode 100755 index 1b718c0..0000000 --- a/scripts/boot/mount-http.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh - -#set -e - -do_httpmount () -{ - rc=1 - - for webfile in HTTPFS FTPFS FETCH - do - local url="$(eval echo \"\$\{${webfile}\}\")" - local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')" - - if [ -n "$url" ] - then - case "${extension}" in - iso|squashfs|tgz|tar) - if [ "${extension}" = "iso" ] - then - mkdir -p "${alt_mountpoint}" - dest="${alt_mountpoint}" - else - local dest="${mountpoint}/${LIVE_MEDIA_PATH}" - mount -t ramfs ram "${mountpoint}" - mkdir -p "${dest}" - fi - if [ "${webfile}" = "FETCH" ] - then - case "$url" in - tftp*) - ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')" - rfile="$(echo $url | sed -e "s|tftp://$ip||g")" - lfile="$(basename $url)" - log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip" - tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip - ;; - - *) - log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})" - wget "${url}" -O "${dest}/$(basename ${url})" - ;; - esac - else - log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})" - if [ "${webfile}" = "FTPFS" ] - then - FUSE_MOUNT="curlftpfs" - url="$(dirname ${url})" - else - FUSE_MOUNT="httpfs" - fi - modprobe fuse - $FUSE_MOUNT "${url}" "${dest}" - ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )" - fi - [ ${?} -eq 0 ] && rc=0 - [ "${extension}" = "tgz" ] && live_dest="ram" - if [ "${extension}" = "iso" ] - then - isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '') - mount -t iso9660 "${isoloop}" "${mountpoint}" - rc=${?} - fi - break - ;; - - *) - log_begin_msg "Unrecognized archive extension for ${url}" - ;; - esac - fi - done - - if [ ${rc} != 0 ] - then - if [ -d "${alt_mountpoint}" ] - then - umount "${alt_mountpoint}" - rmdir "${alt_mountpoint}" - fi - umount "${mountpoint}" - elif [ "${webfile}" != "FETCH" ] ; then - NETBOOT="${webfile}" - export NETBOOT - fi - - return ${rc} -} diff --git a/scripts/boot/mount-iscsi.sh b/scripts/boot/mount-iscsi.sh deleted file mode 100755 index fd29d91..0000000 --- a/scripts/boot/mount-iscsi.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -#set -e - -do_iscsi() -{ - do_netsetup - #modprobe ib_iser - modprobe iscsi_tcp - local debugopt="" - [ "${DEBUG}" = "true" ] && debugopt="-d 8" - #FIXME this name is supposed to be unique - some date + ifconfig hash? - ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)" - export ISCSI_INITIATORNAME - if [ -n "${ISCSI_SERVER}" ] ; then - iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}" - else - iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260 - fi - if [ $? != 0 ] - then - panic "Failed to log into iscsi target" - fi - local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \ - /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')" - if [ -n "${host}" ] - then - local devices="" - local i=0 - while [ -z "${devices}" -a $i -lt 60 ] - do - sleep 1 - devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \ - /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')" - i=$(expr $i + 1) - echo -ne $i\\r - done - for dev in $devices - do - if check_dev "null" "/dev/$dev" - then - NETBOOT="iscsi" - export NETBOOT - return 0; - fi - done - panic "Failed to locate a live device on iSCSI devices (tried: $devices)." - else - panic "Failed to locate iSCSI host in /sys" - fi -} diff --git a/scripts/boot/mount-nfs.sh b/scripts/boot/mount-nfs.sh deleted file mode 100755 index 6a3ae55..0000000 --- a/scripts/boot/mount-nfs.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -#set -e - -do_nfsmount () -{ - rc=1 - - modprobe -q nfs - - if [ -n "${NFSOPTS}" ] - then - NFSOPTS="-o ${NFSOPTS}" - fi - - log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}" - - # FIXME: This while loop is an ugly HACK round an nfs bug - i=0 - while [ "$i" -lt 60 ] - do - nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break - sleep 1 - i="$(($i + 1))" - done - - return ${rc} -} diff --git a/scripts/boot/mountroot.sh b/scripts/boot/mountroot.sh deleted file mode 100755 index 2d14e4d..0000000 --- a/scripts/boot/mountroot.sh +++ /dev/null @@ -1,221 +0,0 @@ -#!/bin/sh - -# set -e - -mountroot () -{ - if [ -x /scripts/local-top/cryptroot ] - then - /scripts/local-top/cryptroot - fi - - exec 6>&1 - exec 7>&2 - exec > boot.log - exec 2>&1 - tail -f boot.log >&7 & - tailpid="${!}" - - . /live.vars - - _CMDLINE="$(cat /proc/cmdline)" - Cmdline - - case "${LIVE_DEBUG}" in - true) - set -x - ;; - esac - - case "${LIVE_READ_ONLY}" in - true) - Read_only - ;; - esac - - Select_eth_device - - # Needed here too because some things (*cough* udev *cough*) - # changes the timeout - - if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ] - then - if do_netmount - then - livefs_root="${mountpoint}" - else - panic "Unable to find a live file system on the network" - fi - else - if [ -n "${ISCSI_PORTAL}" ] - then - do_iscsi && livefs_root="${mountpoint}" - elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ] - then - # Do a local boot from hd - livefs_root=${ROOT} - else - if [ -x /usr/bin/memdiskfind ] - then - MEMDISK=$(/usr/bin/memdiskfind) - - if [ $? -eq 0 ] - then - # We found a memdisk, set up phram - modprobe phram phram=memdisk,${MEMDISK} - - # Load mtdblock, the memdisk will be /dev/mtdblock0 - modprobe mtdblock - fi - fi - - # Scan local devices for the image - i=0 - while [ "$i" -lt 60 ] - do - livefs_root=$(find_livefs ${i}) - - if [ -n "${livefs_root}" ] - then - break - fi - - sleep 1 - i="$(($i + 1))" - done - fi - fi - - if [ -z "${livefs_root}" ] - then - panic "Unable to find a medium containing a live file system" - fi - - case "${LIVE_VERIFY_CHECKSUMS}" in - true) - Verify_checksums "${livefs_root}" - ;; - esac - - if [ "${TORAM}" ] - then - live_dest="ram" - elif [ "${TODISK}" ] - then - live_dest="${TODISK}" - fi - - if [ "${live_dest}" ] - then - log_begin_msg "Copying live media to ${live_dest}" - copy_live_to "${livefs_root}" "${live_dest}" - log_end_msg - fi - - # if we do not unmount the ISO we can't run "fsck /dev/ice" later on - # because the mountpoint is left behind in /proc/mounts, so let's get - # rid of it when running from RAM - if [ -n "$FROMISO" ] && [ "${TORAM}" ] - then - losetup -d /dev/loop0 - - if is_mountpoint /live/fromiso - then - umount /live/fromiso - rmdir --ignore-fail-on-non-empty /live/fromiso \ - >/dev/null 2>&1 || true - fi - fi - - if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ] - then - setup_unionfs "${livefs_root}" "${rootmnt}" - else - mac="$(get_mac)" - mac="$(echo ${mac} | sed 's/-//g')" - mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}" - fi - - - if [ -n "${ROOT_PID}" ] - then - echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid - fi - - log_end_msg - - # unionfs-fuse needs /dev to be bind-mounted for the duration of - # live-bottom; udev's init script will take care of things after that - case "${UNIONTYPE}" in - unionfs-fuse) - mount -n -o bind /dev "${rootmnt}/dev" - ;; - esac - - # Move to the new root filesystem so that programs there can get at it. - if [ ! -d /root/live/image ] - then - mkdir -p /root/live/image - mount --move /live/image /root/live/image - fi - - # aufs2 in kernel versions around 2.6.33 has a regression: - # directories can't be accessed when read for the first the time, - # causing a failure for example when accessing /var/lib/fai - # when booting FAI, this simple workaround solves it - ls /root/* >/dev/null 2>&1 - - # Move findiso directory to the new root filesystem so that programs there can get at it. - if [ -d /live/findiso ] && [ ! -d /root/live/findiso ] - then - mkdir -p /root/live/findiso - mount -n --move /live/findiso /root/live/findiso - fi - - # if we do not unmount the ISO we can't run "fsck /dev/ice" later on - # because the mountpoint is left behind in /proc/mounts, so let's get - # rid of it when running from RAM - if [ -n "$FINDISO" ] && [ "${TORAM}" ] - then - losetup -d /dev/loop0 - - if is_mountpoint /root/live/findiso - then - umount /root/live/findiso - rmdir --ignore-fail-on-non-empty /root/live/findiso \ - >/dev/null 2>&1 || true - fi - fi - - if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ] - then - log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf" - cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf - log_end_msg - fi - - if ! [ -d "/lib/live/boot" ] - then - panic "A wrong rootfs was mounted." - fi - - Fstab - Netbase - - case "${LIVE_SWAPON}" in - true) - Swapon - ;; - esac - - case "${UNIONFS}" in - unionfs-fuse) - umount "${rootmnt}/dev" - ;; - esac - - exec 1>&6 6>&- - exec 2>&7 7>&- - kill ${tailpid} - [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null -} diff --git a/scripts/boot/netbase.sh b/scripts/boot/netbase.sh deleted file mode 100755 index 3f5f7af..0000000 --- a/scripts/boot/netbase.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/bin/sh - -#set -e - -Netbase () -{ - if [ -n "${NONETWORKING}" ] - then - return - fi - - # FIXME: stop hardcoding overloading of initramfs-tools functions - . /scripts/functions - . /lib/live/boot/initramfs-tools.sh - - log_begin_msg "Preconfiguring networking" - - IFFILE="/root/etc/network/interfaces" - - if [ "${STATICIP}" = "frommedia" ] && [ -e "${IFFILE}" ] - then - # will use existent /etc/network/interfaces - log_end_msg - return - fi - -cat > "${IFFILE}" << EOF -auto lo -iface lo inet loopback - -EOF - - udevadm trigger - udevadm settle - - if [ -z "${NETBOOT}" ] && [ -n "${STATICIP}" ] && [ "${STATICIP}" != "frommedia" ] - then - parsed=$(echo "${STATICIP}" | sed -e 's|,| |g') - - for ifline in ${parsed} - do - ifname="$(echo ${ifline} | cut -f1 -d ':')" - ifaddress="$(echo ${ifline} | cut -f2 -d ':')" - ifnetmask="$(echo ${ifline} | cut -f3 -d ':')" - ifgateway="$(echo ${ifline} | cut -f4 -d ':')" - -cat >> "${IFFILE}" << EOF -allow-hotplug ${ifname} -iface ${ifname} inet static - address ${ifaddress} - netmask ${ifnetmask} -EOF - - if [ -n "${ifgateway}" ] - then - -cat >> "${IFFILE}" << EOF - gateway ${ifgateway} - -EOF - - fi - done - else - if [ -z "${NETBOOT}" ] || [ -n "${DHCP}" ] - then - # default, dhcp assigned - method="dhcp" - else - # make sure that the preconfigured interface would not get reassigned by dhcp - # on startup by ifup script - otherwise our root fs might be disconnected! - method="manual" - fi - - # iterate the physical interfaces and add them to the interfaces list and also add when ethdevice= called on cmdline - if [ "${method}" != dhcp ] || ([ ! -x /root/usr/sbin/NetworkManager ] && [ ! -x /root/usr/sbin/wicd ]) || [ ! -z "${ETHDEVICE}" ] - then - for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan* - do - [ -e ${interface} ] || continue - i="$(basename ${interface})" - -cat >> "${IFFILE}" << EOF -allow-hotplug ${i} -iface ${i} inet ${method} - -EOF - - done - fi - - if [ ! -f /root/etc/resolv.conf ] || [ -z "$(cat /root/etc/resolv.conf)" ] - then - if [ -f /netboot.config ] - then - # create a resolv.conf if it is not present or empty - cp /netboot.config /root/var/log/netboot.config - - rc_search=$(cat netboot.config | awk '/domain/{print $3}') - rc_server0=$(cat netboot.config | awk '/dns0/{print $5}') - rc_server1=$(cat netboot.config | awk '/dns0/{print $8}') - rc_server0="nameserver ${rc_server0}" - - if [ "${rc_server1}" = "0.0.0.0" ] - then - rc_server1="" - else - rc_server1="nameserver ${rc_server1}" - fi - -cat > /root/etc/resolv.conf << EOF -# /etc/resolv.conf -# Autogenerated by live-boot -search ${rc_search} -domain ${rc_search} -${rc_server0} -${rc_server1} -EOF - - cat /root/etc/resolv.conf >> /root/var/log/netboot.config - fi - fi - fi - - #if [ ! -x /root/usr/sbin/NetworkManager ] - #then - # for i in eth0 eth1 eth2 ath0 wlan0 - # do - # grep -q "iface ${i}" ${IFFILE} && continue - # - #cat >> "${IFFILE}" << EOF - #allow-hotplug ${i} - #iface ${i} inet dhcp - # - #EOF - # - # done - #fi - - log_end_msg -} diff --git a/scripts/boot/netboot.sh b/scripts/boot/netboot.sh deleted file mode 100755 index 5054fb8..0000000 --- a/scripts/boot/netboot.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh - -#set -e - -do_netmount() -{ - do_netsetup - - if [ "${NFSROOT}" = "auto" ] - then - NFSROOT=${ROOTSERVER}:${ROOTPATH} - fi - - rc=1 - - if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) - then - do_httpmount - return $? - fi - - if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ] - then - NFSROOT=${ROOTSERVER}:${NFSROOT} - fi - - log_begin_msg "Trying netboot from ${NFSROOT}" - - if [ "${NETBOOT}" != "nfs" ] && do_cifsmount - then - rc=0 - elif do_nfsmount - then - NETBOOT="nfs" - export NETBOOT - rc=0 - fi - - log_end_msg - return ${rc} -} diff --git a/scripts/boot/networking.sh b/scripts/boot/networking.sh deleted file mode 100755 index 8c8d840..0000000 --- a/scripts/boot/networking.sh +++ /dev/null @@ -1,163 +0,0 @@ -#!/bin/sh - -#set -e - -do_netsetup () -{ - modprobe -q af_packet # For DHCP - - udevadm trigger - udevadm settle - - [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15 - echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration." - - if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ] - then - # support for Syslinux IPAPPEND parameter - # it sets the BOOTIF variable on the kernel parameter - - if [ -n "${BOOTIF}" ] - then - # pxelinux sets BOOTIF to a value based on the mac address of the - # network card used to PXE boot, so use this value for DEVICE rather - # than a hard-coded device name from initramfs.conf. this facilitates - # network booting when machines may have multiple network cards. - # pxelinux sets BOOTIF to 01-$mac_address - - # strip off the leading "01-", which isn't part of the mac - # address - temp_mac=${BOOTIF#*-} - - # convert to typical mac address format by replacing "-" with ":" - bootif_mac="" - IFS='-' - for x in $temp_mac - do - if [ -z "$bootif_mac" ] - then - bootif_mac="$x" - else - bootif_mac="$bootif_mac:$x" - fi - done - unset IFS - - # look for devices with matching mac address, and set DEVICE to - # appropriate value if match is found. - - for device in /sys/class/net/* - do - if [ -f "$device/address" ] - then - current_mac=$(cat "$device/address") - - if [ "$bootif_mac" = "$current_mac" ] - then - DEVICE=${device##*/} - break - fi - fi - done - fi - - # if ethdevice was not specified on the kernel command line - # make sure we try to get a working network configuration - # for *every* present network device (except for loopback of course) - if [ -z "$ETHDEVICE" ] - then - echo "If you want to boot from a specific device use bootoption ethdevice=..." - for device in /sys/class/net/* - do - dev=${device##*/} - if [ "$dev" != "lo" ] - then - ETHDEVICE="$ETHDEVICE $dev" - fi - done - fi - - # split args of ethdevice=eth0,eth1 into "eth0 eth1" - for device in $(echo $ETHDEVICE | sed 's/,/ /g') - do - devlist="$devlist $device" - done - - # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into - # an endless loop; if execution fails give it two further tries, that's - # why we use '$devlist $devlist $devlist' for the other for loop - for dev in $devlist $devlist $devlist - do - echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev" - ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config & - jobid=$! - sleep "$ETHDEV_TIMEOUT" ; sleep 1 - if [ -r /proc/"$jobid"/status ] - then - echo "Killing job $jobid for device $dev as ipconfig ran into recursion..." - kill -9 $jobid - fi - - # if configuration of device worked we should have an assigned - # IP address, if so let's use the device as $DEVICE for later usage. - # simple and primitive approach which seems to work fine - if ifconfig $dev | grep -q 'inet.*addr:' - then - export DEVICE="$dev" - break - fi - done - else - for interface in ${DEVICE}; do - ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config - [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf - if [ "$IPV4ADDR" != "0.0.0.0" ] - then - break - fi - done - fi - - for interface in ${DEVICE} - do - # source relevant ipconfig output - OLDHOSTNAME=${HOSTNAME} - [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf - [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME} - export HOSTNAME - - if [ -n "${interface}" ] - then - HWADDR="$(cat /sys/class/net/${interface}/address)" - fi - - if [ ! -e "/etc/resolv.conf" ] - then - echo "Creating /etc/resolv.conf" - - if [ -n "${DNSDOMAIN}" ] - then - echo "domain ${DNSDOMAIN}" > /etc/resolv.conf - echo "search ${DNSDOMAIN}" >> /etc/resolv.conf - fi - - for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1} - do - if [ -n "$i" ] && [ "$i" != 0.0.0.0 ] - then - echo "nameserver $i" >> /etc/resolv.conf - fi - done - fi - - # Check if we have a network device at all - if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \ - ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \ - ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \ - ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \ - ! ls /sys/class/net/ra0 > /dev/null 2>&1 - then - panic "No supported network device found, maybe a non-mainline driver is required." - fi - done -} diff --git a/scripts/boot/overlay.sh b/scripts/boot/overlay.sh deleted file mode 100755 index cb12c4b..0000000 --- a/scripts/boot/overlay.sh +++ /dev/null @@ -1,410 +0,0 @@ -#!/bin/sh - -#set -e - -setup_unionfs () -{ - image_directory="${1}" - rootmnt="${2}" - addimage_directory="${3}" - - case ${UNIONTYPE} in - aufs|unionfs|overlayfs) - modprobe -q -b ${UNIONTYPE} - - if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ] - then - echo "${UNIONTYPE} not available, falling back to unionfs-fuse." - echo "This might be really slow." - - UNIONTYPE="unionfs-fuse" - fi - ;; - esac - - case "${UNIONTYPE}" in - unionfs-fuse) - modprobe fuse - ;; - esac - - # run-init can't deal with images in a subdir, but we're going to - # move all of these away before it runs anyway. No, we're not, - # put them in / since move-mounting them into / breaks mono and - # some other apps. - - croot="/" - - # Let's just mount the read-only file systems first - rofslist="" - - if [ -z "${PLAIN_ROOT}" ] - then - # Read image names from ${MODULE}.module if it exists - if [ -e "${image_directory}/filesystem.${MODULE}.module" ] - then - for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module) - do - image_string="${image_string} ${image_directory}/${IMAGE}" - done - elif [ -e "${image_directory}/${MODULE}.module" ] - then - for IMAGE in $(cat ${image_directory}/${MODULE}.module) - do - image_string="${image_string} ${image_directory}/${IMAGE}" - done - else - # ${MODULE}.module does not exist, create a list of images - for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir - do - for IMAGE in "${image_directory}"/*."${FILESYSTEM}" - do - if [ -e "${IMAGE}" ] - then - image_string="${image_string} ${IMAGE}" - fi - done - done - - if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ] - then - for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir - do - for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}" - do - if [ -e "${IMAGE}" ] - then - image_string="${image_string} ${IMAGE}" - fi - done - done - fi - - # Now sort the list - image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )" - fi - - [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})" - - mkdir -p "${croot}" - - for image in ${image_string} - do - imagename=$(basename "${image}") - - export image devname - maybe_break live-realpremount - log_begin_msg "Running /scripts/live-realpremount" - run_scripts /scripts/live-realpremount - log_end_msg - - if [ -d "${image}" ] - then - # it is a plain directory: do nothing - rofslist="${image} ${rofslist}" - elif [ -f "${image}" ] - then - if losetup --help 2>&1 | grep -q -- "-r\b" - then - backdev=$(get_backing_device "${image}" "-r") - else - backdev=$(get_backing_device "${image}") - fi - fstype=$(get_fstype "${backdev}") - - case "${fstype}" in - unknown) - panic "Unknown file system type on ${backdev} (${image})" - ;; - - "") - fstype="${imagename##*.}" - log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}." - ;; - esac - - case "${UNIONTYPE}" in - unionmount) - mpoint="${rootmnt}" - rofslist="${rootmnt} ${rofslist}" - ;; - - *) - mpoint="${croot}/${imagename}" - rofslist="${mpoint} ${rofslist}" - ;; - esac - - mkdir -p "${mpoint}" - log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\"" - mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}" - log_end_msg - fi - done - else - # we have a plain root system - mkdir -p "${croot}/filesystem" - log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\"" - mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \ - panic "Can not mount ${image_directory} on ${croot}/filesystem" && \ - rofslist="${croot}/filesystem ${rofslist}" - # probably broken: - mount -o bind ${croot}/filesystem $mountpoint - log_end_msg - fi - - # tmpfs file systems - touch /etc/fstab - mkdir -p /live - mount -t tmpfs tmpfs /live - mkdir -p /live/overlay - - # Looking for persistence devices or files - if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] - then - - if [ -z "${QUICKUSBMODULES}" ] - then - # Load USB modules - num_block=$(ls -l /sys/block | wc -l) - for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage - do - modprobe -q -b ${module} - done - - udevadm trigger - udevadm settle - - # For some reason, udevsettle does not block in this scenario, - # so we sleep for a little while. - # - # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591 - for timeout in 5 4 3 2 1 - do - sleep 1 - - if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ] - then - break - fi - done - fi - - case "${PERSISTENCE_MEDIA}" in - removable) - whitelistdev="$(removable_dev)" - ;; - - removable-usb) - whitelistdev="$(removable_usb_dev)" - ;; - - *) - whitelistdev="" - ;; - esac - - if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD} - then - overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}" - fi - - local overlay_devices="" - for media in $(find_persistence_media "${overlays}" "${whitelistdev}") - do - media="$(echo ${media} | tr ":" " ")" - - case ${media} in - ${old_root_overlay_label}=*) - device="${media#*=}" - fix_backwards_compatibility ${device} / union - overlay_devices="${overlay_devices} ${device}" - ;; - - ${old_home_overlay_label}=*) - device="${media#*=}" - fix_backwards_compatibility ${device} /home bind - overlay_devices="${overlay_devices} ${device}" - ;; - - ${custom_overlay_label}=*) - device="${media#*=}" - overlay_devices="${overlay_devices} ${device}" - ;; - esac - done - elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ] - then - # check if there are any nfs options - if echo ${NFS_COW} | grep -q ',' - then - nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)" - nfs_cow=$(echo ${NFS_COW}|cut -d, -f1) - else - nfs_cow_opts="-o nolock" - nfs_cow=${NFS_COW} - fi - - if [ -n "${PERSISTENCE_READONLY}" ] - then - nfs_cow_opts="${nfs_cow_opts},nocto,ro" - fi - - mac="$(get_mac)" - if [ -n "${mac}" ] - then - cowdevice=$(echo ${nfs_cow} | sed "s/client_mac_address/${mac}/") - cow_fstype="nfs" - else - panic "unable to determine mac address" - fi - fi - - if [ -z "${cowdevice}" ] - then - cowdevice="tmpfs" - cow_fstype="tmpfs" - cow_mountopt="rw,noatime,mode=755" - fi - - if [ "${UNIONTYPE}" != "unionmount" ] - then - if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ] - then - mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay" - root_backing="/live/persistence/$(basename ${cowdevice})-root" - mkdir -p ${root_backing} - else - root_backing="/live/overlay" - fi - - if [ "${cow_fstype}" = "nfs" ] - then - log_begin_msg \ - "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}" - nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \ - panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}" - else - mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \ - panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}" - fi - fi - - rofscount=$(echo ${rofslist} |wc -w) - - rofs=${rofslist%% } - - if [ -n "${EXPOSED_ROOT}" ] - then - if [ ${rofscount} -ne 1 ] - then - panic "only one RO file system supported with exposedroot: ${rofslist}" - fi - - mount --bind ${rofs} ${rootmnt} || \ - panic "bind mount of ${rofs} failed" - - if [ -z "${SKIP_UNION_MOUNTS}" ] - then - cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live' - else - cow_dirs='' - fi - else - cow_dirs="/" - fi - - if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ] - then - true # FIXME: Maybe it does, I don't really know. - #panic "unionmount does not support subunions (${cow_dirs})." - fi - - for dir in ${cow_dirs}; do - unionmountpoint="${rootmnt}${dir}" - mkdir -p ${unionmountpoint} - if [ "${UNIONTYPE}" = "unionmount" ] - then - # FIXME: handle PERSISTENCE_READONLY - unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}" - mount_full $unionmountopts "${unionmountpoint}" - else - cow_dir="/live/overlay${dir}" - rofs_dir="${rofs}${dir}" - mkdir -p ${cow_dir} - if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ] - then - do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir} - else - do_union ${unionmountpoint} ${cow_dir} ${rofs_dir} - fi - fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}" - done - - # Correct the permissions of /: - chmod 0755 "${rootmnt}" - - live_rofs_list="" - # SHOWMOUNTS is necessary for custom mounts with the union option - # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS - if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] 1) - then - # XXX: is the for loop really necessary? rofslist can only contain one item (see above XXX about EXPOSEDROOT) and this is also assumed elsewhere above (see use of $rofs above). - for d in ${rofslist} - do - live_rofs="/live/rofs/${d##*/}" - live_rofs_list="${live_rofs_list} ${live_rofs}" - mkdir -p "${live_rofs}" - case d in - *.dir) - # do nothing # mount -o bind "${d}" "${live_rofs}" - ;; - *) - case "${UNIONTYPE}" in - unionfs-fuse) - mount -o bind "${d}" "${live_rofs}" - ;; - - *) - mount -o move "${d}" "${live_rofs}" - ;; - esac - ;; - esac - done - fi - - # Adding custom persistence - if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] - then - local custom_mounts="/tmp/custom_mounts.list" - rm -rf ${custom_mounts} 2> /dev/null - - # Gather information about custom mounts from devies detected as overlays - get_custom_mounts ${custom_mounts} ${overlay_devices} - - [ -n "${DEBUG}" ] && cp ${custom_mounts} "/live/persistence" - - # Now we do the actual mounting (and symlinking) - local used_overlays="" - used_overlays=$(activate_custom_mounts ${custom_mounts}) - rm ${custom_mounts} - - # Close unused overlays (e.g. due to missing $persistence_list) - for overlay in ${overlay_devices} - do - if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$" - then - close_persistence_media ${overlay} - fi - done - fi - - mkdir -p "${rootmnt}/live" - mount -o move /live "${rootmnt}/live" >/dev/null 2>&1 || mount -o bind /live "${rootmnt}/live" || log_warning_msg "Unable to move or bind /live to ${rootmnt}/live" - - # shows cow fs on /overlay (FIXME: do we still need/want this? probably yes) - mkdir -p "${rootmnt}/live/overlay" - mount -o move /live/overlay "${rootmnt}/live/overlay" >/dev/null 2>&1 || mount -o bind /overlay "${rootmnt}/live/overlay" || log_warning_msg "Unable to move or bind /overlay to ${rootmnt}/live/overlay" - -} diff --git a/scripts/boot/read-only.sh b/scripts/boot/read-only.sh deleted file mode 100755 index 48aa06c..0000000 --- a/scripts/boot/read-only.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -#set -e - -Read_only () -{ - # Marking some block devices as read-only to ensure that nothing - # gets written as linux still writes to 'only' read-only mounted filesystems. - _DEVICES="/dev/sd* /dev/vd*" - - for _DEVICE in ${_DEVICES} - do - if [ ! -b "${_DEVICE}" ] - then - continue - fi - - echo -n "Setting ${_DEVICE} read-only..." > /dev/console - - blockdev --setro ${_DEVICE} - _RETURN="${?}" - - case "${_RETURN}" in - 0) - echo " done, use 'blockdev --setrw ${_DEVICE}' to set read-write." > /dev/console - ;; - - *) - echo " failed." > /dev/console - ;; - esac - done -} diff --git a/scripts/boot/select-eth-device.sh b/scripts/boot/select-eth-device.sh deleted file mode 100755 index ed1da6f..0000000 --- a/scripts/boot/select-eth-device.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/sh - -Select_eth_device () -{ - # Boot type in initramfs's config - bootconf=$(egrep '^BOOT=' /conf/initramfs.conf | tail -1) - - # can be superseded by command line (used by Debian-Live's netboot for example) - for ARGUMENT in $(cat /proc/cmdline) - do - case "${ARGUMENT}" in - netboot=*) - NETBOOT="${ARGUMENT#netboot=}" - ;; - esac - done - - if [ "$bootconf" != "BOOT=nfs" ] && [ -z "$NETBOOT" ] && [ -z "$FETCH" ] && [ -z "$FTPFS" ] && [ -z "$HTTPFS" ] - then - # Not a net boot : nothing to do - return - fi - - # we want to do some basic IP - modprobe -q af_packet - - # Available Ethernet interfaces ? - l_interfaces="" - echo "Waiting for ethernet card(s) up... If this fails, maybe the ethernet card is not supported by the kernel `uname -r`?" - while [ -z "$l_interfaces" ] - do - l_interfaces="$(cd /sys/class/net/ && ls -d eth* 2>/dev/null)" - done - - if [ $(echo $l_interfaces | wc -w) -lt 2 ] - then - # only one interface : no choice - echo "DEVICE=$l_interfaces" >> /conf/param.conf - return - fi - - # If user force to use specific device, write it - for ARGUMENT in $(cat /proc/cmdline) - do - case "${ARGUMENT}" in - live-netdev=*) - NETDEV="${ARGUMENT#live-netdev=}" - echo "DEVICE=$NETDEV" >> /conf/param.conf - echo "Found live-netdev parameter in /proc/cmdline. Force to use network device $NETDEV." - return - ;; - esac - done - - found_eth_dev="" - while true - do - echo -n "Looking for a connected Ethernet interface ..." - - for interface in $l_interfaces - do - # ATTR{carrier} is not set if this is not done - echo -n " $interface ?" - ipconfig -c none -d $interface -t 1 >/dev/null 2>&1 - done - - echo '' - - for step in 1 2 3 4 5 - do - for interface in $l_interfaces - do - carrier=$(cat /sys/class/net/$interface/carrier \ - 2>/dev/null) - # link detected - - case "${carrier}" in - 1) - echo "Connected $interface found" - # inform initrd's init script : - found_eth_dev="$found_eth_dev $interface" - ;; - esac - done - if [ -n "$found_eth_dev" ] - then - echo "DEVICE='$found_eth_dev'" >> /conf/param.conf - return - else - # wait a bit - sleep 1 - fi - done - done -} diff --git a/scripts/boot/swapon.sh b/scripts/boot/swapon.sh deleted file mode 100755 index 158d81b..0000000 --- a/scripts/boot/swapon.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -#set -e - -Swapon () -{ - _DEVICES="/dev/sd* /dev/vd*" - - if [ -e /run ] - then - # wheezy - _FSTAB="/root/etc/fstab.d/swap" - else - # squeeze - _FSTAB="/root/etc/fstab" - fi - - for _DEVICE in ${_DEVICES} - do - if [ ! -b "${_DEVICE}" ] - then - continue - fi - - blkid -o udev -p ${_DEVICE%%[0-9]*} | grep -q "^ID_FS_USAGE=raid" && continue - - _MAGIC="$(/bin/dd if=${_DEVICE} bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null)" || continue - - case "${_MAGIC}" in - SWAPSPACE2|SWAP-SPACE) - _SWAP_DEVICES="${_SWAP_DEVICES} ${_DEVICE}" - ;; - esac - done - - # Remove all auto swap entries - if grep -qs "swap swap" "${_FSTAB}" - then - grep -v "swap swap" "${_FSTAB}" > "${_FSTAB}".tmp - mv "${_FSTAB}".tmp "${_FSTAB}" - fi - - # Add new swap entries - for _DEVICE in _SWAP_DEVICES - do - echo "${_DEVICE} swap swap defaults 0 0" >> "${_FSTAB}" - done -} diff --git a/scripts/boot/toram-todisk.sh b/scripts/boot/toram-todisk.sh deleted file mode 100755 index 2643eb8..0000000 --- a/scripts/boot/toram-todisk.sh +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/sh - -#set -e - -copy_live_to () -{ - copyfrom="${1}" - copytodev="${2}" - copyto="${copyfrom}_swap" - - if [ -z "${MODULETORAM}" ] - then - size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used") - else - MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}" - - if [ -f "${MODULETORAMFILE}" ] - then - size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 ) - else - log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read." - return 1 - fi - fi - - if [ "${copytodev}" = "ram" ] - then - # copying to ram: - freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo) - mount_options="-o size=${size}k" - free_string="memory" - fstype="tmpfs" - dev="/dev/shm" - else - # it should be a writable block device - if [ -b "${copytodev}" ] - then - dev="${copytodev}" - free_string="space" - fstype=$(get_fstype "${dev}") - freespace=$(fs_size "${dev}") - else - log_warning_msg "${copytodev} is not a block device." - return 1 - fi - fi - - if [ "${freespace}" -lt "${size}" ] - then - log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}." - return 1 - fi - - # Custom ramdisk size - if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ] - then - # FIXME: should check for wrong values - mount_options="-o size=${ramdisk_size}" - fi - - # begin copying (or uncompressing) - mkdir "${copyto}" - log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}" - mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}" - - if [ "${extension}" = "tgz" ] - then - cd "${copyto}" - tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})" - rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})" - mount -r -o move "${copyto}" "${rootmnt}" - cd "${OLDPWD}" - else - if [ -n "${MODULETORAMFILE}" ] - then - if [ -x /bin/rsync ] - then - echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console - rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module - else - cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module - fi - else - if [ -x /bin/rsync ] - then - echo " * Copying whole medium to RAM" 1>/dev/console - rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files - else - mkdir -p ${copyto}/${LIVE_MEDIA_PATH} - cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} - if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ] - then - cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto} - fi - fi - fi - - umount ${copyfrom} - mount -r -o move ${copyto} ${copyfrom} - fi - - rmdir ${copyto} - return 0 -} diff --git a/scripts/boot/verify-checksums.sh b/scripts/boot/verify-checksums.sh deleted file mode 100755 index 7dd5da3..0000000 --- a/scripts/boot/verify-checksums.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/sh - -#set -e - -Verify_checksums () -{ - _MOUNTPOINT="${1}" - - _DIGESTS="sha512 sha384 sha256 sha224 sha1 md5" - _TTY="/dev/tty8" - - log_begin_msg "Verifying checksums" - - cd "${_MOUNTPOINT}" - - for _DIGEST in ${_DIGESTS} - do - _CHECKSUMS="$(echo ${_DIGEST} | tr [a-z] [A-Z])SUMS" - - if [ -e "${_CHECKSUMS}" ] - then - echo "Found ${_CHECKSUMS}..." > "${_TTY}" - - if [ -e "/bin/${_DIGEST}sum" ] - then - echo "Checking ${_CHECKSUMS}..." > "${_TTY}" - - # Verify checksums - /bin/${_DIGEST}sum -c "${_CHECKSUMS}" < "${_TTY}" > "${_TTY}" - _RETURN="${?}" - - # Stop after first verification - break - else - echo "Not found /bin/${_DIGEST}sum..." > "${_TTY}" - fi - fi - done - - log_end_msg - - case "${_RETURN}" in - 0) - log_success_msg "Verification successfull, rebooting in 10 seconds." - sleep 10 - - # Unmount live-media - cd / - umount -f ${_MOUNTPOINT} > /dev/null 2>&1 - sync - - # Attempt to remount all mounted filesystems read-only - echo u > /proc/sysrq-trigger - - # Immediately reboot the system without syncing or unmounting filesystems - echo b > /proc/sysrq-trigger - ;; - - *) - panic "Verification failed, $(basename ${_TTY}) for more information." - ;; - esac -} -- cgit v1.2.3