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
244 PERSISTENT="${ARGUMENT#persistent=}"
245 if [ -z "${PERSISTENT}" ]
253 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
254 export PERSISTENT_PATH
257 persistent-subtext=*)
258 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
259 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
260 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
261 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
275 NOPROMPT="${ARGUMENT#noprompt=}"
280 QUICKUSBMODULES="Yes"
281 export QUICKUSBMODULES
284 preseed/file=*|file=*)
285 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
295 question="${ARGUMENT%%=*}"
296 value="${ARGUMENT#*=}"
297 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
312 TODISK="${ARGUMENT#todisk=}"
323 MODULETORAM="${ARGUMENT#toram=}"
324 export TORAM MODULETORAM
338 SKIP_UNION_MOUNTS="Yes"
339 export SKIP_UNION_MOUNTS
343 ROOT="${ARGUMENT#root=}"
348 UNIONTYPE="${ARGUMENT#union=}"
354 # sort of compatibility with netboot.h from linux docs
355 if [ -z "${NETBOOT}" ]
357 if [ "${ROOT}" = "/dev/nfs" ]
361 elif [ "${ROOT}" = "/dev/cifs" ]
368 if [ -z "${MODULE}" ]
374 if [ -z "${UNIONTYPE}" ]
385 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
387 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
389 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
401 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
407 uuid="$(cat /conf/uuid.conf)"
409 for try_uuid_file in "${path}/.disk/live-uuid"*
411 [ -e "${try_uuid_file}" ] || continue
413 try_uuid="$(cat "${try_uuid_file}")"
415 if [ "${uuid}" = "${try_uuid}" ]
424 get_backing_device ()
427 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
428 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
436 panic "Unrecognized live filesystem: ${1}"
441 match_files_in_dir ()
443 # Does any files match pattern ${1} ?
446 if [ "$(echo ${pattern})" != "${pattern}" ]
454 mount_images_in_directory ()
461 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
462 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
463 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
464 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
465 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
466 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
468 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
469 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
471 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
477 sysfs_path="${1#/sys}"
479 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
482 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
485 elif echo ${sysfs_path} | grep -q "^/block/dm-"
497 copyto="${copyfrom}_swap"
499 if [ -z "${MODULETORAM}" ]
501 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
503 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
505 if [ -f "${MODULETORAMFILE}" ]
507 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
509 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
514 if [ "${copytodev}" = "ram" ]
517 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
518 mount_options="-o size=${size}k"
523 # it should be a writable block device
524 if [ -b "${copytodev}" ]
528 fstype=$(get_fstype "${dev}")
529 freespace=$(fs_size "${dev}")
531 log_warning_msg "${copytodev} is not a block device."
536 if [ "${freespace}" -lt "${size}" ]
538 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
542 # begin copying (or uncompressing)
544 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
545 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
547 if [ "${extension}" = "tgz" ]
550 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
551 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
552 mount -r -o move "${copyto}" "${rootmnt}"
555 if [ -n "${MODULETORAMFILE}" ]
559 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
560 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
562 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
567 echo " * Copying whole medium to RAM" 1>/dev/console
568 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
570 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
571 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
572 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
574 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
580 mount -r -o move ${copyto} ${copyfrom}
589 modprobe -q af_packet # For DHCP
594 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
595 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
597 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
598 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
602 # support for Syslinux IPAPPEND parameter
603 # it sets the BOOTIF variable on the kernel parameter
605 if [ -n "${BOOTIF}" ]
607 # pxelinux sets BOOTIF to a value based on the mac address of the
608 # network card used to PXE boot, so use this value for DEVICE rather
609 # than a hard-coded device name from initramfs.conf. this facilitates
610 # network booting when machines may have multiple network cards.
611 # pxelinux sets BOOTIF to 01-$mac_address
613 # strip off the leading "01-", which isn't part of the mac
615 temp_mac=${BOOTIF#*-}
617 # convert to typical mac address format by replacing "-" with ":"
622 if [ -z "$bootif_mac" ]
626 bootif_mac="$bootif_mac:$x"
631 # look for devices with matching mac address, and set DEVICE to
632 # appropriate value if match is found.
634 for device in /sys/class/net/*
636 if [ -f "$device/address" ]
638 current_mac=$(cat "$device/address")
640 if [ "$bootif_mac" = "$current_mac" ]
649 # if ethdevice was not specified on the kernel command line
650 # make sure we try to get a working network configuration
651 # for *every* present network device (except for loopback of course)
652 if [ -z "$ETHDEVICE" ] ; then
653 echo "If you want to boot from a specific device use bootoption ethdevice=..."
654 for device in /sys/class/net/*; do
656 if [ "$dev" != "lo" ] ; then
657 ETHDEVICE="$ETHDEVICE $dev"
662 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
663 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
664 devlist="$devlist $device"
667 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
668 # an endless loop; iff execution fails give it two further tries, that's
669 # why we use '$devlist $devlist $devlist' for the other for loop
670 for dev in $devlist $devlist $devlist ; do
671 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
672 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
674 sleep "$ETHDEV_TIMEOUT" ; sleep 1
675 if [ -r /proc/"$jobid"/status ] ; then
676 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
680 # if configuration of device worked we should have an assigned
681 # IP address, iff so let's use the according as $DEVICE for later usage
682 # simple and primitive approach which seems to work fine
683 if ifconfig $dev | grep -q 'inet.*addr:' ; then
690 for interface in ${DEVICE}; do
691 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
692 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
693 if [ "$IPV4ADDR" != "0.0.0.0" ]
700 for interface in ${DEVICE}; do
701 # source relevant ipconfig output
702 OLDHOSTNAME=${HOSTNAME}
703 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
704 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
707 if [ -n "${interface}" ]
709 HWADDR="$(cat /sys/class/net/${interface}/address)"
712 if [ ! -e "/etc/resolv.conf" ]
714 echo "Creating /etc/resolv.conf"
716 if [ -n "${DNSDOMAIN}" ]
718 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
719 echo "search ${DNSDOMAIN}" > /etc/resolv.conf
722 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
724 echo "nameserver $i" >> /etc/resolv.conf
728 # Check if we have a network device at all
729 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
730 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
731 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
732 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
733 ! ls /sys/class/net/ra0 > /dev/null 2>&1
735 panic "No supported network device found, maybe a non-mainline driver is required."
744 if [ "${NFSROOT}" = "auto" ]
746 NFSROOT=${ROOTSERVER}:${ROOTPATH}
751 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
757 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
759 NFSROOT=${ROOTSERVER}:${NFSROOT}
762 log_begin_msg "Trying netboot from ${NFSROOT}"
764 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
784 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
785 #FIXME this name is supposed to be unique - some date + ifconfig hash?
786 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
787 export ISCSI_INITIATORNAME
788 if [ -n "${ISCSI_SERVER}" ] ; then
789 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
791 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
795 panic "Failed to log into iscsi target"
797 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
798 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
803 while [ -z "${devices}" -a $i -lt 60 ]
806 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
807 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
813 if check_dev "null" "/dev/$dev"
820 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
822 panic "Failed to locate iSCSI host in /sys"
830 for webfile in HTTPFS FTPFS FETCH
832 local url="$(eval echo \"\$\{${webfile}\}\")"
833 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
837 case "${extension}" in
838 iso|squashfs|tgz|tar)
839 if [ "${extension}" = "iso" ]
841 mkdir -p "${alt_mountpoint}"
842 dest="${alt_mountpoint}"
844 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
845 mount -t ramfs ram "${mountpoint}"
848 if [ "${webfile}" = "FETCH" ]
852 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
853 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
854 lfile="$(basename $url)"
855 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
856 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
860 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
861 wget "${url}" -O "${dest}/$(basename ${url})"
865 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
866 if [ "${webfile}" = "FTPFS" ]
868 FUSE_MOUNT="curlftpfs"
869 url="$(dirname ${url})"
874 $FUSE_MOUNT "${url}" "${dest}"
875 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
877 [ ${?} -eq 0 ] && rc=0
878 [ "${extension}" = "tgz" ] && live_dest="ram"
879 if [ "${extension}" = "iso" ]
881 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
882 mount -t iso9660 "${isoloop}" "${mountpoint}"
889 log_begin_msg "Unrecognized archive extension for ${url}"
897 if [ -d "${alt_mountpoint}" ]
899 umount "${alt_mountpoint}"
900 rmdir "${alt_mountpoint}"
902 umount "${mountpoint}"
903 elif [ "${webfile}" != "FETCH" ] ; then
917 if [ -z "${NFSOPTS}" ]
922 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
924 # FIXME: This while loop is an ugly HACK round an nfs bug
926 while [ "$i" -lt 60 ]
928 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
940 if [ -x "/sbin/mount.cifs" ]
942 if [ -z "${NFSOPTS}" ]
944 CIFSOPTS="-ouser=root,password="
946 CIFSOPTS="${NFSOPTS}"
949 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
952 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
966 size=$(fs_size "${fromdev}" "" "used")
968 if [ -b "${fromdev}" ]
970 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
973 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
975 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
976 freespace=$(df -k | awk '/'${todev}'/{print $4}')
978 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
981 tomount="/mnt/tmpsnap"
983 if [ ! -d "${tomount}" ]
985 mkdir -p "${tomount}"
988 fstype=$(get_fstype "${fromdev}")
990 if [ -n "${fstype}" ]
993 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
994 cp -a "${tomount}"/* ${todir}
997 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1002 if echo ${fromdev} | grep -qs loop
1004 losetup -d "${fromdev}"
1009 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1016 # Look for ${snap_label}.* in block devices
1018 black_listed_devices="${2}"
1020 if [ "${PERSISTENT}" != "nofiles" ]
1022 # search for image files
1023 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}")
1026 if [ -z "${snapdata}" ]
1028 snapdata=$(find_cow_device "${snap_label}" "${black_listed_devices}")
1035 # copy the contents of previously found snapshot to ${snap_mount}
1036 # and remember the device and filename for resync on exit in live-boot.init
1043 if [ -z "${snap_relpath}" ]
1045 # root snapshot, default usage
1048 # relative snapshot (actually used just for "/home" snapshots)
1049 snap_mount="${2}${snap_relpath}"
1052 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1054 log_success_msg "found snapshot: ${snapdata}"
1055 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1056 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1057 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1059 if ! try_mount "${snapdev}" "${snapback}" "ro"
1066 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1068 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1069 dev=$(get_backing_device "${snapback}/${snapfile}")
1071 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1076 # Unfortunately klibc's cpio is incompatible with the
1077 # rest of the world; everything else requires -u -d,
1078 # while klibc doesn't implement them. Try to detect
1079 # whether it's in use.
1080 cpiopath="$(which cpio)" || true
1081 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1085 cpioargs='--unconditional --make-directories'
1088 if [ -s "${snapback}/${snapfile}" ]
1091 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
1095 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
1099 if [ "${RES}" != "0" ]
1101 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1105 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1107 if [ "${RES}" != "0" ]
1109 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1112 elif [ -b "${snapdata}" ]
1114 # Try to find if it could be a snapshot partition
1116 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1117 if echo "${dev}" | grep -qs loop
1119 # strange things happens, user confused?
1120 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1121 snapfile=$(basename ${snaploop})
1122 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1127 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1129 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
1132 if [ -n "${snapfile}" ]
1134 # it was a loop device, user confused
1139 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
1143 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
1149 image_directory="${1}"
1151 addimage_directory="${3}"
1153 case ${UNIONTYPE} in
1155 modprobe -q -b ${UNIONTYPE}
1157 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1159 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1160 echo "This might be really slow."
1162 UNIONTYPE="unionfs-fuse"
1167 if [ "${UNIONTYPE}" = unionfs-fuse ]
1172 # run-init can't deal with images in a subdir, but we're going to
1173 # move all of these away before it runs anyway. No, we're not,
1174 # put them in / since move-mounting them into / breaks mono and
1179 # Let's just mount the read-only file systems first
1183 if [ "${UNIONTYPE}" = "aufs" ]
1186 noxino_opt="noxino,"
1187 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1194 if [ -z "${PLAIN_ROOT}" ]
1196 # Read image names from ${MODULE}.module if it exists
1197 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1199 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1201 image_string="${image_string} ${image_directory}/${IMAGE}"
1203 elif [ -e "${image_directory}/${MODULE}.module" ]
1205 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1207 image_string="${image_string} ${image_directory}/${IMAGE}"
1210 # ${MODULE}.module does not exist, create a list of images
1211 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1213 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1215 if [ -e "${IMAGE}" ]
1217 image_string="${image_string} ${IMAGE}"
1222 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1224 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1226 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1228 if [ -e "${IMAGE}" ]
1230 image_string="${image_string} ${IMAGE}"
1237 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1240 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1244 for image in ${image_string}
1246 imagename=$(basename "${image}")
1248 export image devname
1249 maybe_break live-realpremount
1250 log_begin_msg "Running /scripts/live-realpremount"
1251 run_scripts /scripts/live-realpremount
1254 if [ -d "${image}" ]
1256 # it is a plain directory: do nothing
1257 rofsstring="${image}=${roopt}:${rofsstring}"
1258 rofslist="${image} ${rofslist}"
1259 elif [ -f "${image}" ]
1261 if losetup --help 2>&1 | grep -q -- "-r\b"
1263 backdev=$(get_backing_device "${image}" "-r")
1265 backdev=$(get_backing_device "${image}")
1267 fstype=$(get_fstype "${backdev}")
1269 if [ "${fstype}" = "unknown" ]
1271 panic "Unknown file system type on ${backdev} (${image})"
1274 if [ -z "${fstype}" ]
1276 fstype="${imagename##*.}"
1277 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1280 if [ "${UNIONTYPE}" != "unionmount" ]
1282 mpoint="${croot}/${imagename}"
1283 rofsstring="${mpoint}=${roopt}:${rofsstring}" && rofslist="${mpoint} ${rofslist}"
1287 mkdir -p "${mpoint}"
1288 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
1289 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
1294 # we have a plain root system
1295 mkdir -p "${croot}/filesystem"
1296 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1297 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || panic "Can not mount ${image_directory} on ${croot}/filesystem" && rofsstring="${croot}/filesystem=${roopt}:${rofsstring}" && rofslist="${croot}/filesystem ${rofslist}"
1299 mount -o bind ${croot}/filesystem $mountpoint
1303 rofsstring=${rofsstring%:}
1307 # Looking for "${root_persistence}" device or file
1308 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1310 if [ -z "${QUICKUSBMODULES}" ]
1313 num_block=$(ls -l /sys/block | wc -l)
1314 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1316 modprobe -q -b ${module}
1322 # For some reason, udevsettle does not block in this scenario,
1323 # so we sleep for a little while.
1325 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1326 for timeout in 5 4 3 2 1
1330 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1337 # search for label and files (this could be hugely optimized)
1338 cowprobe=$(find_cow_device "${root_persistence}")
1339 if [ -b "${cowprobe}" ]
1341 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1342 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1343 # snapshots to be sure to really store some e.g key config files,
1344 # but not on the same media
1345 blacklistdev="${cowprobe}"
1346 PERSISTENCE_IS_ON="1"
1347 export PERSISTENCE_IS_ON
1349 # homecow just mount something on /home, this should be generalized some way
1350 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1351 if [ -b "${homecow}" ]
1353 PERSISTENCE_IS_ON="1"
1354 export PERSISTENCE_IS_ON
1356 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1357 # This second type should be removed when snapshot will get smarter,
1358 # hence when "/etc/live-snapshot*list" will be supported also by
1359 # ext2|ext3|ext4|jffs2 snapshot types.
1360 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1362 if [ -b "${cowprobe}" ]
1364 cowdevice=${cowprobe}
1365 cow_fstype=$(get_fstype "${cowprobe}")
1366 cow_mountopt="rw,noatime"
1368 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1370 fsck -y ${cowdevice}
1373 log_warning_msg "Unable to find the persistent medium"
1376 cow_mountopt="rw,noatime,mode=755"
1378 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1380 # check if there are any nfs options
1381 if echo ${NFS_COW}|grep -q ','
1383 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1384 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1386 nfs_cow_opts="-o nolock"
1392 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1395 panic "unable to determine mac address"
1400 cow_mountopt="rw,noatime,mode=755"
1403 if [ "${UNIONTYPE}" != "unionmount" ]
1406 if [ "${cow_fstype}" = "nfs" ]
1409 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1410 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1411 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1413 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1414 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1418 rofscount=$(echo ${rofslist} |wc -w)
1420 if [ -n "${EXPOSED_ROOT}" ]
1422 if [ ${rofscount} -ne 1 ]
1424 panic "only one RO file system supported with exposedroot: ${rofslist}"
1426 exposedrootfs=${rofslist%% }
1428 mount --bind ${exposedrootfs} ${rootmnt} || \
1429 panic "bind mount of ${exposedrootfs} failed"
1431 if [ -z "${SKIP_UNION_MOUNTS}" ]
1433 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1438 for dir in ${cow_dirs}; do
1441 case "${UNIONTYPE}" in
1443 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${exposedrootfs}${dir} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow=RW:${exposedrootfs}${dir}")
1444 mkdir -p /dev/.initramfs/varrun
1445 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1449 mount -t ${UNIONTYPE} -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro ${UNIONTYPE} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro"
1454 case "${UNIONTYPE}" in
1456 (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${rofsstring} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow:RW:${rofsstring}")
1457 mkdir -p /dev/.initramfs/varrun
1458 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1462 mount_full -t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice} "${rootmnt}" || panic "${UNIONTYPE} ${cowdevice} on ${rootmnt} failed with option noatime,union,${cow_mountopt}"
1466 mount -t ${UNIONTYPE} -o noatime,${noxino_opt}dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option noatime,${noxino_opt}dirs=/cow=rw:${rofsstring}"
1471 # Correct the permissions of /:
1472 chmod 0755 "${rootmnt}"
1474 # tmpfs file systems
1476 mkdir -p "${rootmnt}/live"
1477 mount -t tmpfs tmpfs ${rootmnt}/live
1479 # Adding other custom mounts
1480 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1482 # directly mount /home
1483 # FIXME: add a custom mounts configurable system
1485 if [ -b "${homecow}" ]
1487 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1488 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1490 log_warning_msg "Unable to find the persistent home medium"
1493 # Look for other snapshots to copy in
1494 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1495 # This second type should be removed when snapshot grow smarter
1496 try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
1499 if [ -n "${SHOWMOUNTS}" ]
1501 for d in ${rofslist}
1503 mkdir -p "${rootmnt}/live/${d##*/}"
1507 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1511 case "${UNIONTYPE}" in
1513 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1517 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1525 # shows cow fs on /cow for use by live-snapshot
1526 mkdir -p "${rootmnt}/live/cow"
1527 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"
1534 skip_uuid_check="${3}"
1536 # support for fromiso=.../isofrom=....
1537 if [ -n "$FROMISO" ]
1539 ISO_DEVICE=$(dirname $FROMISO)
1540 if ! [ -b $ISO_DEVICE ]
1542 # to support unusual device names like /dev/cciss/c0d0p1
1543 # as well we have to identify the block device name, let's
1544 # do that for up to 15 levels
1546 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1548 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1549 [ -b "$ISO_DEVICE" ] && break
1554 if [ "$ISO_DEVICE" = "/" ]
1556 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1559 mount "$ISO_DEVICE" /isofrom
1560 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1561 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1562 devname="${loopdevname}"
1566 if [ -z "${devname}" ]
1568 devname=$(sys2dev "${sysdev}")
1571 if [ -d "${devname}" ]
1573 mount -o bind "${devname}" $mountpoint || continue
1575 if is_live_path $mountpoint
1583 [ -e "$devname" ] || continue
1585 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1587 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1588 devname="${loopdevname}"
1591 fstype=$(get_fstype "${devname}")
1593 if is_supported_fs ${fstype}
1595 devuid=$(blkid -o value -s UUID "$devname")
1596 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1597 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1598 [ -n "$devuid" ] && echo "$devuid" >> $tried
1600 if is_live_path ${mountpoint} && \
1601 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1606 umount ${mountpoint}
1610 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1612 losetup -d "${loopdevname}"
1622 # don't start autodetection before timeout has expired
1623 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1625 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1631 # first look at the one specified in the command line
1632 case "${LIVE_MEDIA}" in
1634 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1636 if [ "$(cat ${sysblock}/removable)" = "1" ]
1638 if readlink ${sysblock} | grep -q usb ||
1639 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1641 for dev in $(subdevices "${sysblock}")
1643 if check_dev "${dev}"
1655 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1657 if [ "$(cat ${sysblock}/removable)" = "1" ]
1659 for dev in $(subdevices "${sysblock}")
1661 if check_dev "${dev}"
1672 if [ ! -z "${LIVE_MEDIA}" ]
1674 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1682 # or do the scan of block devices
1683 # prefer removable devices over non-removable devices, so scan them first
1684 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1686 if [ "$(cat ${sysblock}/removable)" = "1" ]
1688 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1690 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1693 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1695 for sysblock in $devices_to_scan
1697 devname=$(sys2dev "${sysblock}")
1698 [ -e "$devname" ] || continue
1699 fstype=$(get_fstype "${devname}")
1701 if /lib/udev/cdrom_id ${devname} > /dev/null
1703 if check_dev "null" "${devname}"
1707 elif is_nice_device "${sysblock}"
1709 for dev in $(subdevices "${sysblock}")
1711 if check_dev "${dev}"
1716 elif [ "${fstype}" = "squashfs" -o \
1717 "${fstype}" = "btrfs" -o \
1718 "${fstype}" = "ext2" -o \
1719 "${fstype}" = "ext3" -o \
1720 "${fstype}" = "ext4" -o \
1721 "${fstype}" = "jffs2" ]
1723 # This is an ugly hack situation, the block device has
1724 # an image directly on it. It's hopefully
1725 # live-boot, so take it and run with it.
1726 ln -s "${devname}" "${devname}.${fstype}"
1727 echo "${devname}.${fstype}"
1737 media_mountpoint="${1}"
1739 log_begin_msg "Checking media integrity"
1741 cd ${media_mountpoint}
1742 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1747 if [ "${RC}" -eq 0 ]
1749 log_success_msg "Everything ok, will reboot in 10 seconds."
1752 umount ${media_mountpoint}
1754 echo u > /proc/sysrq-trigger
1755 echo b > /proc/sysrq-trigger
1757 panic "Not ok, a media defect is likely, switch to VT8 for details."
1763 if [ -x /scripts/local-top/cryptroot ]; then
1764 /scripts/local-top/cryptroot
1771 tail -f live.log >&7 &
1774 # Ensure 'panic' function is overridden
1775 . /scripts/live-functions
1779 maybe_break live-premount
1780 log_begin_msg "Running /scripts/live-premount"
1781 run_scripts /scripts/live-premount
1784 # Needed here too because some things (*cough* udev *cough*)
1785 # changes the timeout
1787 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1791 livefs_root="${mountpoint}"
1793 panic "Unable to find a live file system on the network"
1796 if [ -n "${ISCSI_PORTAL}" ]
1798 do_iscsi && livefs_root="${mountpoint}"
1799 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1801 # Do a local boot from hd
1804 if [ -x /usr/bin/memdiskfind ]
1806 MEMDISK=$(/usr/bin/memdiskfind)
1810 # We found a memdisk, set up phram
1811 modprobe phram phram=memdisk,${MEMDISK}
1813 # Load mtdblock, the memdisk will be /dev/mtdblock0
1818 # Scan local devices for the image
1820 while [ "$i" -lt 60 ]
1822 livefs_root=$(find_livefs ${i})
1824 if [ -n "${livefs_root}" ]
1835 if [ -z "${livefs_root}" ]
1837 panic "Unable to find a medium containing a live file system"
1840 if [ "${INTEGRITY_CHECK}" ]
1842 integrity_check "${livefs_root}"
1848 elif [ "${TODISK}" ]
1850 live_dest="${TODISK}"
1853 if [ "${live_dest}" ]
1855 log_begin_msg "Copying live media to ${live_dest}"
1856 copy_live_to "${livefs_root}" "${live_dest}"
1860 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1861 # because the mountpoint is left behind in /proc/mounts, so let's get
1862 # rid of it when running from RAM
1863 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1865 losetup -d /dev/loop0
1866 grep -q /isofrom /proc/mounts && umount /isofrom
1869 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1871 setup_unionfs "${livefs_root}" "${rootmnt}"
1874 mac="$(echo ${mac} | sed 's/-//g')"
1875 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1879 if [ -n "${ROOT_PID}" ] ; then
1880 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1885 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1886 # live-bottom; udev's init script will take care of things after that
1887 if [ "${UNIONTYPE}" = unionfs-fuse ]
1889 mount -n -o bind /dev "${rootmnt}/dev"
1892 # Move to the new root filesystem so that programs there can get at it.
1893 if [ ! -d /root/live/image ]
1895 mkdir -p /root/live/image
1896 mount --move /live/image /root/live/image
1899 # aufs2 in kernel versions around 2.6.33 has a regression:
1900 # directories can't be accessed when read for the first the time,
1901 # causing a failure for example when accessing /var/lib/fai
1902 # when booting FAI, this simple workaround solves it
1903 ls /root/* >/dev/null 2>&1
1905 # copy snapshot configuration if exists
1906 if [ -f snapshot.conf ]
1908 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
1909 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
1911 mkdir -p "${rootmnt}/etc/live/boot.d"
1913 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
1917 maybe_break live-bottom
1918 log_begin_msg "Running /scripts/live-bottom\n"
1920 run_scripts /scripts/live-bottom
1923 if [ "${UNIONFS}" = unionfs-fuse ]
1925 umount "${rootmnt}/dev"
1931 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null