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"
15 USERFULLNAME="Live user"
18 mkdir -p "${mountpoint}"
21 # Create /etc/mtab for debug purpose and future syncs
32 . /scripts/live-helpers
34 if [ ! -f /live.vars ]
43 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
45 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
47 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
59 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
65 uuid="$(cat /conf/uuid.conf)"
67 for try_uuid_file in "${path}/.disk/live-uuid"*
69 [ -e "${try_uuid_file}" ] || continue
71 try_uuid="$(cat "${try_uuid_file}")"
73 if [ "${uuid}" = "${try_uuid}" ]
85 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
86 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
94 panic "Unrecognized live filesystem: ${1}"
101 # Does any files match pattern ${1} ?
104 if [ "$(echo ${pattern})" != "${pattern}" ]
112 mount_images_in_directory ()
119 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
120 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
121 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
122 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
123 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
124 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
126 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
127 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
129 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
135 sysfs_path="${1#/sys}"
137 if [ -e /lib/udev/path_id ]
140 PATH_ID="/lib/udev/path_id"
142 # wheezy/sid (udev >= 174)
143 PATH_ID="/sbin/udevadm test-builtin path_id"
146 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)"
149 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
152 elif echo ${sysfs_path} | grep -q "^/block/dm-"
155 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
167 copyto="${copyfrom}_swap"
169 if [ -z "${MODULETORAM}" ]
171 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
173 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
175 if [ -f "${MODULETORAMFILE}" ]
177 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
179 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
184 if [ "${copytodev}" = "ram" ]
187 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
188 mount_options="-o size=${size}k"
193 # it should be a writable block device
194 if [ -b "${copytodev}" ]
198 fstype=$(get_fstype "${dev}")
199 freespace=$(fs_size "${dev}")
201 log_warning_msg "${copytodev} is not a block device."
206 if [ "${freespace}" -lt "${size}" ]
208 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
212 # Custom ramdisk size
213 if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ]
215 # FIXME: should check for wrong values
216 mount_options="-o size=${ramdisk_size}"
219 # begin copying (or uncompressing)
221 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
222 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
224 if [ "${extension}" = "tgz" ]
227 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
228 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
229 mount -r -o move "${copyto}" "${rootmnt}"
232 if [ -n "${MODULETORAMFILE}" ]
236 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
237 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
239 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
244 echo " * Copying whole medium to RAM" 1>/dev/console
245 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
247 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
248 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
249 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
251 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
257 mount -r -o move ${copyto} ${copyfrom}
266 modprobe -q af_packet # For DHCP
271 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
272 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
274 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
275 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
279 # support for Syslinux IPAPPEND parameter
280 # it sets the BOOTIF variable on the kernel parameter
282 if [ -n "${BOOTIF}" ]
284 # pxelinux sets BOOTIF to a value based on the mac address of the
285 # network card used to PXE boot, so use this value for DEVICE rather
286 # than a hard-coded device name from initramfs.conf. this facilitates
287 # network booting when machines may have multiple network cards.
288 # pxelinux sets BOOTIF to 01-$mac_address
290 # strip off the leading "01-", which isn't part of the mac
292 temp_mac=${BOOTIF#*-}
294 # convert to typical mac address format by replacing "-" with ":"
299 if [ -z "$bootif_mac" ]
303 bootif_mac="$bootif_mac:$x"
308 # look for devices with matching mac address, and set DEVICE to
309 # appropriate value if match is found.
311 for device in /sys/class/net/*
313 if [ -f "$device/address" ]
315 current_mac=$(cat "$device/address")
317 if [ "$bootif_mac" = "$current_mac" ]
326 # if ethdevice was not specified on the kernel command line
327 # make sure we try to get a working network configuration
328 # for *every* present network device (except for loopback of course)
329 if [ -z "$ETHDEVICE" ] ; then
330 echo "If you want to boot from a specific device use bootoption ethdevice=..."
331 for device in /sys/class/net/*; do
333 if [ "$dev" != "lo" ] ; then
334 ETHDEVICE="$ETHDEVICE $dev"
339 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
340 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
341 devlist="$devlist $device"
344 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
345 # an endless loop; iff execution fails give it two further tries, that's
346 # why we use '$devlist $devlist $devlist' for the other for loop
347 for dev in $devlist $devlist $devlist ; do
348 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
349 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
351 sleep "$ETHDEV_TIMEOUT" ; sleep 1
352 if [ -r /proc/"$jobid"/status ] ; then
353 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
357 # if configuration of device worked we should have an assigned
358 # IP address, iff so let's use the according as $DEVICE for later usage
359 # simple and primitive approach which seems to work fine
360 if ifconfig $dev | grep -q 'inet.*addr:' ; then
367 for interface in ${DEVICE}; do
368 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
369 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
370 if [ "$IPV4ADDR" != "0.0.0.0" ]
377 for interface in ${DEVICE}; do
378 # source relevant ipconfig output
379 OLDHOSTNAME=${HOSTNAME}
380 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
381 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
384 if [ -n "${interface}" ]
386 HWADDR="$(cat /sys/class/net/${interface}/address)"
389 if [ ! -e "/etc/resolv.conf" ]
391 echo "Creating /etc/resolv.conf"
393 if [ -n "${DNSDOMAIN}" ]
395 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
396 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
399 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
401 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
403 echo "nameserver $i" >> /etc/resolv.conf
408 # Check if we have a network device at all
409 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
410 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
411 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
412 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
413 ! ls /sys/class/net/ra0 > /dev/null 2>&1
415 panic "No supported network device found, maybe a non-mainline driver is required."
424 if [ "${NFSROOT}" = "auto" ]
426 NFSROOT=${ROOTSERVER}:${ROOTPATH}
431 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
437 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
439 NFSROOT=${ROOTSERVER}:${NFSROOT}
442 log_begin_msg "Trying netboot from ${NFSROOT}"
444 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
464 [ "${DEBUG}" = "Yes" ] && debugopt="-d 8"
465 #FIXME this name is supposed to be unique - some date + ifconfig hash?
466 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
467 export ISCSI_INITIATORNAME
468 if [ -n "${ISCSI_SERVER}" ] ; then
469 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
471 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
475 panic "Failed to log into iscsi target"
477 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
478 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
483 while [ -z "${devices}" -a $i -lt 60 ]
486 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
487 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
493 if check_dev "null" "/dev/$dev"
500 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
502 panic "Failed to locate iSCSI host in /sys"
510 for webfile in HTTPFS FTPFS FETCH
512 local url="$(eval echo \"\$\{${webfile}\}\")"
513 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
517 case "${extension}" in
518 iso|squashfs|tgz|tar)
519 if [ "${extension}" = "iso" ]
521 mkdir -p "${alt_mountpoint}"
522 dest="${alt_mountpoint}"
524 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
525 mount -t ramfs ram "${mountpoint}"
528 if [ "${webfile}" = "FETCH" ]
532 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
533 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
534 lfile="$(basename $url)"
535 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
536 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
540 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
541 wget "${url}" -O "${dest}/$(basename ${url})"
545 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
546 if [ "${webfile}" = "FTPFS" ]
548 FUSE_MOUNT="curlftpfs"
549 url="$(dirname ${url})"
554 $FUSE_MOUNT "${url}" "${dest}"
555 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
557 [ ${?} -eq 0 ] && rc=0
558 [ "${extension}" = "tgz" ] && live_dest="ram"
559 if [ "${extension}" = "iso" ]
561 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
562 mount -t iso9660 "${isoloop}" "${mountpoint}"
569 log_begin_msg "Unrecognized archive extension for ${url}"
577 if [ -d "${alt_mountpoint}" ]
579 umount "${alt_mountpoint}"
580 rmdir "${alt_mountpoint}"
582 umount "${mountpoint}"
583 elif [ "${webfile}" != "FETCH" ] ; then
597 if [ -n "${NFSOPTS}" ]
599 NFSOPTS="-o ${NFSOPTS}"
602 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
604 # FIXME: This while loop is an ugly HACK round an nfs bug
606 while [ "$i" -lt 60 ]
608 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
620 if [ -x "/sbin/mount.cifs" ]
622 if [ -z "${NFSOPTS}" ]
624 CIFSOPTS="-ouser=root,password="
626 CIFSOPTS="-o ${NFSOPTS}"
629 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
632 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
646 size=$(fs_size "${fromdev}" "" "used")
648 if [ -b "${fromdev}" ]
650 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
653 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
655 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
656 freespace=$(df -k | awk '/'${todev}'/{print $4}')
658 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
661 tomount="/mnt/tmpsnap"
663 if [ ! -d "${tomount}" ]
665 mkdir -p "${tomount}"
668 fstype=$(get_fstype "${fromdev}")
670 if [ -n "${fstype}" ]
673 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
674 cp -a "${tomount}"/* ${todir}
677 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
682 if echo ${fromdev} | grep -qs loop
684 losetup -d "${fromdev}"
689 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
696 # copy the contents of previously found snapshot to ${snap_mount}
697 # and remember the device and filename for resync on exit in live-boot.init
704 if [ -z "${snap_relpath}" ]
706 # root snapshot, default usage
709 # relative snapshot (actually used just for "/home" snapshots)
710 snap_mount="${2}${snap_relpath}"
713 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
715 log_success_msg "found snapshot: ${snapdata}"
716 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
717 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
718 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
720 if ! try_mount "${snapdev}" "${snapback}" "ro"
727 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
729 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
730 dev=$(get_backing_device "${snapback}/${snapfile}")
732 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
737 # Unfortunately klibc's cpio is incompatible with the
738 # rest of the world; everything else requires -u -d,
739 # while klibc doesn't implement them. Try to detect
740 # whether it's in use.
741 cpiopath="$(which cpio)" || true
742 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
746 cpioargs='--unconditional --make-directories'
749 if [ -s "${snapback}/${snapfile}" ]
752 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
756 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
760 if [ "${RES}" != "0" ]
762 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
766 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
768 if [ "${RES}" != "0" ]
770 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
773 elif [ -b "${snapdata}" ]
775 # Try to find if it could be a snapshot partition
777 log_success_msg "found snapshot ${snap_type} device on ${dev}"
778 if echo "${dev}" | grep -qs loop
780 # strange things happens, user confused?
781 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
782 snapfile=$(basename ${snaploop})
783 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
788 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
790 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
793 if [ -n "${snapfile}" ]
795 # it was a loop device, user confused
800 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
804 if [ -z ${PERSISTENT_READONLY} ]
806 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
813 image_directory="${1}"
815 addimage_directory="${3}"
818 aufs|unionfs|overlayfs)
819 modprobe -q -b ${UNIONTYPE}
821 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
823 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
824 echo "This might be really slow."
826 UNIONTYPE="unionfs-fuse"
831 if [ "${UNIONTYPE}" = unionfs-fuse ]
836 # run-init can't deal with images in a subdir, but we're going to
837 # move all of these away before it runs anyway. No, we're not,
838 # put them in / since move-mounting them into / breaks mono and
843 # Let's just mount the read-only file systems first
846 if [ -z "${PLAIN_ROOT}" ]
848 # Read image names from ${MODULE}.module if it exists
849 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
851 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
853 image_string="${image_string} ${image_directory}/${IMAGE}"
855 elif [ -e "${image_directory}/${MODULE}.module" ]
857 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
859 image_string="${image_string} ${image_directory}/${IMAGE}"
862 # ${MODULE}.module does not exist, create a list of images
863 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
865 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
869 image_string="${image_string} ${IMAGE}"
874 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
876 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
878 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
882 image_string="${image_string} ${IMAGE}"
889 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
892 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
896 for image in ${image_string}
898 imagename=$(basename "${image}")
901 maybe_break live-realpremount
902 log_begin_msg "Running /scripts/live-realpremount"
903 run_scripts /scripts/live-realpremount
908 # it is a plain directory: do nothing
909 rofslist="${image} ${rofslist}"
910 elif [ -f "${image}" ]
912 if losetup --help 2>&1 | grep -q -- "-r\b"
914 backdev=$(get_backing_device "${image}" "-r")
916 backdev=$(get_backing_device "${image}")
918 fstype=$(get_fstype "${backdev}")
920 if [ "${fstype}" = "unknown" ]
922 panic "Unknown file system type on ${backdev} (${image})"
925 if [ -z "${fstype}" ]
927 fstype="${imagename##*.}"
928 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
931 if [ "${UNIONTYPE}" != "unionmount" ]
933 mpoint="${croot}/${imagename}"
934 rofslist="${mpoint} ${rofslist}"
937 rofslist="${rootmnt} ${rofslist}"
940 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
941 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
946 # we have a plain root system
947 mkdir -p "${croot}/filesystem"
948 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
949 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
950 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
951 rofslist="${croot}/filesystem ${rofslist}"
953 mount -o bind ${croot}/filesystem $mountpoint
959 # Looking for persistent devices or files
960 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
963 if [ -z "${QUICKUSBMODULES}" ]
966 num_block=$(ls -l /sys/block | wc -l)
967 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
969 modprobe -q -b ${module}
975 # For some reason, udevsettle does not block in this scenario,
976 # so we sleep for a little while.
978 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
979 for timeout in 5 4 3 2 1
983 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
990 case "${PERSISTENT_MEDIA}" in
992 whitelistdev="$(removable_dev)"
995 whitelistdev="$(removable_usb_dev)"
1002 if echo ${PERSISTENT_METHOD} | grep -qe "\<overlay\>"
1004 overlays="${root_overlay_label} ${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
1007 if echo ${PERSISTENT_METHOD} | grep -qe "\<snapshot\>"
1009 snapshots="${root_snapshot_label} ${home_snapshot_label}"
1012 local root_snapdata=""
1013 local home_snapshot_label=""
1014 local root_overlay_label=""
1015 local overlay_devices=""
1016 for media in $(find_persistent_media "${overlays}" "${snapshots}" "${whitelistdev}")
1018 media="$(echo ${media} | tr ":" " ")"
1020 ${root_snapshot_label}=*|${old_root_snapshot_label}=*)
1021 if [ -z "${root_snapdata}" ]
1023 root_snapdata="${media#*=}"
1026 ${home_snapshot_label}=*)
1027 # This second type should be removed when snapshot will get smarter,
1028 # hence when "/etc/live-snapshot*list" will be supported also by
1029 # ext2|ext3|ext4|jffs2 snapshot types.
1030 if [ -z "${home_snapdata}" ]
1032 home_snapdata="${media#*=}"
1035 ${root_overlay_label}=*|${old_root_overlay_label}=*)
1036 if [ -z "${root_overlay_device}" ]
1038 device="${media#*=}"
1039 root_overlay_device="${device}"
1042 ${old_home_overlay_label}=*)
1043 device="${media#*=}"
1044 fix_home_rw_compatibility ${device}
1045 overlay_devices="${overlay_devices} ${device}"
1047 ${custom_overlay_label}=*)
1048 device="${media#*=}"
1049 overlay_devices="${overlay_devices} ${device}"
1054 if [ -b "${root_overlay_device}" ]
1056 PERSISTENCE_IS_ON="1"
1057 export PERSISTENCE_IS_ON
1059 cowdevice=${root_overlay_device}
1060 cow_fstype=$(get_fstype "${root_overlay_device}")
1061 if [ -z "${PERSISTENT_READONLY}" ]
1063 cow_mountopt="rw,noatime"
1065 cow_mountopt="ro,noatime"
1068 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1070 fsck -y ${cowdevice}
1073 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1075 # check if there are any nfs options
1076 if echo ${NFS_COW}|grep -q ','
1078 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1079 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1081 nfs_cow_opts="-o nolock"
1085 if [ -n "${PERSISTENT_READONLY}" ]
1087 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
1093 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1096 panic "unable to determine mac address"
1100 if [ -z "${cowdevice}" ]
1104 cow_mountopt="rw,noatime,mode=755"
1107 if [ "${UNIONTYPE}" != "unionmount" ]
1109 if [ -n "${PERSISTENT_READONLY}" ]
1111 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/cow"
1112 root_backing="${rootmnt}/live/persistent/$(basename ${cowdevice})-root"
1113 mkdir -p ${root_backing}
1118 if [ "${cow_fstype}" = "nfs" ]
1121 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
1122 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
1123 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
1125 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
1126 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
1130 rofscount=$(echo ${rofslist} |wc -w)
1132 # XXX: we now ensure that there can only be one read-only filesystem. Should this be inside the EXPOSED_ROOT if?
1133 if [ ${rofscount} -ne 1 ]
1135 panic "only one RO file system supported with exposedroot: ${rofslist}"
1139 if [ -n "${EXPOSED_ROOT}" ]
1141 mount --bind ${rofs} ${rootmnt} || \
1142 panic "bind mount of ${rofs} failed"
1144 if [ -z "${SKIP_UNION_MOUNTS}" ]
1146 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1154 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
1156 true # FIXME: Maybe it does, I don't really know.
1157 #panic "unionmount does not support subunions (${cow_dirs})."
1160 for dir in ${cow_dirs}; do
1161 unionmountpoint="${rootmnt}${dir}"
1162 mkdir -p ${unionmountpoint}
1163 if [ "${UNIONTYPE}" = "unionmount" ]
1165 # FIXME: handle PERSISTENT_READONLY
1166 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
1167 mount_full $unionmountopts "${unionmountpoint}"
1169 cow_dir="/cow${dir}"
1170 rofs_dir="${rofs}${dir}"
1172 if [ -n "${PERSISTENT_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
1174 #mount -t tmpfs -o rw,noatime,mode=755 tmpfs "${cow_dir}"
1175 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir}
1177 do_union ${unionmountpoint} ${cow_dir} ${rofs_dir}
1179 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
1182 # Correct the permissions of /:
1183 chmod 0755 "${rootmnt}"
1185 # tmpfs file systems
1187 mkdir -p "${rootmnt}/live"
1188 mount -t tmpfs tmpfs ${rootmnt}/live
1191 # SHOWMOUNTS is necessary for custom mounts with the union option
1192 # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS
1193 if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ] 1)
1195 # 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).
1196 for d in ${rofslist}
1198 live_rofs="${rootmnt}/live/rofs/${d##*/}"
1199 live_rofs_list="${live_rofs_list} ${live_rofs}"
1200 mkdir -p "${live_rofs}"
1203 # do nothing # mount -o bind "${d}" "${live_rofs}"
1206 case "${UNIONTYPE}" in
1208 mount -o bind "${d}" "${live_rofs}"
1211 mount -o move "${d}" "${live_rofs}"
1219 # Adding custom persistent
1220 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1222 local custom_mounts="/tmp/custom_mounts.list"
1223 rm -rf ${custom_mounts} 2> /dev/null
1225 # Gather information about custom mounts from devies detected as overlays
1226 get_custom_mounts ${custom_mounts} ${overlay_devices}
1228 [ -n "${DEBUG}" ] && cp ${custom_mounts} "${rootmnt}/live/persistent"
1230 # Now we do the actual mounting (and symlinking)
1231 local used_overlays=""
1232 used_overlays=$(activate_custom_mounts ${custom_mounts})
1235 # Close unused overlays (e.g. due to missing $persistence_list)
1236 for overlay in ${overlay_devices}
1238 if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
1240 close_persistent_media ${overlay}
1244 # Look for other snapshots to copy in
1245 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1246 # This second type should be removed when snapshot grow smarter
1247 try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
1250 # shows cow fs on /cow for use by live-snapshot
1251 mkdir -p "${rootmnt}/live/cow"
1252 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"
1259 skip_uuid_check="${3}"
1261 # support for fromiso=.../isofrom=....
1262 if [ -n "$FROMISO" ]
1264 ISO_DEVICE=$(dirname $FROMISO)
1265 if ! [ -b $ISO_DEVICE ]
1267 # to support unusual device names like /dev/cciss/c0d0p1
1268 # as well we have to identify the block device name, let's
1269 # do that for up to 15 levels
1271 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1273 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1274 [ -b "$ISO_DEVICE" ] && break
1279 if [ "$ISO_DEVICE" = "/" ]
1281 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live-boot.log
1283 fs_type=$(get_fstype "${ISO_DEVICE}")
1284 if is_supported_fs ${fs_type}
1287 mount -t $fs_type "$ISO_DEVICE" /isofrom
1288 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1289 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1290 devname="${loopdevname}"
1292 echo "Warning: unable to mount $ISO_DEVICE." >>/live-boot.log
1297 if [ -z "${devname}" ]
1299 devname=$(sys2dev "${sysdev}")
1302 if [ -d "${devname}" ]
1304 mount -o bind "${devname}" $mountpoint || continue
1306 if is_live_path $mountpoint
1316 for device in ${devname}
1320 # Adding lvm support
1321 if [ -x /scripts/local-top/lvm2 ]
1323 ROOT="$device" resume="" /scripts/local-top/lvm2
1328 # Adding raid support
1329 if [ -x /scripts/local-top/mdadm ]
1331 cp /conf/conf.d/md /conf/conf.d/md.orig
1332 echo "MD_DEVS=$device " >> /conf/conf.d/md
1333 /scripts/local-top/mdadm
1334 mv /conf/conf.d/md.orig /conf/conf.d/md
1341 [ -n "$device" ] && devname="$device"
1343 [ -e "$devname" ] || continue
1345 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1347 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1348 devname="${loopdevname}"
1351 fstype=$(get_fstype "${devname}")
1353 if is_supported_fs ${fstype}
1355 devuid=$(blkid -o value -s UUID "$devname")
1356 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1357 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1358 [ -n "$devuid" ] && echo "$devuid" >> $tried
1360 if is_live_path ${mountpoint} && \
1361 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1366 umount ${mountpoint} 2>/dev/null
1370 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1372 losetup -d "${loopdevname}"
1382 # don't start autodetection before timeout has expired
1383 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1385 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1391 # first look at the one specified in the command line
1392 case "${LIVE_MEDIA}" in
1394 for sysblock in $(removable_usb_dev "sys")
1396 for dev in $(subdevices "${sysblock}")
1398 if check_dev "${dev}"
1408 for sysblock in $(removable_dev "sys")
1410 for dev in $(subdevices "${sysblock}")
1412 if check_dev "${dev}"
1422 if [ ! -z "${LIVE_MEDIA}" ]
1424 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1432 # or do the scan of block devices
1433 # prefer removable devices over non-removable devices, so scan them first
1434 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
1436 for sysblock in $devices_to_scan
1438 devname=$(sys2dev "${sysblock}")
1439 [ -e "$devname" ] || continue
1440 fstype=$(get_fstype "${devname}")
1442 if /lib/udev/cdrom_id ${devname} > /dev/null
1444 if check_dev "null" "${devname}"
1448 elif is_nice_device "${sysblock}"
1450 for dev in $(subdevices "${sysblock}")
1452 if check_dev "${dev}"
1457 elif [ "${fstype}" = "squashfs" -o \
1458 "${fstype}" = "btrfs" -o \
1459 "${fstype}" = "ext2" -o \
1460 "${fstype}" = "ext3" -o \
1461 "${fstype}" = "ext4" -o \
1462 "${fstype}" = "jffs2" ]
1464 # This is an ugly hack situation, the block device has
1465 # an image directly on it. It's hopefully
1466 # live-boot, so take it and run with it.
1467 ln -s "${devname}" "${devname}.${fstype}"
1468 echo "${devname}.${fstype}"
1478 media_mountpoint="${1}"
1480 log_begin_msg "Checking media integrity"
1482 cd ${media_mountpoint}
1483 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1488 if [ "${RC}" -eq 0 ]
1490 log_success_msg "Everything ok, will reboot in 10 seconds."
1493 umount ${media_mountpoint}
1495 echo u > /proc/sysrq-trigger
1496 echo b > /proc/sysrq-trigger
1498 panic "Not ok, a media defect is likely, switch to VT8 for details."
1504 if [ -x /scripts/local-top/cryptroot ]; then
1505 /scripts/local-top/cryptroot
1510 exec > live-boot.log
1512 tail -f live-boot.log >&7 &
1515 # Ensure 'panic' function is overridden
1516 . /scripts/live-functions
1520 maybe_break live-premount
1521 log_begin_msg "Running /scripts/live-premount"
1522 run_scripts /scripts/live-premount
1525 # Needed here too because some things (*cough* udev *cough*)
1526 # changes the timeout
1528 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1532 livefs_root="${mountpoint}"
1534 panic "Unable to find a live file system on the network"
1537 if [ -n "${ISCSI_PORTAL}" ]
1539 do_iscsi && livefs_root="${mountpoint}"
1540 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1542 # Do a local boot from hd
1545 if [ -x /usr/bin/memdiskfind ]
1547 MEMDISK=$(/usr/bin/memdiskfind)
1551 # We found a memdisk, set up phram
1552 modprobe phram phram=memdisk,${MEMDISK}
1554 # Load mtdblock, the memdisk will be /dev/mtdblock0
1559 # Scan local devices for the image
1561 while [ "$i" -lt 60 ]
1563 livefs_root=$(find_livefs ${i})
1565 if [ -n "${livefs_root}" ]
1576 if [ -z "${livefs_root}" ]
1578 panic "Unable to find a medium containing a live file system"
1581 if [ "${INTEGRITY_CHECK}" ]
1583 integrity_check "${livefs_root}"
1589 elif [ "${TODISK}" ]
1591 live_dest="${TODISK}"
1594 if [ "${live_dest}" ]
1596 log_begin_msg "Copying live media to ${live_dest}"
1597 copy_live_to "${livefs_root}" "${live_dest}"
1601 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1602 # because the mountpoint is left behind in /proc/mounts, so let's get
1603 # rid of it when running from RAM
1604 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1606 losetup -d /dev/loop0
1607 grep -q /isofrom /proc/mounts && umount /isofrom
1610 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1612 setup_unionfs "${livefs_root}" "${rootmnt}"
1615 mac="$(echo ${mac} | sed 's/-//g')"
1616 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1620 if [ -n "${ROOT_PID}" ] ; then
1621 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1626 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1627 # live-bottom; udev's init script will take care of things after that
1628 if [ "${UNIONTYPE}" = unionfs-fuse ]
1630 mount -n -o bind /dev "${rootmnt}/dev"
1633 # Move to the new root filesystem so that programs there can get at it.
1634 if [ ! -d /root/live/image ]
1636 mkdir -p /root/live/image
1637 mount --move /live/image /root/live/image
1640 # aufs2 in kernel versions around 2.6.33 has a regression:
1641 # directories can't be accessed when read for the first the time,
1642 # causing a failure for example when accessing /var/lib/fai
1643 # when booting FAI, this simple workaround solves it
1644 ls /root/* >/dev/null 2>&1
1646 # copy snapshot configuration if exists
1647 if [ -f snapshot.conf ]
1649 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
1650 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
1652 mkdir -p "${rootmnt}/etc/live/boot.d"
1654 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
1658 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
1660 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
1661 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
1665 maybe_break live-bottom
1666 log_begin_msg "Running /scripts/live-bottom\n"
1668 run_scripts /scripts/live-bottom
1671 if [ "${UNIONFS}" = unionfs-fuse ]
1673 umount "${rootmnt}/dev"
1679 [ -w "${rootmnt}/var/log/" ] && cp live-boot.log "${rootmnt}/var/log/" 2>/dev/null