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"
16 mkdir -p "${mountpoint}"
19 # Create /etc/mtab for debug purpose and future syncs
30 . /scripts/live-helpers
32 if [ ! -f /live.vars ]
41 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
43 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
45 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
57 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
63 uuid="$(cat /conf/uuid.conf)"
65 for try_uuid_file in "${path}/.disk/live-uuid"*
67 [ -e "${try_uuid_file}" ] || continue
69 try_uuid="$(cat "${try_uuid_file}")"
71 if [ "${uuid}" = "${try_uuid}" ]
83 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
84 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
92 panic "Unrecognized live filesystem: ${1}"
99 # Does any files match pattern ${1} ?
102 if [ "$(echo ${pattern})" != "${pattern}" ]
110 mount_images_in_directory ()
117 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
118 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
119 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
120 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
121 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
122 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
124 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
125 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
127 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
133 sysfs_path="${1#/sys}"
135 if [ -e /lib/udev/path_id ]
138 PATH_ID="/lib/udev/path_id"
140 # wheezy/sid (udev >= 174)
141 PATH_ID="/sbin/udevadm test-builtin path_id"
144 if ${PATH_ID} "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)"
147 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
150 elif echo ${sysfs_path} | grep -q "^/block/dm-"
153 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
165 copyto="${copyfrom}_swap"
167 if [ -z "${MODULETORAM}" ]
169 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
171 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
173 if [ -f "${MODULETORAMFILE}" ]
175 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
177 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
182 if [ "${copytodev}" = "ram" ]
185 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
186 mount_options="-o size=${size}k"
191 # it should be a writable block device
192 if [ -b "${copytodev}" ]
196 fstype=$(get_fstype "${dev}")
197 freespace=$(fs_size "${dev}")
199 log_warning_msg "${copytodev} is not a block device."
204 if [ "${freespace}" -lt "${size}" ]
206 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
210 # Custom ramdisk size
211 if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ]
213 # FIXME: should check for wrong values
214 mount_options="-o size=${ramdisk_size}"
217 # begin copying (or uncompressing)
219 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
220 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
222 if [ "${extension}" = "tgz" ]
225 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
226 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
227 mount -r -o move "${copyto}" "${rootmnt}"
230 if [ -n "${MODULETORAMFILE}" ]
234 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
235 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
237 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
242 echo " * Copying whole medium to RAM" 1>/dev/console
243 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
245 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
246 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
247 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
249 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
255 mount -r -o move ${copyto} ${copyfrom}
264 modprobe -q af_packet # For DHCP
269 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
270 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
272 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
273 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
277 # support for Syslinux IPAPPEND parameter
278 # it sets the BOOTIF variable on the kernel parameter
280 if [ -n "${BOOTIF}" ]
282 # pxelinux sets BOOTIF to a value based on the mac address of the
283 # network card used to PXE boot, so use this value for DEVICE rather
284 # than a hard-coded device name from initramfs.conf. this facilitates
285 # network booting when machines may have multiple network cards.
286 # pxelinux sets BOOTIF to 01-$mac_address
288 # strip off the leading "01-", which isn't part of the mac
290 temp_mac=${BOOTIF#*-}
292 # convert to typical mac address format by replacing "-" with ":"
297 if [ -z "$bootif_mac" ]
301 bootif_mac="$bootif_mac:$x"
306 # look for devices with matching mac address, and set DEVICE to
307 # appropriate value if match is found.
309 for device in /sys/class/net/*
311 if [ -f "$device/address" ]
313 current_mac=$(cat "$device/address")
315 if [ "$bootif_mac" = "$current_mac" ]
324 # if ethdevice was not specified on the kernel command line
325 # make sure we try to get a working network configuration
326 # for *every* present network device (except for loopback of course)
327 if [ -z "$ETHDEVICE" ] ; then
328 echo "If you want to boot from a specific device use bootoption ethdevice=..."
329 for device in /sys/class/net/*; do
331 if [ "$dev" != "lo" ] ; then
332 ETHDEVICE="$ETHDEVICE $dev"
337 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
338 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
339 devlist="$devlist $device"
342 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
343 # an endless loop; if execution fails give it two further tries, that's
344 # why we use '$devlist $devlist $devlist' for the other for loop
345 for dev in $devlist $devlist $devlist ; do
346 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
347 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
349 sleep "$ETHDEV_TIMEOUT" ; sleep 1
350 if [ -r /proc/"$jobid"/status ] ; then
351 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
355 # if configuration of device worked we should have an assigned
356 # IP address, if so let's use the device as $DEVICE for later usage.
357 # simple and primitive approach which seems to work fine
358 if ifconfig $dev | grep -q 'inet.*addr:' ; then
365 for interface in ${DEVICE}; do
366 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
367 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
368 if [ "$IPV4ADDR" != "0.0.0.0" ]
375 for interface in ${DEVICE}; do
376 # source relevant ipconfig output
377 OLDHOSTNAME=${HOSTNAME}
378 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
379 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
382 if [ -n "${interface}" ]
384 HWADDR="$(cat /sys/class/net/${interface}/address)"
387 if [ ! -e "/etc/resolv.conf" ]
389 echo "Creating /etc/resolv.conf"
391 if [ -n "${DNSDOMAIN}" ]
393 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
394 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
397 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
399 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
401 echo "nameserver $i" >> /etc/resolv.conf
406 # Check if we have a network device at all
407 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
408 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
409 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
410 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
411 ! ls /sys/class/net/ra0 > /dev/null 2>&1
413 panic "No supported network device found, maybe a non-mainline driver is required."
422 if [ "${NFSROOT}" = "auto" ]
424 NFSROOT=${ROOTSERVER}:${ROOTPATH}
429 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
435 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
437 NFSROOT=${ROOTSERVER}:${NFSROOT}
440 log_begin_msg "Trying netboot from ${NFSROOT}"
442 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
462 [ "${DEBUG}" = "Yes" ] && debugopt="-d 8"
463 #FIXME this name is supposed to be unique - some date + ifconfig hash?
464 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
465 export ISCSI_INITIATORNAME
466 if [ -n "${ISCSI_SERVER}" ] ; then
467 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
469 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
473 panic "Failed to log into iscsi target"
475 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
476 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
481 while [ -z "${devices}" -a $i -lt 60 ]
484 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
485 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
491 if check_dev "null" "/dev/$dev"
498 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
500 panic "Failed to locate iSCSI host in /sys"
508 for webfile in HTTPFS FTPFS FETCH
510 local url="$(eval echo \"\$\{${webfile}\}\")"
511 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
515 case "${extension}" in
516 iso|squashfs|tgz|tar)
517 if [ "${extension}" = "iso" ]
519 mkdir -p "${alt_mountpoint}"
520 dest="${alt_mountpoint}"
522 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
523 mount -t ramfs ram "${mountpoint}"
526 if [ "${webfile}" = "FETCH" ]
530 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
531 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
532 lfile="$(basename $url)"
533 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
534 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
538 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
539 wget "${url}" -O "${dest}/$(basename ${url})"
543 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
544 if [ "${webfile}" = "FTPFS" ]
546 FUSE_MOUNT="curlftpfs"
547 url="$(dirname ${url})"
552 $FUSE_MOUNT "${url}" "${dest}"
553 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
555 [ ${?} -eq 0 ] && rc=0
556 [ "${extension}" = "tgz" ] && live_dest="ram"
557 if [ "${extension}" = "iso" ]
559 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
560 mount -t iso9660 "${isoloop}" "${mountpoint}"
567 log_begin_msg "Unrecognized archive extension for ${url}"
575 if [ -d "${alt_mountpoint}" ]
577 umount "${alt_mountpoint}"
578 rmdir "${alt_mountpoint}"
580 umount "${mountpoint}"
581 elif [ "${webfile}" != "FETCH" ] ; then
595 if [ -n "${NFSOPTS}" ]
597 NFSOPTS="-o ${NFSOPTS}"
600 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
602 # FIXME: This while loop is an ugly HACK round an nfs bug
604 while [ "$i" -lt 60 ]
606 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
618 if [ -x "/sbin/mount.cifs" ]
620 if [ -z "${NFSOPTS}" ]
622 CIFSOPTS="-ouser=root,password="
624 CIFSOPTS="-o ${NFSOPTS}"
627 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
630 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
644 size=$(fs_size "${fromdev}" "" "used")
646 if [ -b "${fromdev}" ]
648 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
651 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
653 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
654 freespace=$(df -k | awk '/'${todev}'/{print $4}')
656 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
659 tomount="/mnt/tmpsnap"
661 if [ ! -d "${tomount}" ]
663 mkdir -p "${tomount}"
666 fstype=$(get_fstype "${fromdev}")
668 if [ -n "${fstype}" ]
671 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
672 cp -a "${tomount}"/* ${todir}
675 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
680 if echo ${fromdev} | grep -qs loop
682 losetup -d "${fromdev}"
687 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
694 # copy the contents of previously found snapshot to ${snap_mount}
695 # and remember the device and filename for resync on exit in live-boot.init
702 if [ -z "${snap_relpath}" ]
704 # root snapshot, default usage
707 # relative snapshot (actually used just for "/home" snapshots)
708 snap_mount="${2}${snap_relpath}"
711 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
713 log_success_msg "found snapshot: ${snapdata}"
714 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
715 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
716 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
718 if ! try_mount "${snapdev}" "${snapback}" "ro"
725 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
727 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
728 dev=$(get_backing_device "${snapback}/${snapfile}")
730 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
735 # Unfortunately klibc's cpio is incompatible with the
736 # rest of the world; everything else requires -u -d,
737 # while klibc doesn't implement them. Try to detect
738 # whether it's in use.
739 cpiopath="$(which cpio)" || true
740 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
744 cpioargs='--unconditional --make-directories'
747 if [ -s "${snapback}/${snapfile}" ]
750 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
754 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
758 if [ "${RES}" != "0" ]
760 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
764 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
766 if [ "${RES}" != "0" ]
768 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
771 elif [ -b "${snapdata}" ]
773 # Try to find if it could be a snapshot partition
775 log_success_msg "found snapshot ${snap_type} device on ${dev}"
776 if echo "${dev}" | grep -qs loop
778 # strange things happens, user confused?
779 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
780 snapfile=$(basename ${snaploop})
781 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
786 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
788 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
791 if [ -n "${snapfile}" ]
793 # it was a loop device, user confused
798 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
802 if [ -z ${PERSISTENCE_READONLY} ]
804 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
811 image_directory="${1}"
813 addimage_directory="${3}"
816 aufs|unionfs|overlayfs)
817 modprobe -q -b ${UNIONTYPE}
819 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
821 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
822 echo "This might be really slow."
824 UNIONTYPE="unionfs-fuse"
829 if [ "${UNIONTYPE}" = unionfs-fuse ]
834 # run-init can't deal with images in a subdir, but we're going to
835 # move all of these away before it runs anyway. No, we're not,
836 # put them in / since move-mounting them into / breaks mono and
841 # Let's just mount the read-only file systems first
844 if [ -z "${PLAIN_ROOT}" ]
846 # Read image names from ${MODULE}.module if it exists
847 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
849 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
851 image_string="${image_string} ${image_directory}/${IMAGE}"
853 elif [ -e "${image_directory}/${MODULE}.module" ]
855 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
857 image_string="${image_string} ${image_directory}/${IMAGE}"
860 # ${MODULE}.module does not exist, create a list of images
861 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
863 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
867 image_string="${image_string} ${IMAGE}"
872 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
874 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
876 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
880 image_string="${image_string} ${IMAGE}"
887 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
890 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
894 for image in ${image_string}
896 imagename=$(basename "${image}")
899 maybe_break live-realpremount
900 log_begin_msg "Running /scripts/live-realpremount"
901 run_scripts /scripts/live-realpremount
906 # it is a plain directory: do nothing
907 rofslist="${image} ${rofslist}"
908 elif [ -f "${image}" ]
910 if losetup --help 2>&1 | grep -q -- "-r\b"
912 backdev=$(get_backing_device "${image}" "-r")
914 backdev=$(get_backing_device "${image}")
916 fstype=$(get_fstype "${backdev}")
918 if [ "${fstype}" = "unknown" ]
920 panic "Unknown file system type on ${backdev} (${image})"
923 if [ -z "${fstype}" ]
925 fstype="${imagename##*.}"
926 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
929 if [ "${UNIONTYPE}" != "unionmount" ]
931 mpoint="${croot}/${imagename}"
932 rofslist="${mpoint} ${rofslist}"
935 rofslist="${rootmnt} ${rofslist}"
938 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
939 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
944 # we have a plain root system
945 mkdir -p "${croot}/filesystem"
946 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
947 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
948 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
949 rofslist="${croot}/filesystem ${rofslist}"
951 mount -o bind ${croot}/filesystem $mountpoint
958 mount -t tmpfs tmpfs /live
959 mkdir -p /live/overlay
961 # Looking for persistence devices or files
962 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
965 if [ -z "${QUICKUSBMODULES}" ]
968 num_block=$(ls -l /sys/block | wc -l)
969 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
971 modprobe -q -b ${module}
977 # For some reason, udevsettle does not block in this scenario,
978 # so we sleep for a little while.
980 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
981 for timeout in 5 4 3 2 1
985 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
992 case "${PERSISTENCE_MEDIA}" in
994 whitelistdev="$(removable_dev)"
997 whitelistdev="$(removable_usb_dev)"
1004 if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
1006 overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
1009 if is_in_comma_sep_list snapshot ${PERSISTENCE_METHOD}
1011 snapshots="${root_snapshot_label} ${home_snapshot_label}"
1014 local root_snapdata=""
1015 local home_snapdata=""
1016 local overlay_devices=""
1017 for media in $(find_persistence_media "${overlays}" "${snapshots}" "${whitelistdev}")
1019 media="$(echo ${media} | tr ":" " ")"
1021 ${root_snapshot_label}=*|${old_root_snapshot_label}=*)
1022 if [ -z "${root_snapdata}" ]
1024 root_snapdata="${media#*=}"
1027 ${home_snapshot_label}=*)
1028 # This second type should be removed when snapshot will get smarter,
1029 # hence when "/etc/live-snapshot*list" will be supported also by
1030 # ext2|ext3|ext4|jffs2 snapshot types.
1031 if [ -z "${home_snapdata}" ]
1033 home_snapdata="${media#*=}"
1036 ${old_root_overlay_label}=*)
1037 device="${media#*=}"
1038 fix_backwards_compatibility ${device} / union
1039 overlay_devices="${overlay_devices} ${device}"
1041 ${old_home_overlay_label}=*)
1042 device="${media#*=}"
1043 fix_backwards_compatibility ${device} /home bind
1044 overlay_devices="${overlay_devices} ${device}"
1046 ${custom_overlay_label}=*)
1047 device="${media#*=}"
1048 overlay_devices="${overlay_devices} ${device}"
1052 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
1054 # check if there are any nfs options
1055 if echo ${NFS_COW}|grep -q ','
1057 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1058 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1060 nfs_cow_opts="-o nolock"
1064 if [ -n "${PERSISTENCE_READONLY}" ]
1066 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
1072 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1075 panic "unable to determine mac address"
1079 if [ -z "${cowdevice}" ]
1083 cow_mountopt="rw,noatime,mode=755"
1086 if [ "${UNIONTYPE}" != "unionmount" ]
1088 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
1090 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
1091 root_backing="/live/persistence/$(basename ${cowdevice})-root"
1092 mkdir -p ${root_backing}
1094 root_backing="/live/overlay"
1097 if [ "${cow_fstype}" = "nfs" ]
1100 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
1101 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
1102 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
1104 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
1105 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
1109 rofscount=$(echo ${rofslist} |wc -w)
1113 if [ -n "${EXPOSED_ROOT}" ]
1115 if [ ${rofscount} -ne 1 ]
1117 panic "only one RO file system supported with exposedroot: ${rofslist}"
1120 mount --bind ${rofs} ${rootmnt} || \
1121 panic "bind mount of ${rofs} failed"
1123 if [ -z "${SKIP_UNION_MOUNTS}" ]
1125 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1133 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
1135 true # FIXME: Maybe it does, I don't really know.
1136 #panic "unionmount does not support subunions (${cow_dirs})."
1139 for dir in ${cow_dirs}; do
1140 unionmountpoint="${rootmnt}${dir}"
1141 mkdir -p ${unionmountpoint}
1142 if [ "${UNIONTYPE}" = "unionmount" ]
1144 # FIXME: handle PERSISTENCE_READONLY
1145 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
1146 mount_full $unionmountopts "${unionmountpoint}"
1148 cow_dir="/live/overlay${dir}"
1149 rofs_dir="${rofs}${dir}"
1151 if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
1153 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir}
1155 do_union ${unionmountpoint} ${cow_dir} ${rofs_dir}
1157 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
1160 # Correct the permissions of /:
1161 chmod 0755 "${rootmnt}"
1164 # SHOWMOUNTS is necessary for custom mounts with the union option
1165 # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS
1166 if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] 1)
1168 # XXX: is the for loop really necessary? rofslist can only contain one item (see above XXX about EXPOSEDROOT) and this is also assumed elsewhere above (see use of $rofs above).
1169 for d in ${rofslist}
1171 live_rofs="/live/rofs/${d##*/}"
1172 live_rofs_list="${live_rofs_list} ${live_rofs}"
1173 mkdir -p "${live_rofs}"
1176 # do nothing # mount -o bind "${d}" "${live_rofs}"
1179 case "${UNIONTYPE}" in
1181 mount -o bind "${d}" "${live_rofs}"
1184 mount -o move "${d}" "${live_rofs}"
1192 # Adding custom persistence
1193 if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
1195 local custom_mounts="/tmp/custom_mounts.list"
1196 rm -rf ${custom_mounts} 2> /dev/null
1198 # Gather information about custom mounts from devies detected as overlays
1199 get_custom_mounts ${custom_mounts} ${overlay_devices}
1201 [ -n "${DEBUG}" ] && cp ${custom_mounts} "/live/persistence"
1203 # Now we do the actual mounting (and symlinking)
1204 local used_overlays=""
1205 used_overlays=$(activate_custom_mounts ${custom_mounts})
1208 # Close unused overlays (e.g. due to missing $persistence_list)
1209 for overlay in ${overlay_devices}
1211 if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1213 close_persistence_media ${overlay}
1217 # Look for other snapshots to copy in
1218 [ -n "${root_snapdata}" ] && try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1219 # This second type should be removed when snapshot grow smarter
1220 [ -n "${home_snapdata}" ] && try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
1223 mkdir -p "${rootmnt}/live"
1224 mount -o move /live "${rootmnt}/live" >/dev/null 2>&1 || mount -o bind /live "${rootmnt}/live" || log_warning_msg "Unable to move or bind /live to ${rootmnt}/live"
1226 # shows cow fs on /overlay for use by live-snapshot
1227 mkdir -p "${rootmnt}/live/overlay"
1228 mount -o move /live/overlay "${rootmnt}/live/overlay" >/dev/null 2>&1 || mount -o bind /overlay "${rootmnt}/live/overlay" || log_warning_msg "Unable to move or bind /overlay to ${rootmnt}/live/overlay"
1236 skip_uuid_check="${3}"
1238 # support for fromiso=.../isofrom=....
1239 if [ -n "$FROMISO" ]
1241 ISO_DEVICE=$(dirname $FROMISO)
1242 if ! [ -b $ISO_DEVICE ]
1244 # to support unusual device names like /dev/cciss/c0d0p1
1245 # as well we have to identify the block device name, let's
1246 # do that for up to 15 levels
1248 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1250 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1251 [ -b "$ISO_DEVICE" ] && break
1256 if [ "$ISO_DEVICE" = "/" ]
1258 echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
1260 fs_type=$(get_fstype "${ISO_DEVICE}")
1261 if is_supported_fs ${fs_type}
1264 mount -t $fs_type "$ISO_DEVICE" /live/fromiso
1265 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1266 loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1267 devname="${loopdevname}"
1269 echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
1274 if [ -z "${devname}" ]
1276 devname=$(sys2dev "${sysdev}")
1279 if [ -d "${devname}" ]
1281 mount -o bind "${devname}" $mountpoint || continue
1283 if is_live_path $mountpoint
1293 for device in ${devname}
1297 # Adding lvm support
1298 if [ -x /scripts/local-top/lvm2 ]
1300 ROOT="$device" resume="" /scripts/local-top/lvm2
1305 # Adding raid support
1306 if [ -x /scripts/local-top/mdadm ]
1308 cp /conf/conf.d/md /conf/conf.d/md.orig
1309 echo "MD_DEVS=$device " >> /conf/conf.d/md
1310 /scripts/local-top/mdadm
1311 mv /conf/conf.d/md.orig /conf/conf.d/md
1318 [ -n "$device" ] && devname="$device"
1320 [ -e "$devname" ] || continue
1322 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1324 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1325 devname="${loopdevname}"
1328 fstype=$(get_fstype "${devname}")
1330 if is_supported_fs ${fstype}
1332 devuid=$(blkid -o value -s UUID "$devname")
1333 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1334 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1335 [ -n "$devuid" ] && echo "$devuid" >> $tried
1337 if [ -n "${FINDISO}" ]
1339 if [ -f ${mountpoint}/${FINDISO} ]
1341 umount ${mountpoint}
1342 mkdir -p /live/findiso
1343 mount -t ${fstype} -o ro,noatime "${devname}" /live/findiso
1344 loopdevname=$(setup_loop "/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
1345 devname="${loopdevname}"
1346 mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint}
1348 umount ${mountpoint}
1352 if is_live_path ${mountpoint} && \
1353 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1358 umount ${mountpoint} 2>/dev/null
1362 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1364 losetup -d "${loopdevname}"
1374 # don't start autodetection before timeout has expired
1375 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1377 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1383 # first look at the one specified in the command line
1384 case "${LIVE_MEDIA}" in
1386 for sysblock in $(removable_usb_dev "sys")
1388 for dev in $(subdevices "${sysblock}")
1390 if check_dev "${dev}"
1400 for sysblock in $(removable_dev "sys")
1402 for dev in $(subdevices "${sysblock}")
1404 if check_dev "${dev}"
1414 if [ ! -z "${LIVE_MEDIA}" ]
1416 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1424 # or do the scan of block devices
1425 # prefer removable devices over non-removable devices, so scan them first
1426 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
1428 for sysblock in $devices_to_scan
1430 devname=$(sys2dev "${sysblock}")
1431 [ -e "$devname" ] || continue
1432 fstype=$(get_fstype "${devname}")
1434 if /lib/udev/cdrom_id ${devname} > /dev/null
1436 if check_dev "null" "${devname}"
1440 elif is_nice_device "${sysblock}"
1442 for dev in $(subdevices "${sysblock}")
1444 if check_dev "${dev}"
1449 elif [ "${fstype}" = "squashfs" -o \
1450 "${fstype}" = "btrfs" -o \
1451 "${fstype}" = "ext2" -o \
1452 "${fstype}" = "ext3" -o \
1453 "${fstype}" = "ext4" -o \
1454 "${fstype}" = "jffs2" ]
1456 # This is an ugly hack situation, the block device has
1457 # an image directly on it. It's hopefully
1458 # live-boot, so take it and run with it.
1459 ln -s "${devname}" "${devname}.${fstype}"
1460 echo "${devname}.${fstype}"
1470 media_mountpoint="${1}"
1472 log_begin_msg "Checking media integrity"
1474 cd ${media_mountpoint}
1475 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1480 if [ "${RC}" -eq 0 ]
1482 log_success_msg "Everything ok, will reboot in 10 seconds."
1485 umount ${media_mountpoint}
1487 echo u > /proc/sysrq-trigger
1488 echo b > /proc/sysrq-trigger
1490 panic "Not ok, a media defect is likely, switch to VT8 for details."
1496 if [ -x /scripts/local-top/cryptroot ]; then
1497 /scripts/local-top/cryptroot
1504 tail -f boot.log >&7 &
1507 # Ensure 'panic' function is overridden
1508 . /scripts/live-functions
1512 maybe_break live-premount
1513 log_begin_msg "Running /scripts/live-premount"
1514 run_scripts /scripts/live-premount
1517 # Needed here too because some things (*cough* udev *cough*)
1518 # changes the timeout
1520 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1524 livefs_root="${mountpoint}"
1526 panic "Unable to find a live file system on the network"
1529 if [ -n "${ISCSI_PORTAL}" ]
1531 do_iscsi && livefs_root="${mountpoint}"
1532 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1534 # Do a local boot from hd
1537 if [ -x /usr/bin/memdiskfind ]
1539 MEMDISK=$(/usr/bin/memdiskfind)
1543 # We found a memdisk, set up phram
1544 modprobe phram phram=memdisk,${MEMDISK}
1546 # Load mtdblock, the memdisk will be /dev/mtdblock0
1551 # Scan local devices for the image
1553 while [ "$i" -lt 60 ]
1555 livefs_root=$(find_livefs ${i})
1557 if [ -n "${livefs_root}" ]
1568 if [ -z "${livefs_root}" ]
1570 panic "Unable to find a medium containing a live file system"
1573 if [ "${INTEGRITY_CHECK}" ]
1575 integrity_check "${livefs_root}"
1581 elif [ "${TODISK}" ]
1583 live_dest="${TODISK}"
1586 if [ "${live_dest}" ]
1588 log_begin_msg "Copying live media to ${live_dest}"
1589 copy_live_to "${livefs_root}" "${live_dest}"
1593 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1594 # because the mountpoint is left behind in /proc/mounts, so let's get
1595 # rid of it when running from RAM
1596 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1598 losetup -d /dev/loop0
1600 if is_mountpoint /live/fromiso
1602 umount /live/fromiso
1603 rmdir --ignore-fail-on-non-empty /live/fromiso \
1604 >/dev/null 2>&1 || true
1608 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1610 setup_unionfs "${livefs_root}" "${rootmnt}"
1613 mac="$(echo ${mac} | sed 's/-//g')"
1614 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1618 if [ -n "${ROOT_PID}" ] ; then
1619 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1624 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1625 # live-bottom; udev's init script will take care of things after that
1626 if [ "${UNIONTYPE}" = unionfs-fuse ]
1628 mount -n -o bind /dev "${rootmnt}/dev"
1631 # Move to the new root filesystem so that programs there can get at it.
1632 if [ ! -d /root/live/image ]
1634 mkdir -p /root/live/image
1635 mount --move /live/image /root/live/image
1638 # aufs2 in kernel versions around 2.6.33 has a regression:
1639 # directories can't be accessed when read for the first the time,
1640 # causing a failure for example when accessing /var/lib/fai
1641 # when booting FAI, this simple workaround solves it
1642 ls /root/* >/dev/null 2>&1
1644 # Move findiso directory to the new root filesystem so that programs there can get at it.
1645 if [ -d /live/findiso ] && [ ! -d /root/live/findiso ]
1647 mkdir -p /root/live/findiso
1648 mount -n --move /live/findiso /root/live/findiso
1651 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1652 # because the mountpoint is left behind in /proc/mounts, so let's get
1653 # rid of it when running from RAM
1654 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
1656 losetup -d /dev/loop0
1658 if is_mountpoint /root/live/findiso
1660 umount /root/live/findiso
1661 rmdir --ignore-fail-on-non-empty /root/live/findiso \
1662 >/dev/null 2>&1 || true
1666 # copy snapshot configuration if exists
1667 if [ -f snapshot.conf ]
1669 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
1670 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
1672 mkdir -p "${rootmnt}/etc/live/boot.d"
1674 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
1678 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
1680 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
1681 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
1685 maybe_break live-bottom
1686 log_begin_msg "Running /scripts/live-bottom\n"
1688 run_scripts /scripts/live-bottom
1691 if [ "${UNIONFS}" = unionfs-fuse ]
1693 umount "${rootmnt}/dev"
1699 [ -w "${rootmnt}/var/log/" ] && mkdir -p /var/log/live && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null