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 [ -f /etc/live.conf ] && . /etc/live.conf
38 export USERNAME USERFULLNAME HOSTNAME
40 . /scripts/live-helpers
42 if [ ! -f /live.vars ]
52 for ARGUMENT in $(cat /proc/cmdline)
59 NOCONSOLEKEYBOARD="Yes"
68 export NOACCESSIBILITY NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOHOSTS NONETWORKING NOTIMEZONE NOXAUTOCONFIG NOXAUTOLOGIN
72 ACCESS="${ARGUMENT#access=}"
77 DEFCONSOLE="${ARGUMENT#*=}"
89 # Force dhcp even while netbooting
90 # Use for debugging in case somebody works on fixing dhclient
100 DEVICE="${ARGUMENT#ethdevice=}"
105 ETHDEVICE="${ARGUMENT#ethdevice=}"
110 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
111 export ETHDEV_TIMEOUT
115 FETCH="${ARGUMENT#fetch=}"
120 FORCEPERSISTENTFSCK="Yes"
121 export FORCEPERSISTENTFSCK
125 FTPFS="${ARGUMENT#ftpfs=}"
130 HTTPFS="${ARGUMENT#httpfs=}"
135 FROMISO="${ARGUMENT#*=}"
140 USERNAME="${ARGUMENT#username=}"
142 export USERNAME LIVECONF
146 USERFULLNAME="${ARGUMENT#userfullname=}"
148 export USERFULLNAME LIVECONF
157 INTEGRITY_CHECK="Yes"
158 export INTEGRITY_CHECK
162 STATICIP="${ARGUMENT#ip=}"
164 if [ -z "${STATICIP}" ]
172 keyb=*|kbd-chooser/method=*)
177 klayout=*|console-setup/layoutcode=*)
178 KLAYOUT="${ARGUMENT#*=}"
182 kvariant=*|console-setup/variantcode=*)
183 KVARIANT="${ARGUMENT#*=}"
187 kmodel=*|console-setup/modelcode=*)
188 KMODEL="${ARGUMENT#*=}"
193 KOPTIONS="${ARGUMENT#koptions=}"
202 live-media=*|bootfrom=*)
203 LIVE_MEDIA="${ARGUMENT#*=}"
207 live-media-encryption=*|encryption=*)
208 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
209 export LIVE_MEDIA_ENCRYPTION
213 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
214 export LIVE_MEDIA_OFFSET
218 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
219 export LIVE_MEDIA_PATH
222 live-media-timeout=*)
223 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
224 export LIVE_MEDIA_TIMEOUT
228 MODULE="${ARGUMENT#module=}"
233 NETBOOT="${ARGUMENT#netboot=}"
238 NFSOPTS="${ARGUMENT#nfsopts=}"
243 NFS_COW="${ARGUMENT#nfscow=}"
248 NOACCESSIBILITY="Yes"
249 export NOACCESSIBILITY
268 NOCONSOLEKEYBOARD="Yes"
269 export NOCONSOLEKEYBOARD
304 export NOXSCREENSAVER
313 PERSISTENT="${ARGUMENT#persistent=}"
314 if [ -z "${PERSISTENT}" ]
322 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
323 export PERSISTENT_PATH
326 persistent-subtext=*)
327 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
328 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
329 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
330 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
339 QUICKUSBMODULES="Yes"
340 export QUICKUSBMODULES
343 preseed/file=*|file=*)
344 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
354 question="${ARGUMENT%%=*}"
355 value="${ARGUMENT#*=}"
356 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
376 TIMEZONE="${ARGUMENT#timezone=}"
386 TODISK="${ARGUMENT#todisk=}"
397 MODULETORAM="${ARGUMENT#toram=}"
398 export TORAM MODULETORAM
412 SKIP_UNION_MOUNTS="Yes"
413 export SKIP_UNION_MOUNTS
417 ROOT="${ARGUMENT#root=}"
422 UNIONTYPE="${ARGUMENT#union=}"
432 XDRIVER="${ARGUMENT#xdriver=}"
437 XVIDEOMODE="${ARGUMENT#xvideomode=}"
443 # sort of compatibility with netboot.h from linux docs
444 if [ -z "${NETBOOT}" ]
446 if [ "${ROOT}" = "/dev/nfs" ]
450 elif [ "${ROOT}" = "/dev/cifs" ]
457 if [ -z "${MODULE}" ]
463 if [ -z "${UNIONTYPE}" ]
474 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
476 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
478 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
490 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
496 uuid="$(cat /conf/uuid.conf)"
498 for try_uuid_file in "${path}/.disk/live-uuid"*
500 [ -e "${try_uuid_file}" ] || continue
502 try_uuid="$(cat "${try_uuid_file}")"
504 if [ "${uuid}" = "${try_uuid}" ]
513 get_backing_device ()
516 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
517 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
525 panic "Unrecognized live filesystem: ${1}"
530 match_files_in_dir ()
532 # Does any files match pattern ${1} ?
535 if [ "$(echo ${pattern})" != "${pattern}" ]
543 mount_images_in_directory ()
550 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
551 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
552 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
553 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
554 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
555 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
557 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
558 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
560 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
566 sysfs_path="${1#/sys}"
568 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
571 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
574 elif echo ${sysfs_path} | grep -q "^/block/dm-"
586 copyto="${copyfrom}_swap"
588 if [ -z "${MODULETORAM}" ]
590 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
592 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
594 if [ -f "${MODULETORAMFILE}" ]
596 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
598 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
603 if [ "${copytodev}" = "ram" ]
606 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
607 mount_options="-o size=${size}k"
612 # it should be a writable block device
613 if [ -b "${copytodev}" ]
617 fstype=$(get_fstype "${dev}")
618 freespace=$(fs_size "${dev}")
620 log_warning_msg "${copytodev} is not a block device."
625 if [ "${freespace}" -lt "${size}" ]
627 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
631 # begin copying (or uncompressing)
633 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
634 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
636 if [ "${extension}" = "tgz" ]
639 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
640 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
641 mount -r -o move "${copyto}" "${rootmnt}"
644 if [ -n "${MODULETORAMFILE}" ]
648 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
649 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
651 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
656 echo " * Copying whole medium to RAM" 1>/dev/console
657 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
659 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
660 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
661 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
663 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
669 mount -r -o move ${copyto} ${copyfrom}
678 modprobe -q af_packet # For DHCP
683 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
684 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
687 # if ethdevice was not specified on the kernel command line
688 # make sure we try to get a working network configuration
689 # for *every* present network device (except for loopback of course)
690 if [ -z "$ETHDEVICE" ] ; then
691 echo "If you want to boot from a specific device use bootoption ethdevice=..."
692 for device in /sys/class/net/*; do
694 if [ "$dev" != "lo" ] ; then
695 ETHDEVICE="$ETHDEVICE $dev"
700 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
701 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
702 devlist="$devlist $device"
705 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
706 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
708 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
709 # an endless loop; iff execution fails give it two further tries, that's
710 # why we use '$devlist $devlist $devlist' for the other for loop
711 for dev in $devlist $devlist $devlist ; do
712 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
713 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
715 sleep "$ETHDEV_TIMEOUT" ; sleep 1
716 if [ -r /proc/"$jobid"/status ] ; then
717 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
721 # if configuration of device worked we should have an assigned
722 # IP address, iff so let's use the according as $DEVICE for later usage
723 # simple and primitive approach which seems to work fine
724 if ifconfig $dev | grep -q 'inet.*addr:' ; then
731 ipconfig ${DEVICE} | tee /netboot.config
734 # source relevant ipconfig output
735 OLDHOSTNAME=${HOSTNAME}
736 . /tmp/net-${DEVICE}.conf
737 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
740 # Check if we have a network device at all
741 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
742 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
743 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
744 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
745 ! ls /sys/class/net/ra0 > /dev/null 2>&1
747 panic "No supported network device found, maybe a non-mainline driver is required."
750 if [ "${NFSROOT}" = "auto" ]
752 NFSROOT=${ROOTSERVER}:${ROOTPATH}
757 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
763 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
765 NFSROOT=${ROOTSERVER}:${NFSROOT}
768 log_begin_msg "Trying netboot from ${NFSROOT}"
770 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
788 for webfile in HTTPFS FTPFS FETCH
790 local url="$(eval echo \"\$\{${webfile}\}\")"
791 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
795 case "${extension}" in
796 iso|squashfs|tgz|tar)
797 if [ "${extension}" = "iso" ]
799 mkdir -p "${alt_mountpoint}"
800 dest="${alt_mountpoint}"
802 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
803 mount -t ramfs ram "${mountpoint}"
806 if [ "${webfile}" = "FETCH" ]
810 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
811 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
812 lfile="$(basename $url)"
813 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
814 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
818 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
819 wget "${url}" -O "${dest}/$(basename ${url})"
823 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
824 if [ "${webfile}" = "FTPFS" ]
826 FUSE_MOUNT="curlftpfs"
827 url="$(dirname ${url})"
832 $FUSE_MOUNT "${url}" "${dest}"
834 [ ${?} -eq 0 ] && rc=0
835 [ "${extension}" = "tgz" ] && live_dest="ram"
836 if [ "${extension}" = "iso" ]
838 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
839 mount -t iso9660 "${isoloop}" "${mountpoint}"
846 log_begin_msg "Unrecognized archive extension for ${url}"
854 if [ -d "${alt_mountpoint}" ]
856 umount "${alt_mountpoint}"
857 rmdir "${alt_mountpoint}"
859 umount "${mountpoint}"
860 elif [ "${webfile}" != "FETCH" ] ; then
874 if [ -z "${NFSOPTS}" ]
879 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
881 # FIXME: This while loop is an ugly HACK round an nfs bug
883 while [ "$i" -lt 60 ]
885 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
897 if [ -x "/sbin/mount.cifs" ]
899 if [ -z "${NFSOPTS}" ]
901 CIFSOPTS="-ouser=root,password="
903 CIFSOPTS="${NFSOPTS}"
906 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
909 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
923 size=$(fs_size "${fromdev}" "" "used")
925 if [ -b "${fromdev}" ]
928 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
930 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
931 freespace=$(df -k | awk '/'${todev}'/{print $4}')
933 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
936 tomount="/mnt/tmpsnap"
938 if [ ! -d "${tomount}" ]
940 mkdir -p "${tomount}"
943 fstype=$(get_fstype "${fromdev}")
945 if [ -n "${fstype}" ]
948 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
949 cp -a "${tomount}"/* ${todir}
952 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
957 if echo ${fromdev} | grep -qs loop
959 losetup -d "${fromdev}"
966 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
972 # Look for ${snap_label}.* in block devices
975 if [ "${PERSISTENT}" != "nofiles" ]
977 # search for image files
978 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")
981 if [ -z "${snapdata}" ]
983 snapdata=$(find_cow_device "${snap_label}")
990 # copy the contents of previously found snapshot to ${snap_mount}
991 # and remember the device and filename for resync on exit in live-boot.init
997 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
999 log_success_msg "found snapshot: ${snapdata}"
1000 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1001 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1002 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1005 if ! try_mount "${snapdev}" "${snapback}" "ro"
1010 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1012 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1013 dev=$(get_backing_device "${snapback}/${snapfile}")
1015 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1020 # Unfortunately klibc's cpio is incompatible with the
1021 # rest of the world; everything else requires -u -d,
1022 # while klibc doesn't implement them. Try to detect
1023 # whether it's in use.
1024 cpiopath="$(which cpio)" || true
1025 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1029 cpioargs='--unconditional --make-directories'
1032 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1034 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1038 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1040 if [ "${RES}" != "0" ]
1042 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1045 elif [ -b "${snapdata}" ]
1047 # Try to find if it could be a snapshot partition
1049 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1050 if echo "${dev}" | grep -qs loop
1052 # strange things happens, user confused?
1053 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1054 snapfile=$(basename ${snaploop})
1055 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1060 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1062 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1065 if [ -n "${snapfile}" ]
1067 # it was a loop device, user confused
1072 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1076 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1082 image_directory="${1}"
1084 addimage_directory="${3}"
1086 case ${UNIONTYPE} in
1088 modprobe -q -b ${UNIONTYPE}
1090 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1092 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1093 echo "This might be really slow."
1095 UNIONTYPE="unionfs-fuse"
1100 if [ "${UNIONTYPE}" = unionfs-fuse ]
1105 # run-init can't deal with images in a subdir, but we're going to
1106 # move all of these away before it runs anyway. No, we're not,
1107 # put them in / since move-mounting them into / breaks mono and
1112 # Let's just mount the read-only file systems first
1116 if [ "${UNIONTYPE}" = "aufs" ]
1119 noxino_opt="noxino,"
1120 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1127 if [ -z "${PLAIN_ROOT}" ]
1129 # Read image names from ${MODULE}.module if it exists
1130 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1132 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1134 image_string="${image_string} ${image_directory}/${IMAGE}"
1136 elif [ -e "${image_directory}/${MODULE}.module" ]
1138 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1140 image_string="${image_string} ${image_directory}/${IMAGE}"
1143 # ${MODULE}.module does not exist, create a list of images
1144 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1146 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1148 if [ -e "${IMAGE}" ]
1150 image_string="${image_string} ${IMAGE}"
1155 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1157 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1159 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1161 if [ -e "${IMAGE}" ]
1163 image_string="${image_string} ${IMAGE}"
1170 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1173 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1177 for image in ${image_string}
1179 imagename=$(basename "${image}")
1181 export image devname
1182 maybe_break live-realpremount
1183 log_begin_msg "Running /scripts/live-realpremount"
1184 run_scripts /scripts/live-realpremount
1187 if [ -d "${image}" ]
1189 # it is a plain directory: do nothing
1190 rofsstring="${image}=${roopt}:${rofsstring}"
1191 rofslist="${image} ${rofslist}"
1192 elif [ -f "${image}" ]
1194 if losetup --help 2>&1 | grep -q -- "-r\b"
1196 backdev=$(get_backing_device "${image}" "-r")
1198 backdev=$(get_backing_device "${image}")
1200 fstype=$(get_fstype "${backdev}")
1202 if [ "${fstype}" = "unknown" ]
1204 panic "Unknown file system type on ${backdev} (${image})"
1207 if [ -z "${fstype}" ]
1209 fstype="${imagename##*.}"
1210 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1213 mkdir -p "${croot}/${imagename}"
1214 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1215 mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
1220 # we have a plain root system
1221 mkdir -p "${croot}/filesystem"
1222 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1223 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}"
1225 mount -o bind ${croot}/filesystem $mountpoint
1229 rofsstring=${rofsstring%:}
1233 # Looking for "${root_persistence}" device or file
1234 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1236 if [ -z "${QUICKUSBMODULES}" ]
1239 num_block=$(ls -l /sys/block | wc -l)
1240 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1242 modprobe -q -b ${module}
1248 # For some reason, udevsettle does not block in this scenario,
1249 # so we sleep for a little while.
1251 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1252 for timeout in 5 4 3 2 1
1256 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1263 # search for label and files (this could be hugely optimized)
1264 cowprobe=$(find_cow_device "${root_persistence}")
1265 if [ -b "${cowprobe}" ]
1267 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1268 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1269 # snapshots to be sure to really store some e.g key config files,
1270 # but not on the same media
1271 blacklistdev="${cowprobe}"
1272 PERSISTENCE_IS_ON="1"
1273 export PERSISTENCE_IS_ON
1275 # homecow just mount something on /home, this should be generalized some way
1276 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1277 if [ -b "${homecow}" ]
1279 PERSISTENCE_IS_ON="1"
1280 export PERSISTENCE_IS_ON
1282 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1283 # This second type should be removed when snapshot will get smarter,
1284 # hence when "/etc/live-snapshot*list" will be supported also by
1285 # ext2|ext3|ext4|jffs2 snapshot types.
1286 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1288 if [ -b "${cowprobe}" ]
1290 cowdevice=${cowprobe}
1291 cow_fstype=$(get_fstype "${cowprobe}")
1292 cow_mountopt="rw,noatime"
1294 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1296 fsck -y ${cowdevice}
1299 log_warning_msg "Unable to find the persistent medium"
1302 cow_mountopt="rw,noatime,mode=755"
1304 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1306 # check if there are any nfs options
1307 if echo ${NFS_COW}|grep -q ','
1309 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1310 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1312 nfs_cow_opts="-o nolock"
1318 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1321 panic "unable to determine mac address"
1326 cow_mountopt="rw,noatime,mode=755"
1329 if [ "${cow_fstype}" = "nfs" ]
1332 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1333 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1334 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1336 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1337 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1340 rofscount=$(echo ${rofslist} |wc -w)
1342 if [ -n "${EXPOSED_ROOT}" ]
1344 if [ ${rofscount} -ne 1 ]
1346 panic "only one RO file system supported with exposedroot: ${rofslist}"
1348 exposedrootfs=${rofslist%% }
1350 mount --bind ${exposedrootfs} ${rootmnt} || \
1351 panic "bind mount of ${exposedrootfs} failed"
1353 if [ -z "${SKIP_UNION_MOUNTS}" ]
1355 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1360 for dir in ${cow_dirs}; do
1363 case "${UNIONTYPE}" in
1365 (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}")
1366 mkdir -p /dev/.initramfs/varrun
1367 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1371 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"
1376 case "${UNIONTYPE}" in
1378 (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}")
1379 mkdir -p /dev/.initramfs/varrun
1380 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1384 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}"
1389 # Correct the permissions of /:
1390 chmod 0755 "${rootmnt}"
1392 # tmpfs file systems
1394 mkdir -p "${rootmnt}/live"
1395 mount -t tmpfs tmpfs ${rootmnt}/live
1397 # Adding other custom mounts
1398 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1400 # directly mount /home
1401 # FIXME: add a custom mounts configurable system
1403 if [ -b "${homecow}" ]
1405 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1406 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1408 log_warning_msg "Unable to find the persistent home medium"
1411 # Look for other snapshots to copy in
1412 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1413 # This second type should be removed when snapshot grow smarter
1414 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1417 if [ -n "${SHOWMOUNTS}" ]
1419 for d in ${rofslist}
1421 mkdir -p "${rootmnt}/live/${d##*/}"
1425 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1429 case "${UNIONTYPE}" in
1431 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1435 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1443 # shows cow fs on /cow for use by live-snapshot
1444 mkdir -p "${rootmnt}/live/cow"
1445 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"
1452 skip_uuid_check="${3}"
1454 # support for fromiso=.../isofrom=....
1455 if [ -n "$FROMISO" ]
1457 ISO_DEVICE=$(dirname $FROMISO)
1458 if ! [ -b $ISO_DEVICE ]
1460 # to support unusual device names like /dev/cciss/c0d0p1
1461 # as well we have to identify the block device name, let's
1462 # do that for up to 15 levels
1464 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1466 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1467 [ -b "$ISO_DEVICE" ] && break
1472 if [ "$ISO_DEVICE" = "/" ]
1474 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1477 mount "$ISO_DEVICE" /isofrom
1478 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1479 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1480 devname="${loopdevname}"
1484 if [ -z "${devname}" ]
1486 devname=$(sys2dev "${sysdev}")
1489 if [ -d "${devname}" ]
1491 mount -o bind "${devname}" $mountpoint || continue
1493 if is_live_path $mountpoint
1501 [ -e "$devname" ] || continue
1503 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1505 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1506 devname="${loopdevname}"
1509 fstype=$(get_fstype "${devname}")
1511 if is_supported_fs ${fstype}
1513 devuid=$(blkid -o value -s UUID "$devname")
1514 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1515 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1516 [ -n "$devuid" ] && echo "$devuid" >> $tried
1518 if is_live_path ${mountpoint} && \
1519 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1524 umount ${mountpoint}
1528 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1530 losetup -d "${loopdevname}"
1540 # don't start autodetection before timeout has expired
1541 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1543 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1549 # first look at the one specified in the command line
1550 case "${LIVE_MEDIA}" in
1552 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1554 if [ "$(cat ${sysblock}/removable)" = "1" ]
1556 if readlink ${sysblock} | grep -q usb ||
1557 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1559 for dev in $(subdevices "${sysblock}")
1561 if check_dev "${dev}"
1573 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1575 if [ "$(cat ${sysblock}/removable)" = "1" ]
1577 for dev in $(subdevices "${sysblock}")
1579 if check_dev "${dev}"
1590 if [ ! -z "${LIVE_MEDIA}" ]
1592 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1600 # or do the scan of block devices
1601 # prefer removable devices over non-removable devices, so scan them first
1602 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1604 if [ "$(cat ${sysblock}/removable)" = "1" ]
1606 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1608 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1611 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1613 for sysblock in $devices_to_scan
1615 devname=$(sys2dev "${sysblock}")
1616 [ -e "$devname" ] || continue
1617 fstype=$(get_fstype "${devname}")
1619 if /lib/udev/cdrom_id ${devname} > /dev/null
1621 if check_dev "null" "${devname}"
1625 elif is_nice_device "${sysblock}"
1627 for dev in $(subdevices "${sysblock}")
1629 if check_dev "${dev}"
1634 elif [ "${fstype}" = "squashfs" -o \
1635 "${fstype}" = "ext2" -o \
1636 "${fstype}" = "ext3" -o \
1637 "${fstype}" = "ext4" -o \
1638 "${fstype}" = "jffs2" ]
1640 # This is an ugly hack situation, the block device has
1641 # an image directly on it. It's hopefully
1642 # live-boot, so take it and run with it.
1643 ln -s "${devname}" "${devname}.${fstype}"
1644 echo "${devname}.${fstype}"
1652 set_usplash_timeout ()
1654 if [ -x /sbin/usplash_write ]
1656 /sbin/usplash_write "TIMEOUT 120"
1657 else if [ -x /sbin/splashy_update ] ; then
1658 /sbin/splashy_update "TIMEOUT 120"
1664 media_mountpoint="${1}"
1666 log_begin_msg "Checking media integrity"
1668 cd ${media_mountpoint}
1669 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1674 if [ "${RC}" -eq 0 ]
1676 log_success_msg "Everything ok, will reboot in 10 seconds."
1679 umount ${media_mountpoint}
1681 echo u > /proc/sysrq-trigger
1682 echo b > /proc/sysrq-trigger
1684 panic "Not ok, a media defect is likely, switch to VT8 for details."
1688 start_usplash_pulse ()
1690 if [ -x /sbin/usplash_write ]
1692 /sbin/usplash_write "PULSELOGO"
1698 if [ -x /scripts/local-top/cryptroot ]; then
1699 /scripts/local-top/cryptroot
1706 tail -f live.log >&7 &
1709 # Ensure 'panic' function is overridden
1710 . /scripts/live-functions
1717 maybe_break live-premount
1718 log_begin_msg "Running /scripts/live-premount"
1719 run_scripts /scripts/live-premount
1722 # Needed here too because some things (*cough* udev *cough*)
1723 # changes the timeout
1727 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1731 livefs_root="${mountpoint}"
1733 panic "Unable to find a live file system on the network"
1736 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1738 # Do a local boot from hd
1741 # Scan local devices for the image
1743 while [ "$i" -lt 60 ]
1745 livefs_root=$(find_livefs ${i})
1747 if [ -n "${livefs_root}" ]
1758 if [ -z "${livefs_root}" ]
1760 panic "Unable to find a medium containing a live file system"
1763 if [ "${INTEGRITY_CHECK}" ]
1765 integrity_check "${livefs_root}"
1771 elif [ "${TODISK}" ]
1773 live_dest="${TODISK}"
1776 if [ "${live_dest}" ]
1778 log_begin_msg "Copying live media to ${live_dest}"
1779 copy_live_to "${livefs_root}" "${live_dest}"
1783 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1784 # because the mountpoint is left behind in /proc/mounts, so let's get
1785 # rid of it when running from RAM
1786 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1788 losetup -d /dev/loop0
1789 grep -q /isofrom /proc/mounts && umount /isofrom
1792 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1794 setup_unionfs "${livefs_root}" "${rootmnt}"
1797 mac="$(echo ${mac} | sed 's/-//g')"
1798 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1803 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1804 # live-bottom; udev's init script will take care of things after that
1805 if [ "${UNIONTYPE}" = unionfs-fuse ]
1807 mount -n -o bind /dev "${rootmnt}/dev"
1810 # Move to the new root filesystem so that programs there can get at it.
1811 if [ ! -d /root/live/image ]
1813 mkdir -p /root/live/image
1814 mount --move /live/image /root/live/image
1817 maybe_break live-bottom
1818 log_begin_msg "Running /scripts/live-bottom\n"
1820 run_scripts /scripts/live-bottom
1823 if [ "${UNIONFS}" = unionfs-fuse ]
1825 umount "${rootmnt}/dev"
1831 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1832 if [ -f /etc/live.conf ]
1834 cp /etc/live.conf "${rootmnt}/etc/"