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 ' ')"
967 if ! try_mount "${snapdev}" "${snapback}" "ro"
974 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
976 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
977 dev=$(get_backing_device "${snapback}/${snapfile}")
979 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
984 # Unfortunately klibc's cpio is incompatible with the
985 # rest of the world; everything else requires -u -d,
986 # while klibc doesn't implement them. Try to detect
987 # whether it's in use.
988 cpiopath="$(which cpio)" || true
989 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
993 cpioargs='--unconditional --make-directories'
996 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
999 if [ "${RES}" != "0" ]
1001 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1005 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1007 if [ "${RES}" != "0" ]
1009 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1012 elif [ -b "${snapdata}" ]
1014 # Try to find if it could be a snapshot partition
1016 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1017 if echo "${dev}" | grep -qs loop
1019 # strange things happens, user confused?
1020 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1021 snapfile=$(basename ${snaploop})
1022 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1027 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1029 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1032 if [ -n "${snapfile}" ]
1034 # it was a loop device, user confused
1039 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1043 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1049 image_directory="${1}"
1051 addimage_directory="${3}"
1053 case ${UNIONTYPE} in
1055 modprobe -q -b ${UNIONTYPE}
1057 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1059 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1060 echo "This might be really slow."
1062 UNIONTYPE="unionfs-fuse"
1067 if [ "${UNIONTYPE}" = unionfs-fuse ]
1072 # run-init can't deal with images in a subdir, but we're going to
1073 # move all of these away before it runs anyway. No, we're not,
1074 # put them in / since move-mounting them into / breaks mono and
1079 # Let's just mount the read-only file systems first
1083 if [ "${UNIONTYPE}" = "aufs" ]
1086 noxino_opt="noxino,"
1087 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1094 if [ -z "${PLAIN_ROOT}" ]
1096 # Read image names from ${MODULE}.module if it exists
1097 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1099 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1101 image_string="${image_string} ${image_directory}/${IMAGE}"
1103 elif [ -e "${image_directory}/${MODULE}.module" ]
1105 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1107 image_string="${image_string} ${image_directory}/${IMAGE}"
1110 # ${MODULE}.module does not exist, create a list of images
1111 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1113 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1115 if [ -e "${IMAGE}" ]
1117 image_string="${image_string} ${IMAGE}"
1122 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1124 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1126 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1128 if [ -e "${IMAGE}" ]
1130 image_string="${image_string} ${IMAGE}"
1137 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1140 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1144 for image in ${image_string}
1146 imagename=$(basename "${image}")
1148 export image devname
1149 maybe_break live-realpremount
1150 log_begin_msg "Running /scripts/live-realpremount"
1151 run_scripts /scripts/live-realpremount
1154 if [ -d "${image}" ]
1156 # it is a plain directory: do nothing
1157 rofsstring="${image}=${roopt}:${rofsstring}"
1158 rofslist="${image} ${rofslist}"
1159 elif [ -f "${image}" ]
1161 if losetup --help 2>&1 | grep -q -- "-r\b"
1163 backdev=$(get_backing_device "${image}" "-r")
1165 backdev=$(get_backing_device "${image}")
1167 fstype=$(get_fstype "${backdev}")
1169 if [ "${fstype}" = "unknown" ]
1171 panic "Unknown file system type on ${backdev} (${image})"
1174 if [ -z "${fstype}" ]
1176 fstype="${imagename##*.}"
1177 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1180 mkdir -p "${croot}/${imagename}"
1181 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1182 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}"
1187 # we have a plain root system
1188 mkdir -p "${croot}/filesystem"
1189 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1190 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}"
1192 mount -o bind ${croot}/filesystem $mountpoint
1196 rofsstring=${rofsstring%:}
1200 # Looking for "${root_persistence}" device or file
1201 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1203 if [ -z "${QUICKUSBMODULES}" ]
1206 num_block=$(ls -l /sys/block | wc -l)
1207 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1209 modprobe -q -b ${module}
1215 # For some reason, udevsettle does not block in this scenario,
1216 # so we sleep for a little while.
1218 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1219 for timeout in 5 4 3 2 1
1223 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1230 # search for label and files (this could be hugely optimized)
1231 cowprobe=$(find_cow_device "${root_persistence}")
1232 if [ -b "${cowprobe}" ]
1234 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1235 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1236 # snapshots to be sure to really store some e.g key config files,
1237 # but not on the same media
1238 blacklistdev="${cowprobe}"
1239 PERSISTENCE_IS_ON="1"
1240 export PERSISTENCE_IS_ON
1242 # homecow just mount something on /home, this should be generalized some way
1243 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1244 if [ -b "${homecow}" ]
1246 PERSISTENCE_IS_ON="1"
1247 export PERSISTENCE_IS_ON
1249 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1250 # This second type should be removed when snapshot will get smarter,
1251 # hence when "/etc/live-snapshot*list" will be supported also by
1252 # ext2|ext3|ext4|jffs2 snapshot types.
1253 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1255 if [ -b "${cowprobe}" ]
1257 cowdevice=${cowprobe}
1258 cow_fstype=$(get_fstype "${cowprobe}")
1259 cow_mountopt="rw,noatime"
1261 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1263 fsck -y ${cowdevice}
1266 log_warning_msg "Unable to find the persistent medium"
1269 cow_mountopt="rw,noatime,mode=755"
1271 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1273 # check if there are any nfs options
1274 if echo ${NFS_COW}|grep -q ','
1276 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1277 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1279 nfs_cow_opts="-o nolock"
1285 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1288 panic "unable to determine mac address"
1293 cow_mountopt="rw,noatime,mode=755"
1296 if [ "${cow_fstype}" = "nfs" ]
1299 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1300 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1301 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1303 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1304 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1307 rofscount=$(echo ${rofslist} |wc -w)
1309 if [ -n "${EXPOSED_ROOT}" ]
1311 if [ ${rofscount} -ne 1 ]
1313 panic "only one RO file system supported with exposedroot: ${rofslist}"
1315 exposedrootfs=${rofslist%% }
1317 mount --bind ${exposedrootfs} ${rootmnt} || \
1318 panic "bind mount of ${exposedrootfs} failed"
1320 if [ -z "${SKIP_UNION_MOUNTS}" ]
1322 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1327 for dir in ${cow_dirs}; do
1330 case "${UNIONTYPE}" in
1332 (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}")
1333 mkdir -p /dev/.initramfs/varrun
1334 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1338 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"
1343 case "${UNIONTYPE}" in
1345 (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}")
1346 mkdir -p /dev/.initramfs/varrun
1347 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1351 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}"
1356 # Correct the permissions of /:
1357 chmod 0755 "${rootmnt}"
1359 # tmpfs file systems
1361 mkdir -p "${rootmnt}/live"
1362 mount -t tmpfs tmpfs ${rootmnt}/live
1364 # Adding other custom mounts
1365 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1367 # directly mount /home
1368 # FIXME: add a custom mounts configurable system
1370 if [ -b "${homecow}" ]
1372 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1373 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1375 log_warning_msg "Unable to find the persistent home medium"
1378 # Look for other snapshots to copy in
1379 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1380 # This second type should be removed when snapshot grow smarter
1381 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1384 if [ -n "${SHOWMOUNTS}" ]
1386 for d in ${rofslist}
1388 mkdir -p "${rootmnt}/live/${d##*/}"
1392 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1396 case "${UNIONTYPE}" in
1398 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1402 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1410 # shows cow fs on /cow for use by live-snapshot
1411 mkdir -p "${rootmnt}/live/cow"
1412 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"
1419 skip_uuid_check="${3}"
1421 # support for fromiso=.../isofrom=....
1422 if [ -n "$FROMISO" ]
1424 ISO_DEVICE=$(dirname $FROMISO)
1425 if ! [ -b $ISO_DEVICE ]
1427 # to support unusual device names like /dev/cciss/c0d0p1
1428 # as well we have to identify the block device name, let's
1429 # do that for up to 15 levels
1431 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1433 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1434 [ -b "$ISO_DEVICE" ] && break
1439 if [ "$ISO_DEVICE" = "/" ]
1441 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1444 mount "$ISO_DEVICE" /isofrom
1445 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1446 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1447 devname="${loopdevname}"
1451 if [ -z "${devname}" ]
1453 devname=$(sys2dev "${sysdev}")
1456 if [ -d "${devname}" ]
1458 mount -o bind "${devname}" $mountpoint || continue
1460 if is_live_path $mountpoint
1468 [ -e "$devname" ] || continue
1470 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1472 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1473 devname="${loopdevname}"
1476 fstype=$(get_fstype "${devname}")
1478 if is_supported_fs ${fstype}
1480 devuid=$(blkid -o value -s UUID "$devname")
1481 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1482 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1483 [ -n "$devuid" ] && echo "$devuid" >> $tried
1485 if is_live_path ${mountpoint} && \
1486 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1491 umount ${mountpoint}
1495 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1497 losetup -d "${loopdevname}"
1507 # don't start autodetection before timeout has expired
1508 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1510 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1516 # first look at the one specified in the command line
1517 case "${LIVE_MEDIA}" in
1519 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1521 if [ "$(cat ${sysblock}/removable)" = "1" ]
1523 if readlink ${sysblock} | grep -q usb ||
1524 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1526 for dev in $(subdevices "${sysblock}")
1528 if check_dev "${dev}"
1540 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1542 if [ "$(cat ${sysblock}/removable)" = "1" ]
1544 for dev in $(subdevices "${sysblock}")
1546 if check_dev "${dev}"
1557 if [ ! -z "${LIVE_MEDIA}" ]
1559 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1567 # or do the scan of block devices
1568 # prefer removable devices over non-removable devices, so scan them first
1569 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1571 if [ "$(cat ${sysblock}/removable)" = "1" ]
1573 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1575 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1578 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1580 for sysblock in $devices_to_scan
1582 devname=$(sys2dev "${sysblock}")
1583 [ -e "$devname" ] || continue
1584 fstype=$(get_fstype "${devname}")
1586 if /lib/udev/cdrom_id ${devname} > /dev/null
1588 if check_dev "null" "${devname}"
1592 elif is_nice_device "${sysblock}"
1594 for dev in $(subdevices "${sysblock}")
1596 if check_dev "${dev}"
1601 elif [ "${fstype}" = "squashfs" -o \
1602 "${fstype}" = "ext2" -o \
1603 "${fstype}" = "ext3" -o \
1604 "${fstype}" = "ext4" -o \
1605 "${fstype}" = "jffs2" ]
1607 # This is an ugly hack situation, the block device has
1608 # an image directly on it. It's hopefully
1609 # live-boot, so take it and run with it.
1610 ln -s "${devname}" "${devname}.${fstype}"
1611 echo "${devname}.${fstype}"
1619 set_usplash_timeout ()
1621 if [ -x /sbin/usplash_write ]
1623 /sbin/usplash_write "TIMEOUT 120"
1624 else if [ -x /sbin/splashy_update ] ; then
1625 /sbin/splashy_update "TIMEOUT 120"
1631 media_mountpoint="${1}"
1633 log_begin_msg "Checking media integrity"
1635 cd ${media_mountpoint}
1636 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1641 if [ "${RC}" -eq 0 ]
1643 log_success_msg "Everything ok, will reboot in 10 seconds."
1646 umount ${media_mountpoint}
1648 echo u > /proc/sysrq-trigger
1649 echo b > /proc/sysrq-trigger
1651 panic "Not ok, a media defect is likely, switch to VT8 for details."
1655 start_usplash_pulse ()
1657 if [ -x /sbin/usplash_write ]
1659 /sbin/usplash_write "PULSELOGO"
1665 if [ -x /scripts/local-top/cryptroot ]; then
1666 /scripts/local-top/cryptroot
1673 tail -f live.log >&7 &
1676 # Ensure 'panic' function is overridden
1677 . /scripts/live-functions
1684 maybe_break live-premount
1685 log_begin_msg "Running /scripts/live-premount"
1686 run_scripts /scripts/live-premount
1689 # Needed here too because some things (*cough* udev *cough*)
1690 # changes the timeout
1694 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1698 livefs_root="${mountpoint}"
1700 panic "Unable to find a live file system on the network"
1703 if [ -n "${ISCSI_PORTAL}" ]
1705 do_iscsi && livefs_root="${mountpoint}"
1706 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1708 # Do a local boot from hd
1711 if [ -x /usr/bin/memdiskfind ]
1713 MEMDISK=$(/usr/bin/memdiskfind)
1717 # We found a memdisk, set up phram
1718 modprobe phram phram=memdisk,${MEMDISK}
1720 # Load mtdblock, the memdisk will be /dev/mtdblock0
1725 # Scan local devices for the image
1727 while [ "$i" -lt 60 ]
1729 livefs_root=$(find_livefs ${i})
1731 if [ -n "${livefs_root}" ]
1742 if [ -z "${livefs_root}" ]
1744 panic "Unable to find a medium containing a live file system"
1747 if [ "${INTEGRITY_CHECK}" ]
1749 integrity_check "${livefs_root}"
1755 elif [ "${TODISK}" ]
1757 live_dest="${TODISK}"
1760 if [ "${live_dest}" ]
1762 log_begin_msg "Copying live media to ${live_dest}"
1763 copy_live_to "${livefs_root}" "${live_dest}"
1767 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1768 # because the mountpoint is left behind in /proc/mounts, so let's get
1769 # rid of it when running from RAM
1770 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1772 losetup -d /dev/loop0
1773 grep -q /isofrom /proc/mounts && umount /isofrom
1776 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1778 setup_unionfs "${livefs_root}" "${rootmnt}"
1781 mac="$(echo ${mac} | sed 's/-//g')"
1782 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1787 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1788 # live-bottom; udev's init script will take care of things after that
1789 if [ "${UNIONTYPE}" = unionfs-fuse ]
1791 mount -n -o bind /dev "${rootmnt}/dev"
1794 # Move to the new root filesystem so that programs there can get at it.
1795 if [ ! -d /root/live/image ]
1797 mkdir -p /root/live/image
1798 mount --move /live/image /root/live/image
1801 maybe_break live-bottom
1802 log_begin_msg "Running /scripts/live-bottom\n"
1804 run_scripts /scripts/live-bottom
1807 if [ "${UNIONFS}" = unionfs-fuse ]
1809 umount "${rootmnt}/dev"
1815 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null