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_MEDIA="${ARGUMENT#*=}"
258 export PERSISTENT_MEDIA
262 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
263 export PERSISTENT_PATH
266 persistent-subtext=*)
267 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
268 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
269 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
270 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
284 NOPROMPT="${ARGUMENT#noprompt=}"
289 QUICKUSBMODULES="Yes"
290 export QUICKUSBMODULES
293 preseed/file=*|file=*)
294 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
304 question="${ARGUMENT%%=*}"
305 value="${ARGUMENT#*=}"
306 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
321 TODISK="${ARGUMENT#todisk=}"
332 MODULETORAM="${ARGUMENT#toram=}"
333 export TORAM MODULETORAM
347 SKIP_UNION_MOUNTS="Yes"
348 export SKIP_UNION_MOUNTS
352 ROOT="${ARGUMENT#root=}"
357 UNIONTYPE="${ARGUMENT#union=}"
363 # sort of compatibility with netboot.h from linux docs
364 if [ -z "${NETBOOT}" ]
366 if [ "${ROOT}" = "/dev/nfs" ]
370 elif [ "${ROOT}" = "/dev/cifs" ]
377 if [ -z "${MODULE}" ]
383 if [ -z "${UNIONTYPE}" ]
394 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
396 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
398 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
410 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
416 uuid="$(cat /conf/uuid.conf)"
418 for try_uuid_file in "${path}/.disk/live-uuid"*
420 [ -e "${try_uuid_file}" ] || continue
422 try_uuid="$(cat "${try_uuid_file}")"
424 if [ "${uuid}" = "${try_uuid}" ]
433 get_backing_device ()
436 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
437 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
445 panic "Unrecognized live filesystem: ${1}"
450 match_files_in_dir ()
452 # Does any files match pattern ${1} ?
455 if [ "$(echo ${pattern})" != "${pattern}" ]
463 mount_images_in_directory ()
470 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
471 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
472 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
473 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
474 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
475 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
477 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
478 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
480 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
486 sysfs_path="${1#/sys}"
488 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
491 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
494 elif echo ${sysfs_path} | grep -q "^/block/dm-"
497 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
509 copyto="${copyfrom}_swap"
511 if [ -z "${MODULETORAM}" ]
513 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
515 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
517 if [ -f "${MODULETORAMFILE}" ]
519 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
521 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
526 if [ "${copytodev}" = "ram" ]
529 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
530 mount_options="-o size=${size}k"
535 # it should be a writable block device
536 if [ -b "${copytodev}" ]
540 fstype=$(get_fstype "${dev}")
541 freespace=$(fs_size "${dev}")
543 log_warning_msg "${copytodev} is not a block device."
548 if [ "${freespace}" -lt "${size}" ]
550 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
554 # Custom ramdisk size
555 if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ]
557 # FIXME: should check for wrong values
558 mount_options="-o size=${ramdisk_size}"
561 # begin copying (or uncompressing)
563 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
564 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
566 if [ "${extension}" = "tgz" ]
569 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
570 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
571 mount -r -o move "${copyto}" "${rootmnt}"
574 if [ -n "${MODULETORAMFILE}" ]
578 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
579 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
581 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
586 echo " * Copying whole medium to RAM" 1>/dev/console
587 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
589 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
590 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
591 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
593 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
599 mount -r -o move ${copyto} ${copyfrom}
608 modprobe -q af_packet # For DHCP
613 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
614 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
616 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
617 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
621 # support for Syslinux IPAPPEND parameter
622 # it sets the BOOTIF variable on the kernel parameter
624 if [ -n "${BOOTIF}" ]
626 # pxelinux sets BOOTIF to a value based on the mac address of the
627 # network card used to PXE boot, so use this value for DEVICE rather
628 # than a hard-coded device name from initramfs.conf. this facilitates
629 # network booting when machines may have multiple network cards.
630 # pxelinux sets BOOTIF to 01-$mac_address
632 # strip off the leading "01-", which isn't part of the mac
634 temp_mac=${BOOTIF#*-}
636 # convert to typical mac address format by replacing "-" with ":"
641 if [ -z "$bootif_mac" ]
645 bootif_mac="$bootif_mac:$x"
650 # look for devices with matching mac address, and set DEVICE to
651 # appropriate value if match is found.
653 for device in /sys/class/net/*
655 if [ -f "$device/address" ]
657 current_mac=$(cat "$device/address")
659 if [ "$bootif_mac" = "$current_mac" ]
668 # if ethdevice was not specified on the kernel command line
669 # make sure we try to get a working network configuration
670 # for *every* present network device (except for loopback of course)
671 if [ -z "$ETHDEVICE" ] ; then
672 echo "If you want to boot from a specific device use bootoption ethdevice=..."
673 for device in /sys/class/net/*; do
675 if [ "$dev" != "lo" ] ; then
676 ETHDEVICE="$ETHDEVICE $dev"
681 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
682 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
683 devlist="$devlist $device"
686 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
687 # an endless loop; iff execution fails give it two further tries, that's
688 # why we use '$devlist $devlist $devlist' for the other for loop
689 for dev in $devlist $devlist $devlist ; do
690 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
691 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
693 sleep "$ETHDEV_TIMEOUT" ; sleep 1
694 if [ -r /proc/"$jobid"/status ] ; then
695 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
699 # if configuration of device worked we should have an assigned
700 # IP address, iff so let's use the according as $DEVICE for later usage
701 # simple and primitive approach which seems to work fine
702 if ifconfig $dev | grep -q 'inet.*addr:' ; then
709 for interface in ${DEVICE}; do
710 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
711 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
712 if [ "$IPV4ADDR" != "0.0.0.0" ]
719 for interface in ${DEVICE}; do
720 # source relevant ipconfig output
721 OLDHOSTNAME=${HOSTNAME}
722 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
723 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
726 if [ -n "${interface}" ]
728 HWADDR="$(cat /sys/class/net/${interface}/address)"
731 if [ ! -e "/etc/resolv.conf" ]
733 echo "Creating /etc/resolv.conf"
735 if [ -n "${DNSDOMAIN}" ]
737 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
738 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
741 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
743 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
745 echo "nameserver $i" >> /etc/resolv.conf
750 # Check if we have a network device at all
751 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
752 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
753 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
754 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
755 ! ls /sys/class/net/ra0 > /dev/null 2>&1
757 panic "No supported network device found, maybe a non-mainline driver is required."
766 if [ "${NFSROOT}" = "auto" ]
768 NFSROOT=${ROOTSERVER}:${ROOTPATH}
773 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
779 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
781 NFSROOT=${ROOTSERVER}:${NFSROOT}
784 log_begin_msg "Trying netboot from ${NFSROOT}"
786 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
806 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
807 #FIXME this name is supposed to be unique - some date + ifconfig hash?
808 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
809 export ISCSI_INITIATORNAME
810 if [ -n "${ISCSI_SERVER}" ] ; then
811 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
813 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
817 panic "Failed to log into iscsi target"
819 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
820 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
825 while [ -z "${devices}" -a $i -lt 60 ]
828 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
829 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
835 if check_dev "null" "/dev/$dev"
842 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
844 panic "Failed to locate iSCSI host in /sys"
852 for webfile in HTTPFS FTPFS FETCH
854 local url="$(eval echo \"\$\{${webfile}\}\")"
855 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
859 case "${extension}" in
860 iso|squashfs|tgz|tar)
861 if [ "${extension}" = "iso" ]
863 mkdir -p "${alt_mountpoint}"
864 dest="${alt_mountpoint}"
866 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
867 mount -t ramfs ram "${mountpoint}"
870 if [ "${webfile}" = "FETCH" ]
874 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
875 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
876 lfile="$(basename $url)"
877 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
878 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
882 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
883 wget "${url}" -O "${dest}/$(basename ${url})"
887 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
888 if [ "${webfile}" = "FTPFS" ]
890 FUSE_MOUNT="curlftpfs"
891 url="$(dirname ${url})"
896 $FUSE_MOUNT "${url}" "${dest}"
897 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
899 [ ${?} -eq 0 ] && rc=0
900 [ "${extension}" = "tgz" ] && live_dest="ram"
901 if [ "${extension}" = "iso" ]
903 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
904 mount -t iso9660 "${isoloop}" "${mountpoint}"
911 log_begin_msg "Unrecognized archive extension for ${url}"
919 if [ -d "${alt_mountpoint}" ]
921 umount "${alt_mountpoint}"
922 rmdir "${alt_mountpoint}"
924 umount "${mountpoint}"
925 elif [ "${webfile}" != "FETCH" ] ; then
939 if [ -z "${NFSOPTS}" ]
944 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
946 # FIXME: This while loop is an ugly HACK round an nfs bug
948 while [ "$i" -lt 60 ]
950 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
962 if [ -x "/sbin/mount.cifs" ]
964 if [ -z "${NFSOPTS}" ]
966 CIFSOPTS="-ouser=root,password="
968 CIFSOPTS="${NFSOPTS}"
971 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
974 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
988 size=$(fs_size "${fromdev}" "" "used")
990 if [ -b "${fromdev}" ]
992 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
995 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
997 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
998 freespace=$(df -k | awk '/'${todev}'/{print $4}')
1000 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
1003 tomount="/mnt/tmpsnap"
1005 if [ ! -d "${tomount}" ]
1007 mkdir -p "${tomount}"
1010 fstype=$(get_fstype "${fromdev}")
1012 if [ -n "${fstype}" ]
1015 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1016 cp -a "${tomount}"/* ${todir}
1019 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1024 if echo ${fromdev} | grep -qs loop
1026 losetup -d "${fromdev}"
1031 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1038 # Look for ${snap_label}.* in block devices
1040 black_listed_devices="${2}"
1041 white_listed_devices="${3}"
1043 if [ "${PERSISTENT}" != "nofiles" ]
1045 # search for image files
1046 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}")
1049 if [ -z "${snapdata}" ]
1051 snapdata=$(find_cow_device "${snap_label}" "${black_listed_devices}" "${white_listed_devices}")
1058 # copy the contents of previously found snapshot to ${snap_mount}
1059 # and remember the device and filename for resync on exit in live-boot.init
1066 if [ -z "${snap_relpath}" ]
1068 # root snapshot, default usage
1071 # relative snapshot (actually used just for "/home" snapshots)
1072 snap_mount="${2}${snap_relpath}"
1075 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1077 log_success_msg "found snapshot: ${snapdata}"
1078 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1079 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1080 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1082 if ! try_mount "${snapdev}" "${snapback}" "ro"
1089 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1091 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1092 dev=$(get_backing_device "${snapback}/${snapfile}")
1094 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1099 # Unfortunately klibc's cpio is incompatible with the
1100 # rest of the world; everything else requires -u -d,
1101 # while klibc doesn't implement them. Try to detect
1102 # whether it's in use.
1103 cpiopath="$(which cpio)" || true
1104 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1108 cpioargs='--unconditional --make-directories'
1111 if [ -s "${snapback}/${snapfile}" ]
1114 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
1118 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
1122 if [ "${RES}" != "0" ]
1124 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1128 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1130 if [ "${RES}" != "0" ]
1132 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1135 elif [ -b "${snapdata}" ]
1137 # Try to find if it could be a snapshot partition
1139 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1140 if echo "${dev}" | grep -qs loop
1142 # strange things happens, user confused?
1143 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1144 snapfile=$(basename ${snaploop})
1145 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1150 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1152 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
1155 if [ -n "${snapfile}" ]
1157 # it was a loop device, user confused
1162 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
1166 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
1172 image_directory="${1}"
1174 addimage_directory="${3}"
1176 case ${UNIONTYPE} in
1178 modprobe -q -b ${UNIONTYPE}
1180 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1182 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1183 echo "This might be really slow."
1185 UNIONTYPE="unionfs-fuse"
1190 if [ "${UNIONTYPE}" = unionfs-fuse ]
1195 # run-init can't deal with images in a subdir, but we're going to
1196 # move all of these away before it runs anyway. No, we're not,
1197 # put them in / since move-mounting them into / breaks mono and
1202 # Let's just mount the read-only file systems first
1205 if [ "${UNIONTYPE}" = "aufs" ]
1208 noxino_opt="noxino,"
1209 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1216 if [ -z "${PLAIN_ROOT}" ]
1218 # Read image names from ${MODULE}.module if it exists
1219 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1221 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1223 image_string="${image_string} ${image_directory}/${IMAGE}"
1225 elif [ -e "${image_directory}/${MODULE}.module" ]
1227 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1229 image_string="${image_string} ${image_directory}/${IMAGE}"
1232 # ${MODULE}.module does not exist, create a list of images
1233 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1235 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1237 if [ -e "${IMAGE}" ]
1239 image_string="${image_string} ${IMAGE}"
1244 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1246 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1248 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1250 if [ -e "${IMAGE}" ]
1252 image_string="${image_string} ${IMAGE}"
1259 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1262 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1266 for image in ${image_string}
1268 imagename=$(basename "${image}")
1270 export image devname
1271 maybe_break live-realpremount
1272 log_begin_msg "Running /scripts/live-realpremount"
1273 run_scripts /scripts/live-realpremount
1276 if [ -d "${image}" ]
1278 # it is a plain directory: do nothing
1279 rofslist="${image} ${rofslist}"
1280 elif [ -f "${image}" ]
1282 if losetup --help 2>&1 | grep -q -- "-r\b"
1284 backdev=$(get_backing_device "${image}" "-r")
1286 backdev=$(get_backing_device "${image}")
1288 fstype=$(get_fstype "${backdev}")
1290 if [ "${fstype}" = "unknown" ]
1292 panic "Unknown file system type on ${backdev} (${image})"
1295 if [ -z "${fstype}" ]
1297 fstype="${imagename##*.}"
1298 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1301 if [ "${UNIONTYPE}" != "unionmount" ]
1303 mpoint="${croot}/${imagename}"
1304 rofslist="${mpoint} ${rofslist}"
1307 rofslist="${rootmnt} ${rofslist}"
1309 mkdir -p "${mpoint}"
1310 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
1311 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
1316 # we have a plain root system
1317 mkdir -p "${croot}/filesystem"
1318 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1319 mount -t $(get_fstype "${image_directory}") -o ro,noatime "${image_directory}" "${croot}/filesystem" || \
1320 panic "Can not mount ${image_directory} on ${croot}/filesystem" && \
1321 rofslist="${croot}/filesystem ${rofslist}"
1323 mount -o bind ${croot}/filesystem $mountpoint
1329 # Looking for "${root_persistence}" device or file
1330 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1333 if [ -z "${QUICKUSBMODULES}" ]
1336 num_block=$(ls -l /sys/block | wc -l)
1337 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1339 modprobe -q -b ${module}
1345 # For some reason, udevsettle does not block in this scenario,
1346 # so we sleep for a little while.
1348 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1349 for timeout in 5 4 3 2 1
1353 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1360 case "${PERSISTENT_MEDIA}" in
1362 whitelistdev="$(removable_dev)"
1365 whitelistdev="$(removable_usb_dev)"
1372 # search for label and files (this could be hugely optimized)
1373 cowprobe=$(find_cow_device "${root_persistence}" "${blacklistdev}" "${whitelistdev}")
1374 if [ -b "${cowprobe}" ]
1376 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1377 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1378 # snapshots to be sure to really store some e.g key config files,
1379 # but not on the same media
1380 blacklistdev="${cowprobe}"
1381 PERSISTENCE_IS_ON="1"
1382 export PERSISTENCE_IS_ON
1384 # homecow just mount something on /home, this should be generalized some way
1385 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}" "${whitelistdev}")
1386 if [ -b "${homecow}" ]
1388 PERSISTENCE_IS_ON="1"
1389 export PERSISTENCE_IS_ON
1391 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}" "${whitelistdev}")
1392 # This second type should be removed when snapshot will get smarter,
1393 # hence when "/etc/live-snapshot*list" will be supported also by
1394 # ext2|ext3|ext4|jffs2 snapshot types.
1395 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}" "${whitelistdev}")
1397 if [ -b "${cowprobe}" ]
1399 cowdevice=${cowprobe}
1400 cow_fstype=$(get_fstype "${cowprobe}")
1401 cow_mountopt="rw,noatime"
1403 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1405 fsck -y ${cowdevice}
1408 log_warning_msg "Unable to find the persistent medium"
1411 cow_mountopt="rw,noatime,mode=755"
1413 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1415 # check if there are any nfs options
1416 if echo ${NFS_COW}|grep -q ','
1418 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1419 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1421 nfs_cow_opts="-o nolock"
1427 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1430 panic "unable to determine mac address"
1435 cow_mountopt="rw,noatime,mode=755"
1438 if [ "${UNIONTYPE}" != "unionmount" ]
1441 if [ "${cow_fstype}" = "nfs" ]
1444 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1445 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1446 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1448 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1449 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1453 rofscount=$(echo ${rofslist} |wc -w)
1455 if [ ${rofscount} -ne 1 ]
1457 panic "only one RO file system supported with exposedroot: ${rofslist}"
1461 if [ -n "${EXPOSED_ROOT}" ]
1463 mount --bind ${rofs} ${rootmnt} || \
1464 panic "bind mount of ${rofs} failed"
1466 if [ -z "${SKIP_UNION_MOUNTS}" ]
1468 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1476 if [ "${cow_fstype}" != "tmpfs" ] && [ "${cow_dirs}" != "/" ] && [ "${UNIONTYPE}" = "unionmount" ]
1478 true # FIXME: Maybe it does, I don't really know.
1479 #panic "unionmount does not support subunions (${cow_dirs})."
1485 for dir in ${cow_dirs}; do
1488 unionmountpoint="${rootmnt}${dir}"
1489 unionrw="/cow${dir}"
1490 unionro="${rofs}${dir}"
1491 # We don't handle spaces and other junk gracefully here, hopefully not needed.
1492 case "${UNIONTYPE}" in
1494 unionmountopts="-o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid"
1495 unionmountopts="${unionmountopts} ${unionrw}=RW:${unionro}=RO"
1496 ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
1497 unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
1498 ( mkdir -p /run/sendsigs.omit.d
1499 pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
1503 unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
1504 mount_full $unionmountopts "${unionmountpoint}"
1509 unionmountopts="-o noatime,${noxino_opt}dirs=${unionrw}=rw:${unionro}=${roopt}"
1510 mount -t ${UNIONTYPE} ${unionmountopts} ${UNIONTYPE} "${unionmountpoint}"
1513 panic "mount ${UNIONTYPE} on ${unionmountpoint} failed with option ${unionmountopts}"
1516 # Correct the permissions of /:
1517 chmod 0755 "${rootmnt}"
1519 # tmpfs file systems
1521 mkdir -p "${rootmnt}/live"
1522 mount -t tmpfs tmpfs ${rootmnt}/live
1524 # Adding other custom mounts
1525 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1527 # directly mount /home
1528 # FIXME: add a custom mounts configurable system
1530 if [ -b "${homecow}" ]
1532 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1533 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1535 log_warning_msg "Unable to find the persistent home medium"
1538 # Look for other snapshots to copy in
1539 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1540 # This second type should be removed when snapshot grow smarter
1541 try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
1544 if [ -n "${SHOWMOUNTS}" ]
1546 for d in ${rofslist}
1548 mkdir -p "${rootmnt}/live/${d##*/}"
1552 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1556 case "${UNIONTYPE}" in
1558 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1562 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1570 # shows cow fs on /cow for use by live-snapshot
1571 mkdir -p "${rootmnt}/live/cow"
1572 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"
1579 skip_uuid_check="${3}"
1581 # support for fromiso=.../isofrom=....
1582 if [ -n "$FROMISO" ]
1584 ISO_DEVICE=$(dirname $FROMISO)
1585 if ! [ -b $ISO_DEVICE ]
1587 # to support unusual device names like /dev/cciss/c0d0p1
1588 # as well we have to identify the block device name, let's
1589 # do that for up to 15 levels
1591 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1593 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1594 [ -b "$ISO_DEVICE" ] && break
1599 if [ "$ISO_DEVICE" = "/" ]
1601 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live-boot.log
1603 fs_type=$(get_fstype "${ISO_DEVICE}")
1604 if is_supported_fs ${fs_type}
1607 mount -t $fs_type "$ISO_DEVICE" /isofrom
1608 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1609 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1610 devname="${loopdevname}"
1612 echo "Warning: unable to mount $ISO_DEVICE." >>/live-boot.log
1617 if [ -z "${devname}" ]
1619 devname=$(sys2dev "${sysdev}")
1622 if [ -d "${devname}" ]
1624 mount -o bind "${devname}" $mountpoint || continue
1626 if is_live_path $mountpoint
1636 for device in ${devname}
1640 # Adding lvm support
1641 if [ -x /scripts/local-top/lvm2 ]
1643 ROOT="$device" resume="" /scripts/local-top/lvm2
1648 # Adding raid support
1649 if [ -x /scripts/local-top/mdadm ]
1651 cp /conf/conf.d/md /conf/conf.d/md.orig
1652 echo "MD_DEVS=$device " >> /conf/conf.d/md
1653 /scripts/local-top/mdadm
1654 mv /conf/conf.d/md.orig /conf/conf.d/md
1661 [ -n "$device" ] && devname="$device"
1663 [ -e "$devname" ] || continue
1665 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1667 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1668 devname="${loopdevname}"
1671 fstype=$(get_fstype "${devname}")
1673 if is_supported_fs ${fstype}
1675 devuid=$(blkid -o value -s UUID "$devname")
1676 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1677 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1678 [ -n "$devuid" ] && echo "$devuid" >> $tried
1680 if is_live_path ${mountpoint} && \
1681 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1686 umount ${mountpoint}
1690 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1692 losetup -d "${loopdevname}"
1702 # don't start autodetection before timeout has expired
1703 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1705 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1711 # first look at the one specified in the command line
1712 case "${LIVE_MEDIA}" in
1714 for sysblock in $(removable_usb_dev "sys")
1716 for dev in $(subdevices "${sysblock}")
1718 if check_dev "${dev}"
1728 for sysblock in $(removable_dev "sys")
1730 for dev in $(subdevices "${sysblock}")
1732 if check_dev "${dev}"
1742 if [ ! -z "${LIVE_MEDIA}" ]
1744 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1752 # or do the scan of block devices
1753 # prefer removable devices over non-removable devices, so scan them first
1754 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
1756 for sysblock in $devices_to_scan
1758 devname=$(sys2dev "${sysblock}")
1759 [ -e "$devname" ] || continue
1760 fstype=$(get_fstype "${devname}")
1762 if /lib/udev/cdrom_id ${devname} > /dev/null
1764 if check_dev "null" "${devname}"
1768 elif is_nice_device "${sysblock}"
1770 for dev in $(subdevices "${sysblock}")
1772 if check_dev "${dev}"
1777 elif [ "${fstype}" = "squashfs" -o \
1778 "${fstype}" = "btrfs" -o \
1779 "${fstype}" = "ext2" -o \
1780 "${fstype}" = "ext3" -o \
1781 "${fstype}" = "ext4" -o \
1782 "${fstype}" = "jffs2" ]
1784 # This is an ugly hack situation, the block device has
1785 # an image directly on it. It's hopefully
1786 # live-boot, so take it and run with it.
1787 ln -s "${devname}" "${devname}.${fstype}"
1788 echo "${devname}.${fstype}"
1798 media_mountpoint="${1}"
1800 log_begin_msg "Checking media integrity"
1802 cd ${media_mountpoint}
1803 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1808 if [ "${RC}" -eq 0 ]
1810 log_success_msg "Everything ok, will reboot in 10 seconds."
1813 umount ${media_mountpoint}
1815 echo u > /proc/sysrq-trigger
1816 echo b > /proc/sysrq-trigger
1818 panic "Not ok, a media defect is likely, switch to VT8 for details."
1824 if [ -x /scripts/local-top/cryptroot ]; then
1825 /scripts/local-top/cryptroot
1830 exec > live-boot.log
1832 tail -f live-boot.log >&7 &
1835 # Ensure 'panic' function is overridden
1836 . /scripts/live-functions
1840 maybe_break live-premount
1841 log_begin_msg "Running /scripts/live-premount"
1842 run_scripts /scripts/live-premount
1845 # Needed here too because some things (*cough* udev *cough*)
1846 # changes the timeout
1848 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1852 livefs_root="${mountpoint}"
1854 panic "Unable to find a live file system on the network"
1857 if [ -n "${ISCSI_PORTAL}" ]
1859 do_iscsi && livefs_root="${mountpoint}"
1860 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1862 # Do a local boot from hd
1865 if [ -x /usr/bin/memdiskfind ]
1867 MEMDISK=$(/usr/bin/memdiskfind)
1871 # We found a memdisk, set up phram
1872 modprobe phram phram=memdisk,${MEMDISK}
1874 # Load mtdblock, the memdisk will be /dev/mtdblock0
1879 # Scan local devices for the image
1881 while [ "$i" -lt 60 ]
1883 livefs_root=$(find_livefs ${i})
1885 if [ -n "${livefs_root}" ]
1896 if [ -z "${livefs_root}" ]
1898 panic "Unable to find a medium containing a live file system"
1901 if [ "${INTEGRITY_CHECK}" ]
1903 integrity_check "${livefs_root}"
1909 elif [ "${TODISK}" ]
1911 live_dest="${TODISK}"
1914 if [ "${live_dest}" ]
1916 log_begin_msg "Copying live media to ${live_dest}"
1917 copy_live_to "${livefs_root}" "${live_dest}"
1921 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1922 # because the mountpoint is left behind in /proc/mounts, so let's get
1923 # rid of it when running from RAM
1924 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1926 losetup -d /dev/loop0
1927 grep -q /isofrom /proc/mounts && umount /isofrom
1930 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1932 setup_unionfs "${livefs_root}" "${rootmnt}"
1935 mac="$(echo ${mac} | sed 's/-//g')"
1936 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1940 if [ -n "${ROOT_PID}" ] ; then
1941 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1946 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1947 # live-bottom; udev's init script will take care of things after that
1948 if [ "${UNIONTYPE}" = unionfs-fuse ]
1950 mount -n -o bind /dev "${rootmnt}/dev"
1953 # Move to the new root filesystem so that programs there can get at it.
1954 if [ ! -d /root/live/image ]
1956 mkdir -p /root/live/image
1957 mount --move /live/image /root/live/image
1960 # aufs2 in kernel versions around 2.6.33 has a regression:
1961 # directories can't be accessed when read for the first the time,
1962 # causing a failure for example when accessing /var/lib/fai
1963 # when booting FAI, this simple workaround solves it
1964 ls /root/* >/dev/null 2>&1
1966 # copy snapshot configuration if exists
1967 if [ -f snapshot.conf ]
1969 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
1970 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
1972 mkdir -p "${rootmnt}/etc/live/boot.d"
1974 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
1978 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
1980 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
1981 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
1985 maybe_break live-bottom
1986 log_begin_msg "Running /scripts/live-bottom\n"
1988 run_scripts /scripts/live-bottom
1991 if [ "${UNIONFS}" = unionfs-fuse ]
1993 umount "${rootmnt}/dev"
1999 [ -w "${rootmnt}/var/log/" ] && cp live-boot.log "${rootmnt}/var/log/" 2>/dev/null