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_overlay_label="full-ov"
15 custom_overlay_label="custom-ov"
16 root_snapshot_label="live-sn"
17 home_snapshot_label="home-sn"
18 persistence_list="live.persist"
21 USERFULLNAME="Live user"
24 mkdir -p "${mountpoint}"
27 # Create /etc/mtab for debug purpose and future syncs
38 . /scripts/live-helpers
40 if [ ! -f /live.vars ]
49 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
51 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
53 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
65 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
71 uuid="$(cat /conf/uuid.conf)"
73 for try_uuid_file in "${path}/.disk/live-uuid"*
75 [ -e "${try_uuid_file}" ] || continue
77 try_uuid="$(cat "${try_uuid_file}")"
79 if [ "${uuid}" = "${try_uuid}" ]
91 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
92 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
100 panic "Unrecognized live filesystem: ${1}"
105 match_files_in_dir ()
107 # Does any files match pattern ${1} ?
110 if [ "$(echo ${pattern})" != "${pattern}" ]
118 mount_images_in_directory ()
125 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
126 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
127 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
128 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
129 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
130 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
132 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
133 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
135 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
141 sysfs_path="${1#/sys}"
143 if [ -e /lib/udev/path_id ]
146 PATH_ID="/lib/udev/path_id"
148 # wheezy/sid (udev >= 174)
149 PATH_ID="/sbin/udevadm test-builtin path_id"
152 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)"
155 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
158 elif echo ${sysfs_path} | grep -q "^/block/dm-"
161 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
173 copyto="${copyfrom}_swap"
175 if [ -z "${MODULETORAM}" ]
177 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
179 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
181 if [ -f "${MODULETORAMFILE}" ]
183 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
185 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
190 if [ "${copytodev}" = "ram" ]
193 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
194 mount_options="-o size=${size}k"
199 # it should be a writable block device
200 if [ -b "${copytodev}" ]
204 fstype=$(get_fstype "${dev}")
205 freespace=$(fs_size "${dev}")
207 log_warning_msg "${copytodev} is not a block device."
212 if [ "${freespace}" -lt "${size}" ]
214 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
218 # Custom ramdisk size
219 if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ]
221 # FIXME: should check for wrong values
222 mount_options="-o size=${ramdisk_size}"
225 # begin copying (or uncompressing)
227 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
228 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
230 if [ "${extension}" = "tgz" ]
233 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
234 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
235 mount -r -o move "${copyto}" "${rootmnt}"
238 if [ -n "${MODULETORAMFILE}" ]
242 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
243 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
245 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
250 echo " * Copying whole medium to RAM" 1>/dev/console
251 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
253 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
254 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
255 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
257 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
263 mount -r -o move ${copyto} ${copyfrom}
272 modprobe -q af_packet # For DHCP
277 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
278 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
280 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
281 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
285 # support for Syslinux IPAPPEND parameter
286 # it sets the BOOTIF variable on the kernel parameter
288 if [ -n "${BOOTIF}" ]
290 # pxelinux sets BOOTIF to a value based on the mac address of the
291 # network card used to PXE boot, so use this value for DEVICE rather
292 # than a hard-coded device name from initramfs.conf. this facilitates
293 # network booting when machines may have multiple network cards.
294 # pxelinux sets BOOTIF to 01-$mac_address
296 # strip off the leading "01-", which isn't part of the mac
298 temp_mac=${BOOTIF#*-}
300 # convert to typical mac address format by replacing "-" with ":"
305 if [ -z "$bootif_mac" ]
309 bootif_mac="$bootif_mac:$x"
314 # look for devices with matching mac address, and set DEVICE to
315 # appropriate value if match is found.
317 for device in /sys/class/net/*
319 if [ -f "$device/address" ]
321 current_mac=$(cat "$device/address")
323 if [ "$bootif_mac" = "$current_mac" ]
332 # if ethdevice was not specified on the kernel command line
333 # make sure we try to get a working network configuration
334 # for *every* present network device (except for loopback of course)
335 if [ -z "$ETHDEVICE" ] ; then
336 echo "If you want to boot from a specific device use bootoption ethdevice=..."
337 for device in /sys/class/net/*; do
339 if [ "$dev" != "lo" ] ; then
340 ETHDEVICE="$ETHDEVICE $dev"
345 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
346 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
347 devlist="$devlist $device"
350 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
351 # an endless loop; iff execution fails give it two further tries, that's
352 # why we use '$devlist $devlist $devlist' for the other for loop
353 for dev in $devlist $devlist $devlist ; do
354 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
355 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
357 sleep "$ETHDEV_TIMEOUT" ; sleep 1
358 if [ -r /proc/"$jobid"/status ] ; then
359 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
363 # if configuration of device worked we should have an assigned
364 # IP address, iff so let's use the according as $DEVICE for later usage
365 # simple and primitive approach which seems to work fine
366 if ifconfig $dev | grep -q 'inet.*addr:' ; then
373 for interface in ${DEVICE}; do
374 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
375 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
376 if [ "$IPV4ADDR" != "0.0.0.0" ]
383 for interface in ${DEVICE}; do
384 # source relevant ipconfig output
385 OLDHOSTNAME=${HOSTNAME}
386 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
387 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
390 if [ -n "${interface}" ]
392 HWADDR="$(cat /sys/class/net/${interface}/address)"
395 if [ ! -e "/etc/resolv.conf" ]
397 echo "Creating /etc/resolv.conf"
399 if [ -n "${DNSDOMAIN}" ]
401 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
402 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
405 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
407 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
409 echo "nameserver $i" >> /etc/resolv.conf
414 # Check if we have a network device at all
415 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
416 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
417 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
418 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
419 ! ls /sys/class/net/ra0 > /dev/null 2>&1
421 panic "No supported network device found, maybe a non-mainline driver is required."
430 if [ "${NFSROOT}" = "auto" ]
432 NFSROOT=${ROOTSERVER}:${ROOTPATH}
437 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
443 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
445 NFSROOT=${ROOTSERVER}:${NFSROOT}
448 log_begin_msg "Trying netboot from ${NFSROOT}"
450 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
470 [ "${DEBUG}" = "Yes" ] && debugopt="-d 8"
471 #FIXME this name is supposed to be unique - some date + ifconfig hash?
472 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
473 export ISCSI_INITIATORNAME
474 if [ -n "${ISCSI_SERVER}" ] ; then
475 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
477 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
481 panic "Failed to log into iscsi target"
483 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
484 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
489 while [ -z "${devices}" -a $i -lt 60 ]
492 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
493 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
499 if check_dev "null" "/dev/$dev"
506 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
508 panic "Failed to locate iSCSI host in /sys"
516 for webfile in HTTPFS FTPFS FETCH
518 local url="$(eval echo \"\$\{${webfile}\}\")"
519 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
523 case "${extension}" in
524 iso|squashfs|tgz|tar)
525 if [ "${extension}" = "iso" ]
527 mkdir -p "${alt_mountpoint}"
528 dest="${alt_mountpoint}"
530 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
531 mount -t ramfs ram "${mountpoint}"
534 if [ "${webfile}" = "FETCH" ]
538 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
539 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
540 lfile="$(basename $url)"
541 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
542 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
546 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
547 wget "${url}" -O "${dest}/$(basename ${url})"
551 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
552 if [ "${webfile}" = "FTPFS" ]
554 FUSE_MOUNT="curlftpfs"
555 url="$(dirname ${url})"
560 $FUSE_MOUNT "${url}" "${dest}"
561 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
563 [ ${?} -eq 0 ] && rc=0
564 [ "${extension}" = "tgz" ] && live_dest="ram"
565 if [ "${extension}" = "iso" ]
567 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
568 mount -t iso9660 "${isoloop}" "${mountpoint}"
575 log_begin_msg "Unrecognized archive extension for ${url}"
583 if [ -d "${alt_mountpoint}" ]
585 umount "${alt_mountpoint}"
586 rmdir "${alt_mountpoint}"
588 umount "${mountpoint}"
589 elif [ "${webfile}" != "FETCH" ] ; then
603 if [ -n "${NFSOPTS}" ]
605 NFSOPTS="-o ${NFSOPTS}"
608 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
610 # FIXME: This while loop is an ugly HACK round an nfs bug
612 while [ "$i" -lt 60 ]
614 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
626 if [ -x "/sbin/mount.cifs" ]
628 if [ -z "${NFSOPTS}" ]
630 CIFSOPTS="-ouser=root,password="
632 CIFSOPTS="-o ${NFSOPTS}"
635 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
638 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
652 size=$(fs_size "${fromdev}" "" "used")
654 if [ -b "${fromdev}" ]
656 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
659 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
661 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
662 freespace=$(df -k | awk '/'${todev}'/{print $4}')
664 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
667 tomount="/mnt/tmpsnap"
669 if [ ! -d "${tomount}" ]
671 mkdir -p "${tomount}"
674 fstype=$(get_fstype "${fromdev}")
676 if [ -n "${fstype}" ]
679 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
680 cp -a "${tomount}"/* ${todir}
683 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
688 if echo ${fromdev} | grep -qs loop
690 losetup -d "${fromdev}"
695 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
702 # copy the contents of previously found snapshot to ${snap_mount}
703 # and remember the device and filename for resync on exit in live-boot.init
710 if [ -z "${snap_relpath}" ]
712 # root snapshot, default usage
715 # relative snapshot (actually used just for "/home" snapshots)
716 snap_mount="${2}${snap_relpath}"
719 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
721 log_success_msg "found snapshot: ${snapdata}"
722 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
723 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
724 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
726 if ! try_mount "${snapdev}" "${snapback}" "ro"
733 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
735 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
736 dev=$(get_backing_device "${snapback}/${snapfile}")
738 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
743 # Unfortunately klibc's cpio is incompatible with the
744 # rest of the world; everything else requires -u -d,
745 # while klibc doesn't implement them. Try to detect
746 # whether it's in use.
747 cpiopath="$(which cpio)" || true
748 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
752 cpioargs='--unconditional --make-directories'
755 if [ -s "${snapback}/${snapfile}" ]
758 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
762 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
766 if [ "${RES}" != "0" ]
768 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
772 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
774 if [ "${RES}" != "0" ]
776 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
779 elif [ -b "${snapdata}" ]
781 # Try to find if it could be a snapshot partition
783 log_success_msg "found snapshot ${snap_type} device on ${dev}"
784 if echo "${dev}" | grep -qs loop
786 # strange things happens, user confused?
787 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
788 snapfile=$(basename ${snaploop})
789 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
794 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
796 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
799 if [ -n "${snapfile}" ]
801 # it was a loop device, user confused
806 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
810 if [ -z ${PERSISTENT_READONLY} ]
812 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
819 image_directory="${1}"
821 addimage_directory="${3}"
824 aufs|unionfs|overlayfs)
825 modprobe -q -b ${UNIONTYPE}
827 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
829 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
830 echo "This might be really slow."
832 UNIONTYPE="unionfs-fuse"
837 if [ "${UNIONTYPE}" = unionfs-fuse ]
842 # run-init can't deal with images in a subdir, but we're going to
843 # move all of these away before it runs anyway. No, we're not,
844 # put them in / since move-mounting them into / breaks mono and
849 # Let's just mount the read-only file systems first
852 if [ -z "${PLAIN_ROOT}" ]
854 # Read image names from ${MODULE}.module if it exists
855 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
857 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
859 image_string="${image_string} ${image_directory}/${IMAGE}"
861 elif [ -e "${image_directory}/${MODULE}.module" ]
863 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
865 image_string="${image_string} ${image_directory}/${IMAGE}"
868 # ${MODULE}.module does not exist, create a list of images
869 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
871 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
875 image_string="${image_string} ${IMAGE}"
880 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
882 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
884 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
888 image_string="${image_string} ${IMAGE}"
895 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
898 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
902 for image in ${image_string}
904 imagename=$(basename "${image}")
907 maybe_break live-realpremount
908 log_begin_msg "Running /scripts/live-realpremount"
909 run_scripts /scripts/live-realpremount
914 # it is a plain directory: do nothing
915 rofslist="${image} ${rofslist}"
916 elif [ -f "${image}" ]
918 if losetup --help 2>&1 | grep -q -- "-r\b"
920 backdev=$(get_backing_device "${image}" "-r")
922 backdev=$(get_backing_device "${image}")
924 fstype=$(get_fstype "${backdev}")
926 if [ "${fstype}" = "unknown" ]
928 panic "Unknown file system type on ${backdev} (${image})"
931 if [ -z "${fstype}" ]
933 fstype="${imagename##*.}"
934 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
937 if [ "${UNIONTYPE}" != "unionmount" ]
939 mpoint="${croot}/${imagename}"
940 rofslist="${mpoint} ${rofslist}"
943 rofslist="${rootmnt} ${rofslist}"
946 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
947 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
952 # we have a plain root system
953 mkdir -p "${croot}/filesystem"
954 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
955 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
956 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
957 rofslist="${croot}/filesystem ${rofslist}"
959 mount -o bind ${croot}/filesystem $mountpoint
965 # Looking for persistent devices or files
966 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
969 if [ -z "${QUICKUSBMODULES}" ]
972 num_block=$(ls -l /sys/block | wc -l)
973 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
975 modprobe -q -b ${module}
981 # For some reason, udevsettle does not block in this scenario,
982 # so we sleep for a little while.
984 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
985 for timeout in 5 4 3 2 1
989 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
996 case "${PERSISTENT_MEDIA}" in
998 whitelistdev="$(removable_dev)"
1001 whitelistdev="$(removable_usb_dev)"
1008 if echo ${PERSISTENT_METHOD} | grep -qe "\<overlay\>"
1010 overlays="${root_overlay_label} ${custom_overlay_label}"
1013 if echo ${PERSISTENT_METHOD} | grep -qe "\<snapshot\>"
1015 snapshots="${root_snapshot_label} ${home_snapshot_label}"
1018 local root_snapdata=""
1019 local home_snapshot_label=""
1020 local root_overlay_label=""
1021 local overlay_devices=""
1022 for media in $(find_persistent_media "${overlays}" "${snapshots}" "${blacklistdev}" "${whitelistdev}")
1024 media="$(echo ${media} | tr ":" " ")"
1026 ${root_snapshot_label}=*)
1027 if [ -z "${root_snapdata}" ]
1029 root_snapdata="${media#*=}"
1032 ${home_snapshot_label}=*)
1033 # This second type should be removed when snapshot will get smarter,
1034 # hence when "/etc/live-snapshot*list" will be supported also by
1035 # ext2|ext3|ext4|jffs2 snapshot types.
1036 if [ -z "${home_snapdata}" ]
1038 home_snapdata="${media#*=}"
1041 ${root_overlay_label}=*)
1042 if [ -z "${root_overlay_device}" ]
1044 device="${media#*=}"
1045 root_overlay_device="${device}"
1048 ${custom_overlay_label}=*)
1049 device="${media#*=}"
1050 overlay_devices="${overlay_devices} ${device}"
1055 if [ -b "${root_overlay_device}" ]
1057 PERSISTENCE_IS_ON="1"
1058 export PERSISTENCE_IS_ON
1060 cowdevice=${root_overlay_device}
1061 cow_fstype=$(get_fstype "${root_overlay_device}")
1062 if [ -z "${PERSISTENT_READONLY}" ]
1064 cow_mountopt="rw,noatime"
1066 cow_mountopt="ro,noatime"
1069 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1071 fsck -y ${cowdevice}
1074 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1076 # check if there are any nfs options
1077 if echo ${NFS_COW}|grep -q ','
1079 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1080 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1082 nfs_cow_opts="-o nolock"
1086 if [ -n "${PERSISTENT_READONLY}" ]
1088 nfs_cow_opts="${nfs_cow_opts},nocto,ro"
1094 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1097 panic "unable to determine mac address"
1101 if [ -z "${cowdevice}" ]
1105 cow_mountopt="rw,noatime,mode=755"
1108 if [ "${UNIONTYPE}" != "unionmount" ]
1110 if [ -n "${PERSISTENT_READONLY}" ]
1112 mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/cow"
1113 root_backing="${rootmnt}/live/persistent/$(basename ${cowdevice})-root"
1114 mkdir -p ${root_backing}
1119 if [ "${cow_fstype}" = "nfs" ]
1122 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing}"
1123 nfsmount ${nfs_cow_opts} ${cowdevice} ${root_backing} || \
1124 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on ${root_backing}"
1126 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} ${root_backing} || \
1127 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on ${root_backing}"
1131 rofscount=$(echo ${rofslist} |wc -w)
1133 # XXX: we now ensure that there can only be one read-only filesystem. Should this be inside the EXPOSED_ROOT if?
1134 if [ ${rofscount} -ne 1 ]
1136 panic "only one RO file system supported with exposedroot: ${rofslist}"
1140 if [ -n "${EXPOSED_ROOT}" ]
1142 mount --bind ${rofs} ${rootmnt} || \
1143 panic "bind mount of ${rofs} failed"
1145 if [ -z "${SKIP_UNION_MOUNTS}" ]
1147 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1155 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
1157 true # FIXME: Maybe it does, I don't really know.
1158 #panic "unionmount does not support subunions (${cow_dirs})."
1161 for dir in ${cow_dirs}; do
1162 unionmountpoint="${rootmnt}${dir}"
1163 mkdir -p ${unionmountpoint}
1164 if [ "${UNIONTYPE}" = "unionmount" ]
1166 # FIXME: handle PERSISTENT_READONLY
1167 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
1168 mount_full $unionmountopts "${unionmountpoint}"
1170 cow_dir="/cow${dir}"
1171 rofs_dir="${rofs}${dir}"
1173 if [ -n "${PERSISTENT_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
1175 #mount -t tmpfs -o rw,noatime,mode=755 tmpfs "${cow_dir}"
1176 do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir}
1178 do_union ${unionmountpoint} ${cow_dir} ${rofs_dir}
1180 fi || panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
1183 # Correct the permissions of /:
1184 chmod 0755 "${rootmnt}"
1186 # tmpfs file systems
1188 mkdir -p "${rootmnt}/live"
1189 mount -t tmpfs tmpfs ${rootmnt}/live
1192 # SHOWMOUNTS is necessary for custom mounts with the union option
1193 # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS
1194 if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ] 1)
1196 # 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).
1197 for d in ${rofslist}
1199 live_rofs="${rootmnt}/live/rofs/${d##*/}"
1200 live_rofs_list="${live_rofs_list} ${live_rofs}"
1201 mkdir -p "${live_rofs}"
1204 # do nothing # mount -o bind "${d}" "${live_rofs}"
1207 case "${UNIONTYPE}" in
1209 mount -o bind "${d}" "${live_rofs}"
1212 mount -o move "${d}" "${live_rofs}"
1220 # Adding custom persistent
1221 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1223 local custom_mounts="/custom_mounts.list"
1224 rm -rf ${custom_mounts} 2> /dev/null
1226 # Gather information about custom mounts from devies detected as overlays
1227 get_custom_mounts ${overlay_devices} ${custom_mounts} ${rootmnt}
1229 [ "${DEBUG}" = "Yes" ] && cp ${custom_mounts} "${rootmnt}/live/persistent"
1231 # Now we do the actual mounting (and symlinking)
1232 do_custom_mounts ${custom_mounts} ${rootmnt}
1235 # Look for other snapshots to copy in
1236 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1237 # This second type should be removed when snapshot grow smarter
1238 try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
1241 # shows cow fs on /cow for use by live-snapshot
1242 mkdir -p "${rootmnt}/live/cow"
1243 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"
1250 skip_uuid_check="${3}"
1252 # support for fromiso=.../isofrom=....
1253 if [ -n "$FROMISO" ]
1255 ISO_DEVICE=$(dirname $FROMISO)
1256 if ! [ -b $ISO_DEVICE ]
1258 # to support unusual device names like /dev/cciss/c0d0p1
1259 # as well we have to identify the block device name, let's
1260 # do that for up to 15 levels
1262 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1264 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1265 [ -b "$ISO_DEVICE" ] && break
1270 if [ "$ISO_DEVICE" = "/" ]
1272 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live-boot.log
1274 fs_type=$(get_fstype "${ISO_DEVICE}")
1275 if is_supported_fs ${fs_type}
1278 mount -t $fs_type "$ISO_DEVICE" /isofrom
1279 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1280 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1281 devname="${loopdevname}"
1283 echo "Warning: unable to mount $ISO_DEVICE." >>/live-boot.log
1288 if [ -z "${devname}" ]
1290 devname=$(sys2dev "${sysdev}")
1293 if [ -d "${devname}" ]
1295 mount -o bind "${devname}" $mountpoint || continue
1297 if is_live_path $mountpoint
1307 for device in ${devname}
1311 # Adding lvm support
1312 if [ -x /scripts/local-top/lvm2 ]
1314 ROOT="$device" resume="" /scripts/local-top/lvm2
1319 # Adding raid support
1320 if [ -x /scripts/local-top/mdadm ]
1322 cp /conf/conf.d/md /conf/conf.d/md.orig
1323 echo "MD_DEVS=$device " >> /conf/conf.d/md
1324 /scripts/local-top/mdadm
1325 mv /conf/conf.d/md.orig /conf/conf.d/md
1332 [ -n "$device" ] && devname="$device"
1334 [ -e "$devname" ] || continue
1336 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1338 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1339 devname="${loopdevname}"
1342 fstype=$(get_fstype "${devname}")
1344 if is_supported_fs ${fstype}
1346 devuid=$(blkid -o value -s UUID "$devname")
1347 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1348 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1349 [ -n "$devuid" ] && echo "$devuid" >> $tried
1351 if is_live_path ${mountpoint} && \
1352 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1357 umount ${mountpoint} 2>/dev/null
1361 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1363 losetup -d "${loopdevname}"
1373 # don't start autodetection before timeout has expired
1374 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1376 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1382 # first look at the one specified in the command line
1383 case "${LIVE_MEDIA}" in
1385 for sysblock in $(removable_usb_dev "sys")
1387 for dev in $(subdevices "${sysblock}")
1389 if check_dev "${dev}"
1399 for sysblock in $(removable_dev "sys")
1401 for dev in $(subdevices "${sysblock}")
1403 if check_dev "${dev}"
1413 if [ ! -z "${LIVE_MEDIA}" ]
1415 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1423 # or do the scan of block devices
1424 # prefer removable devices over non-removable devices, so scan them first
1425 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
1427 for sysblock in $devices_to_scan
1429 devname=$(sys2dev "${sysblock}")
1430 [ -e "$devname" ] || continue
1431 fstype=$(get_fstype "${devname}")
1433 if /lib/udev/cdrom_id ${devname} > /dev/null
1435 if check_dev "null" "${devname}"
1439 elif is_nice_device "${sysblock}"
1441 for dev in $(subdevices "${sysblock}")
1443 if check_dev "${dev}"
1448 elif [ "${fstype}" = "squashfs" -o \
1449 "${fstype}" = "btrfs" -o \
1450 "${fstype}" = "ext2" -o \
1451 "${fstype}" = "ext3" -o \
1452 "${fstype}" = "ext4" -o \
1453 "${fstype}" = "jffs2" ]
1455 # This is an ugly hack situation, the block device has
1456 # an image directly on it. It's hopefully
1457 # live-boot, so take it and run with it.
1458 ln -s "${devname}" "${devname}.${fstype}"
1459 echo "${devname}.${fstype}"
1469 media_mountpoint="${1}"
1471 log_begin_msg "Checking media integrity"
1473 cd ${media_mountpoint}
1474 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1479 if [ "${RC}" -eq 0 ]
1481 log_success_msg "Everything ok, will reboot in 10 seconds."
1484 umount ${media_mountpoint}
1486 echo u > /proc/sysrq-trigger
1487 echo b > /proc/sysrq-trigger
1489 panic "Not ok, a media defect is likely, switch to VT8 for details."
1495 if [ -x /scripts/local-top/cryptroot ]; then
1496 /scripts/local-top/cryptroot
1501 exec > live-boot.log
1503 tail -f live-boot.log >&7 &
1506 # Ensure 'panic' function is overridden
1507 . /scripts/live-functions
1511 maybe_break live-premount
1512 log_begin_msg "Running /scripts/live-premount"
1513 run_scripts /scripts/live-premount
1516 # Needed here too because some things (*cough* udev *cough*)
1517 # changes the timeout
1519 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1523 livefs_root="${mountpoint}"
1525 panic "Unable to find a live file system on the network"
1528 if [ -n "${ISCSI_PORTAL}" ]
1530 do_iscsi && livefs_root="${mountpoint}"
1531 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1533 # Do a local boot from hd
1536 if [ -x /usr/bin/memdiskfind ]
1538 MEMDISK=$(/usr/bin/memdiskfind)
1542 # We found a memdisk, set up phram
1543 modprobe phram phram=memdisk,${MEMDISK}
1545 # Load mtdblock, the memdisk will be /dev/mtdblock0
1550 # Scan local devices for the image
1552 while [ "$i" -lt 60 ]
1554 livefs_root=$(find_livefs ${i})
1556 if [ -n "${livefs_root}" ]
1567 if [ -z "${livefs_root}" ]
1569 panic "Unable to find a medium containing a live file system"
1572 if [ "${INTEGRITY_CHECK}" ]
1574 integrity_check "${livefs_root}"
1580 elif [ "${TODISK}" ]
1582 live_dest="${TODISK}"
1585 if [ "${live_dest}" ]
1587 log_begin_msg "Copying live media to ${live_dest}"
1588 copy_live_to "${livefs_root}" "${live_dest}"
1592 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1593 # because the mountpoint is left behind in /proc/mounts, so let's get
1594 # rid of it when running from RAM
1595 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1597 losetup -d /dev/loop0
1598 grep -q /isofrom /proc/mounts && umount /isofrom
1601 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1603 setup_unionfs "${livefs_root}" "${rootmnt}"
1606 mac="$(echo ${mac} | sed 's/-//g')"
1607 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1611 if [ -n "${ROOT_PID}" ] ; then
1612 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1617 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1618 # live-bottom; udev's init script will take care of things after that
1619 if [ "${UNIONTYPE}" = unionfs-fuse ]
1621 mount -n -o bind /dev "${rootmnt}/dev"
1624 # Move to the new root filesystem so that programs there can get at it.
1625 if [ ! -d /root/live/image ]
1627 mkdir -p /root/live/image
1628 mount --move /live/image /root/live/image
1631 # aufs2 in kernel versions around 2.6.33 has a regression:
1632 # directories can't be accessed when read for the first the time,
1633 # causing a failure for example when accessing /var/lib/fai
1634 # when booting FAI, this simple workaround solves it
1635 ls /root/* >/dev/null 2>&1
1637 # copy snapshot configuration if exists
1638 if [ -f snapshot.conf ]
1640 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
1641 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
1643 mkdir -p "${rootmnt}/etc/live/boot.d"
1645 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
1649 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
1651 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
1652 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
1656 maybe_break live-bottom
1657 log_begin_msg "Running /scripts/live-bottom\n"
1659 run_scripts /scripts/live-bottom
1662 if [ "${UNIONFS}" = unionfs-fuse ]
1664 umount "${rootmnt}/dev"
1670 [ -w "${rootmnt}/var/log/" ] && cp live-boot.log "${rootmnt}/var/log/" 2>/dev/null