5 export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
7 echo "/root/lib" >> /etc/ld.so.conf
8 echo "/root/usr/lib" >> /etc/ld.so.conf
10 mountpoint="/live/image"
11 alt_mountpoint="/media"
12 LIVE_MEDIA_PATH="live"
14 root_persistence="live-rw"
15 home_persistence="home-rw"
16 root_snapshot_label="live-sn"
17 home_snapshot_label="home-sn"
20 USERFULLNAME="Live user"
23 mkdir -p "${mountpoint}"
26 # Create /etc/mtab for debug purpose and future syncs
37 . /scripts/live-helpers
39 if [ ! -f /live.vars ]
49 for ARGUMENT in $(cat /proc/cmdline)
58 export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
62 ACCESS="${ARGUMENT#access=}"
67 DEFCONSOLE="${ARGUMENT#*=}"
79 # Force dhcp even while netbooting
80 # Use for debugging in case somebody works on fixing dhclient
90 DEVICE="${ARGUMENT#ethdevice=}"
95 ETHDEVICE="${ARGUMENT#ethdevice=}"
100 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
101 export ETHDEV_TIMEOUT
105 FETCH="${ARGUMENT#fetch=}"
110 FORCEPERSISTENTFSCK="Yes"
111 export FORCEPERSISTENTFSCK
115 FTPFS="${ARGUMENT#ftpfs=}"
120 HTTPFS="${ARGUMENT#httpfs=}"
125 ISCSI="${ARGUMENT#iscsi=}"
126 #ip:port - separated by ;
127 ISCSI_PORTAL="${ISCSI%;*}"
128 if echo "${ISCSI_PORTAL}" | grep -q , ; then
129 ISCSI_SERVER="${ISCSI_PORTAL%,*}"
130 ISCSI_PORT="${ISCSI_PORTAL#*,}"
133 ISCSI_TARGET="${ISCSI#*;}"
134 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
138 FROMISO="${ARGUMENT#*=}"
148 INTEGRITY_CHECK="Yes"
149 export INTEGRITY_CHECK
153 STATICIP="${ARGUMENT#ip=}"
155 if [ -z "${STATICIP}" ]
168 live-media=*|bootfrom=*)
169 LIVE_MEDIA="${ARGUMENT#*=}"
173 live-media-encryption=*|encryption=*)
174 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
175 export LIVE_MEDIA_ENCRYPTION
179 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
180 export LIVE_MEDIA_OFFSET
184 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
185 export LIVE_MEDIA_PATH
188 live-media-timeout=*)
189 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
190 export LIVE_MEDIA_TIMEOUT
194 MODULE="${ARGUMENT#module=}"
199 NETBOOT="${ARGUMENT#netboot=}"
204 NFSOPTS="${ARGUMENT#nfsopts=}"
209 NFS_COW="${ARGUMENT#nfscow=}"
214 NOACCESSIBILITY="Yes"
215 export NOACCESSIBILITY
244 PERSISTENT="${ARGUMENT#persistent=}"
245 if [ -z "${PERSISTENT}" ]
253 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
254 export PERSISTENT_PATH
257 persistent-subtext=*)
258 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
259 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
260 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
261 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
270 QUICKUSBMODULES="Yes"
271 export QUICKUSBMODULES
274 preseed/file=*|file=*)
275 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
285 question="${ARGUMENT%%=*}"
286 value="${ARGUMENT#*=}"
287 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
302 TODISK="${ARGUMENT#todisk=}"
313 MODULETORAM="${ARGUMENT#toram=}"
314 export TORAM MODULETORAM
328 SKIP_UNION_MOUNTS="Yes"
329 export SKIP_UNION_MOUNTS
333 ROOT="${ARGUMENT#root=}"
338 UNIONTYPE="${ARGUMENT#union=}"
344 # sort of compatibility with netboot.h from linux docs
345 if [ -z "${NETBOOT}" ]
347 if [ "${ROOT}" = "/dev/nfs" ]
351 elif [ "${ROOT}" = "/dev/cifs" ]
358 if [ -z "${MODULE}" ]
364 if [ -z "${UNIONTYPE}" ]
375 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
377 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
379 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
391 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
397 uuid="$(cat /conf/uuid.conf)"
399 for try_uuid_file in "${path}/.disk/live-uuid"*
401 [ -e "${try_uuid_file}" ] || continue
403 try_uuid="$(cat "${try_uuid_file}")"
405 if [ "${uuid}" = "${try_uuid}" ]
414 get_backing_device ()
417 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
418 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
426 panic "Unrecognized live filesystem: ${1}"
431 match_files_in_dir ()
433 # Does any files match pattern ${1} ?
436 if [ "$(echo ${pattern})" != "${pattern}" ]
444 mount_images_in_directory ()
451 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
452 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
453 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
454 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
455 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
456 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
458 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
459 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
461 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
467 sysfs_path="${1#/sys}"
469 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
472 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
475 elif echo ${sysfs_path} | grep -q "^/block/dm-"
487 copyto="${copyfrom}_swap"
489 if [ -z "${MODULETORAM}" ]
491 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
493 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
495 if [ -f "${MODULETORAMFILE}" ]
497 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
499 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
504 if [ "${copytodev}" = "ram" ]
507 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
508 mount_options="-o size=${size}k"
513 # it should be a writable block device
514 if [ -b "${copytodev}" ]
518 fstype=$(get_fstype "${dev}")
519 freespace=$(fs_size "${dev}")
521 log_warning_msg "${copytodev} is not a block device."
526 if [ "${freespace}" -lt "${size}" ]
528 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
532 # begin copying (or uncompressing)
534 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
535 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
537 if [ "${extension}" = "tgz" ]
540 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
541 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
542 mount -r -o move "${copyto}" "${rootmnt}"
545 if [ -n "${MODULETORAMFILE}" ]
549 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
550 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
552 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
557 echo " * Copying whole medium to RAM" 1>/dev/console
558 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
560 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
561 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
562 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
564 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
570 mount -r -o move ${copyto} ${copyfrom}
579 modprobe -q af_packet # For DHCP
584 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
585 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
588 # if ethdevice was not specified on the kernel command line
589 # make sure we try to get a working network configuration
590 # for *every* present network device (except for loopback of course)
591 if [ -z "$ETHDEVICE" ] ; then
592 echo "If you want to boot from a specific device use bootoption ethdevice=..."
593 for device in /sys/class/net/*; do
595 if [ "$dev" != "lo" ] ; then
596 ETHDEVICE="$ETHDEVICE $dev"
601 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
602 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
603 devlist="$devlist $device"
606 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
607 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
609 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
610 # an endless loop; iff execution fails give it two further tries, that's
611 # why we use '$devlist $devlist $devlist' for the other for loop
612 for dev in $devlist $devlist $devlist ; do
613 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
614 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
616 sleep "$ETHDEV_TIMEOUT" ; sleep 1
617 if [ -r /proc/"$jobid"/status ] ; then
618 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
622 # if configuration of device worked we should have an assigned
623 # IP address, iff so let's use the according as $DEVICE for later usage
624 # simple and primitive approach which seems to work fine
625 if ifconfig $dev | grep -q 'inet.*addr:' ; then
632 ipconfig ${DEVICE} | tee /netboot.config
635 # source relevant ipconfig output
636 OLDHOSTNAME=${HOSTNAME}
637 . /tmp/net-${DEVICE}.conf
638 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
641 if [ -n "${DEVICE}" ]
643 HWADDR="$(cat /sys/class/net/${DEVICE}/address)"
646 # Check if we have a network device at all
647 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
648 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
649 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
650 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
651 ! ls /sys/class/net/ra0 > /dev/null 2>&1
653 panic "No supported network device found, maybe a non-mainline driver is required."
661 if [ "${NFSROOT}" = "auto" ]
663 NFSROOT=${ROOTSERVER}:${ROOTPATH}
668 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
674 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
676 NFSROOT=${ROOTSERVER}:${NFSROOT}
679 log_begin_msg "Trying netboot from ${NFSROOT}"
681 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
701 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
702 #FIXME this name is supposed to be unique - some date + ifconfig hash?
703 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
704 export ISCSI_INITIATORNAME
705 if [ -n "${ISCSI_SERVER}" ] ; then
706 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
708 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
712 panic "Failed to log into iscsi target"
714 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
715 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
720 while [ -z "${devices}" -a $i -lt 60 ]
723 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
724 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
730 if check_dev "null" "/dev/$dev"
737 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
739 panic "Failed to locate iSCSI host in /sys"
747 for webfile in HTTPFS FTPFS FETCH
749 local url="$(eval echo \"\$\{${webfile}\}\")"
750 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
754 case "${extension}" in
755 iso|squashfs|tgz|tar)
756 if [ "${extension}" = "iso" ]
758 mkdir -p "${alt_mountpoint}"
759 dest="${alt_mountpoint}"
761 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
762 mount -t ramfs ram "${mountpoint}"
765 if [ "${webfile}" = "FETCH" ]
769 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
770 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
771 lfile="$(basename $url)"
772 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
773 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
777 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
778 wget "${url}" -O "${dest}/$(basename ${url})"
782 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
783 if [ "${webfile}" = "FTPFS" ]
785 FUSE_MOUNT="curlftpfs"
786 url="$(dirname ${url})"
791 $FUSE_MOUNT "${url}" "${dest}"
792 FUSE_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
794 [ ${?} -eq 0 ] && rc=0
795 [ "${extension}" = "tgz" ] && live_dest="ram"
796 if [ "${extension}" = "iso" ]
798 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
799 mount -t iso9660 "${isoloop}" "${mountpoint}"
806 log_begin_msg "Unrecognized archive extension for ${url}"
814 if [ -d "${alt_mountpoint}" ]
816 umount "${alt_mountpoint}"
817 rmdir "${alt_mountpoint}"
819 umount "${mountpoint}"
820 elif [ "${webfile}" != "FETCH" ] ; then
823 if [ -n "${FUSE_PID}" ] ; then
824 echo "${FUSE_PID}" > ${mountpoint}/root.pid
837 if [ -z "${NFSOPTS}" ]
842 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
844 # FIXME: This while loop is an ugly HACK round an nfs bug
846 while [ "$i" -lt 60 ]
848 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
860 if [ -x "/sbin/mount.cifs" ]
862 if [ -z "${NFSOPTS}" ]
864 CIFSOPTS="-ouser=root,password="
866 CIFSOPTS="${NFSOPTS}"
869 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
872 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
886 size=$(fs_size "${fromdev}" "" "used")
888 if [ -b "${fromdev}" ]
891 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
893 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
894 freespace=$(df -k | awk '/'${todev}'/{print $4}')
896 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
899 tomount="/mnt/tmpsnap"
901 if [ ! -d "${tomount}" ]
903 mkdir -p "${tomount}"
906 fstype=$(get_fstype "${fromdev}")
908 if [ -n "${fstype}" ]
911 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
912 cp -a "${tomount}"/* ${todir}
915 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
920 if echo ${fromdev} | grep -qs loop
922 losetup -d "${fromdev}"
929 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
935 # Look for ${snap_label}.* in block devices
938 if [ "${PERSISTENT}" != "nofiles" ]
940 # search for image files
941 snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2")
944 if [ -z "${snapdata}" ]
946 snapdata=$(find_cow_device "${snap_label}")
953 # copy the contents of previously found snapshot to ${snap_mount}
954 # and remember the device and filename for resync on exit in live-boot.init
960 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
962 log_success_msg "found snapshot: ${snapdata}"
963 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
964 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
965 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
968 if ! try_mount "${snapdev}" "${snapback}" "ro"
973 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
975 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
976 dev=$(get_backing_device "${snapback}/${snapfile}")
978 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
983 # Unfortunately klibc's cpio is incompatible with the
984 # rest of the world; everything else requires -u -d,
985 # while klibc doesn't implement them. Try to detect
986 # whether it's in use.
987 cpiopath="$(which cpio)" || true
988 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
992 cpioargs='--unconditional --make-directories'
995 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
997 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1001 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1003 if [ "${RES}" != "0" ]
1005 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1008 elif [ -b "${snapdata}" ]
1010 # Try to find if it could be a snapshot partition
1012 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1013 if echo "${dev}" | grep -qs loop
1015 # strange things happens, user confused?
1016 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1017 snapfile=$(basename ${snaploop})
1018 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1023 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1025 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1028 if [ -n "${snapfile}" ]
1030 # it was a loop device, user confused
1035 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1039 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1045 image_directory="${1}"
1047 addimage_directory="${3}"
1049 case ${UNIONTYPE} in
1051 modprobe -q -b ${UNIONTYPE}
1053 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1055 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1056 echo "This might be really slow."
1058 UNIONTYPE="unionfs-fuse"
1063 if [ "${UNIONTYPE}" = unionfs-fuse ]
1068 # run-init can't deal with images in a subdir, but we're going to
1069 # move all of these away before it runs anyway. No, we're not,
1070 # put them in / since move-mounting them into / breaks mono and
1075 # Let's just mount the read-only file systems first
1079 if [ "${UNIONTYPE}" = "aufs" ]
1082 noxino_opt="noxino,"
1083 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1090 if [ -z "${PLAIN_ROOT}" ]
1092 # Read image names from ${MODULE}.module if it exists
1093 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1095 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1097 image_string="${image_string} ${image_directory}/${IMAGE}"
1099 elif [ -e "${image_directory}/${MODULE}.module" ]
1101 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1103 image_string="${image_string} ${image_directory}/${IMAGE}"
1106 # ${MODULE}.module does not exist, create a list of images
1107 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1109 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1111 if [ -e "${IMAGE}" ]
1113 image_string="${image_string} ${IMAGE}"
1118 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1120 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1122 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1124 if [ -e "${IMAGE}" ]
1126 image_string="${image_string} ${IMAGE}"
1133 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1136 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1140 for image in ${image_string}
1142 imagename=$(basename "${image}")
1144 export image devname
1145 maybe_break live-realpremount
1146 log_begin_msg "Running /scripts/live-realpremount"
1147 run_scripts /scripts/live-realpremount
1150 if [ -d "${image}" ]
1152 # it is a plain directory: do nothing
1153 rofsstring="${image}=${roopt}:${rofsstring}"
1154 rofslist="${image} ${rofslist}"
1155 elif [ -f "${image}" ]
1157 if losetup --help 2>&1 | grep -q -- "-r\b"
1159 backdev=$(get_backing_device "${image}" "-r")
1161 backdev=$(get_backing_device "${image}")
1163 fstype=$(get_fstype "${backdev}")
1165 if [ "${fstype}" = "unknown" ]
1167 panic "Unknown file system type on ${backdev} (${image})"
1170 if [ -z "${fstype}" ]
1172 fstype="${imagename##*.}"
1173 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1176 mkdir -p "${croot}/${imagename}"
1177 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1178 mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
1183 # we have a plain root system
1184 mkdir -p "${croot}/filesystem"
1185 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1186 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || panic "Can not mount ${image_directory} on ${croot}/filesystem" && rofsstring="${croot}/filesystem=${roopt}:${rofsstring}" && rofslist="${croot}/filesystem ${rofslist}"
1188 mount -o bind ${croot}/filesystem $mountpoint
1192 rofsstring=${rofsstring%:}
1196 # Looking for "${root_persistence}" device or file
1197 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1199 if [ -z "${QUICKUSBMODULES}" ]
1202 num_block=$(ls -l /sys/block | wc -l)
1203 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1205 modprobe -q -b ${module}
1211 # For some reason, udevsettle does not block in this scenario,
1212 # so we sleep for a little while.
1214 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1215 for timeout in 5 4 3 2 1
1219 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1226 # search for label and files (this could be hugely optimized)
1227 cowprobe=$(find_cow_device "${root_persistence}")
1228 if [ -b "${cowprobe}" ]
1230 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1231 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1232 # snapshots to be sure to really store some e.g key config files,
1233 # but not on the same media
1234 blacklistdev="${cowprobe}"
1235 PERSISTENCE_IS_ON="1"
1236 export PERSISTENCE_IS_ON
1238 # homecow just mount something on /home, this should be generalized some way
1239 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1240 if [ -b "${homecow}" ]
1242 PERSISTENCE_IS_ON="1"
1243 export PERSISTENCE_IS_ON
1245 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1246 # This second type should be removed when snapshot will get smarter,
1247 # hence when "/etc/live-snapshot*list" will be supported also by
1248 # ext2|ext3|ext4|jffs2 snapshot types.
1249 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1251 if [ -b "${cowprobe}" ]
1253 cowdevice=${cowprobe}
1254 cow_fstype=$(get_fstype "${cowprobe}")
1255 cow_mountopt="rw,noatime"
1257 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1259 fsck -y ${cowdevice}
1262 log_warning_msg "Unable to find the persistent medium"
1265 cow_mountopt="rw,noatime,mode=755"
1267 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1269 # check if there are any nfs options
1270 if echo ${NFS_COW}|grep -q ','
1272 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1273 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1275 nfs_cow_opts="-o nolock"
1281 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1284 panic "unable to determine mac address"
1289 cow_mountopt="rw,noatime,mode=755"
1292 if [ "${cow_fstype}" = "nfs" ]
1295 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1296 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1297 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1299 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1300 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1303 rofscount=$(echo ${rofslist} |wc -w)
1305 if [ -n "${EXPOSED_ROOT}" ]
1307 if [ ${rofscount} -ne 1 ]
1309 panic "only one RO file system supported with exposedroot: ${rofslist}"
1311 exposedrootfs=${rofslist%% }
1313 mount --bind ${exposedrootfs} ${rootmnt} || \
1314 panic "bind mount of ${exposedrootfs} failed"
1316 if [ -z "${SKIP_UNION_MOUNTS}" ]
1318 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1323 for dir in ${cow_dirs}; do
1326 case "${UNIONTYPE}" in
1328 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${exposedrootfs}${dir} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow=RW:${exposedrootfs}${dir}")
1329 mkdir -p /dev/.initramfs/varrun
1330 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1334 mount -t ${UNIONTYPE} -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro ${UNIONTYPE} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro"
1339 case "${UNIONTYPE}" in
1341 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${rofsstring} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow:RW:${rofsstring}")
1342 mkdir -p /dev/.initramfs/varrun
1343 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1347 mount -t ${UNIONTYPE} -o noatime,${noxino_opt}dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option noatime,${noxino_opt}dirs=/cow=rw:${rofsstring}"
1352 # Correct the permissions of /:
1353 chmod 0755 "${rootmnt}"
1355 # tmpfs file systems
1357 mkdir -p "${rootmnt}/live"
1358 mount -t tmpfs tmpfs ${rootmnt}/live
1360 # Adding other custom mounts
1361 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1363 # directly mount /home
1364 # FIXME: add a custom mounts configurable system
1366 if [ -b "${homecow}" ]
1368 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1369 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1371 log_warning_msg "Unable to find the persistent home medium"
1374 # Look for other snapshots to copy in
1375 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1376 # This second type should be removed when snapshot grow smarter
1377 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1380 if [ -n "${SHOWMOUNTS}" ]
1382 for d in ${rofslist}
1384 mkdir -p "${rootmnt}/live/${d##*/}"
1388 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1392 case "${UNIONTYPE}" in
1394 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1398 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1406 # shows cow fs on /cow for use by live-snapshot
1407 mkdir -p "${rootmnt}/live/cow"
1408 mount -o move /cow "${rootmnt}/live/cow" >/dev/null 2>&1 || mount -o bind /cow "${rootmnt}/live/cow" || log_warning_msg "Unable to move or bind /cow to ${rootmnt}/live/cow"
1415 skip_uuid_check="${3}"
1417 # support for fromiso=.../isofrom=....
1418 if [ -n "$FROMISO" ]
1420 ISO_DEVICE=$(dirname $FROMISO)
1421 if ! [ -b $ISO_DEVICE ]
1423 # to support unusual device names like /dev/cciss/c0d0p1
1424 # as well we have to identify the block device name, let's
1425 # do that for up to 15 levels
1427 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1429 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1430 [ -b "$ISO_DEVICE" ] && break
1435 if [ "$ISO_DEVICE" = "/" ]
1437 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1440 mount "$ISO_DEVICE" /isofrom
1441 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1442 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1443 devname="${loopdevname}"
1447 if [ -z "${devname}" ]
1449 devname=$(sys2dev "${sysdev}")
1452 if [ -d "${devname}" ]
1454 mount -o bind "${devname}" $mountpoint || continue
1456 if is_live_path $mountpoint
1464 [ -e "$devname" ] || continue
1466 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1468 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1469 devname="${loopdevname}"
1472 fstype=$(get_fstype "${devname}")
1474 if is_supported_fs ${fstype}
1476 devuid=$(blkid -o value -s UUID "$devname")
1477 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1478 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1479 [ -n "$devuid" ] && echo "$devuid" >> $tried
1481 if is_live_path ${mountpoint} && \
1482 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1487 umount ${mountpoint}
1491 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1493 losetup -d "${loopdevname}"
1503 # don't start autodetection before timeout has expired
1504 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1506 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1512 # first look at the one specified in the command line
1513 case "${LIVE_MEDIA}" in
1515 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1517 if [ "$(cat ${sysblock}/removable)" = "1" ]
1519 if readlink ${sysblock} | grep -q usb ||
1520 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1522 for dev in $(subdevices "${sysblock}")
1524 if check_dev "${dev}"
1536 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1538 if [ "$(cat ${sysblock}/removable)" = "1" ]
1540 for dev in $(subdevices "${sysblock}")
1542 if check_dev "${dev}"
1553 if [ ! -z "${LIVE_MEDIA}" ]
1555 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1563 # or do the scan of block devices
1564 # prefer removable devices over non-removable devices, so scan them first
1565 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1567 if [ "$(cat ${sysblock}/removable)" = "1" ]
1569 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1571 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1574 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1576 for sysblock in $devices_to_scan
1578 devname=$(sys2dev "${sysblock}")
1579 [ -e "$devname" ] || continue
1580 fstype=$(get_fstype "${devname}")
1582 if /lib/udev/cdrom_id ${devname} > /dev/null
1584 if check_dev "null" "${devname}"
1588 elif is_nice_device "${sysblock}"
1590 for dev in $(subdevices "${sysblock}")
1592 if check_dev "${dev}"
1597 elif [ "${fstype}" = "squashfs" -o \
1598 "${fstype}" = "ext2" -o \
1599 "${fstype}" = "ext3" -o \
1600 "${fstype}" = "ext4" -o \
1601 "${fstype}" = "jffs2" ]
1603 # This is an ugly hack situation, the block device has
1604 # an image directly on it. It's hopefully
1605 # live-boot, so take it and run with it.
1606 ln -s "${devname}" "${devname}.${fstype}"
1607 echo "${devname}.${fstype}"
1615 set_usplash_timeout ()
1617 if [ -x /sbin/usplash_write ]
1619 /sbin/usplash_write "TIMEOUT 120"
1620 else if [ -x /sbin/splashy_update ] ; then
1621 /sbin/splashy_update "TIMEOUT 120"
1627 media_mountpoint="${1}"
1629 log_begin_msg "Checking media integrity"
1631 cd ${media_mountpoint}
1632 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1637 if [ "${RC}" -eq 0 ]
1639 log_success_msg "Everything ok, will reboot in 10 seconds."
1642 umount ${media_mountpoint}
1644 echo u > /proc/sysrq-trigger
1645 echo b > /proc/sysrq-trigger
1647 panic "Not ok, a media defect is likely, switch to VT8 for details."
1651 start_usplash_pulse ()
1653 if [ -x /sbin/usplash_write ]
1655 /sbin/usplash_write "PULSELOGO"
1661 if [ -x /scripts/local-top/cryptroot ]; then
1662 /scripts/local-top/cryptroot
1669 tail -f live.log >&7 &
1672 # Ensure 'panic' function is overridden
1673 . /scripts/live-functions
1680 maybe_break live-premount
1681 log_begin_msg "Running /scripts/live-premount"
1682 run_scripts /scripts/live-premount
1685 # Needed here too because some things (*cough* udev *cough*)
1686 # changes the timeout
1690 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1694 livefs_root="${mountpoint}"
1696 panic "Unable to find a live file system on the network"
1699 if [ -n "${ISCSI_PORTAL}" ]
1701 do_iscsi && livefs_root="${mountpoint}"
1702 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1704 # Do a local boot from hd
1707 # Scan local devices for the image
1709 while [ "$i" -lt 60 ]
1711 livefs_root=$(find_livefs ${i})
1713 if [ -n "${livefs_root}" ]
1724 if [ -z "${livefs_root}" ]
1726 panic "Unable to find a medium containing a live file system"
1729 if [ "${INTEGRITY_CHECK}" ]
1731 integrity_check "${livefs_root}"
1737 elif [ "${TODISK}" ]
1739 live_dest="${TODISK}"
1742 if [ "${live_dest}" ]
1744 log_begin_msg "Copying live media to ${live_dest}"
1745 copy_live_to "${livefs_root}" "${live_dest}"
1749 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1750 # because the mountpoint is left behind in /proc/mounts, so let's get
1751 # rid of it when running from RAM
1752 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1754 losetup -d /dev/loop0
1755 grep -q /isofrom /proc/mounts && umount /isofrom
1758 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1760 setup_unionfs "${livefs_root}" "${rootmnt}"
1763 mac="$(echo ${mac} | sed 's/-//g')"
1764 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1769 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1770 # live-bottom; udev's init script will take care of things after that
1771 if [ "${UNIONTYPE}" = unionfs-fuse ]
1773 mount -n -o bind /dev "${rootmnt}/dev"
1776 # Move to the new root filesystem so that programs there can get at it.
1777 if [ ! -d /root/live/image ]
1779 mkdir -p /root/live/image
1780 mount --move /live/image /root/live/image
1783 maybe_break live-bottom
1784 log_begin_msg "Running /scripts/live-bottom\n"
1786 run_scripts /scripts/live-bottom
1789 if [ "${UNIONFS}" = unionfs-fuse ]
1791 umount "${rootmnt}/dev"
1797 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null