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
249 PERSISTENT="${ARGUMENT#persistent=}"
250 if [ -z "${PERSISTENT}" ]
258 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
259 export PERSISTENT_PATH
262 persistent-subtext=*)
263 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
264 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
265 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
266 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
275 QUICKUSBMODULES="Yes"
276 export QUICKUSBMODULES
279 preseed/file=*|file=*)
280 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
290 question="${ARGUMENT%%=*}"
291 value="${ARGUMENT#*=}"
292 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
307 TODISK="${ARGUMENT#todisk=}"
318 MODULETORAM="${ARGUMENT#toram=}"
319 export TORAM MODULETORAM
333 SKIP_UNION_MOUNTS="Yes"
334 export SKIP_UNION_MOUNTS
338 ROOT="${ARGUMENT#root=}"
343 UNIONTYPE="${ARGUMENT#union=}"
349 # sort of compatibility with netboot.h from linux docs
350 if [ -z "${NETBOOT}" ]
352 if [ "${ROOT}" = "/dev/nfs" ]
356 elif [ "${ROOT}" = "/dev/cifs" ]
363 if [ -z "${MODULE}" ]
369 if [ -z "${UNIONTYPE}" ]
380 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
382 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
384 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
396 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
402 uuid="$(cat /conf/uuid.conf)"
404 for try_uuid_file in "${path}/.disk/live-uuid"*
406 [ -e "${try_uuid_file}" ] || continue
408 try_uuid="$(cat "${try_uuid_file}")"
410 if [ "${uuid}" = "${try_uuid}" ]
419 get_backing_device ()
422 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
423 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
431 panic "Unrecognized live filesystem: ${1}"
436 match_files_in_dir ()
438 # Does any files match pattern ${1} ?
441 if [ "$(echo ${pattern})" != "${pattern}" ]
449 mount_images_in_directory ()
456 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
457 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
458 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
459 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
460 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
461 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
463 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
464 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
466 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
472 sysfs_path="${1#/sys}"
474 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
477 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
480 elif echo ${sysfs_path} | grep -q "^/block/dm-"
492 copyto="${copyfrom}_swap"
494 if [ -z "${MODULETORAM}" ]
496 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
498 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
500 if [ -f "${MODULETORAMFILE}" ]
502 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
504 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
509 if [ "${copytodev}" = "ram" ]
512 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
513 mount_options="-o size=${size}k"
518 # it should be a writable block device
519 if [ -b "${copytodev}" ]
523 fstype=$(get_fstype "${dev}")
524 freespace=$(fs_size "${dev}")
526 log_warning_msg "${copytodev} is not a block device."
531 if [ "${freespace}" -lt "${size}" ]
533 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
537 # begin copying (or uncompressing)
539 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
540 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
542 if [ "${extension}" = "tgz" ]
545 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
546 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
547 mount -r -o move "${copyto}" "${rootmnt}"
550 if [ -n "${MODULETORAMFILE}" ]
554 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
555 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
557 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
562 echo " * Copying whole medium to RAM" 1>/dev/console
563 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
565 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
566 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
567 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
569 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
575 mount -r -o move ${copyto} ${copyfrom}
584 modprobe -q af_packet # For DHCP
589 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
590 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
593 # if ethdevice was not specified on the kernel command line
594 # make sure we try to get a working network configuration
595 # for *every* present network device (except for loopback of course)
596 if [ -z "$ETHDEVICE" ] ; then
597 echo "If you want to boot from a specific device use bootoption ethdevice=..."
598 for device in /sys/class/net/*; do
600 if [ "$dev" != "lo" ] ; then
601 ETHDEVICE="$ETHDEVICE $dev"
606 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
607 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
608 devlist="$devlist $device"
611 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
612 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
614 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
615 # an endless loop; iff execution fails give it two further tries, that's
616 # why we use '$devlist $devlist $devlist' for the other for loop
617 for dev in $devlist $devlist $devlist ; do
618 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
619 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
621 sleep "$ETHDEV_TIMEOUT" ; sleep 1
622 if [ -r /proc/"$jobid"/status ] ; then
623 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
627 # if configuration of device worked we should have an assigned
628 # IP address, iff so let's use the according as $DEVICE for later usage
629 # simple and primitive approach which seems to work fine
630 if ifconfig $dev | grep -q 'inet.*addr:' ; then
637 ipconfig ${DEVICE} | tee /netboot.config
640 # source relevant ipconfig output
641 OLDHOSTNAME=${HOSTNAME}
642 . /tmp/net-${DEVICE}.conf
643 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
646 if [ -n "${DEVICE}" ]
648 HWADDR="$(cat /sys/class/net/${DEVICE}/address)"
651 # Check if we have a network device at all
652 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
653 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
654 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
655 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
656 ! ls /sys/class/net/ra0 > /dev/null 2>&1
658 panic "No supported network device found, maybe a non-mainline driver is required."
666 if [ "${NFSROOT}" = "auto" ]
668 NFSROOT=${ROOTSERVER}:${ROOTPATH}
673 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
679 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
681 NFSROOT=${ROOTSERVER}:${NFSROOT}
684 log_begin_msg "Trying netboot from ${NFSROOT}"
686 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
706 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
707 #FIXME this name is supposed to be unique - some date + ifconfig hash?
708 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
709 export ISCSI_INITIATORNAME
710 if [ -n "${ISCSI_SERVER}" ] ; then
711 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
713 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
717 panic "Failed to log into iscsi target"
719 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
720 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
725 while [ -z "${devices}" -a $i -lt 60 ]
728 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
729 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
735 if check_dev "null" "/dev/$dev"
742 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
744 panic "Failed to locate iSCSI host in /sys"
752 for webfile in HTTPFS FTPFS FETCH
754 local url="$(eval echo \"\$\{${webfile}\}\")"
755 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
759 case "${extension}" in
760 iso|squashfs|tgz|tar)
761 if [ "${extension}" = "iso" ]
763 mkdir -p "${alt_mountpoint}"
764 dest="${alt_mountpoint}"
766 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
767 mount -t ramfs ram "${mountpoint}"
770 if [ "${webfile}" = "FETCH" ]
774 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
775 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
776 lfile="$(basename $url)"
777 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
778 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
782 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
783 wget "${url}" -O "${dest}/$(basename ${url})"
787 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
788 if [ "${webfile}" = "FTPFS" ]
790 FUSE_MOUNT="curlftpfs"
791 url="$(dirname ${url})"
796 $FUSE_MOUNT "${url}" "${dest}"
797 FUSE_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
799 [ ${?} -eq 0 ] && rc=0
800 [ "${extension}" = "tgz" ] && live_dest="ram"
801 if [ "${extension}" = "iso" ]
803 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
804 mount -t iso9660 "${isoloop}" "${mountpoint}"
811 log_begin_msg "Unrecognized archive extension for ${url}"
819 if [ -d "${alt_mountpoint}" ]
821 umount "${alt_mountpoint}"
822 rmdir "${alt_mountpoint}"
824 umount "${mountpoint}"
825 elif [ "${webfile}" != "FETCH" ] ; then
828 if [ -n "${FUSE_PID}" ] ; then
829 echo "${FUSE_PID}" > ${mountpoint}/root.pid
842 if [ -z "${NFSOPTS}" ]
847 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
849 # FIXME: This while loop is an ugly HACK round an nfs bug
851 while [ "$i" -lt 60 ]
853 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
865 if [ -x "/sbin/mount.cifs" ]
867 if [ -z "${NFSOPTS}" ]
869 CIFSOPTS="-ouser=root,password="
871 CIFSOPTS="${NFSOPTS}"
874 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
877 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
891 size=$(fs_size "${fromdev}" "" "used")
893 if [ -b "${fromdev}" ]
896 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
898 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
899 freespace=$(df -k | awk '/'${todev}'/{print $4}')
901 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
904 tomount="/mnt/tmpsnap"
906 if [ ! -d "${tomount}" ]
908 mkdir -p "${tomount}"
911 fstype=$(get_fstype "${fromdev}")
913 if [ -n "${fstype}" ]
916 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
917 cp -a "${tomount}"/* ${todir}
920 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
925 if echo ${fromdev} | grep -qs loop
927 losetup -d "${fromdev}"
934 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
940 # Look for ${snap_label}.* in block devices
943 if [ "${PERSISTENT}" != "nofiles" ]
945 # search for image files
946 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")
949 if [ -z "${snapdata}" ]
951 snapdata=$(find_cow_device "${snap_label}")
958 # copy the contents of previously found snapshot to ${snap_mount}
959 # and remember the device and filename for resync on exit in live-boot.init
965 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
967 log_success_msg "found snapshot: ${snapdata}"
968 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
969 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
970 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
973 if ! try_mount "${snapdev}" "${snapback}" "ro"
978 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
980 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
981 dev=$(get_backing_device "${snapback}/${snapfile}")
983 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
988 # Unfortunately klibc's cpio is incompatible with the
989 # rest of the world; everything else requires -u -d,
990 # while klibc doesn't implement them. Try to detect
991 # whether it's in use.
992 cpiopath="$(which cpio)" || true
993 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
997 cpioargs='--unconditional --make-directories'
1000 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1002 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1006 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1008 if [ "${RES}" != "0" ]
1010 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1013 elif [ -b "${snapdata}" ]
1015 # Try to find if it could be a snapshot partition
1017 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1018 if echo "${dev}" | grep -qs loop
1020 # strange things happens, user confused?
1021 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1022 snapfile=$(basename ${snaploop})
1023 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1028 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1030 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1033 if [ -n "${snapfile}" ]
1035 # it was a loop device, user confused
1040 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1044 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1050 image_directory="${1}"
1052 addimage_directory="${3}"
1054 case ${UNIONTYPE} in
1056 modprobe -q -b ${UNIONTYPE}
1058 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1060 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1061 echo "This might be really slow."
1063 UNIONTYPE="unionfs-fuse"
1068 if [ "${UNIONTYPE}" = unionfs-fuse ]
1073 # run-init can't deal with images in a subdir, but we're going to
1074 # move all of these away before it runs anyway. No, we're not,
1075 # put them in / since move-mounting them into / breaks mono and
1080 # Let's just mount the read-only file systems first
1084 if [ "${UNIONTYPE}" = "aufs" ]
1087 noxino_opt="noxino,"
1088 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1095 if [ -z "${PLAIN_ROOT}" ]
1097 # Read image names from ${MODULE}.module if it exists
1098 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1100 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1102 image_string="${image_string} ${image_directory}/${IMAGE}"
1104 elif [ -e "${image_directory}/${MODULE}.module" ]
1106 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1108 image_string="${image_string} ${image_directory}/${IMAGE}"
1111 # ${MODULE}.module does not exist, create a list of images
1112 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1114 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1116 if [ -e "${IMAGE}" ]
1118 image_string="${image_string} ${IMAGE}"
1123 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1125 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1127 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1129 if [ -e "${IMAGE}" ]
1131 image_string="${image_string} ${IMAGE}"
1138 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1141 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1145 for image in ${image_string}
1147 imagename=$(basename "${image}")
1149 export image devname
1150 maybe_break live-realpremount
1151 log_begin_msg "Running /scripts/live-realpremount"
1152 run_scripts /scripts/live-realpremount
1155 if [ -d "${image}" ]
1157 # it is a plain directory: do nothing
1158 rofsstring="${image}=${roopt}:${rofsstring}"
1159 rofslist="${image} ${rofslist}"
1160 elif [ -f "${image}" ]
1162 if losetup --help 2>&1 | grep -q -- "-r\b"
1164 backdev=$(get_backing_device "${image}" "-r")
1166 backdev=$(get_backing_device "${image}")
1168 fstype=$(get_fstype "${backdev}")
1170 if [ "${fstype}" = "unknown" ]
1172 panic "Unknown file system type on ${backdev} (${image})"
1175 if [ -z "${fstype}" ]
1177 fstype="${imagename##*.}"
1178 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1181 mkdir -p "${croot}/${imagename}"
1182 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1183 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}"
1188 # we have a plain root system
1189 mkdir -p "${croot}/filesystem"
1190 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1191 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}"
1193 mount -o bind ${croot}/filesystem $mountpoint
1197 rofsstring=${rofsstring%:}
1201 # Looking for "${root_persistence}" device or file
1202 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1204 if [ -z "${QUICKUSBMODULES}" ]
1207 num_block=$(ls -l /sys/block | wc -l)
1208 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1210 modprobe -q -b ${module}
1216 # For some reason, udevsettle does not block in this scenario,
1217 # so we sleep for a little while.
1219 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1220 for timeout in 5 4 3 2 1
1224 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1231 # search for label and files (this could be hugely optimized)
1232 cowprobe=$(find_cow_device "${root_persistence}")
1233 if [ -b "${cowprobe}" ]
1235 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1236 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1237 # snapshots to be sure to really store some e.g key config files,
1238 # but not on the same media
1239 blacklistdev="${cowprobe}"
1240 PERSISTENCE_IS_ON="1"
1241 export PERSISTENCE_IS_ON
1243 # homecow just mount something on /home, this should be generalized some way
1244 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1245 if [ -b "${homecow}" ]
1247 PERSISTENCE_IS_ON="1"
1248 export PERSISTENCE_IS_ON
1250 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1251 # This second type should be removed when snapshot will get smarter,
1252 # hence when "/etc/live-snapshot*list" will be supported also by
1253 # ext2|ext3|ext4|jffs2 snapshot types.
1254 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1256 if [ -b "${cowprobe}" ]
1258 cowdevice=${cowprobe}
1259 cow_fstype=$(get_fstype "${cowprobe}")
1260 cow_mountopt="rw,noatime"
1262 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1264 fsck -y ${cowdevice}
1267 log_warning_msg "Unable to find the persistent medium"
1270 cow_mountopt="rw,noatime,mode=755"
1272 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1274 # check if there are any nfs options
1275 if echo ${NFS_COW}|grep -q ','
1277 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1278 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1280 nfs_cow_opts="-o nolock"
1286 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1289 panic "unable to determine mac address"
1294 cow_mountopt="rw,noatime,mode=755"
1297 if [ "${cow_fstype}" = "nfs" ]
1300 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1301 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1302 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1304 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1305 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1308 rofscount=$(echo ${rofslist} |wc -w)
1310 if [ -n "${EXPOSED_ROOT}" ]
1312 if [ ${rofscount} -ne 1 ]
1314 panic "only one RO file system supported with exposedroot: ${rofslist}"
1316 exposedrootfs=${rofslist%% }
1318 mount --bind ${exposedrootfs} ${rootmnt} || \
1319 panic "bind mount of ${exposedrootfs} failed"
1321 if [ -z "${SKIP_UNION_MOUNTS}" ]
1323 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1328 for dir in ${cow_dirs}; do
1331 case "${UNIONTYPE}" in
1333 (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}")
1334 mkdir -p /dev/.initramfs/varrun
1335 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1339 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"
1344 case "${UNIONTYPE}" in
1346 (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}")
1347 mkdir -p /dev/.initramfs/varrun
1348 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1352 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}"
1357 # Correct the permissions of /:
1358 chmod 0755 "${rootmnt}"
1360 # tmpfs file systems
1362 mkdir -p "${rootmnt}/live"
1363 mount -t tmpfs tmpfs ${rootmnt}/live
1365 # Adding other custom mounts
1366 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1368 # directly mount /home
1369 # FIXME: add a custom mounts configurable system
1371 if [ -b "${homecow}" ]
1373 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1374 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1376 log_warning_msg "Unable to find the persistent home medium"
1379 # Look for other snapshots to copy in
1380 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1381 # This second type should be removed when snapshot grow smarter
1382 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1385 if [ -n "${SHOWMOUNTS}" ]
1387 for d in ${rofslist}
1389 mkdir -p "${rootmnt}/live/${d##*/}"
1393 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1397 case "${UNIONTYPE}" in
1399 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1403 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1411 # shows cow fs on /cow for use by live-snapshot
1412 mkdir -p "${rootmnt}/live/cow"
1413 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"
1420 skip_uuid_check="${3}"
1422 # support for fromiso=.../isofrom=....
1423 if [ -n "$FROMISO" ]
1425 ISO_DEVICE=$(dirname $FROMISO)
1426 if ! [ -b $ISO_DEVICE ]
1428 # to support unusual device names like /dev/cciss/c0d0p1
1429 # as well we have to identify the block device name, let's
1430 # do that for up to 15 levels
1432 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1434 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1435 [ -b "$ISO_DEVICE" ] && break
1440 if [ "$ISO_DEVICE" = "/" ]
1442 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1445 mount "$ISO_DEVICE" /isofrom
1446 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1447 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1448 devname="${loopdevname}"
1452 if [ -z "${devname}" ]
1454 devname=$(sys2dev "${sysdev}")
1457 if [ -d "${devname}" ]
1459 mount -o bind "${devname}" $mountpoint || continue
1461 if is_live_path $mountpoint
1469 [ -e "$devname" ] || continue
1471 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1473 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1474 devname="${loopdevname}"
1477 fstype=$(get_fstype "${devname}")
1479 if is_supported_fs ${fstype}
1481 devuid=$(blkid -o value -s UUID "$devname")
1482 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1483 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1484 [ -n "$devuid" ] && echo "$devuid" >> $tried
1486 if is_live_path ${mountpoint} && \
1487 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1492 umount ${mountpoint}
1496 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1498 losetup -d "${loopdevname}"
1508 # don't start autodetection before timeout has expired
1509 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1511 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1517 # first look at the one specified in the command line
1518 case "${LIVE_MEDIA}" in
1520 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1522 if [ "$(cat ${sysblock}/removable)" = "1" ]
1524 if readlink ${sysblock} | grep -q usb ||
1525 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1527 for dev in $(subdevices "${sysblock}")
1529 if check_dev "${dev}"
1541 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1543 if [ "$(cat ${sysblock}/removable)" = "1" ]
1545 for dev in $(subdevices "${sysblock}")
1547 if check_dev "${dev}"
1558 if [ ! -z "${LIVE_MEDIA}" ]
1560 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1568 # or do the scan of block devices
1569 # prefer removable devices over non-removable devices, so scan them first
1570 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1572 if [ "$(cat ${sysblock}/removable)" = "1" ]
1574 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1576 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1579 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1581 for sysblock in $devices_to_scan
1583 devname=$(sys2dev "${sysblock}")
1584 [ -e "$devname" ] || continue
1585 fstype=$(get_fstype "${devname}")
1587 if /lib/udev/cdrom_id ${devname} > /dev/null
1589 if check_dev "null" "${devname}"
1593 elif is_nice_device "${sysblock}"
1595 for dev in $(subdevices "${sysblock}")
1597 if check_dev "${dev}"
1602 elif [ "${fstype}" = "squashfs" -o \
1603 "${fstype}" = "ext2" -o \
1604 "${fstype}" = "ext3" -o \
1605 "${fstype}" = "ext4" -o \
1606 "${fstype}" = "jffs2" ]
1608 # This is an ugly hack situation, the block device has
1609 # an image directly on it. It's hopefully
1610 # live-boot, so take it and run with it.
1611 ln -s "${devname}" "${devname}.${fstype}"
1612 echo "${devname}.${fstype}"
1620 set_usplash_timeout ()
1622 if [ -x /sbin/usplash_write ]
1624 /sbin/usplash_write "TIMEOUT 120"
1625 else if [ -x /sbin/splashy_update ] ; then
1626 /sbin/splashy_update "TIMEOUT 120"
1632 media_mountpoint="${1}"
1634 log_begin_msg "Checking media integrity"
1636 cd ${media_mountpoint}
1637 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1642 if [ "${RC}" -eq 0 ]
1644 log_success_msg "Everything ok, will reboot in 10 seconds."
1647 umount ${media_mountpoint}
1649 echo u > /proc/sysrq-trigger
1650 echo b > /proc/sysrq-trigger
1652 panic "Not ok, a media defect is likely, switch to VT8 for details."
1656 start_usplash_pulse ()
1658 if [ -x /sbin/usplash_write ]
1660 /sbin/usplash_write "PULSELOGO"
1666 if [ -x /scripts/local-top/cryptroot ]; then
1667 /scripts/local-top/cryptroot
1674 tail -f live.log >&7 &
1677 # Ensure 'panic' function is overridden
1678 . /scripts/live-functions
1685 maybe_break live-premount
1686 log_begin_msg "Running /scripts/live-premount"
1687 run_scripts /scripts/live-premount
1690 # Needed here too because some things (*cough* udev *cough*)
1691 # changes the timeout
1695 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1699 livefs_root="${mountpoint}"
1701 panic "Unable to find a live file system on the network"
1704 if [ -n "${ISCSI_PORTAL}" ]
1706 do_iscsi && livefs_root="${mountpoint}"
1707 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1709 # Do a local boot from hd
1712 # Scan local devices for the image
1714 while [ "$i" -lt 60 ]
1716 livefs_root=$(find_livefs ${i})
1718 if [ -n "${livefs_root}" ]
1729 if [ -z "${livefs_root}" ]
1731 panic "Unable to find a medium containing a live file system"
1734 if [ "${INTEGRITY_CHECK}" ]
1736 integrity_check "${livefs_root}"
1742 elif [ "${TODISK}" ]
1744 live_dest="${TODISK}"
1747 if [ "${live_dest}" ]
1749 log_begin_msg "Copying live media to ${live_dest}"
1750 copy_live_to "${livefs_root}" "${live_dest}"
1754 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1755 # because the mountpoint is left behind in /proc/mounts, so let's get
1756 # rid of it when running from RAM
1757 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1759 losetup -d /dev/loop0
1760 grep -q /isofrom /proc/mounts && umount /isofrom
1763 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1765 setup_unionfs "${livefs_root}" "${rootmnt}"
1768 mac="$(echo ${mac} | sed 's/-//g')"
1769 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1774 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1775 # live-bottom; udev's init script will take care of things after that
1776 if [ "${UNIONTYPE}" = unionfs-fuse ]
1778 mount -n -o bind /dev "${rootmnt}/dev"
1781 # Move to the new root filesystem so that programs there can get at it.
1782 if [ ! -d /root/live/image ]
1784 mkdir -p /root/live/image
1785 mount --move /live/image /root/live/image
1788 maybe_break live-bottom
1789 log_begin_msg "Running /scripts/live-bottom\n"
1791 run_scripts /scripts/live-bottom
1794 if [ "${UNIONFS}" = unionfs-fuse ]
1796 umount "${rootmnt}/dev"
1802 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null