summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rwxr-xr-xcomponents/0010-debug27
-rwxr-xr-xcomponents/0020-read-only56
-rwxr-xr-xcomponents/0030-verify-checksums89
-rwxr-xr-xcomponents/3020-swapon62
-rwxr-xr-xcomponents/9990-aaa-fixme.sh50
-rwxr-xr-xcomponents/9990-cmdline-old305
-rwxr-xr-xcomponents/9990-fstab.sh29
-rwxr-xr-xcomponents/9990-initramfs-tools.sh66
-rwxr-xr-xcomponents/9990-main.sh210
-rwxr-xr-xcomponents/9990-misc-helpers.sh1561
-rwxr-xr-xcomponents/9990-mount-cifs.sh28
-rwxr-xr-xcomponents/9990-mount-http.sh96
-rwxr-xr-xcomponents/9990-mount-iscsi.sh54
-rwxr-xr-xcomponents/9990-mount-nfs.sh28
-rwxr-xr-xcomponents/9990-netbase.sh139
-rwxr-xr-xcomponents/9990-netboot.sh41
-rwxr-xr-xcomponents/9990-networking.sh174
-rwxr-xr-xcomponents/9990-overlay.sh406
-rwxr-xr-xcomponents/9990-select-eth-device.sh104
-rwxr-xr-xcomponents/9990-toram-todisk.sh104
20 files changed, 3629 insertions, 0 deletions
diff --git a/components/0010-debug b/components/0010-debug
new file mode 100755
index 0000000..cfb2fc8
--- /dev/null
+++ b/components/0010-debug
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+#set -e
+
+Debug ()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ live-boot.debug|debug)
+ LIVE_BOOT_DEBUG="true"
+ ;;
+ esac
+ done
+
+ case "${LIVE_BOOT_DEBUG}" in
+ true)
+ ;;
+
+ *)
+ return 0
+ ;;
+ esac
+
+ # Write the trace output
+ set -x
+}
diff --git a/components/0020-read-only b/components/0020-read-only
new file mode 100755
index 0000000..fc0dde0
--- /dev/null
+++ b/components/0020-read-only
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+#set -e
+
+Read_only ()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ live-boot.read-only=*|read-only=*)
+ LIVE_READ_ONLY="true"
+ LIVE_READ_ONLY_DEVICES="${_PARAMETER#*read-only=}"
+ ;;
+
+ live-boot.read-only|read-only)
+ LIVE_READ_ONLY="true"
+ ;;
+ esac
+ done
+
+ case "${LIVE_READ_ONLY}" in
+ true)
+ ;;
+
+ *)
+ return 0
+ ;;
+ esac
+
+ # Marking some block devices as read-only to ensure that nothing
+ # gets written as linux still writes to 'only' read-only mounted filesystems.
+ LIVE_READ_ONLY_DEVICES="${LIVE_READ_ONLY_DEVICES:-/dev/sd* /dev/vd*}"
+
+ for _DEVICE in $(echo ${LIVE_READ_ONLY_DEVICES} | sed -e 's|,| |g')
+ do
+ if [ ! -b "${_DEVICE}" ]
+ then
+ continue
+ fi
+
+ echo -n "live-boot: 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/components/0030-verify-checksums b/components/0030-verify-checksums
new file mode 100755
index 0000000..3249b34
--- /dev/null
+++ b/components/0030-verify-checksums
@@ -0,0 +1,89 @@
+#!/bin/sh
+
+#set -e
+
+Verify_checksums ()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ live-boot.verify-checksums=*|verify-checksums=*)
+ LIVE_VERIFY_CHECKSUMS="true"
+ LIVE_VERIFY_CHECKSUMS_DIGESTS="${_PARAMETER#*verify-checksums=}"
+ ;;
+
+ live-boot.verify-checksums|verify-checksums)
+ LIVE_VERIFY_CHECKSUMS="true"
+ ;;
+ esac
+ done
+
+ case "${LIVE_VERIFY_CHECKSUMS}" in
+ true)
+ ;;
+
+ *)
+ return 0
+ ;;
+ esac
+
+ _MOUNTPOINT="${1}"
+
+ LIVE_VERIFY_CHECKSUMS_DIGESTS="${LIVE_VERIFY_CHECKSUMS_DIGESTS:-sha512 sha384 sha256 sha224 sha1 md5}"
+ _TTY="/dev/tty8"
+
+ log_begin_msg "Verifying checksums"
+
+ cd "${_MOUNTPOINT}"
+
+ for _DIGEST in $(echo ${LIVE_VERIFY_CHECKSUMS_DIGESTS} | sed -e 's|,| |g')
+ do
+ _CHECKSUMS="$(echo ${_DIGEST} | tr [a-z] [A-Z])SUMS ${_DIGEST}sum.txt"
+
+ for _CHECKSUM in ${_CHECKSUMS}
+ do
+ if [ -e "${_CHECKSUM}" ]
+ then
+ echo "Found ${_CHECKSUM}..." > "${_TTY}"
+
+ if [ -e "/bin/${_DIGEST}sum" ]
+ then
+ echo "Checking ${_CHECKSUM}..." > "${_TTY}"
+
+ # Verify checksums
+ /bin/${_DIGEST}sum -c "${_CHECKSUM}" < "${_TTY}" > "${_TTY}"
+ _RETURN="${?}"
+
+ # Stop after first verification
+ break
+ else
+ echo "Not found /bin/${_DIGEST}sum..." > "${_TTY}"
+ fi
+ fi
+ done
+ 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/components/3020-swapon b/components/3020-swapon
new file mode 100755
index 0000000..a1bcdbe
--- /dev/null
+++ b/components/3020-swapon
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#set -e
+
+Swap ()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ live-boot.swap=*|swap=*)
+ LIVE_SWAP="true"
+ LIVE_SWAP_DEVICES="${_PARAMETER#*swap=}"
+ ;;
+
+ live-boot.swap|swap)
+ LIVE_SWAP="true"
+ ;;
+ esac
+ done
+
+ case "${LIVE_SWAP}" in
+ true)
+ ;;
+
+ *)
+ return 0
+ ;;
+ esac
+
+ LIVE_SWAP_DEVICES="${LIVE_SWAP_DEVICES:-/dev/sd* /dev/vd*}"
+
+ for _DEVICE in $(echo ${LIVE_SWAP_DEVICES} | sed -e 's|,| |g')
+ 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" /root/etc/fstab.d/swap
+ then
+ grep -v "swap swap" /root/etc/fstab.d/swap > /root/etc/fstab.d/swap.tmp
+ mv /root/etc/fstab.d/swap.tmp /root/etc/fstab.d/swap
+ fi
+
+ # Add new swap entries
+ for _DEVICE in ${_SWAP_DEVICES}
+ do
+ echo "${_DEVICE} swap swap defaults 0 0" >> /root/etc/fstab.d/swap
+ done
+}
diff --git a/components/9990-aaa-fixme.sh b/components/9990-aaa-fixme.sh
new file mode 100755
index 0000000..416d6b4
--- /dev/null
+++ b/components/9990-aaa-fixme.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+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/medium"
+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
+
+custom_overlay_label="persistence"
+persistence_list="persistence.conf"
+old_persistence_list="live-persistence.conf"
+
+if [ ! -f /live.vars ]
+then
+ touch /live.vars
+fi
diff --git a/components/9990-cmdline-old b/components/9990-cmdline-old
new file mode 100755
index 0000000..8bb8254
--- /dev/null
+++ b/components/9990-cmdline-old
@@ -0,0 +1,305 @@
+#!/bin/sh
+
+#set -e
+
+Cmdline_old ()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ skipconfig)
+ NOFSTAB="true"
+ NONETWORKING="true"
+
+ export NOFSTAB NONETWORKING
+ ;;
+
+ BOOTIF=*)
+ BOOTIF="${_PARAMETER#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=*)
+ custom_overlay_label="${_PARAMETER#persistence-label=*}"
+ ;;
+
+ nopersistence)
+ NOPERSISTENCE="true"
+ export NOPERSISTENCE
+ ;;
+
+ quickusbmodules)
+ QUICKUSBMODULES="true"
+ export QUICKUSBMODULES
+ ;;
+
+ 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/\<luks,\|,\?luks$//g')
+ export PERSISTENCE_ENCRYPTION
+ fi
+
+ if [ ! -x /lib/cryptsetup/askpass ] || [ ! -x /sbin/cryptsetup ]
+ then
+ log_warning_msg "cryptsetup in unavailable"
+ PERSISTENCE_ENCRYPTION=$(echo ${PERSISTENCE_ENCRYPTION} | sed -e 's/\<luks,\|,\?luks$//g')
+ export PERSISTENCE_ENCRYPTION
+ fi
+ fi
+
+ if [ -z "${PERSISTENCE_METHOD}" ]
+ then
+ PERSISTENCE_METHOD="overlay"
+ export PERSISTENCE_METHOD
+ fi
+
+ if [ -z "${PERSISTENCE_STORAGE}" ]
+ then
+ PERSISTENCE_STORAGE="filesystem,file"
+ export PERSISTENCE_STORAGE
+ fi
+}
diff --git a/components/9990-fstab.sh b/components/9990-fstab.sh
new file mode 100755
index 0000000..5ae9546
--- /dev/null
+++ b/components/9990-fstab.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+#set -e
+
+Fstab ()
+{
+ # FIXME: stop hardcoding overloading of initramfs-tools functions
+ . /scripts/functions
+ . /lib/live/boot/9990-initramfs-tools.sh
+
+ if [ -n "${NOFSTAB}" ]
+ then
+ return
+ fi
+
+ log_begin_msg "Configuring fstab"
+
+ if ! grep -qs "^${UNIONTYPE}" /root/etc/fstab.d/live
+ then
+ echo "${UNIONTYPE} / ${UNIONTYPE} rw 0 0" >> /root/etc/fstab.d/live
+ fi
+
+ if ! grep -qs "^tmpfs /tmp" /root/etc/fstab.d/live
+ then
+ echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> /root/etc/fstab.d/live
+ fi
+
+ log_end_msg
+}
diff --git a/components/9990-initramfs-tools.sh b/components/9990-initramfs-tools.sh
new file mode 100755
index 0000000..5354134
--- /dev/null
+++ b/components/9990-initramfs-tools.sh
@@ -0,0 +1,66 @@
+#!/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 " \033[1;37mBOOT FAILED!\033[0m\n"
+ printf "\n"
+ printf " This Live System image failed to boot.\n\n"
+
+ printf " Please file a bug against the 'live-boot' package or email the Live Systems\n"
+ printf " mailing list at <debian-live@lists.debian.org>, 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/components/9990-main.sh b/components/9990-main.sh
new file mode 100755
index 0000000..e67176e
--- /dev/null
+++ b/components/9990-main.sh
@@ -0,0 +1,210 @@
+#!/bin/sh
+
+# set -e
+
+Live ()
+{
+ 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
+
+ LIVE_BOOT_CMDLINE="${LIVE_BOOT_CMDLINE:-$(cat /proc/cmdline)}"
+ Cmdline_old
+
+ Debug
+
+ Read_only
+
+ Select_eth_device
+
+ if [ -e /conf/param.conf ]
+ then
+ . /conf/param.conf
+ fi
+
+ # 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
+
+ Verify_checksums "${livefs_root}"
+
+ 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
+
+ # At this point /root should contain the final root filesystem.
+ # Move all mountpoints below /live into /root/lib/live/mount.
+ # This has to be done after mounting the root filesystem to /
+ # otherwise these mount points won't be accessible from the running system.
+ for _MOUNT in $(cat /proc/mounts | cut -f 2 -d " " | grep -e "^/live/")
+ do
+ local newmount
+ newmount="${rootmnt}/lib/live/mount/${_MOUNT#/live/}"
+ mkdir -p "${newmount}"
+ mount -o move "${_MOUNT}" "${newmount}" > /dev/null 2>&1 || \
+ mount -o bind "${_MOUNT}" "${newmount}" > /dev/null || \
+ log_warning_msg "W: failed to move or bindmount ${_MOUNT} to ${newmount}"
+ done
+
+ if [ -n "${ROOT_PID}" ]
+ then
+ echo "${ROOT_PID}" > "${rootmnt}"/lib/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
+
+
+ # 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
+
+ # 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/lib/live/mount/findiso
+ then
+ umount /root/lib/live/mount/findiso
+ rmdir --ignore-fail-on-non-empty /root/lib/live/mount/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
+
+ Swap
+
+ 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/components/9990-misc-helpers.sh b/components/9990-misc-helpers.sh
new file mode 100755
index 0000000..82099a4
--- /dev/null
+++ b/components/9990-misc-helpers.sh
@@ -0,0 +1,1561 @@
+#!/bin/sh
+
+#set -e
+
+file_pattern_matches()
+{
+ [ -e "$1" ]
+}
+
+is_live_path()
+{
+ DIRECTORY="${1}/${LIVE_MEDIA_PATH}"
+ for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs
+ do
+ if file_pattern_matches "${DIRECTORY}/"*.${FILESYSTEM}
+ then
+ return 0
+ fi
+ done
+ 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
+}
+
+mount_images_in_directory ()
+{
+ directory="${1}"
+ rootmnt="${2}"
+ mac="${3}"
+
+ if is_live_path "${directory}"
+ 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 /sbin/udevadm test-builtin path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)"
+ 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 element list
+ sep=${1}
+ shift
+ element=${1}
+ shift
+ list=${*}
+ echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
+}
+
+is_in_space_sep_list ()
+{
+ local element
+ element=${1}
+ shift
+ is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
+}
+
+is_in_comma_sep_list ()
+{
+ local element
+ 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
+ dir="$(trim_path ${1})"
+ grep -m1 "^[^ ]\+ ${dir} " /proc/mounts | cut -d' ' -f1
+}
+
+chown_ref ()
+{
+ local reference targets owner
+ reference="${1}"
+ shift
+ targets=${@}
+ owner=$(stat -c %u:%g "${reference}")
+ chown -h ${owner} ${targets}
+}
+
+chmod_ref ()
+{
+ local reference targets rights
+ reference="${1}"
+ shift
+ targets=${@}
+ 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 -kP | 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 --quiet /etc/boottime.kmap.gz
+ fi
+}
+
+setup_loop ()
+{
+ local fspath module pattern offset encryption readonly
+ fspath=${1}
+ module=${2}
+ pattern=${3}
+ offset=${4}
+ encryption=${5}
+ 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</tmp/passphrase
+ /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
+ error=${?}
+ exec 9<&-
+ rm -f /tmp/passphrase
+
+ if [ 0 -eq ${error} ]
+ then
+ unset error
+ break
+ fi
+
+ echo
+ echo -n "There was an error decrypting the root filesystem ... Retry? [Y/n] " >&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
+}
+
+# Try to mount $device to the place expected by live-boot. If $device
+# is already mounted somewhere, move it to the expected place. If
+# we're only probing $device (to check if it has custom persistence)
+# $probe should be set, which suppresses warnings upon failure. On
+# success, print the mount point for $device.
+mount_persistence_media ()
+{
+ local device probe backing old_backing fstype mount_opts
+ device=${1}
+ probe=${2}
+
+ backing="/live/persistence/$(basename ${device})"
+
+ mkdir -p "${backing}"
+ old_backing="$(where_is_mounted ${device})"
+ if [ -z "${old_backing}" ]
+ then
+ fstype="$(get_fstype ${device})"
+ 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
+ else
+ # This means that $device has already been mounted on
+ # the place expected by live-boot, so we're done.
+ echo ${backing}
+ return 0
+ fi
+}
+
+close_persistence_media ()
+{
+ local device backing
+ device=${1}
+ 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
+ dev="${1}"
+ /sbin/blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
+}
+
+is_gpt_device ()
+{
+ local dev
+ dev="${1}"
+ [ "$(/sbin/blkid -s PART_ENTRY_SCHEME -p -o value ${dev} 2>/dev/null)" = "gpt" ]
+}
+
+probe_for_gpt_name ()
+{
+ local overlays dev gpt_dev gpt_name
+ overlays="${1}"
+ dev="${2}"
+
+ 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
+
+ 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 dev
+ overlays="${1}"
+ 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 dev ret backing
+ overlays="${1}"
+ dev="${2}"
+
+ ret=""
+ backing="$(mount_persistence_media ${dev} probe)"
+ if [ -z "${backing}" ]
+ then
+ return
+ fi
+
+ for label in ${overlays}
+ do
+ path=${backing}/${PERSISTENCE_PATH}${label}
+ if [ -f "${path}" ]
+ then
+ local loopdev
+ loopdev=$(setup_loop "${path}" "loop" "/sys/block/loop*")
+ ret="${ret} ${label}=${loopdev}"
+ fi
+ done
+
+ if [ -n "${ret}" ]
+ then
+ echo ${ret}
+ else
+ # unmount and remove mountpoint
+ umount ${backing} > /dev/null 2>&1 || true
+ rmdir ${backing} > /dev/null 2>&1 || true
+ fi
+}
+
+find_persistence_media ()
+{
+ # Scans devices for overlays, and returns a whitespace
+ # 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 white_listed_devices ret black_listed_devices
+ overlays="${1}"
+ white_listed_devices="${2}"
+ ret=""
+
+ black_listed_devices="$(what_is_mounted_on /live/medium) $(what_is_mounted_on /live/findiso) $(what_is_mounted_on /live/fromiso)"
+
+ for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
+ do
+ local result luks_device
+ result=""
+
+ 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
+ local loopdevice
+ loopdevice=${result##*=}
+ if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && is_luks_partition ${loopdevice}
+ then
+ local luksfile
+ luksfile=""
+ if luksfile=$(open_luks_device "${loopdevice}")
+ then
+ result=${result%%=*}
+ result="${result}=${luksfile}"
+ else
+ losetup -d $loopdevice
+ result=""
+ fi
+ fi
+ 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)).
+ local src_dir dest_dir src_transform
+
+ # remove multiple /:s and ensure ending on /
+ src_dir="$(trim_path ${1})/"
+ dest_dir="$(trim_path ${2})/"
+ src_transform="${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 final_src
+ 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_transform}"
+ else
+ final_src=${src}
+ if [ -n "${src_transform}" ]
+ then
+ final_src="$(echo ${final_src} | sed "${src_transform}")"
+ fi
+ rm -rf "${dest}" 2> /dev/null
+ ln -s "${final_src}" "${dest}"
+ chown_ref "${src}" "${dest}"
+ fi
+ done
+}
+
+do_union ()
+{
+ local unionmountpoint unionrw unionro
+ unionmountpoint="${1}" # directory where the union is mounted
+ shift
+ unionrw="${1}" # branch where the union changes are stored
+ shift
+ unionro="${*}" # space separated list of read-only branches (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 "${unionro}" ]
+ then
+ for rofs in ${unionro}
+ do
+ unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
+ done
+ fi
+ ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
+ unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
+ ( mkdir -p /run/sendsigs.omit.d
+ pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
+ ;;
+
+ overlayfs)
+ # XXX: can multiple unionro be used? (overlayfs only handles two dirs, but perhaps they can be chained?)
+ # XXX: and can unionro be optional? i.e. can overlayfs skip lowerdir?
+ if echo ${unionro} | grep -q " "
+ then
+ panic "Multiple lower filesystems are currently not supported with overlayfs (unionro = ${unionro})."
+ elif [ -z "${unionro}" ]
+ then
+ panic "Overlayfs needs at least one lower filesystem (read-only branch)."
+ fi
+ unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}"
+ mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
+ ;;
+
+ *)
+ unionmountopts="-o noatime,${noxino_opt},dirs=${unionrw}=${rw_opt}"
+ if [ -n "${unionro}" ]
+ then
+ for rofs in ${unionro}
+ do
+ unionmountopts="${unionmountopts}:${rofs}=${ro_opt}"
+ done
+ fi
+ mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
+ ;;
+ esac
+}
+
+get_custom_mounts ()
+{
+ # Side-effect: leaves $devices with persistence.conf mounted in /live/persistence
+ # Side-effect: prints info to file $custom_mounts
+
+ local custom_mounts devices bindings links
+ custom_mounts=${1}
+ shift
+ devices=${@}
+
+ bindings="/tmp/bindings.list"
+ 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 backing include_list
+ device_name="$(basename ${device})"
+ backing=$(mount_persistence_media ${device})
+ if [ -z "${backing}" ]
+ then
+ continue
+ fi
+
+ if [ -r "${backing}/${persistence_list}" ]
+ then
+ include_list="${backing}/${persistence_list}"
+ elif [ -r "${backing}/${old_persistence_list}" ]
+ then
+ include_list="${backing}/${old_persistence_list}"
+ else
+ continue
+ fi
+
+ if [ -n "${LIVE_BOOT_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 "^/lib" -e "^/lib/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
+ then
+ log_warning_msg "Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/lib\", or \"/lib/live\" or any of its sub-directories."
+ continue
+ fi
+
+ local opt_source opt_link source full_source full_dest
+ opt_source=""
+ 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
+
+ source="${dir}"
+ if [ -n "${opt_source}" ]
+ then
+ if echo ${opt_source} | grep -q -e "^/" -e "^\(.*/\)\?\.\.\?\(/.*\)\?$" && [ "${opt_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
+
+ full_source="$(trim_path ${backing}/${source})"
+ 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 prev_dest
+ prev_source="impossible source" # first iteration must not match
+ 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 used_devices
+ custom_mounts="${1}" # the ouput from get_custom_mounts()
+ used_devices=""
+
+ while read device source dest options # < ${custom_mounts}
+ do
+ local opt_bind opt_link opt_union
+ opt_bind="true"
+ opt_link=""
+ 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 rootfs_dest_backing=$dest
+ local rootfs_dest_backing
+ rootfs_dest_backing=""
+ if [ -n "${opt_link}" ] || [ -n "${opt_union}" ]
+ then
+ for d in /live/rootfs/*
+ do
+ if [ -n "${rootmnt}" ]
+ then
+ fs="${d}/$(echo ${dest} | sed -e "s|${rootmnt}||")"
+ else
+ fs="${d}/${dest}"
+ fi
+ if [ -d "${fs}" ]
+ then
+ rootfs_dest_backing="${rootfs_dest_backing} ${fs}"
+ fi
+ done
+ fi
+
+ local cow_dir links_source
+ if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
+ then
+ link_files ${source} ${dest} "s|^/live/|/lib/live/mount/|"
+ elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
+ then
+ mkdir -p ${rootmnt}/lib/live/mount/persistence
+ links_source=$(mktemp -d ${rootmnt}/lib/live/mount/persistence/links-source-XXXXXX)
+ 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.
+ cow_dir="/live/overlay/lib/live/mount/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} ${rootfs_dest_backing}
+ link_files ${links_source} ${dest} "s|^${rootmnt}||"
+ elif [ -n "${opt_union}" ] && [ -z "${PERSISTENCE_READONLY}" ]
+ then
+ do_union ${dest} ${source} ${rootfs_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 rootfs_dest_backing
+ # is non-empty (and necessary) only for unions
+ cow_dir="/live/overlay/${dest}"
+ 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} ${rootfs_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}
+}
+
+is_mountpoint ()
+{
+ directory="$1"
+
+ [ $(stat -fc%d:%D "${directory}") != $(stat -fc%d:%D "${directory}/..") ]
+}
diff --git a/components/9990-mount-cifs.sh b/components/9990-mount-cifs.sh
new file mode 100755
index 0000000..8dd1818
--- /dev/null
+++ b/components/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="-o user=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/components/9990-mount-http.sh b/components/9990-mount-http.sh
new file mode 100755
index 0000000..16e69b6
--- /dev/null
+++ b/components/9990-mount-http.sh
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+#set -e
+
+do_httpmount ()
+{
+ rc=1
+
+ for webfile in HTTPFS FTPFS FETCH
+ do
+ local url extension dest
+ url="$(eval echo \"\$\{${webfile}\}\")"
+ 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
+ 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 65464 -r $rfile -l ${dest}/$lfile $ip"
+ tftp -g -b 65464 -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
+
+ if [ -n "${FUSE_MOUNT}" ] && [ -x /bin/mount.util-linux ]
+ then
+ # fuse does not work with klibc mount
+ ln -f /bin/mount.util-linux /bin/mount
+ 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/components/9990-mount-iscsi.sh b/components/9990-mount-iscsi.sh
new file mode 100755
index 0000000..c9bab90
--- /dev/null
+++ b/components/9990-mount-iscsi.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+#set -e
+
+do_iscsi()
+{
+ do_netsetup
+ #modprobe ib_iser
+ modprobe iscsi_tcp
+ local debugopt
+ debugopt=""
+ [ "${LIVE_BOOT_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
+ 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 i
+ devices=""
+ 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/components/9990-mount-nfs.sh b/components/9990-mount-nfs.sh
new file mode 100755
index 0000000..6a3ae55
--- /dev/null
+++ b/components/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/components/9990-netbase.sh b/components/9990-netbase.sh
new file mode 100755
index 0000000..b3f886c
--- /dev/null
+++ b/components/9990-netbase.sh
@@ -0,0 +1,139 @@
+#!/bin/sh
+
+#set -e
+
+Netbase ()
+{
+ if [ -n "${NONETWORKING}" ]
+ then
+ return
+ fi
+
+ # FIXME: stop hardcoding overloading of initramfs-tools functions
+ . /scripts/functions
+ . /lib/live/boot/9990-initramfs-tools.sh
+
+ log_begin_msg "Preconfiguring networking"
+
+ IFFILE="/root/etc/network/interfaces"
+ DNSFILE="/root/etc/resolv.conf"
+
+ 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 ':')"
+ nameserver="$(echo ${ifline} | cut -f5 -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
+
+ if [ -n "${nameserver}" ]
+ then
+ if [ -e "${DNSFILE}" ]
+ then
+ grep -v ^nameserver "${DNSFILE}" > "${DNSFILE}.tmp"
+ mv "${DNSFILE}.tmp" "${DNSFILE}"
+ fi
+
+ echo "nameserver ${nameserver}" >> "${DNSFILE}"
+ 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
+
+ log_end_msg
+}
diff --git a/components/9990-netboot.sh b/components/9990-netboot.sh
new file mode 100755
index 0000000..5054fb8
--- /dev/null
+++ b/components/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/components/9990-networking.sh b/components/9990-networking.sh
new file mode 100755
index 0000000..cdec92a
--- /dev/null
+++ b/components/9990-networking.sh
@@ -0,0 +1,174 @@
+#!/bin/sh
+
+#set -e
+
+Device_from_bootif ()
+{
+ # 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
+
+}
+
+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
+ # See if we can select the device from BOOTIF
+ Device_from_bootif
+
+ # 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 /run/net-${interface}.conf ] && . /run/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 /run/net-${interface}.conf ] && . /run/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/components/9990-overlay.sh b/components/9990-overlay.sh
new file mode 100755
index 0000000..6b62093
--- /dev/null
+++ b/components/9990-overlay.sh
@@ -0,0 +1,406 @@
+#!/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
+ rootfslist=""
+
+ 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
+ rootfslist="${image} ${rootfslist}"
+ 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}"
+ rootfslist="${rootmnt} ${rootfslist}"
+ ;;
+
+ *)
+ mpoint="${croot}/${imagename}"
+ rootfslist="${mpoint} ${rootfslist}"
+ ;;
+ 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" && \
+ rootfslist="${croot}/filesystem ${rootfslist}"
+ # probably broken:
+ mount -o bind ${croot}/filesystem $mountpoint
+ log_end_msg
+ fi
+
+ # tmpfs file systems
+ touch /etc/fstab
+ mkdir -p /live/overlay
+ mount -t tmpfs tmpfs /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
+
+ local whitelistdev
+ whitelistdev=""
+ if [ -n "${PERSISTENCE_MEDIA}" ]
+ then
+ case "${PERSISTENCE_MEDIA}" in
+ removable)
+ whitelistdev="$(removable_dev)"
+ ;;
+
+ removable-usb)
+ whitelistdev="$(removable_usb_dev)"
+ ;;
+ esac
+ if [ -z "${whitelistdev}" ]
+ then
+ whitelistdev="ignore_all_devices"
+ fi
+ fi
+
+ if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
+ then
+ overlays="${custom_overlay_label}"
+ fi
+
+ local overlay_devices
+ overlay_devices=""
+ if [ "${whitelistdev}" != "ignore_all_devices" ]
+ then
+ for media in $(find_persistence_media "${overlays}" "${whitelistdev}")
+ do
+ media="$(echo ${media} | tr ":" " ")"
+
+ case ${media} in
+ ${custom_overlay_label}=*)
+ device="${media#*=}"
+ overlay_devices="${overlay_devices} ${device}"
+ ;;
+ esac
+ done
+ fi
+ 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
+
+ rootfscount=$(echo ${rootfslist} |wc -w)
+
+ rootfs=${rootfslist%% }
+
+ if [ -n "${EXPOSED_ROOT}" ]
+ then
+ if [ ${rootfscount} -ne 1 ]
+ then
+ panic "only one RO file system supported with exposedroot: ${rootfslist}"
+ fi
+
+ mount --bind ${rootfs} ${rootmnt} || \
+ panic "bind mount of ${rootfs} 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}"
+ # unionmount only works with util-linux mount
+ mount.util-linux $unionmountopts "${unionmountpoint}"
+ else
+ cow_dir="/live/overlay${dir}"
+ rootfs_dir="${rootfs}${dir}"
+ mkdir -p ${cow_dir}
+ if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
+ then
+ do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rootfs_dir}
+ else
+ do_union ${unionmountpoint} ${cow_dir} ${rootfs_dir}
+ fi
+ fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
+ done
+
+ # Correct the permissions of /:
+ chmod 0755 "${rootmnt}"
+
+ # Correct the permission of /tmp:
+ if [ -d "${rootmnt}/tmp" ]
+ then
+ chmod 1777 "${rootmnt}"/tmp
+ fi
+
+ live_rootfs_list=""
+ for d in ${rootfslist}
+ do
+ live_rootfs="/live/rootfs/${d##*/}"
+ live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
+ mkdir -p "${live_rootfs}"
+ case d in
+ *.dir)
+ # do nothing # mount -o bind "${d}" "${live_rootfs}"
+ ;;
+ *)
+ case "${UNIONTYPE}" in
+ unionfs-fuse)
+ mount -o bind "${d}" "${live_rootfs}"
+ ;;
+
+ *)
+ mount -o move "${d}" "${live_rootfs}"
+ ;;
+ esac
+ ;;
+ esac
+ done
+
+ # Adding custom persistence
+ if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
+ then
+ local custom_mounts
+ 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 "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
+
+ # Now we do the actual mounting (and symlinking)
+ local used_overlays
+ 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 "^\(.* \)\?${overlay}\( .*\)\?$"
+ then
+ close_persistence_media ${overlay}
+ fi
+ done
+ fi
+
+ # ensure that a potentially stray tmpfs gets removed
+ # otherways, initramfs-tools is unable to remove /live
+ # and fails to boot
+ umount /live/overlay > /dev/null 2>&1 || true
+}
diff --git a/components/9990-select-eth-device.sh b/components/9990-select-eth-device.sh
new file mode 100755
index 0000000..7d1aa16
--- /dev/null
+++ b/components/9990-select-eth-device.sh
@@ -0,0 +1,104 @@
+#!/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 ${LIVE_BOOT_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=""
+
+ # See if we can derive the boot device
+ Device_from_bootif
+
+ if [ -z "$DEVICE" ]
+ then
+ 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 ${LIVE_BOOT_CMDLINE}
+ do
+ case "${ARGUMENT}" in
+ live-netdev=*)
+ NETDEV="${ARGUMENT#live-netdev=}"
+ echo "DEVICE=$NETDEV" >> /conf/param.conf
+ echo "Found live-netdev parameter, forcing to to use network device $NETDEV."
+ return
+ ;;
+ esac
+ done
+ else
+ l_interfaces="$DEVICE"
+ fi
+
+ 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/components/9990-toram-todisk.sh b/components/9990-toram-todisk.sh
new file mode 100755
index 0000000..e7938e0
--- /dev/null
+++ b/components/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}/ "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
+}