summaryrefslogtreecommitdiffstats
path: root/system-boot/components
diff options
context:
space:
mode:
Diffstat (limited to 'system-boot/components')
-rwxr-xr-xsystem-boot/components/0001-init-vars.sh11
-rwxr-xr-xsystem-boot/components/0010-debug27
-rwxr-xr-xsystem-boot/components/0020-read-only72
-rwxr-xr-xsystem-boot/components/0030-verify-checksums89
-rwxr-xr-xsystem-boot/components/2010-remove-persistence31
-rwxr-xr-xsystem-boot/components/3020-swap62
-rwxr-xr-xsystem-boot/components/9990-cmdline-old327
-rwxr-xr-xsystem-boot/components/9990-fstab.sh25
-rwxr-xr-xsystem-boot/components/9990-initramfs-tools.sh75
-rwxr-xr-xsystem-boot/components/9990-main.sh195
-rwxr-xr-xsystem-boot/components/9990-misc-helpers.sh1713
-rwxr-xr-xsystem-boot/components/9990-mount-cifs.sh28
-rwxr-xr-xsystem-boot/components/9990-mount-http.sh93
-rwxr-xr-xsystem-boot/components/9990-mount-iscsi.sh54
-rwxr-xr-xsystem-boot/components/9990-mount-nfs.sh28
-rwxr-xr-xsystem-boot/components/9990-netbase.sh139
-rwxr-xr-xsystem-boot/components/9990-netboot.sh41
-rwxr-xr-xsystem-boot/components/9990-networking.sh179
-rwxr-xr-xsystem-boot/components/9990-overlay.sh337
-rwxr-xr-xsystem-boot/components/9990-select-eth-device.sh108
-rwxr-xr-xsystem-boot/components/9990-toram-todisk.sh103
21 files changed, 3737 insertions, 0 deletions
diff --git a/system-boot/components/0001-init-vars.sh b/system-boot/components/0001-init-vars.sh
new file mode 100755
index 0000000..603cf43
--- /dev/null
+++ b/system-boot/components/0001-init-vars.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+mountpoint="/run/live/medium"
+alt_mountpoint="/media"
+LIVE_MEDIA_PATH="live"
+HOSTNAME="host"
+custom_overlay_label="persistence"
+persistence_list="persistence.conf"
+
+mkdir -p "${mountpoint}"
+mkdir -p /var/lib/live/boot
diff --git a/system-boot/components/0010-debug b/system-boot/components/0010-debug
new file mode 100755
index 0000000..cfb2fc8
--- /dev/null
+++ b/system-boot/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/system-boot/components/0020-read-only b/system-boot/components/0020-read-only
new file mode 100755
index 0000000..f56b8cf
--- /dev/null
+++ b/system-boot/components/0020-read-only
@@ -0,0 +1,72 @@
+#!/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
+
+ if grep -qw persistence /proc/cmdline
+ then
+ printf " * Persistence mode enabled, searching for persistency related devices to unlock\n" >/dev/console
+
+ for label in custom-ov home-rw home-sn live-rw live-sn persistence
+ do
+ if blkid -t LABEL="$label" | grep -q '.'
+ then
+ device=$(blkid -t LABEL="$label" | awk -F: '{print $1}')
+ printf " - Setting device %-9s with label '%s' to write mode for persistence mode: " "$device" "$label" >/dev/console
+ blockdev --setrw $device && printf "done\n" >/dev/console || printf "failed\n" >/dev/console
+ fi
+ done
+ fi
+
+}
diff --git a/system-boot/components/0030-verify-checksums b/system-boot/components/0030-verify-checksums
new file mode 100755
index 0000000..4453558
--- /dev/null
+++ b/system-boot/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
+ grep -v '^#' "${_CHECKSUM}" | /bin/${_DIGEST}sum -c > "${_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/system-boot/components/2010-remove-persistence b/system-boot/components/2010-remove-persistence
new file mode 100755
index 0000000..717a408
--- /dev/null
+++ b/system-boot/components/2010-remove-persistence
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+#set -e
+
+Remove_persistence ()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ live-boot.persistence-remove=*|persistence-remove=*)
+ LIVE_PERSISTENCE_REMOVE="${_PARAMETER#*persistence-remove=}"
+ ;;
+
+ live-boot.persistence-remove|persistence-remove)
+ LIVE_PERSISTENCE_REMOVE="true"
+ ;;
+ esac
+ done
+
+ case "${LIVE_PERSISTENCE_REMOVE}" in
+ true)
+ ;;
+
+ *)
+ return 0
+ ;;
+ esac
+
+ # Remove persistence
+ cd /run/live/overlay && find . -not -name 'persistence.conf' | xargs rm -rf
+}
diff --git a/system-boot/components/3020-swap b/system-boot/components/3020-swap
new file mode 100755
index 0000000..345b9a0
--- /dev/null
+++ b/system-boot/components/3020-swap
@@ -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
+ then
+ grep -v "swap swap" /root/etc/fstab > /root/etc/fstab.tmp
+ mv /root/etc/fstab.tmp /root/etc/fstab
+ fi
+
+ # Add new swap entries
+ for _DEVICE in ${_SWAP_DEVICES}
+ do
+ echo "${_DEVICE} swap swap defaults 0 0" >> /root/etc/fstab
+ done
+}
diff --git a/system-boot/components/9990-cmdline-old b/system-boot/components/9990-cmdline-old
new file mode 100755
index 0000000..dad5ecb
--- /dev/null
+++ b/system-boot/components/9990-cmdline-old
@@ -0,0 +1,327 @@
+#!/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=}"
+ ;;
+ dns=*)
+ DNS=${_PARAMETER#dns=}
+ DNSSERVERS=$(echo ${DNS} | sed 's/,/ /g')
+ export DNSSERVERS
+ unset DNS
+ ;;
+ dhcp)
+ # Force dhcp even while netbooting
+ # Use for debugging in case somebody works on fixing dhclient
+ DHCP="true";
+ export DHCP
+ ;;
+
+ nodhcp)
+ DHCP=""
+ export DHCP
+ NODHCP="true"
+ export NODHCP
+ ;;
+
+ 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-uuid=*)
+ LIVE_MEDIA_UUID="${_PARAMETER#*=}"
+ export LIVE_MEDIA_UUID
+ ;;
+
+ live-media-mount-opts=*)
+ LIVE_MEDIA_MOUNT_OPTS="${_PARAMETER#*=}"
+ export LIVE_MEDIA_MOUNT_OPTS
+ ;;
+
+ 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=}"
+ ;;
+
+ overlay-size=*)
+ OVERLAY_SIZE="${_PARAMETER#overlay-size=}"
+ export OVERLAY_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="overlay"
+ 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 is 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/system-boot/components/9990-fstab.sh b/system-boot/components/9990-fstab.sh
new file mode 100755
index 0000000..ba579de
--- /dev/null
+++ b/system-boot/components/9990-fstab.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+#set -e
+
+Fstab ()
+{
+ if [ -n "${NOFSTAB}" ]
+ then
+ return
+ fi
+
+ log_begin_msg "Configuring fstab"
+
+ if ! grep -qs "^${UNIONTYPE}" /root/etc/fstab
+ then
+ echo "${UNIONTYPE} / ${UNIONTYPE} rw 0 0" >> /root/etc/fstab
+ fi
+
+ if ! grep -qs "^tmpfs /tmp" /root/etc/fstab
+ then
+ echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> /root/etc/fstab
+ fi
+
+ log_end_msg
+}
diff --git a/system-boot/components/9990-initramfs-tools.sh b/system-boot/components/9990-initramfs-tools.sh
new file mode 100755
index 0000000..eb11d23
--- /dev/null
+++ b/system-boot/components/9990-initramfs-tools.sh
@@ -0,0 +1,75 @@
+#!/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()
+{
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ panic=*)
+ panic="${_PARAMETER#*panic=}"
+ ;;
+ esac
+ done
+
+ 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/system-boot/components/9990-main.sh b/system-boot/components/9990-main.sh
new file mode 100755
index 0000000..ed48be3
--- /dev/null
+++ b/system-boot/components/9990-main.sh
@@ -0,0 +1,195 @@
+#!/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_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}
+ 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 /run/live/fromiso
+ then
+ umount /run/live/fromiso
+ rmdir --ignore-fail-on-non-empty /run/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}"/lib/live/root.pid
+ fi
+
+ log_end_msg
+
+ # 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 /run/live/findiso
+ then
+ umount /run/live/findiso
+ rmdir --ignore-fail-on-non-empty /run/live/findiso \
+ >/dev/null 2>&1 || true
+ fi
+ fi
+
+ if [ -L /root/etc/resolv.conf ] ; then
+ # assume we have resolvconf
+ DNSFILE="${rootmnt}/etc/resolvconf/resolv.conf.d/base"
+ else
+ DNSFILE="${rootmnt}/etc/resolv.conf"
+ fi
+ if [ -f /etc/resolv.conf ] && ! grep -E -q -v '^[[:space:]]*#|^[[:space:]]*$' ${DNSFILE}
+ then
+ log_begin_msg "Copying /etc/resolv.conf to ${DNSFILE}"
+ cp -v /etc/resolv.conf ${DNSFILE}
+ log_end_msg
+ fi
+
+ if ! [ -d "/lib/live/boot" ]
+ then
+ panic "A wrong rootfs was mounted."
+ fi
+
+ # avoid breaking existing user scripts that rely on the old path
+ # this includes code that checks what is mounted on /lib/live/mount/*
+ # (eg: grep /lib/live /proc/mount)
+ # XXX: to be removed before the bullseye release
+ mkdir -p ${rootmnt}/lib/live/mount
+ mount --rbind /run/live ${rootmnt}/lib/live/mount
+
+ Fstab
+ Netbase
+
+ Swap
+
+ 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; \
+ cp fsck.log "${rootmnt}/var/log/live" 2>/dev/null )
+}
diff --git a/system-boot/components/9990-misc-helpers.sh b/system-boot/components/9990-misc-helpers.sh
new file mode 100755
index 0000000..2811aaa
--- /dev/null
+++ b/system-boot/components/9990-misc-helpers.sh
@@ -0,0 +1,1713 @@
+#!/bin/sh
+
+#set -e
+
+is_live_path()
+{
+ DIRECTORY="${1}/${LIVE_MEDIA_PATH}"
+ for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs
+ do
+ if ls "${DIRECTORY}/"*.${FILESYSTEM} > /dev/null 2>&1
+ then
+ return 0
+ fi
+ done
+ return 1
+}
+
+matches_uuid ()
+{
+ if [ "${IGNORE_UUID}" ] || ([ ! -e /conf/uuid.conf ] && [ ! "${LIVE_MEDIA_UUID}" ])
+ then
+ return 0
+ fi
+
+ path="${1}"
+ uuid="$(cat /conf/uuid.conf)"
+ uuid="${LIVE_MEDIA_UUID:-${uuid}}"
+
+ 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 udevadm info --query=all --path="${sysfs_path}" | egrep -q "DEVTYPE=disk"
+ 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 ()
+{
+ local force fix
+ sysdev="${1}"
+ devname="${2}"
+ skip_uuid_check="${3}"
+ mount_opts="${LIVE_MEDIA_MOUNT_OPTS:-ro,noatime}"
+
+ # 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
+ # not a block device, check if it's an iso file, for
+ # example an ISO when booting on an ONIE system
+ if echo "${FROMISO}" | grep -q "\.iso$"
+ then
+ fs_type=$(get_fstype "${FROMISO}")
+ if is_supported_fs ${fs_type}
+ then
+ mkdir /run/live/fromiso
+ mount -t $fs_type "${FROMISO}" /run/live/fromiso
+ if [ "$?" != 0 ]
+ then
+ echo "Warning: unable to mount ${FROMISO}." >>/boot.log
+ fi
+ devname="/run/live/fromiso"
+ fi
+ else
+ echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
+ fi
+ else
+ fs_type=$(get_fstype "${ISO_DEVICE}")
+ if is_supported_fs ${fs_type}
+ then
+ mkdir /run/live/fromiso
+ mount -t $fs_type "$ISO_DEVICE" /run/live/fromiso
+ ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
+ loopdevname=$(setup_loop "/run/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 >>/boot.log
+ fi
+ ;;
+
+ /dev/md*)
+ # Adding raid support
+ if [ -x /scripts/local-top/mdadm ]
+ then
+ [ -r /conf/conf.d/md ] && cp /conf/conf.d/md /conf/conf.d/md.orig
+ echo "MD_DEVS=$device " >> /conf/conf.d/md
+ /scripts/local-top/mdadm >>/boot.log
+ [ -r /conf/conf.d/md.orig ] && mv /conf/conf.d/md.orig /conf/conf.d/md
+ 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\>" /var/lib/live/boot/devices-already-tried-to-mount && continue
+
+ for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+ do
+ case "${_PARAMETER}" in
+ forcefsck)
+ FORCEFSCK="true"
+ ;;
+ esac
+ done
+
+ if [ "${PERSISTENCE_FSCK}" = "true" ] || [ "${PERSISTENCE_FSCK}" = "yes" ] || [ "${FORCEFSCK}" = "true" ]
+ then
+ force=""
+ if [ "$FORCEFSCK" = "true" ]
+ then
+ force="-f"
+ fi
+
+ fix="-a"
+ if [ "$FSCKFIX" = "true" ] || [ "$FSCKFIX" = "yes" ]
+ then
+ fix="-y"
+ fi
+
+ fsck $fix $force ${devname} >> fsck.log 2>&1
+ fi
+
+ mount -t ${fstype} -o "${mount_opts}" "${devname}" ${mountpoint} || continue
+ [ -n "$devuid" ] && echo "$devuid" >> /var/lib/live/boot/devices-already-tried-to-mount
+
+ if [ -n "${FINDISO}" ]
+ then
+ if [ -f ${mountpoint}/${FINDISO} ]
+ then
+ umount ${mountpoint}
+ mkdir -p /run/live/findiso
+ mount -t ${fstype} -o "${mount_opts}" "${devname}" /run/live/findiso
+ loopdevname=$(setup_loop "/run/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
+ devname="${loopdevname}"
+ mount -t iso9660 -o "${mount_opts}" "${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}"
+
+ # first look at the one specified in the command line This is OK
+ # before the timeout has expired, if more than one device matches the
+ # criteria the outcome is undefined anyway, so we can pick the first
+ # one that appears.
+ case "${LIVE_MEDIA}" in
+ removable-usb|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
+ ;;
+ cdrom)
+ for sysblock in $(removable_cdrom_dev "sys")
+ do
+ for dev in $(subdevices "${sysblock}")
+ do
+ if check_dev "${dev}"
+ then
+ return 0
+ fi
+ done
+ done
+ ;;
+ removable)
+ for sysblock in $(removable_dev "sys")
+ do
+ for dev in $(subdevices "${sysblock}")
+ do
+ if check_dev "${dev}"
+ then
+ return 0
+ fi
+ done
+ done
+ ;;
+
+ *)
+ if [ ! -z "${LIVE_MEDIA}" ]
+ then
+ if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
+ then
+ return 0
+ fi
+ fi
+ ;;
+ esac
+
+ # 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
+
+ # autodetection of live media
+ # 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
+}
+
+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/$(udevadm info -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
+
+ # get_fstype might report "unknown" or "swap", ignore it as no such kernel module exists
+ if [ "${fstype}" = "unknown" ] || [ "${fstype}" = "swap" ]
+ then
+ return 1
+ fi
+
+ # Try to look if it is already supported by the kernel
+ if grep -q ${fstype} /proc/filesystems
+ then
+ return 0
+ else
+ # Then try to add support for it the gentle way using the initramfs capabilities
+ modprobe -q -b ${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 ()
+{
+ 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="$(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
+ 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 $device
+# ends with a "/" this is a directory path.
+# If we're only probing $device (to check if it has custom persistence)
+# $probe should be set, which suppresses warnings upon failure. On
+# success, print the mount point for $device.
+mount_persistence_media ()
+{
+ local device probe backing old_backing fstype mount_opts
+ device=${1}
+ probe=${2}
+
+ # get_custom_mounts() might call this with a directory path instead
+ # of a block device path. This means we have found sub-directory path
+ # underneath /run/live/persistence, so we're done
+ if [ -d "${device}" ]
+ then
+ echo "${device}"
+ return 0
+ fi
+
+ if [ ! -b "${device}" ]
+ then
+ return 1
+ fi
+
+ backing="/run/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 -o move ${old_backing} ${backing} >/dev/null
+ then
+ [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}"
+ rmdir "${backing}"
+ return 1
+ fi
+ mount_opts="rw,noatime"
+ if [ -n "${PERSISTENCE_READONLY}" ]
+ then
+ mount_opts="ro,noatime"
+ fi
+ if ! mount -o "remount,${mount_opts}" "${backing}" >/dev/null
+ then
+ log_warning_msg "Failed to remount persistence media ${device} writable"
+ # Don't unmount or rmdir the new mountpoint in this case
+ fi
+ echo ${backing}
+ return 0
+ else
+ # This means that $device has already been mounted on
+ # the place expected by live-boot, so we're done.
+ 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
+ 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 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
+
+ # check for plymouth
+ [ -x /bin/plymouth ] && plymouth --ping && plymouth="y"
+
+ # export udisk properties (used to get a nice device label)
+ unset ID_VENDOR_ENC ID_MODEL_ENC ID_PART_ENTRY_NUMBER
+ eval $(udevadm info --name=${dev} --query=property -x)
+ [ -z "${ID_VENDOR_ENC}" -a -z "${ID_MODEL_ENC}" ] && ID_MODEL_ENC="Unidentified device"
+ label="$(echo -e "${ID_VENDOR_ENC}${ID_MODEL_ENC}, Partition ${ID_PART_ENTRY_NUMBER} (${dev})")"
+
+ if [ "${plymouth}" = "y" ]
+ then
+ cryptkeyscript="plymouth ask-for-password --prompt"
+ # Plymouth will add a : if it is a non-graphical prompt
+ cryptkeyprompt="Please unlock disk '${label}'"
+ else
+ cryptkeyscript="/lib/cryptsetup/askpass"
+ cryptkeyprompt="Please unlock disk '${label}': "
+ fi
+
+ while true
+ do
+ $cryptkeyscript "$cryptkeyprompt" | \
+ /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
+ retryprompt="There was an error decrypting '${label}' ... Retry? [Y/n]"
+
+ if [ "${plymouth}" == "y" ]
+ then
+ plymouth display-message --text "${retryprompt}"
+ plymouth pause-progress
+ answer=$(plymouth watch-keystroke --keys="YNyn")
+ plymouth unpause-progress
+ else
+ echo -n "${retryprompt} " >&6
+ read answer
+ fi
+
+ if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
+ then
+ [ "${plymouth}" = "y" ] && plymouth display-message --text ""
+ return 2
+ fi
+ done
+}
+
+get_gpt_name ()
+{
+ local dev
+ dev="${1}"
+ blkid -s PART_ENTRY_NAME -p -o value ${dev} 2>/dev/null
+}
+
+is_gpt_device ()
+{
+ local dev
+ dev="${1}"
+ [ "$(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 [ "$(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
+}
+
+probe_for_directory_name ()
+{
+ local overlays dev ret backing
+ overlays="${1}"
+ dev="${2}"
+
+ ret=""
+ backing="$(mount_persistence_media ${dev} probe)"
+ if [ -z "${backing}" ]
+ then
+ return
+ fi
+
+ for label in ${overlays}
+ do
+ path=${backing}/${PERSISTENCE_PATH}/${label}
+ if [ -d "${path}" ]
+ then
+ # in this case the "device" ends with a "/"
+ ret="${ret} ${label}=${backing}/${PERSISTENCE_PATH}/${label%%/}/"
+ fi
+ done
+
+ if [ -n "${ret}" ]
+ then
+ echo ${ret}
+ else
+ # unmount and remove mountpoint
+ umount ${backing} > /dev/null 2>&1 || true
+ rmdir ${backing} > /dev/null 2>&1 || true
+ fi
+}
+
+find_persistence_media ()
+{
+ # Scans devices for overlays, and returns a whitespace
+ # 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=""
+
+ #
+ # The devices that are hosting the actual live rootfs should not be
+ # used for persistence storage since otherwise you might mount a
+ # parent directory on top of a sub-directory of the same filesystem
+ # in one union together.
+ #
+ black_listed_devices=""
+ for d in /run/live/rootfs/* /run/live/findiso /run/live/fromiso
+ do
+ black_listed_devices="${black_listed_devices} $(what_is_mounted_on d)"
+ done
+
+ for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")
+ do
+ 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
+
+ # Probe for directory with matching name on mounted partition
+ if is_in_comma_sep_list directory ${PERSISTENCE_STORAGE}
+ then
+ result=$(probe_for_directory_name "${overlays}" ${dev})
+ if [ -n "${result}" ]
+ then
+ ret="${ret} ${result}"
+ continue
+ fi
+ fi
+
+ # Close luks device if it isn't used
+ if [ -z "${result}" ] && [ -n "${luks_device}" ] && is_active_luks_mapping "${luks_device}"
+ then
+ 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}"
+ cryptsetup isLuks "${device}" 1>/dev/null 2>&1
+}
+
+is_active_luks_mapping ()
+{
+ device="${1}"
+ 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}"
+ device_class="${2}"
+ ret=
+
+ for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+ do
+ if [ ! -d "${sysblock}" ]; then
+ continue
+ fi
+
+ dev_ok=
+ if [ "${device_class}" = "usb" ] && readlink ${sysblock} | grep -Eq "/usb[0-9]+/"
+ then
+ # We only want USB and this is an USB device
+ dev_ok="true"
+ elif [ "${device_class}" = "cdrom" ] && echo ${sysblock} | grep -Eq "/sr[0-9]+$"
+ then
+ # We only want CD-ROM devices and this is such a device
+ dev_ok="true"
+ elif [ -z "${device_class}" ]
+ then
+ if readlink ${sysblock} | grep -Eq "/(usb[0-9]+|fw[0-9]+|mmc[0-9]+)/" || [ "$(cat ${sysblock}/removable)" = "1" ]
+ then
+ # Assume all USB, Firewire and SD cards are external,
+ # This is the best possible guess, eg. udisks has the same logic
+ # There is NO property which indicates with certainity if a device is
+ # removable or not.
+ # Devices that contain a removable medium are considered removable
+ # too. Many (older) USB sticks also set this property although it's
+ # technically wrong. The flash chips are NOT removable from the device.
+ dev_ok="true"
+ 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}" "usb"
+}
+
+removable_cdrom_dev ()
+{
+ output_format="${1}"
+
+ removable_dev "${output_format}" "cdrom"
+}
+
+non_removable_dev ()
+{
+ output_format="${1}"
+ ret=
+
+ for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+ do
+ if [ ! -d "${sysblock}" ]; then
+ continue
+ fi
+
+ if [ "$(cat ${sysblock}/removable)" = "0" ]
+ then
+ case "${output_format}" in
+ 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"
+
+ 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
+ ;;
+
+ overlay)
+ # XXX: can unionro be optional? i.e. can overlay skip lowerdir?
+ if [ -z "${unionro}" ]
+ then
+ panic "overlay needs at least one lower filesystem (read-only branch)."
+ fi
+ # Multiple lower layers can now be given using the the colon (":") as a
+ # separator character between the directory names.
+ unionro="$(echo ${unionro} | sed -e 's| |:|g')"
+ # overlayfs requires:
+ # + a workdir to become mounted
+ # + workdir and upperdir to reside under the same mount
+ # + workdir and upperdir to be in separate directories
+ mkdir "${unionrw}/rw"
+ mkdir "${unionrw}/work"
+ unionmountopts="-o noatime,lowerdir=${unionro},upperdir=${unionrw}/rw,workdir=${unionrw}/work"
+ ;;
+ esac
+
+ mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
+}
+
+get_custom_mounts ()
+{
+ # Side-effect: leaves $devices with persistence.conf mounted in /run/live/persistence
+ # Side-effect: prints info to file $custom_mounts
+
+ local custom_mounts devices bindings links
+ 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
+ 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}"
+ else
+ continue
+ fi
+
+ if [ -n "${LIVE_BOOT_DEBUG}" ] && [ -e "${include_list}" ]
+ then
+ cp ${include_list} /run/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 "^/run/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
+ then
+ log_warning_msg "Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/lib\", or \"/run/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 unknown 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
+ [ -e ${custom_mounts} ] && 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 /run/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} ""
+ elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
+ then
+ mkdir -p /run/live/persistence
+ links_source=$(mktemp -d /run/live/persistence/links-source-XXXXXX)
+ chown_ref ${source} ${links_source}
+ chmod_ref ${source} ${links_source}
+ # We put the cow dir in the below strange place to
+ # 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="/run/live/overlay/run/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} ${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 -o bind "${source}" "${dest}"
+ elif [ -n "${opt_bind}" -o -n "${opt_union}" ] && [ -n "${PERSISTENCE_READONLY}" ]
+ then
+ # bind-mount and union mount are handled the same
+ # in read-only mode, but note that rootfs_dest_backing
+ # is non-empty (and necessary) only for unions
+ cow_dir="/run/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}"
+ if [ "${UNIONTYPE}" = "overlay" ]
+ then
+ # When we use overlay we add the "/rw" postfix to our source when using it
+ # as upper layer. Therefore we also have to add it here when using it as
+ # the lower layer.
+ source="${source}/rw"
+ fi
+ do_union ${dest} ${cow_dir} ${source} ${rootfs_dest_backing}
+ fi
+
+ 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/system-boot/components/9990-mount-cifs.sh b/system-boot/components/9990-mount-cifs.sh
new file mode 100755
index 0000000..8dd1818
--- /dev/null
+++ b/system-boot/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/system-boot/components/9990-mount-http.sh b/system-boot/components/9990-mount-http.sh
new file mode 100755
index 0000000..f58c3a3
--- /dev/null
+++ b/system-boot/components/9990-mount-http.sh
@@ -0,0 +1,93 @@
+#!/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
+ case "${url}" in
+ *:///*) url="${url%%:///*}://${ROOTSERVER}/${url##*:///}" ;;
+ esac
+ 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
+
+ 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/system-boot/components/9990-mount-iscsi.sh b/system-boot/components/9990-mount-iscsi.sh
new file mode 100755
index 0000000..c9bab90
--- /dev/null
+++ b/system-boot/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/system-boot/components/9990-mount-nfs.sh b/system-boot/components/9990-mount-nfs.sh
new file mode 100755
index 0000000..6a3ae55
--- /dev/null
+++ b/system-boot/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/system-boot/components/9990-netbase.sh b/system-boot/components/9990-netbase.sh
new file mode 100755
index 0000000..bae858a
--- /dev/null
+++ b/system-boot/components/9990-netbase.sh
@@ -0,0 +1,139 @@
+#!/bin/sh
+
+#set -e
+
+Netbase ()
+{
+ if [ -n "${NONETWORKING}" ]
+ then
+ return
+ fi
+
+ log_begin_msg "Preconfiguring networking"
+
+ IFFILE="/root/etc/network/interfaces"
+ if [ -L /root/etc/resolv.conf ] ; then
+ # assume we have resolvconf
+ DNSFILE="/root/etc/resolvconf/resolv.conf.d/base"
+ else
+ DNSFILE="/root/etc/resolv.conf"
+ fi
+
+ 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 [ -n "${NODHCP}" ]
+ then
+ # force DHCP off
+ method="manual"
+ elif [ -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* /sys/class/net/en*
+ do
+ [ -e ${interface} ] || continue
+ i="$(basename ${interface})"
+
+cat >> "${IFFILE}" << EOF
+allow-hotplug ${i}
+iface ${i} inet ${method}
+
+EOF
+
+ done
+ fi
+
+ if [ ! -f "${DNSFILE}" ] || [ -z "$(cat ${DNSFILE})" ]
+ 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 }')"
+
+cat > $DNSFILE << EOF
+search ${rc_search}
+domain ${rc_search}
+nameserver ${rc_server0}
+EOF
+
+ rc_server1=$(cat netboot.config | awk '/dns0/ { print $8 }')
+
+ if [ "${rc_server1}" != "0.0.0.0" ]
+ then
+ echo "nameserver ${rc_server1}" >> $DNSFILE
+ fi
+
+ cat $DNSFILE >> /root/var/log/netboot.config
+ fi
+ fi
+ fi
+
+ log_end_msg
+}
diff --git a/system-boot/components/9990-netboot.sh b/system-boot/components/9990-netboot.sh
new file mode 100755
index 0000000..5054fb8
--- /dev/null
+++ b/system-boot/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/system-boot/components/9990-networking.sh b/system-boot/components/9990-networking.sh
new file mode 100755
index 0000000..9cc3674
--- /dev/null
+++ b/system-boot/components/9990-networking.sh
@@ -0,0 +1,179 @@
+#!/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
+
+ for dev in $devlist
+ do
+ echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
+ ipconfig -t "$ETHDEV_TIMEOUT" "$dev" | tee -a /netboot.config
+
+ # 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 -E 'inet.*addr:|inet [0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*'
+ 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
+
+ # Only create /etc/hosts if FQDN is known (to let 'hostname -f' query
+ # this file). Otherwise DNS will be queried to determine the FQDN.
+ if [ ! -e "/etc/hosts" ] && [ -n "${DNSDOMAIN}" ]
+ then
+ echo "Creating /etc/hosts"
+ cat > /etc/hosts <<EOF
+127.0.0.1 localhost
+127.0.1.1 ${HOSTNAME}.${DNSDOMAIN} ${HOSTNAME}
+
+# The following lines are desirable for IPv6 capable hosts
+::1 localhost ip6-localhost ip6-loopback
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
+EOF
+ 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} ${DNSSERVERS}
+ 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/system-boot/components/9990-overlay.sh b/system-boot/components/9990-overlay.sh
new file mode 100755
index 0000000..61b1f26
--- /dev/null
+++ b/system-boot/components/9990-overlay.sh
@@ -0,0 +1,337 @@
+#!/bin/sh
+
+#set -e
+
+setup_unionfs ()
+{
+ image_directory="${1}"
+ rootmnt="${2}"
+ addimage_directory="${3}"
+
+ modprobe -q -b ${UNIONTYPE}
+
+ if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$"
+ then
+ panic "${UNIONTYPE} not available."
+ fi
+
+ croot="/run/live/rootfs"
+
+ # 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
+
+ mpoint=$(trim_path "${croot}/${imagename}")
+ rootfslist="${mpoint} ${rootfslist}"
+
+ 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
+ else
+ log_warning_msg "Could not find image '${image}'. Most likely it is listed in a .module file, perhaps by mistake."
+ 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 /run/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,size=${OVERLAY_SIZE:-50%}"
+ fi
+
+ if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
+ then
+ mount -t tmpfs -o rw,noatime,mode=755,size=${OVERLAY_SIZE:-50%} tmpfs "/run/live/overlay"
+ root_backing="/run/live/persistence/$(basename ${cowdevice})-root"
+ mkdir -p ${root_backing}
+ else
+ root_backing="/run/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
+
+ 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 -o 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
+
+ for dir in ${cow_dirs}; do
+ unionmountpoint=$(trim_path "${rootmnt}${dir}")
+ mkdir -p ${unionmountpoint}
+ cow_dir=$(trim_path "/run/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 || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
+ done
+
+ # Remove persistence depending on boot parameter
+ Remove_persistence
+
+ # Correct the permissions of /:
+ chmod 0755 "${rootmnt}"
+
+ # Correct the permission of /tmp:
+ if [ -d "${rootmnt}/tmp" ]
+ then
+ chmod 1777 "${rootmnt}"/tmp
+ fi
+
+ # Adding custom persistence
+ if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
+ then
+ local custom_mounts
+ custom_mounts="/tmp/custom_mounts.list"
+ rm -f ${custom_mounts}
+
+ # Gather information about custom mounts from devies detected as overlays
+ get_custom_mounts ${custom_mounts} ${overlay_devices}
+
+ [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/run/live/persistence"
+
+ # Now we do the actual mounting (and symlinking)
+ local used_overlays
+ used_overlays=""
+ used_overlays=$(activate_custom_mounts ${custom_mounts})
+ rm -f ${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
+}
diff --git a/system-boot/components/9990-select-eth-device.sh b/system-boot/components/9990-select-eth-device.sh
new file mode 100755
index 0000000..c8f36b0
--- /dev/null
+++ b/system-boot/components/9990-select-eth-device.sh
@@ -0,0 +1,108 @@
+#!/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
+
+ # Ensure all our net modules get loaded so we can actually compare MAC addresses...
+ udevadm trigger
+ udevadm settle
+
+ # 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 * 2>/dev/null | grep -v "lo")"
+ 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/system-boot/components/9990-toram-todisk.sh b/system-boot/components/9990-toram-todisk.sh
new file mode 100755
index 0000000..5b76d54
--- /dev/null
+++ b/system-boot/components/9990-toram-todisk.sh
@@ -0,0 +1,103 @@
+#!/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
+ cp -a ${copyfrom}/* ${copyto}/
+ 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
+}