5 export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
7 echo "/root/lib" >> /etc/ld.so.conf
8 echo "/root/usr/lib" >> /etc/ld.so.conf
10 mountpoint="/live/image"
11 alt_mountpoint="/media"
12 LIVE_MEDIA_PATH="live"
14 root_persistence="live-rw"
15 home_persistence="home-rw"
16 root_snapshot_label="live-sn"
17 home_snapshot_label="home-sn"
20 USERFULLNAME="Live user"
23 mkdir -p "${mountpoint}"
26 # Create /etc/mtab for debug purpose and future syncs
37 . /scripts/live-helpers
39 if [ ! -f /live.vars ]
49 for ARGUMENT in $(cat /proc/cmdline)
58 export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
62 ACCESS="${ARGUMENT#access=}"
67 DEFCONSOLE="${ARGUMENT#*=}"
83 # Force dhcp even while netbooting
84 # Use for debugging in case somebody works on fixing dhclient
94 DEVICE="${ARGUMENT#ethdevice=}"
96 export DEVICE ETHDEVICE
100 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
101 export ETHDEV_TIMEOUT
105 FETCH="${ARGUMENT#fetch=}"
110 FORCEPERSISTENTFSCK="Yes"
111 export FORCEPERSISTENTFSCK
115 FTPFS="${ARGUMENT#ftpfs=}"
120 HTTPFS="${ARGUMENT#httpfs=}"
125 ISCSI="${ARGUMENT#iscsi=}"
126 #ip:port - separated by ;
127 ISCSI_PORTAL="${ISCSI%;*}"
128 if echo "${ISCSI_PORTAL}" | grep -q , ; then
129 ISCSI_SERVER="${ISCSI_PORTAL%,*}"
130 ISCSI_PORT="${ISCSI_PORTAL#*,}"
133 ISCSI_TARGET="${ISCSI#*;}"
134 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
138 FROMISO="${ARGUMENT#*=}"
148 INTEGRITY_CHECK="Yes"
149 export INTEGRITY_CHECK
153 STATICIP="${ARGUMENT#ip=}"
155 if [ -z "${STATICIP}" ]
168 live-media=*|bootfrom=*)
169 LIVE_MEDIA="${ARGUMENT#*=}"
173 live-media-encryption=*|encryption=*)
174 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
175 export LIVE_MEDIA_ENCRYPTION
179 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
180 export LIVE_MEDIA_OFFSET
184 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
185 export LIVE_MEDIA_PATH
188 live-media-timeout=*)
189 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
190 export LIVE_MEDIA_TIMEOUT
194 MODULE="${ARGUMENT#module=}"
199 NETBOOT="${ARGUMENT#netboot=}"
204 NFSOPTS="${ARGUMENT#nfsopts=}"
209 NFS_COW="${ARGUMENT#nfscow=}"
214 NOACCESSIBILITY="Yes"
215 export NOACCESSIBILITY
234 ramdisk_size="${ARGUMENT#ramdisk-size=}"
248 PERSISTENT="${ARGUMENT#persistent=}"
249 if [ -z "${PERSISTENT}" ]
257 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
258 export PERSISTENT_PATH
261 persistent-subtext=*)
262 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
263 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
264 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
265 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
279 NOPROMPT="${ARGUMENT#noprompt=}"
284 QUICKUSBMODULES="Yes"
285 export QUICKUSBMODULES
288 preseed/file=*|file=*)
289 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
299 question="${ARGUMENT%%=*}"
300 value="${ARGUMENT#*=}"
301 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
316 TODISK="${ARGUMENT#todisk=}"
327 MODULETORAM="${ARGUMENT#toram=}"
328 export TORAM MODULETORAM
342 SKIP_UNION_MOUNTS="Yes"
343 export SKIP_UNION_MOUNTS
347 ROOT="${ARGUMENT#root=}"
352 UNIONTYPE="${ARGUMENT#union=}"
358 # sort of compatibility with netboot.h from linux docs
359 if [ -z "${NETBOOT}" ]
361 if [ "${ROOT}" = "/dev/nfs" ]
365 elif [ "${ROOT}" = "/dev/cifs" ]
372 if [ -z "${MODULE}" ]
378 if [ -z "${UNIONTYPE}" ]
389 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
391 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
393 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
405 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
411 uuid="$(cat /conf/uuid.conf)"
413 for try_uuid_file in "${path}/.disk/live-uuid"*
415 [ -e "${try_uuid_file}" ] || continue
417 try_uuid="$(cat "${try_uuid_file}")"
419 if [ "${uuid}" = "${try_uuid}" ]
428 get_backing_device ()
431 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
432 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
440 panic "Unrecognized live filesystem: ${1}"
445 match_files_in_dir ()
447 # Does any files match pattern ${1} ?
450 if [ "$(echo ${pattern})" != "${pattern}" ]
458 mount_images_in_directory ()
465 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
466 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
467 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
468 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
469 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
470 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
472 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
473 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
475 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
481 sysfs_path="${1#/sys}"
483 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
486 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
489 elif echo ${sysfs_path} | grep -q "^/block/dm-"
492 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
504 copyto="${copyfrom}_swap"
506 if [ -z "${MODULETORAM}" ]
508 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
510 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
512 if [ -f "${MODULETORAMFILE}" ]
514 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
516 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
521 if [ "${copytodev}" = "ram" ]
524 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
525 mount_options="-o size=${size}k"
530 # it should be a writable block device
531 if [ -b "${copytodev}" ]
535 fstype=$(get_fstype "${dev}")
536 freespace=$(fs_size "${dev}")
538 log_warning_msg "${copytodev} is not a block device."
543 if [ "${freespace}" -lt "${size}" ]
545 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
549 # Custom ramdisk size
550 if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ]
552 # FIXME: should check for wrong values
553 mount_options="-o size=${ramdisk_size}"
556 # begin copying (or uncompressing)
558 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
559 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
561 if [ "${extension}" = "tgz" ]
564 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
565 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
566 mount -r -o move "${copyto}" "${rootmnt}"
569 if [ -n "${MODULETORAMFILE}" ]
573 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
574 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
576 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
581 echo " * Copying whole medium to RAM" 1>/dev/console
582 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
584 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
585 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
586 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
588 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
594 mount -r -o move ${copyto} ${copyfrom}
603 modprobe -q af_packet # For DHCP
608 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
609 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
611 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
612 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
616 # support for Syslinux IPAPPEND parameter
617 # it sets the BOOTIF variable on the kernel parameter
619 if [ -n "${BOOTIF}" ]
621 # pxelinux sets BOOTIF to a value based on the mac address of the
622 # network card used to PXE boot, so use this value for DEVICE rather
623 # than a hard-coded device name from initramfs.conf. this facilitates
624 # network booting when machines may have multiple network cards.
625 # pxelinux sets BOOTIF to 01-$mac_address
627 # strip off the leading "01-", which isn't part of the mac
629 temp_mac=${BOOTIF#*-}
631 # convert to typical mac address format by replacing "-" with ":"
636 if [ -z "$bootif_mac" ]
640 bootif_mac="$bootif_mac:$x"
645 # look for devices with matching mac address, and set DEVICE to
646 # appropriate value if match is found.
648 for device in /sys/class/net/*
650 if [ -f "$device/address" ]
652 current_mac=$(cat "$device/address")
654 if [ "$bootif_mac" = "$current_mac" ]
663 # if ethdevice was not specified on the kernel command line
664 # make sure we try to get a working network configuration
665 # for *every* present network device (except for loopback of course)
666 if [ -z "$ETHDEVICE" ] ; then
667 echo "If you want to boot from a specific device use bootoption ethdevice=..."
668 for device in /sys/class/net/*; do
670 if [ "$dev" != "lo" ] ; then
671 ETHDEVICE="$ETHDEVICE $dev"
676 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
677 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
678 devlist="$devlist $device"
681 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
682 # an endless loop; iff execution fails give it two further tries, that's
683 # why we use '$devlist $devlist $devlist' for the other for loop
684 for dev in $devlist $devlist $devlist ; do
685 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
686 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
688 sleep "$ETHDEV_TIMEOUT" ; sleep 1
689 if [ -r /proc/"$jobid"/status ] ; then
690 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
694 # if configuration of device worked we should have an assigned
695 # IP address, iff so let's use the according as $DEVICE for later usage
696 # simple and primitive approach which seems to work fine
697 if ifconfig $dev | grep -q 'inet.*addr:' ; then
704 for interface in ${DEVICE}; do
705 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
706 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
707 if [ "$IPV4ADDR" != "0.0.0.0" ]
714 for interface in ${DEVICE}; do
715 # source relevant ipconfig output
716 OLDHOSTNAME=${HOSTNAME}
717 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
718 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
721 if [ -n "${interface}" ]
723 HWADDR="$(cat /sys/class/net/${interface}/address)"
726 if [ ! -e "/etc/resolv.conf" ]
728 echo "Creating /etc/resolv.conf"
730 if [ -n "${DNSDOMAIN}" ]
732 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
733 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
736 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
738 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
740 echo "nameserver $i" >> /etc/resolv.conf
745 # Check if we have a network device at all
746 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
747 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
748 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
749 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
750 ! ls /sys/class/net/ra0 > /dev/null 2>&1
752 panic "No supported network device found, maybe a non-mainline driver is required."
761 if [ "${NFSROOT}" = "auto" ]
763 NFSROOT=${ROOTSERVER}:${ROOTPATH}
768 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
774 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
776 NFSROOT=${ROOTSERVER}:${NFSROOT}
779 log_begin_msg "Trying netboot from ${NFSROOT}"
781 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
801 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
802 #FIXME this name is supposed to be unique - some date + ifconfig hash?
803 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
804 export ISCSI_INITIATORNAME
805 if [ -n "${ISCSI_SERVER}" ] ; then
806 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
808 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
812 panic "Failed to log into iscsi target"
814 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
815 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
820 while [ -z "${devices}" -a $i -lt 60 ]
823 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
824 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
830 if check_dev "null" "/dev/$dev"
837 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
839 panic "Failed to locate iSCSI host in /sys"
847 for webfile in HTTPFS FTPFS FETCH
849 local url="$(eval echo \"\$\{${webfile}\}\")"
850 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
854 case "${extension}" in
855 iso|squashfs|tgz|tar)
856 if [ "${extension}" = "iso" ]
858 mkdir -p "${alt_mountpoint}"
859 dest="${alt_mountpoint}"
861 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
862 mount -t ramfs ram "${mountpoint}"
865 if [ "${webfile}" = "FETCH" ]
869 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
870 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
871 lfile="$(basename $url)"
872 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
873 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
877 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
878 wget "${url}" -O "${dest}/$(basename ${url})"
882 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
883 if [ "${webfile}" = "FTPFS" ]
885 FUSE_MOUNT="curlftpfs"
886 url="$(dirname ${url})"
891 $FUSE_MOUNT "${url}" "${dest}"
892 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
894 [ ${?} -eq 0 ] && rc=0
895 [ "${extension}" = "tgz" ] && live_dest="ram"
896 if [ "${extension}" = "iso" ]
898 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
899 mount -t iso9660 "${isoloop}" "${mountpoint}"
906 log_begin_msg "Unrecognized archive extension for ${url}"
914 if [ -d "${alt_mountpoint}" ]
916 umount "${alt_mountpoint}"
917 rmdir "${alt_mountpoint}"
919 umount "${mountpoint}"
920 elif [ "${webfile}" != "FETCH" ] ; then
934 if [ -z "${NFSOPTS}" ]
939 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
941 # FIXME: This while loop is an ugly HACK round an nfs bug
943 while [ "$i" -lt 60 ]
945 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
957 if [ -x "/sbin/mount.cifs" ]
959 if [ -z "${NFSOPTS}" ]
961 CIFSOPTS="-ouser=root,password="
963 CIFSOPTS="${NFSOPTS}"
966 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
969 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
983 size=$(fs_size "${fromdev}" "" "used")
985 if [ -b "${fromdev}" ]
987 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
990 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
992 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
993 freespace=$(df -k | awk '/'${todev}'/{print $4}')
995 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
998 tomount="/mnt/tmpsnap"
1000 if [ ! -d "${tomount}" ]
1002 mkdir -p "${tomount}"
1005 fstype=$(get_fstype "${fromdev}")
1007 if [ -n "${fstype}" ]
1010 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1011 cp -a "${tomount}"/* ${todir}
1014 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1019 if echo ${fromdev} | grep -qs loop
1021 losetup -d "${fromdev}"
1026 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1033 # Look for ${snap_label}.* in block devices
1035 black_listed_devices="${2}"
1036 white_listed_devices="${3}"
1038 if [ "${PERSISTENT}" != "nofiles" ]
1040 # search for image files
1041 snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2" "${black_listed_devices}" "${white_listed_devices}")
1044 if [ -z "${snapdata}" ]
1046 snapdata=$(find_cow_device "${snap_label}" "${black_listed_devices}" "${white_listed_devices}")
1053 # copy the contents of previously found snapshot to ${snap_mount}
1054 # and remember the device and filename for resync on exit in live-boot.init
1061 if [ -z "${snap_relpath}" ]
1063 # root snapshot, default usage
1066 # relative snapshot (actually used just for "/home" snapshots)
1067 snap_mount="${2}${snap_relpath}"
1070 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1072 log_success_msg "found snapshot: ${snapdata}"
1073 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1074 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1075 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1077 if ! try_mount "${snapdev}" "${snapback}" "ro"
1084 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1086 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1087 dev=$(get_backing_device "${snapback}/${snapfile}")
1089 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1094 # Unfortunately klibc's cpio is incompatible with the
1095 # rest of the world; everything else requires -u -d,
1096 # while klibc doesn't implement them. Try to detect
1097 # whether it's in use.
1098 cpiopath="$(which cpio)" || true
1099 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1103 cpioargs='--unconditional --make-directories'
1106 if [ -s "${snapback}/${snapfile}" ]
1109 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
1113 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
1117 if [ "${RES}" != "0" ]
1119 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1123 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1125 if [ "${RES}" != "0" ]
1127 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1130 elif [ -b "${snapdata}" ]
1132 # Try to find if it could be a snapshot partition
1134 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1135 if echo "${dev}" | grep -qs loop
1137 # strange things happens, user confused?
1138 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1139 snapfile=$(basename ${snaploop})
1140 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1145 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1147 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
1150 if [ -n "${snapfile}" ]
1152 # it was a loop device, user confused
1157 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
1161 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
1167 image_directory="${1}"
1169 addimage_directory="${3}"
1171 case ${UNIONTYPE} in
1173 modprobe -q -b ${UNIONTYPE}
1175 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1177 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1178 echo "This might be really slow."
1180 UNIONTYPE="unionfs-fuse"
1185 if [ "${UNIONTYPE}" = unionfs-fuse ]
1190 # run-init can't deal with images in a subdir, but we're going to
1191 # move all of these away before it runs anyway. No, we're not,
1192 # put them in / since move-mounting them into / breaks mono and
1197 # Let's just mount the read-only file systems first
1200 if [ "${UNIONTYPE}" = "aufs" ]
1203 noxino_opt="noxino,"
1204 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1211 if [ -z "${PLAIN_ROOT}" ]
1213 # Read image names from ${MODULE}.module if it exists
1214 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1216 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1218 image_string="${image_string} ${image_directory}/${IMAGE}"
1220 elif [ -e "${image_directory}/${MODULE}.module" ]
1222 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1224 image_string="${image_string} ${image_directory}/${IMAGE}"
1227 # ${MODULE}.module does not exist, create a list of images
1228 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1230 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1232 if [ -e "${IMAGE}" ]
1234 image_string="${image_string} ${IMAGE}"
1239 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1241 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1243 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1245 if [ -e "${IMAGE}" ]
1247 image_string="${image_string} ${IMAGE}"
1254 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1257 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1261 for image in ${image_string}
1263 imagename=$(basename "${image}")
1265 export image devname
1266 maybe_break live-realpremount
1267 log_begin_msg "Running /scripts/live-realpremount"
1268 run_scripts /scripts/live-realpremount
1271 if [ -d "${image}" ]
1273 # it is a plain directory: do nothing
1274 rofslist="${image} ${rofslist}"
1275 elif [ -f "${image}" ]
1277 if losetup --help 2>&1 | grep -q -- "-r\b"
1279 backdev=$(get_backing_device "${image}" "-r")
1281 backdev=$(get_backing_device "${image}")
1283 fstype=$(get_fstype "${backdev}")
1285 if [ "${fstype}" = "unknown" ]
1287 panic "Unknown file system type on ${backdev} (${image})"
1290 if [ -z "${fstype}" ]
1292 fstype="${imagename##*.}"
1293 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1296 if [ "${UNIONTYPE}" != "unionmount" ]
1298 mpoint="${croot}/${imagename}"
1299 rofslist="${mpoint} ${rofslist}"
1302 rofslist="${rootmnt} ${rofslist}"
1304 mkdir -p "${mpoint}"
1305 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
1306 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
1311 # we have a plain root system
1312 mkdir -p "${croot}/filesystem"
1313 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1314 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
1315 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
1316 rofslist="${croot}/filesystem ${rofslist}"
1318 mount -o bind ${croot}/filesystem $mountpoint
1324 # Looking for "${root_persistence}" device or file
1325 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1327 if [ -z "${QUICKUSBMODULES}" ]
1330 num_block=$(ls -l /sys/block | wc -l)
1331 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1333 modprobe -q -b ${module}
1339 # For some reason, udevsettle does not block in this scenario,
1340 # so we sleep for a little while.
1342 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1343 for timeout in 5 4 3 2 1
1347 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1354 # search for label and files (this could be hugely optimized)
1355 cowprobe=$(find_cow_device "${root_persistence}" "${blacklistdev}" "${whitelistdev}")
1356 if [ -b "${cowprobe}" ]
1358 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1359 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1360 # snapshots to be sure to really store some e.g key config files,
1361 # but not on the same media
1362 blacklistdev="${cowprobe}"
1363 PERSISTENCE_IS_ON="1"
1364 export PERSISTENCE_IS_ON
1366 # homecow just mount something on /home, this should be generalized some way
1367 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}" "${whitelistdev}")
1368 if [ -b "${homecow}" ]
1370 PERSISTENCE_IS_ON="1"
1371 export PERSISTENCE_IS_ON
1373 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}" "${whitelistdev}")
1374 # This second type should be removed when snapshot will get smarter,
1375 # hence when "/etc/live-snapshot*list" will be supported also by
1376 # ext2|ext3|ext4|jffs2 snapshot types.
1377 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}" "${whitelistdev}")
1379 if [ -b "${cowprobe}" ]
1381 cowdevice=${cowprobe}
1382 cow_fstype=$(get_fstype "${cowprobe}")
1383 cow_mountopt="rw,noatime"
1385 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1387 fsck -y ${cowdevice}
1390 log_warning_msg "Unable to find the persistent medium"
1393 cow_mountopt="rw,noatime,mode=755"
1395 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1397 # check if there are any nfs options
1398 if echo ${NFS_COW}|grep -q ','
1400 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1401 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1403 nfs_cow_opts="-o nolock"
1409 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1412 panic "unable to determine mac address"
1417 cow_mountopt="rw,noatime,mode=755"
1420 if [ "${UNIONTYPE}" != "unionmount" ]
1423 if [ "${cow_fstype}" = "nfs" ]
1426 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1427 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1428 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1430 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1431 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1435 rofscount=$(echo ${rofslist} |wc -w)
1437 if [ ${rofscount} -ne 1 ]
1439 panic "only one RO file system supported with exposedroot: ${rofslist}"
1443 if [ -n "${EXPOSED_ROOT}" ]
1445 mount --bind ${rofs} ${rootmnt} || \
1446 panic "bind mount of ${rofs} failed"
1448 if [ -z "${SKIP_UNION_MOUNTS}" ]
1450 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1458 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
1460 true # FIXME: Maybe it does, I don't really know.
1461 #panic "unionmount does not support subunions (${cow_dirs})."
1467 for dir in ${cow_dirs}; do
1470 unionmountpoint="${rootmnt}${dir}"
1471 unionrw="/cow${dir}"
1472 unionro="${rofs}${dir}"
1473 # We don't handle spaces and other junk gracefully here, hopefully not needed.
1474 case "${UNIONTYPE}" in
1476 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1477 unionmountopts="${unionmountopts} ${unionrw}=RW:${unionro}=RO"
1478 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1479 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1480 ( mkdir -p /run/sendsigs.omit.d
1481 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1485 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
1486 mount_full $unionmountopts "${unionmountpoint}"
1491 unionmountopts="-o noatime,${noxino_opt}dirs=${unionrw}=rw:${unionro}=${roopt}"
1492 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1495 panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
1498 # Correct the permissions of /:
1499 chmod 0755 "${rootmnt}"
1501 # tmpfs file systems
1503 mkdir -p "${rootmnt}/live"
1504 mount -t tmpfs tmpfs ${rootmnt}/live
1506 # Adding other custom mounts
1507 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1509 # directly mount /home
1510 # FIXME: add a custom mounts configurable system
1512 if [ -b "${homecow}" ]
1514 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1515 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1517 log_warning_msg "Unable to find the persistent home medium"
1520 # Look for other snapshots to copy in
1521 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1522 # This second type should be removed when snapshot grow smarter
1523 try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
1526 if [ -n "${SHOWMOUNTS}" ]
1528 for d in ${rofslist}
1530 mkdir -p "${rootmnt}/live/${d##*/}"
1534 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1538 case "${UNIONTYPE}" in
1540 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1544 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1552 # shows cow fs on /cow for use by live-snapshot
1553 mkdir -p "${rootmnt}/live/cow"
1554 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"
1561 skip_uuid_check="${3}"
1563 # support for fromiso=.../isofrom=....
1564 if [ -n "$FROMISO" ]
1566 ISO_DEVICE=$(dirname $FROMISO)
1567 if ! [ -b $ISO_DEVICE ]
1569 # to support unusual device names like /dev/cciss/c0d0p1
1570 # as well we have to identify the block device name, let's
1571 # do that for up to 15 levels
1573 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1575 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1576 [ -b "$ISO_DEVICE" ] && break
1581 if [ "$ISO_DEVICE" = "/" ]
1583 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live-boot.log
1585 fs_type=$(get_fstype "${ISO_DEVICE}")
1586 if is_supported_fs ${fs_type}
1589 mount -t $fs_type "$ISO_DEVICE" /isofrom
1590 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1591 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1592 devname="${loopdevname}"
1594 echo "Warning: unable to mount $ISO_DEVICE." >>/live-boot.log
1599 if [ -z "${devname}" ]
1601 devname=$(sys2dev "${sysdev}")
1604 if [ -d "${devname}" ]
1606 mount -o bind "${devname}" $mountpoint || continue
1608 if is_live_path $mountpoint
1618 for device in ${devname}
1622 # Adding lvm support
1623 if [ -x /scripts/local-top/lvm2 ]
1625 ROOT="$device" resume="" /scripts/local-top/lvm2
1630 # Adding raid support
1631 if [ -x /scripts/local-top/mdadm ]
1633 cp /conf/conf.d/md /conf/conf.d/md.orig
1634 echo "MD_DEVS=$device " >> /conf/conf.d/md
1635 /scripts/local-top/mdadm
1636 mv /conf/conf.d/md.orig /conf/conf.d/md
1643 [ -n "$device" ] && devname="$device"
1645 [ -e "$devname" ] || continue
1647 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1649 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1650 devname="${loopdevname}"
1653 fstype=$(get_fstype "${devname}")
1655 if is_supported_fs ${fstype}
1657 devuid=$(blkid -o value -s UUID "$devname")
1658 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1659 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1660 [ -n "$devuid" ] && echo "$devuid" >> $tried
1662 if is_live_path ${mountpoint} && \
1663 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1668 umount ${mountpoint}
1672 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1674 losetup -d "${loopdevname}"
1684 # don't start autodetection before timeout has expired
1685 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1687 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1693 # first look at the one specified in the command line
1694 case "${LIVE_MEDIA}" in
1696 for sysblock in $(removable_usb_dev "sys")
1698 for dev in $(subdevices "${sysblock}")
1700 if check_dev "${dev}"
1710 for sysblock in $(removable_dev "sys")
1712 for dev in $(subdevices "${sysblock}")
1714 if check_dev "${dev}"
1724 if [ ! -z "${LIVE_MEDIA}" ]
1726 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1734 # or do the scan of block devices
1735 # prefer removable devices over non-removable devices, so scan them first
1736 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
1738 for sysblock in $devices_to_scan
1740 devname=$(sys2dev "${sysblock}")
1741 [ -e "$devname" ] || continue
1742 fstype=$(get_fstype "${devname}")
1744 if /lib/udev/cdrom_id ${devname} > /dev/null
1746 if check_dev "null" "${devname}"
1750 elif is_nice_device "${sysblock}"
1752 for dev in $(subdevices "${sysblock}")
1754 if check_dev "${dev}"
1759 elif [ "${fstype}" = "squashfs" -o \
1760 "${fstype}" = "btrfs" -o \
1761 "${fstype}" = "ext2" -o \
1762 "${fstype}" = "ext3" -o \
1763 "${fstype}" = "ext4" -o \
1764 "${fstype}" = "jffs2" ]
1766 # This is an ugly hack situation, the block device has
1767 # an image directly on it. It's hopefully
1768 # live-boot, so take it and run with it.
1769 ln -s "${devname}" "${devname}.${fstype}"
1770 echo "${devname}.${fstype}"
1780 media_mountpoint="${1}"
1782 log_begin_msg "Checking media integrity"
1784 cd ${media_mountpoint}
1785 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1790 if [ "${RC}" -eq 0 ]
1792 log_success_msg "Everything ok, will reboot in 10 seconds."
1795 umount ${media_mountpoint}
1797 echo u > /proc/sysrq-trigger
1798 echo b > /proc/sysrq-trigger
1800 panic "Not ok, a media defect is likely, switch to VT8 for details."
1806 if [ -x /scripts/local-top/cryptroot ]; then
1807 /scripts/local-top/cryptroot
1812 exec > live-boot.log
1814 tail -f live-boot.log >&7 &
1817 # Ensure 'panic' function is overridden
1818 . /scripts/live-functions
1822 maybe_break live-premount
1823 log_begin_msg "Running /scripts/live-premount"
1824 run_scripts /scripts/live-premount
1827 # Needed here too because some things (*cough* udev *cough*)
1828 # changes the timeout
1830 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1834 livefs_root="${mountpoint}"
1836 panic "Unable to find a live file system on the network"
1839 if [ -n "${ISCSI_PORTAL}" ]
1841 do_iscsi && livefs_root="${mountpoint}"
1842 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1844 # Do a local boot from hd
1847 if [ -x /usr/bin/memdiskfind ]
1849 MEMDISK=$(/usr/bin/memdiskfind)
1853 # We found a memdisk, set up phram
1854 modprobe phram phram=memdisk,${MEMDISK}
1856 # Load mtdblock, the memdisk will be /dev/mtdblock0
1861 # Scan local devices for the image
1863 while [ "$i" -lt 60 ]
1865 livefs_root=$(find_livefs ${i})
1867 if [ -n "${livefs_root}" ]
1878 if [ -z "${livefs_root}" ]
1880 panic "Unable to find a medium containing a live file system"
1883 if [ "${INTEGRITY_CHECK}" ]
1885 integrity_check "${livefs_root}"
1891 elif [ "${TODISK}" ]
1893 live_dest="${TODISK}"
1896 if [ "${live_dest}" ]
1898 log_begin_msg "Copying live media to ${live_dest}"
1899 copy_live_to "${livefs_root}" "${live_dest}"
1903 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1904 # because the mountpoint is left behind in /proc/mounts, so let's get
1905 # rid of it when running from RAM
1906 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1908 losetup -d /dev/loop0
1909 grep -q /isofrom /proc/mounts && umount /isofrom
1912 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1914 setup_unionfs "${livefs_root}" "${rootmnt}"
1917 mac="$(echo ${mac} | sed 's/-//g')"
1918 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1922 if [ -n "${ROOT_PID}" ] ; then
1923 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1928 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1929 # live-bottom; udev's init script will take care of things after that
1930 if [ "${UNIONTYPE}" = unionfs-fuse ]
1932 mount -n -o bind /dev "${rootmnt}/dev"
1935 # Move to the new root filesystem so that programs there can get at it.
1936 if [ ! -d /root/live/image ]
1938 mkdir -p /root/live/image
1939 mount --move /live/image /root/live/image
1942 # aufs2 in kernel versions around 2.6.33 has a regression:
1943 # directories can't be accessed when read for the first the time,
1944 # causing a failure for example when accessing /var/lib/fai
1945 # when booting FAI, this simple workaround solves it
1946 ls /root/* >/dev/null 2>&1
1948 # copy snapshot configuration if exists
1949 if [ -f snapshot.conf ]
1951 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
1952 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
1954 mkdir -p "${rootmnt}/etc/live/boot.d"
1956 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
1960 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
1962 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
1963 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
1967 maybe_break live-bottom
1968 log_begin_msg "Running /scripts/live-bottom\n"
1970 run_scripts /scripts/live-bottom
1973 if [ "${UNIONFS}" = unionfs-fuse ]
1975 umount "${rootmnt}/dev"
1981 [ -w "${rootmnt}/var/log/" ] && cp live-boot.log "${rootmnt}/var/log/" 2>/dev/null