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 LIVE_MEDIA_PATH="live"
13 root_persistence="live-rw"
14 home_persistence="home-rw"
15 root_snapshot_label="live-sn"
16 home_snapshot_label="home-sn"
19 USERFULLNAME="Live user"
22 mkdir -p "${mountpoint}"
25 # Create /etc/mtab for debug purpose and future syncs
36 [ -f /etc/live.conf ] && . /etc/live.conf
37 export USERNAME USERFULLNAME HOSTNAME
39 . /scripts/live-helpers
41 if [ ! -f /live.vars ]
51 for ARGUMENT in $(cat /proc/cmdline)
58 NOCONSOLEKEYBOARD="Yes"
67 export NOACCESSIBILITY NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOHOSTS NONETWORKING NOTIMEZONE NOXAUTOCONFIG NOXAUTOLOGIN
71 ACCESS="${ARGUMENT#access=}"
76 DEFCONSOLE="${ARGUMENT#*=}"
88 DEVICE="${ARGUMENT#ethdevice=}"
93 ETHDEVICE="${ARGUMENT#ethdevice=}"
98 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
103 FETCH="${ARGUMENT#fetch=}"
108 FORCEPERSISTENTFSCK="Yes"
109 export FORCEPERSISTENTFSCK
113 FTPFS="${ARGUMENT#ftpfs=}"
118 HTTPFS="${ARGUMENT#httpfs=}"
123 FROMISO="${ARGUMENT#*=}"
128 USERNAME="${ARGUMENT#username=}"
130 export USERNAME LIVECONF
134 USERFULLNAME="${ARGUMENT#userfullname=}"
136 export USERFULLNAME LIVECONF
145 INTEGRITY_CHECK="Yes"
146 export INTEGRITY_CHECK
150 STATICIP="${ARGUMENT#ip=}"
152 if [ -z "${STATICIP}" ]
160 keyb=*|kbd-chooser/method=*)
165 klayout=*|console-setup/layoutcode=*)
166 KLAYOUT="${ARGUMENT#*=}"
170 kvariant=*|console-setup/variantcode=*)
171 KVARIANT="${ARGUMENT#*=}"
175 kmodel=*|console-setup/modelcode=*)
176 KMODEL="${ARGUMENT#*=}"
181 KOPTIONS="${ARGUMENT#koptions=}"
190 live-media=*|bootfrom=*)
191 LIVE_MEDIA="${ARGUMENT#*=}"
195 live-media-encryption=*|encryption=*)
196 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
197 export LIVE_MEDIA_ENCRYPTION
201 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
202 export LIVE_MEDIA_OFFSET
206 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
207 export LIVE_MEDIA_PATH
210 live-media-timeout=*)
211 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
212 export LIVE_MEDIA_TIMEOUT
216 MODULE="${ARGUMENT#module=}"
221 NETBOOT="${ARGUMENT#netboot=}"
226 NFSOPTS="${ARGUMENT#nfsopts=}"
231 NFS_COW="${ARGUMENT#nfscow=}"
236 NOACCESSIBILITY="Yes"
237 export NOACCESSIBILITY
256 NOCONSOLEKEYBOARD="Yes"
257 export NOCONSOLEKEYBOARD
292 export NOXSCREENSAVER
301 PERSISTENT="${ARGUMENT#persistent=}"
302 if [ -z "${PERSISTENT}" ]
310 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
311 export PERSISTENT_PATH
314 persistent-subtext=*)
315 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
316 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
317 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
318 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
327 QUICKUSBMODULES="Yes"
328 export QUICKUSBMODULES
331 preseed/file=*|file=*)
332 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
342 URL_LOCATION="${ARGUMENT#url=}"
344 mount -o bind /sys /root/sys
345 mount -o bind /proc /root/proc
346 mount -o bind /dev /root/dev
348 mkdir -p /root/var/run/network
349 [ "${NETBOOT}" ] || chroot /root dhclient eth0
350 chroot /root wget -P /tmp "${URL_LOCATION}"
351 [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down
357 LOCATIONS="/tmp/$(basename ${URL_LOCATION}) ${LOCATIONS}"
361 question="${ARGUMENT%%=*}"
362 value="${ARGUMENT#*=}"
363 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
383 TIMEZONE="${ARGUMENT#timezone=}"
393 TODISK="${ARGUMENT#todisk=}"
404 MODULETORAM="${ARGUMENT#toram=}"
405 export TORAM MODULETORAM
419 SKIP_UNION_MOUNTS="Yes"
420 export SKIP_UNION_MOUNTS
424 ROOT="${ARGUMENT#root=}"
429 UNIONTYPE="${ARGUMENT#union=}"
439 XDRIVER="${ARGUMENT#xdriver=}"
444 XVIDEOMODE="${ARGUMENT#xvideomode=}"
450 # sort of compatibility with netboot.h from linux docs
451 if [ -z "${NETBOOT}" ]
453 if [ "${ROOT}" = "/dev/nfs" ]
457 elif [ "${ROOT}" = "/dev/cifs" ]
464 if [ -z "${MODULE}" ]
470 if [ -z "${UNIONTYPE}" ]
481 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
483 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
485 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
497 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
503 uuid="$(cat /conf/uuid.conf)"
505 for try_uuid_file in "${path}/.disk/live-uuid"*
507 [ -e "${try_uuid_file}" ] || continue
509 try_uuid="$(cat "${try_uuid_file}")"
511 if [ "${uuid}" = "${try_uuid}" ]
520 get_backing_device ()
523 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
524 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
532 panic "Unrecognized live filesystem: ${1}"
537 match_files_in_dir ()
539 # Does any files match pattern ${1} ?
542 if [ "$(echo ${pattern})" != "${pattern}" ]
550 mount_images_in_directory ()
557 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
558 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
559 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
560 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
561 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
562 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
564 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
565 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
567 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
573 sysfs_path="${1#/sys}"
575 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
578 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
581 elif echo ${sysfs_path} | grep -q "^/block/dm-"
593 copyto="${copyfrom}_swap"
595 if [ -z "${MODULETORAM}" ]
597 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
599 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
601 if [ -f "${MODULETORAMFILE}" ]
603 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
605 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
610 if [ "${copytodev}" = "ram" ]
613 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
614 mount_options="-o size=${size}k"
619 # it should be a writable block device
620 if [ -b "${copytodev}" ]
624 fstype=$(get_fstype "${dev}")
625 freespace=$(fs_size "${dev}")
627 log_warning_msg "${copytodev} is not a block device."
632 if [ "${freespace}" -lt "${size}" ]
634 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
638 # begin copying (or uncompressing)
640 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
641 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
643 if [ "${extension}" = "tgz" ]
646 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
647 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
648 mount -r -o move "${copyto}" "${rootmnt}"
651 if [ -n "${MODULETORAMFILE}" ]
655 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
656 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
658 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
663 echo " * Copying whole medium to RAM" 1>/dev/console
664 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
666 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
667 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
668 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
670 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
676 mount -r -o move ${copyto} ${copyfrom}
685 modprobe -q af_packet # For DHCP
690 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
691 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
694 # if ethdevice was not specified on the kernel command line
695 # make sure we try to get a working network configuration
696 # for *every* present network device (except for loopback of course)
697 if [ -z "$ETHDEVICE" ] ; then
698 echo "If you want to boot from a specific device use bootoption ethdevice=..."
699 for device in /sys/class/net/*; do
701 if [ "$dev" != "lo" ] ; then
702 ETHDEVICE="$ETHDEVICE $dev"
707 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
708 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
709 devlist="$devlist $device"
712 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
713 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
715 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
716 # an endless loop; iff execution fails give it two further tries, that's
717 # why we use '$devlist $devlist $devlist' for the other for loop
718 for dev in $devlist $devlist $devlist ; do
719 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
720 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
722 sleep "$ETHDEV_TIMEOUT" ; sleep 1
723 if [ -r /proc/"$jobid"/status ] ; then
724 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
728 # if configuration of device worked we should have an assigned
729 # IP address, iff so let's use the according as $DEVICE for later usage
730 # simple and primitive approach which seems to work fine
731 if ifconfig $dev | grep -q 'inet.*addr:' ; then
738 ipconfig ${DEVICE} | tee /netboot.config
741 # source relevant ipconfig output
742 OLDHOSTNAME=${HOSTNAME}
743 . /tmp/net-${DEVICE}.conf
744 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
747 # Check if we have a network device at all
748 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
749 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
750 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
751 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
752 ! ls /sys/class/net/ra0 > /dev/null 2>&1
754 panic "No supported network device found, maybe a non-mainline driver is required."
757 if [ "${NFSROOT}" = "auto" ]
759 NFSROOT=${ROOTSERVER}:${ROOTPATH}
764 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
770 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
772 NFSROOT=${ROOTSERVER}:${NFSROOT}
775 log_begin_msg "Trying netboot from ${NFSROOT}"
777 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
794 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
795 mount -t ramfs ram "${mountpoint}"
798 for webfile in HTTPFS FTPFS FETCH
800 url="$(eval echo \"\$\{${webfile}\}\")"
801 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
805 case "${extension}" in
807 if [ "${webfile}" = "FETCH" ]
811 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
812 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
813 lfile="$(basename $url)"
814 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
815 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
819 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
820 wget "${url}" -O "${dest}/$(basename ${url})"
824 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
825 if [ "${webfile}" = "FTPFS" ]
827 FUSE_MOUNT="curlftpfs"
828 url="$(dirname ${url})"
833 $FUSE_MOUNT "${url}" "${dest}"
835 [ ${?} -eq 0 ] && rc=0
836 [ "${extension}" = "tgz" ] && live_dest="ram"
841 log_begin_msg "Unrecognized archive extension for ${url}"
849 umount "${mountpoint}"
850 elif [ "${webfile}" != "FETCH" ] ; then
864 if [ -z "${NFSOPTS}" ]
869 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
871 # FIXME: This while loop is an ugly HACK round an nfs bug
873 while [ "$i" -lt 60 ]
875 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
887 if [ -x "/sbin/mount.cifs" ]
889 if [ -z "${NFSOPTS}" ]
891 CIFSOPTS="-ouser=root,password="
893 CIFSOPTS="${NFSOPTS}"
896 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
899 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
913 size=$(fs_size "${fromdev}" "" "used")
915 if [ -b "${fromdev}" ]
918 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
920 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
921 freespace=$(df -k | awk '/'${todev}'/{print $4}')
923 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
926 tomount="/mnt/tmpsnap"
928 if [ ! -d "${tomount}" ]
930 mkdir -p "${tomount}"
933 fstype=$(get_fstype "${fromdev}")
935 if [ -n "${fstype}" ]
938 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
939 cp -a "${tomount}"/* ${todir}
942 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
947 if echo ${fromdev} | grep -qs loop
949 losetup -d "${fromdev}"
956 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
962 # Look for ${snap_label}.* in block devices
965 if [ "${PERSISTENT}" != "nofiles" ]
967 # search for image files
968 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")
971 if [ -z "${snapdata}" ]
973 snapdata=$(find_cow_device "${snap_label}")
980 # copy the contents of previously found snapshot to ${snap_mount}
981 # and remember the device and filename for resync on exit in live-boot.init
987 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
989 log_success_msg "found snapshot: ${snapdata}"
990 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
991 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
992 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
995 if ! try_mount "${snapdev}" "${snapback}" "ro"
1000 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1002 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1003 dev=$(get_backing_device "${snapback}/${snapfile}")
1005 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1010 # Unfortunately klibc's cpio is incompatible with the
1011 # rest of the world; everything else requires -u -d,
1012 # while klibc doesn't implement them. Try to detect
1013 # whether it's in use.
1014 cpiopath="$(which cpio)" || true
1015 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1019 cpioargs='--unconditional --make-directories'
1022 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1024 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1028 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1030 if [ "${RES}" != "0" ]
1032 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1035 elif [ -b "${snapdata}" ]
1037 # Try to find if it could be a snapshot partition
1039 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1040 if echo "${dev}" | grep -qs loop
1042 # strange things happens, user confused?
1043 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1044 snapfile=$(basename ${snaploop})
1045 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1050 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1052 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1055 if [ -n "${snapfile}" ]
1057 # it was a loop device, user confused
1062 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1066 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1072 image_directory="${1}"
1074 addimage_directory="${3}"
1076 case ${UNIONTYPE} in
1078 modprobe -q -b ${UNIONTYPE}
1080 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1082 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1083 echo "This might be really slow."
1085 UNIONTYPE="unionfs-fuse"
1090 if [ "${UNIONTYPE}" = unionfs-fuse ]
1095 # run-init can't deal with images in a subdir, but we're going to
1096 # move all of these away before it runs anyway. No, we're not,
1097 # put them in / since move-mounting them into / breaks mono and
1102 # Let's just mount the read-only file systems first
1106 if [ "${UNIONTYPE}" = "aufs" ]
1109 noxino_opt="noxino,"
1110 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1117 if [ -z "${PLAIN_ROOT}" ]
1119 # Read image names from ${MODULE}.module if it exists
1120 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1122 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1124 image_string="${image_string} ${image_directory}/${IMAGE}"
1126 elif [ -e "${image_directory}/${MODULE}.module" ]
1128 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1130 image_string="${image_string} ${image_directory}/${IMAGE}"
1133 # ${MODULE}.module does not exist, create a list of images
1134 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1136 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1138 if [ -e "${IMAGE}" ]
1140 image_string="${image_string} ${IMAGE}"
1145 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1147 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1149 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1151 if [ -e "${IMAGE}" ]
1153 image_string="${image_string} ${IMAGE}"
1160 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1163 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1167 for image in ${image_string}
1169 imagename=$(basename "${image}")
1171 export image devname
1172 maybe_break live-realpremount
1173 log_begin_msg "Running /scripts/live-realpremount"
1174 run_scripts /scripts/live-realpremount
1177 if [ -d "${image}" ]
1179 # it is a plain directory: do nothing
1180 rofsstring="${image}=${roopt}:${rofsstring}"
1181 rofslist="${image} ${rofslist}"
1182 elif [ -f "${image}" ]
1184 if losetup --help 2>&1 | grep -q -- "-r\b"
1186 backdev=$(get_backing_device "${image}" "-r")
1188 backdev=$(get_backing_device "${image}")
1190 fstype=$(get_fstype "${backdev}")
1192 if [ "${fstype}" = "unknown" ]
1194 panic "Unknown file system type on ${backdev} (${image})"
1197 if [ -z "${fstype}" ]
1199 fstype="${imagename##*.}"
1200 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1203 mkdir -p "${croot}/${imagename}"
1204 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1205 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}"
1210 # we have a plain root system
1211 mkdir -p "${croot}/filesystem"
1212 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1213 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}"
1215 mount -o bind ${croot}/filesystem $mountpoint
1219 rofsstring=${rofsstring%:}
1223 # Looking for "${root_persistence}" device or file
1224 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1226 if [ -z "${QUICKUSBMODULES}" ]
1229 num_block=$(ls -l /sys/block | wc -l)
1230 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1232 modprobe -q -b ${module}
1238 # For some reason, udevsettle does not block in this scenario,
1239 # so we sleep for a little while.
1241 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1242 for timeout in 5 4 3 2 1
1246 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1253 # search for label and files (this could be hugely optimized)
1254 cowprobe=$(find_cow_device "${root_persistence}")
1255 if [ -b "${cowprobe}" ]
1257 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1258 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1259 # snapshots to be sure to really store some e.g key config files,
1260 # but not on the same media
1261 blacklistdev="${cowprobe}"
1262 PERSISTENCE_IS_ON="1"
1263 export PERSISTENCE_IS_ON
1265 # homecow just mount something on /home, this should be generalized some way
1266 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1267 if [ -b "${homecow}" ]
1269 PERSISTENCE_IS_ON="1"
1270 export PERSISTENCE_IS_ON
1272 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1273 # This second type should be removed when snapshot will get smarter,
1274 # hence when "/etc/live-snapshot*list" will be supported also by
1275 # ext2|ext3|ext4|jffs2 snapshot types.
1276 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1278 if [ -b "${cowprobe}" ]
1280 cowdevice=${cowprobe}
1281 cow_fstype=$(get_fstype "${cowprobe}")
1282 cow_mountopt="rw,noatime"
1284 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1286 fsck -y ${cowdevice}
1289 log_warning_msg "Unable to find the persistent medium"
1292 cow_mountopt="rw,noatime,mode=755"
1294 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1296 # check if there are any nfs options
1297 if echo ${NFS_COW}|grep -q ','
1299 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1300 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1302 nfs_cow_opts="-o nolock"
1308 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1311 panic "unable to determine mac address"
1316 cow_mountopt="rw,noatime,mode=755"
1319 if [ "${cow_fstype}" = "nfs" ]
1322 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1323 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1324 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1326 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1327 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1330 rofscount=$(echo ${rofslist} |wc -w)
1332 if [ -n "${EXPOSED_ROOT}" ]
1334 if [ ${rofscount} -ne 1 ]
1336 panic "only one RO file system supported with exposedroot: ${rofslist}"
1338 exposedrootfs=${rofslist%% }
1340 mount --bind ${exposedrootfs} ${rootmnt} || \
1341 panic "bind mount of ${exposedrootfs} failed"
1343 if [ -z "${SKIP_UNION_MOUNTS}" ]
1345 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1350 for dir in ${cow_dirs}; do
1353 case "${UNIONTYPE}" in
1355 (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}")
1356 mkdir -p /dev/.initramfs/varrun
1357 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1361 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"
1366 case "${UNIONTYPE}" in
1368 (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}")
1369 mkdir -p /dev/.initramfs/varrun
1370 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1374 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}"
1379 # Correct the permissions of /:
1380 chmod 0755 "${rootmnt}"
1382 # tmpfs file systems
1384 mkdir -p "${rootmnt}/live"
1385 mount -t tmpfs tmpfs ${rootmnt}/live
1387 # Adding other custom mounts
1388 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1390 # directly mount /home
1391 # FIXME: add a custom mounts configurable system
1393 if [ -b "${homecow}" ]
1395 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1396 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1398 log_warning_msg "Unable to find the persistent home medium"
1401 # Look for other snapshots to copy in
1402 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1403 # This second type should be removed when snapshot grow smarter
1404 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1407 if [ -n "${SHOWMOUNTS}" ]
1409 for d in ${rofslist}
1411 mkdir -p "${rootmnt}/live/${d##*/}"
1415 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1419 case "${UNIONTYPE}" in
1421 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1425 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1433 # shows cow fs on /cow for use by live-snapshot
1434 mkdir -p "${rootmnt}/live/cow"
1435 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"
1442 skip_uuid_check="${3}"
1444 # support for fromiso=.../isofrom=....
1445 if [ -n "$FROMISO" ]
1447 ISO_DEVICE=$(dirname $FROMISO)
1448 if ! [ -b $ISO_DEVICE ]
1450 # to support unusual device names like /dev/cciss/c0d0p1
1451 # as well we have to identify the block device name, let's
1452 # do that for up to 15 levels
1454 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1456 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1457 [ -b "$ISO_DEVICE" ] && break
1462 if [ "$ISO_DEVICE" = "/" ]
1464 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1467 mount "$ISO_DEVICE" /isofrom
1468 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1469 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1470 devname="${loopdevname}"
1474 if [ -z "${devname}" ]
1476 devname=$(sys2dev "${sysdev}")
1479 if [ -d "${devname}" ]
1481 mount -o bind "${devname}" $mountpoint || continue
1483 if is_live_path $mountpoint
1491 [ -e "$devname" ] || continue
1493 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1495 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1496 devname="${loopdevname}"
1499 fstype=$(get_fstype "${devname}")
1501 if is_supported_fs ${fstype}
1503 devuid=$(blkid -o value -s UUID "$devname")
1504 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1505 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1506 [ -n "$devuid" ] && echo "$devuid" >> $tried
1508 if is_live_path ${mountpoint} && \
1509 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1514 umount ${mountpoint}
1518 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1520 losetup -d "${loopdevname}"
1530 # don't start autodetection before timeout has expired
1531 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1533 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1539 # first look at the one specified in the command line
1540 case "${LIVE_MEDIA}" in
1542 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1544 if [ "$(cat ${sysblock}/removable)" = "1" ]
1546 if readlink ${sysblock} | grep -q usb ||
1547 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1549 for dev in $(subdevices "${sysblock}")
1551 if check_dev "${dev}"
1563 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1565 if [ "$(cat ${sysblock}/removable)" = "1" ]
1567 for dev in $(subdevices "${sysblock}")
1569 if check_dev "${dev}"
1580 if [ ! -z "${LIVE_MEDIA}" ]
1582 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1590 # or do the scan of block devices
1591 # prefer removable devices over non-removable devices, so scan them first
1592 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1594 if [ "$(cat ${sysblock}/removable)" = "1" ]
1596 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1598 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1601 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1603 for sysblock in $devices_to_scan
1605 devname=$(sys2dev "${sysblock}")
1606 [ -e "$devname" ] || continue
1607 fstype=$(get_fstype "${devname}")
1609 if /lib/udev/cdrom_id ${devname} > /dev/null
1611 if check_dev "null" "${devname}"
1615 elif is_nice_device "${sysblock}"
1617 for dev in $(subdevices "${sysblock}")
1619 if check_dev "${dev}"
1624 elif [ "${fstype}" = "squashfs" -o \
1625 "${fstype}" = "ext2" -o \
1626 "${fstype}" = "ext3" -o \
1627 "${fstype}" = "ext4" -o \
1628 "${fstype}" = "jffs2" ]
1630 # This is an ugly hack situation, the block device has
1631 # an image directly on it. It's hopefully
1632 # live-boot, so take it and run with it.
1633 ln -s "${devname}" "${devname}.${fstype}"
1634 echo "${devname}.${fstype}"
1642 set_usplash_timeout ()
1644 if [ -x /sbin/usplash_write ]
1646 /sbin/usplash_write "TIMEOUT 120"
1647 else if [ -x /sbin/splashy_update ] ; then
1648 /sbin/splashy_update "TIMEOUT 120"
1654 media_mountpoint="${1}"
1656 log_begin_msg "Checking media integrity"
1658 cd ${media_mountpoint}
1659 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1664 if [ "${RC}" -eq 0 ]
1666 log_success_msg "Everything ok, will reboot in 10 seconds."
1669 umount ${media_mountpoint}
1671 echo u > /proc/sysrq-trigger
1672 echo b > /proc/sysrq-trigger
1674 panic "Not ok, a media defect is likely, switch to VT8 for details."
1678 start_usplash_pulse ()
1680 if [ -x /sbin/usplash_write ]
1682 /sbin/usplash_write "PULSELOGO"
1688 if [ -x /scripts/local-top/cryptroot ]; then
1689 /scripts/local-top/cryptroot
1696 tail -f live.log >&7 &
1699 # Ensure 'panic' function is overridden
1700 . /scripts/live-functions
1707 maybe_break live-premount
1708 log_begin_msg "Running /scripts/live-premount"
1709 run_scripts /scripts/live-premount
1712 # Needed here too because some things (*cough* udev *cough*)
1713 # changes the timeout
1717 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1721 livefs_root="${mountpoint}"
1723 panic "Unable to find a live file system on the network"
1726 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1728 # Do a local boot from hd
1731 # Scan local devices for the image
1733 while [ "$i" -lt 60 ]
1735 livefs_root=$(find_livefs ${i})
1737 if [ -n "${livefs_root}" ]
1748 if [ -z "${livefs_root}" ]
1750 panic "Unable to find a medium containing a live file system"
1753 if [ "${INTEGRITY_CHECK}" ]
1755 integrity_check "${livefs_root}"
1761 elif [ "${TODISK}" ]
1763 live_dest="${TODISK}"
1766 if [ "${live_dest}" ]
1768 log_begin_msg "Copying live media to ${live_dest}"
1769 copy_live_to "${livefs_root}" "${live_dest}"
1773 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1774 # because the mountpoint is left behind in /proc/mounts, so let's get
1775 # rid of it when running from RAM
1776 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1778 losetup -d /dev/loop0
1779 grep -q /isofrom /proc/mounts && umount /isofrom
1782 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1784 setup_unionfs "${livefs_root}" "${rootmnt}"
1787 mac="$(echo ${mac} | sed 's/-//g')"
1788 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1793 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1794 # live-bottom; udev's init script will take care of things after that
1795 if [ "${UNIONTYPE}" = unionfs-fuse ]
1797 mount -n -o bind /dev "${rootmnt}/dev"
1800 # Move to the new root filesystem so that programs there can get at it.
1801 if [ ! -d /root/live/image ]
1803 mkdir -p /root/live/image
1804 mount --move /live/image /root/live/image
1807 maybe_break live-bottom
1808 log_begin_msg "Running /scripts/live-bottom\n"
1810 run_scripts /scripts/live-bottom
1813 if [ "${UNIONFS}" = unionfs-fuse ]
1815 umount "${rootmnt}/dev"
1821 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1822 if [ -f /etc/live.conf ]
1824 cp /etc/live.conf "${rootmnt}/etc/"