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 DEVICE="${ARGUMENT#ethdevice=}"
94 ETHDEVICE="${ARGUMENT#ethdevice=}"
99 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
100 export ETHDEV_TIMEOUT
104 FETCH="${ARGUMENT#fetch=}"
109 FORCEPERSISTENTFSCK="Yes"
110 export FORCEPERSISTENTFSCK
114 FTPFS="${ARGUMENT#ftpfs=}"
119 HTTPFS="${ARGUMENT#httpfs=}"
124 FROMISO="${ARGUMENT#*=}"
129 USERNAME="${ARGUMENT#username=}"
131 export USERNAME LIVECONF
135 USERFULLNAME="${ARGUMENT#userfullname=}"
137 export USERFULLNAME LIVECONF
146 INTEGRITY_CHECK="Yes"
147 export INTEGRITY_CHECK
151 STATICIP="${ARGUMENT#ip=}"
153 if [ -z "${STATICIP}" ]
161 keyb=*|kbd-chooser/method=*)
166 klayout=*|console-setup/layoutcode=*)
167 KLAYOUT="${ARGUMENT#*=}"
171 kvariant=*|console-setup/variantcode=*)
172 KVARIANT="${ARGUMENT#*=}"
176 kmodel=*|console-setup/modelcode=*)
177 KMODEL="${ARGUMENT#*=}"
182 KOPTIONS="${ARGUMENT#koptions=}"
191 live-media=*|bootfrom=*)
192 LIVE_MEDIA="${ARGUMENT#*=}"
196 live-media-encryption=*|encryption=*)
197 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
198 export LIVE_MEDIA_ENCRYPTION
202 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
203 export LIVE_MEDIA_OFFSET
207 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
208 export LIVE_MEDIA_PATH
211 live-media-timeout=*)
212 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
213 export LIVE_MEDIA_TIMEOUT
217 MODULE="${ARGUMENT#module=}"
222 NETBOOT="${ARGUMENT#netboot=}"
227 NFSOPTS="${ARGUMENT#nfsopts=}"
232 NFS_COW="${ARGUMENT#nfscow=}"
237 NOACCESSIBILITY="Yes"
238 export NOACCESSIBILITY
257 NOCONSOLEKEYBOARD="Yes"
258 export NOCONSOLEKEYBOARD
293 export NOXSCREENSAVER
302 PERSISTENT="${ARGUMENT#persistent=}"
303 if [ -z "${PERSISTENT}" ]
311 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
312 export PERSISTENT_PATH
315 persistent-subtext=*)
316 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
317 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
318 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
319 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
328 QUICKUSBMODULES="Yes"
329 export QUICKUSBMODULES
332 preseed/file=*|file=*)
333 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
343 question="${ARGUMENT%%=*}"
344 value="${ARGUMENT#*=}"
345 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
365 TIMEZONE="${ARGUMENT#timezone=}"
375 TODISK="${ARGUMENT#todisk=}"
386 MODULETORAM="${ARGUMENT#toram=}"
387 export TORAM MODULETORAM
401 SKIP_UNION_MOUNTS="Yes"
402 export SKIP_UNION_MOUNTS
406 ROOT="${ARGUMENT#root=}"
411 UNIONTYPE="${ARGUMENT#union=}"
421 XDRIVER="${ARGUMENT#xdriver=}"
426 XVIDEOMODE="${ARGUMENT#xvideomode=}"
432 # sort of compatibility with netboot.h from linux docs
433 if [ -z "${NETBOOT}" ]
435 if [ "${ROOT}" = "/dev/nfs" ]
439 elif [ "${ROOT}" = "/dev/cifs" ]
446 if [ -z "${MODULE}" ]
452 if [ -z "${UNIONTYPE}" ]
463 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
465 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
467 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
479 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
485 uuid="$(cat /conf/uuid.conf)"
487 for try_uuid_file in "${path}/.disk/live-uuid"*
489 [ -e "${try_uuid_file}" ] || continue
491 try_uuid="$(cat "${try_uuid_file}")"
493 if [ "${uuid}" = "${try_uuid}" ]
502 get_backing_device ()
505 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
506 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
514 panic "Unrecognized live filesystem: ${1}"
519 match_files_in_dir ()
521 # Does any files match pattern ${1} ?
524 if [ "$(echo ${pattern})" != "${pattern}" ]
532 mount_images_in_directory ()
539 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
540 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
541 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
542 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
543 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
544 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
546 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
547 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
549 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
555 sysfs_path="${1#/sys}"
557 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
560 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
563 elif echo ${sysfs_path} | grep -q "^/block/dm-"
575 copyto="${copyfrom}_swap"
577 if [ -z "${MODULETORAM}" ]
579 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
581 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
583 if [ -f "${MODULETORAMFILE}" ]
585 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
587 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
592 if [ "${copytodev}" = "ram" ]
595 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
596 mount_options="-o size=${size}k"
601 # it should be a writable block device
602 if [ -b "${copytodev}" ]
606 fstype=$(get_fstype "${dev}")
607 freespace=$(fs_size "${dev}")
609 log_warning_msg "${copytodev} is not a block device."
614 if [ "${freespace}" -lt "${size}" ]
616 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
620 # begin copying (or uncompressing)
622 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
623 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
625 if [ "${extension}" = "tgz" ]
628 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
629 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
630 mount -r -o move "${copyto}" "${rootmnt}"
633 if [ -n "${MODULETORAMFILE}" ]
637 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
638 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
640 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
645 echo " * Copying whole medium to RAM" 1>/dev/console
646 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
648 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
649 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
650 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
652 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
658 mount -r -o move ${copyto} ${copyfrom}
667 modprobe -q af_packet # For DHCP
672 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
673 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
676 # if ethdevice was not specified on the kernel command line
677 # make sure we try to get a working network configuration
678 # for *every* present network device (except for loopback of course)
679 if [ -z "$ETHDEVICE" ] ; then
680 echo "If you want to boot from a specific device use bootoption ethdevice=..."
681 for device in /sys/class/net/*; do
683 if [ "$dev" != "lo" ] ; then
684 ETHDEVICE="$ETHDEVICE $dev"
689 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
690 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
691 devlist="$devlist $device"
694 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
695 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
697 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
698 # an endless loop; iff execution fails give it two further tries, that's
699 # why we use '$devlist $devlist $devlist' for the other for loop
700 for dev in $devlist $devlist $devlist ; do
701 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
702 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
704 sleep "$ETHDEV_TIMEOUT" ; sleep 1
705 if [ -r /proc/"$jobid"/status ] ; then
706 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
710 # if configuration of device worked we should have an assigned
711 # IP address, iff so let's use the according as $DEVICE for later usage
712 # simple and primitive approach which seems to work fine
713 if ifconfig $dev | grep -q 'inet.*addr:' ; then
720 ipconfig ${DEVICE} | tee /netboot.config
723 # source relevant ipconfig output
724 OLDHOSTNAME=${HOSTNAME}
725 . /tmp/net-${DEVICE}.conf
726 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
729 # Check if we have a network device at all
730 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
731 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
732 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
733 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
734 ! ls /sys/class/net/ra0 > /dev/null 2>&1
736 panic "No supported network device found, maybe a non-mainline driver is required."
739 if [ "${NFSROOT}" = "auto" ]
741 NFSROOT=${ROOTSERVER}:${ROOTPATH}
746 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
752 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
754 NFSROOT=${ROOTSERVER}:${NFSROOT}
757 log_begin_msg "Trying netboot from ${NFSROOT}"
759 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
777 for webfile in HTTPFS FTPFS FETCH
779 local url="$(eval echo \"\$\{${webfile}\}\")"
780 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
784 case "${extension}" in
785 iso|squashfs|tgz|tar)
786 if [ "${extension}" = "iso" ]
788 mkdir -p "${alt_mountpoint}"
789 dest="${alt_mountpoint}"
791 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
792 mount -t ramfs ram "${mountpoint}"
795 if [ "${webfile}" = "FETCH" ]
799 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
800 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
801 lfile="$(basename $url)"
802 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
803 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
807 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
808 wget "${url}" -O "${dest}/$(basename ${url})"
812 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
813 if [ "${webfile}" = "FTPFS" ]
815 FUSE_MOUNT="curlftpfs"
816 url="$(dirname ${url})"
821 $FUSE_MOUNT "${url}" "${dest}"
823 [ ${?} -eq 0 ] && rc=0
824 [ "${extension}" = "tgz" ] && live_dest="ram"
825 if [ "${extension}" = "iso" ]
827 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
828 mount -t iso9660 "${isoloop}" "${mountpoint}"
835 log_begin_msg "Unrecognized archive extension for ${url}"
843 if [ -d "${alt_mountpoint}" ]
845 umount "${alt_mountpoint}"
846 rmdir "${alt_mountpoint}"
848 umount "${mountpoint}"
849 elif [ "${webfile}" != "FETCH" ] ; then
863 if [ -z "${NFSOPTS}" ]
868 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
870 # FIXME: This while loop is an ugly HACK round an nfs bug
872 while [ "$i" -lt 60 ]
874 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
886 if [ -x "/sbin/mount.cifs" ]
888 if [ -z "${NFSOPTS}" ]
890 CIFSOPTS="-ouser=root,password="
892 CIFSOPTS="${NFSOPTS}"
895 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
898 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
912 size=$(fs_size "${fromdev}" "" "used")
914 if [ -b "${fromdev}" ]
917 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
919 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
920 freespace=$(df -k | awk '/'${todev}'/{print $4}')
922 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
925 tomount="/mnt/tmpsnap"
927 if [ ! -d "${tomount}" ]
929 mkdir -p "${tomount}"
932 fstype=$(get_fstype "${fromdev}")
934 if [ -n "${fstype}" ]
937 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
938 cp -a "${tomount}"/* ${todir}
941 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
946 if echo ${fromdev} | grep -qs loop
948 losetup -d "${fromdev}"
955 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
961 # Look for ${snap_label}.* in block devices
964 if [ "${PERSISTENT}" != "nofiles" ]
966 # search for image files
967 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")
970 if [ -z "${snapdata}" ]
972 snapdata=$(find_cow_device "${snap_label}")
979 # copy the contents of previously found snapshot to ${snap_mount}
980 # and remember the device and filename for resync on exit in live-boot.init
986 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
988 log_success_msg "found snapshot: ${snapdata}"
989 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
990 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
991 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
994 if ! try_mount "${snapdev}" "${snapback}" "ro"
999 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1001 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1002 dev=$(get_backing_device "${snapback}/${snapfile}")
1004 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1009 # Unfortunately klibc's cpio is incompatible with the
1010 # rest of the world; everything else requires -u -d,
1011 # while klibc doesn't implement them. Try to detect
1012 # whether it's in use.
1013 cpiopath="$(which cpio)" || true
1014 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1018 cpioargs='--unconditional --make-directories'
1021 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1023 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1027 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1029 if [ "${RES}" != "0" ]
1031 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1034 elif [ -b "${snapdata}" ]
1036 # Try to find if it could be a snapshot partition
1038 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1039 if echo "${dev}" | grep -qs loop
1041 # strange things happens, user confused?
1042 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1043 snapfile=$(basename ${snaploop})
1044 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1049 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1051 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1054 if [ -n "${snapfile}" ]
1056 # it was a loop device, user confused
1061 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1065 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1071 image_directory="${1}"
1073 addimage_directory="${3}"
1075 case ${UNIONTYPE} in
1077 modprobe -q -b ${UNIONTYPE}
1079 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1081 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1082 echo "This might be really slow."
1084 UNIONTYPE="unionfs-fuse"
1089 if [ "${UNIONTYPE}" = unionfs-fuse ]
1094 # run-init can't deal with images in a subdir, but we're going to
1095 # move all of these away before it runs anyway. No, we're not,
1096 # put them in / since move-mounting them into / breaks mono and
1101 # Let's just mount the read-only file systems first
1105 if [ "${UNIONTYPE}" = "aufs" ]
1108 noxino_opt="noxino,"
1109 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1116 if [ -z "${PLAIN_ROOT}" ]
1118 # Read image names from ${MODULE}.module if it exists
1119 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1121 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1123 image_string="${image_string} ${image_directory}/${IMAGE}"
1125 elif [ -e "${image_directory}/${MODULE}.module" ]
1127 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1129 image_string="${image_string} ${image_directory}/${IMAGE}"
1132 # ${MODULE}.module does not exist, create a list of images
1133 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1135 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1137 if [ -e "${IMAGE}" ]
1139 image_string="${image_string} ${IMAGE}"
1144 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1146 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1148 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1150 if [ -e "${IMAGE}" ]
1152 image_string="${image_string} ${IMAGE}"
1159 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1162 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1166 for image in ${image_string}
1168 imagename=$(basename "${image}")
1170 export image devname
1171 maybe_break live-realpremount
1172 log_begin_msg "Running /scripts/live-realpremount"
1173 run_scripts /scripts/live-realpremount
1176 if [ -d "${image}" ]
1178 # it is a plain directory: do nothing
1179 rofsstring="${image}=${roopt}:${rofsstring}"
1180 rofslist="${image} ${rofslist}"
1181 elif [ -f "${image}" ]
1183 if losetup --help 2>&1 | grep -q -- "-r\b"
1185 backdev=$(get_backing_device "${image}" "-r")
1187 backdev=$(get_backing_device "${image}")
1189 fstype=$(get_fstype "${backdev}")
1191 if [ "${fstype}" = "unknown" ]
1193 panic "Unknown file system type on ${backdev} (${image})"
1196 if [ -z "${fstype}" ]
1198 fstype="${imagename##*.}"
1199 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1202 mkdir -p "${croot}/${imagename}"
1203 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1204 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}"
1209 # we have a plain root system
1210 mkdir -p "${croot}/filesystem"
1211 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1212 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}"
1214 mount -o bind ${croot}/filesystem $mountpoint
1218 rofsstring=${rofsstring%:}
1222 # Looking for "${root_persistence}" device or file
1223 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1225 if [ -z "${QUICKUSBMODULES}" ]
1228 num_block=$(ls -l /sys/block | wc -l)
1229 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1231 modprobe -q -b ${module}
1237 # For some reason, udevsettle does not block in this scenario,
1238 # so we sleep for a little while.
1240 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1241 for timeout in 5 4 3 2 1
1245 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1252 # search for label and files (this could be hugely optimized)
1253 cowprobe=$(find_cow_device "${root_persistence}")
1254 if [ -b "${cowprobe}" ]
1256 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1257 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1258 # snapshots to be sure to really store some e.g key config files,
1259 # but not on the same media
1260 blacklistdev="${cowprobe}"
1261 PERSISTENCE_IS_ON="1"
1262 export PERSISTENCE_IS_ON
1264 # homecow just mount something on /home, this should be generalized some way
1265 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1266 if [ -b "${homecow}" ]
1268 PERSISTENCE_IS_ON="1"
1269 export PERSISTENCE_IS_ON
1271 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1272 # This second type should be removed when snapshot will get smarter,
1273 # hence when "/etc/live-snapshot*list" will be supported also by
1274 # ext2|ext3|ext4|jffs2 snapshot types.
1275 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1277 if [ -b "${cowprobe}" ]
1279 cowdevice=${cowprobe}
1280 cow_fstype=$(get_fstype "${cowprobe}")
1281 cow_mountopt="rw,noatime"
1283 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1285 fsck -y ${cowdevice}
1288 log_warning_msg "Unable to find the persistent medium"
1291 cow_mountopt="rw,noatime,mode=755"
1293 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1295 # check if there are any nfs options
1296 if echo ${NFS_COW}|grep -q ','
1298 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1299 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1301 nfs_cow_opts="-o nolock"
1307 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1310 panic "unable to determine mac address"
1315 cow_mountopt="rw,noatime,mode=755"
1318 if [ "${cow_fstype}" = "nfs" ]
1321 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1322 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1323 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1325 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1326 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1329 rofscount=$(echo ${rofslist} |wc -w)
1331 if [ -n "${EXPOSED_ROOT}" ]
1333 if [ ${rofscount} -ne 1 ]
1335 panic "only one RO file system supported with exposedroot: ${rofslist}"
1337 exposedrootfs=${rofslist%% }
1339 mount --bind ${exposedrootfs} ${rootmnt} || \
1340 panic "bind mount of ${exposedrootfs} failed"
1342 if [ -z "${SKIP_UNION_MOUNTS}" ]
1344 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1349 for dir in ${cow_dirs}; do
1352 case "${UNIONTYPE}" in
1354 (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}")
1355 mkdir -p /dev/.initramfs/varrun
1356 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1360 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"
1365 case "${UNIONTYPE}" in
1367 (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}")
1368 mkdir -p /dev/.initramfs/varrun
1369 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1373 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}"
1378 # Correct the permissions of /:
1379 chmod 0755 "${rootmnt}"
1381 # tmpfs file systems
1383 mkdir -p "${rootmnt}/live"
1384 mount -t tmpfs tmpfs ${rootmnt}/live
1386 # Adding other custom mounts
1387 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1389 # directly mount /home
1390 # FIXME: add a custom mounts configurable system
1392 if [ -b "${homecow}" ]
1394 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1395 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1397 log_warning_msg "Unable to find the persistent home medium"
1400 # Look for other snapshots to copy in
1401 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1402 # This second type should be removed when snapshot grow smarter
1403 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1406 if [ -n "${SHOWMOUNTS}" ]
1408 for d in ${rofslist}
1410 mkdir -p "${rootmnt}/live/${d##*/}"
1414 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1418 case "${UNIONTYPE}" in
1420 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1424 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1432 # shows cow fs on /cow for use by live-snapshot
1433 mkdir -p "${rootmnt}/live/cow"
1434 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"
1441 skip_uuid_check="${3}"
1443 # support for fromiso=.../isofrom=....
1444 if [ -n "$FROMISO" ]
1446 ISO_DEVICE=$(dirname $FROMISO)
1447 if ! [ -b $ISO_DEVICE ]
1449 # to support unusual device names like /dev/cciss/c0d0p1
1450 # as well we have to identify the block device name, let's
1451 # do that for up to 15 levels
1453 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1455 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1456 [ -b "$ISO_DEVICE" ] && break
1461 if [ "$ISO_DEVICE" = "/" ]
1463 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1466 mount "$ISO_DEVICE" /isofrom
1467 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1468 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1469 devname="${loopdevname}"
1473 if [ -z "${devname}" ]
1475 devname=$(sys2dev "${sysdev}")
1478 if [ -d "${devname}" ]
1480 mount -o bind "${devname}" $mountpoint || continue
1482 if is_live_path $mountpoint
1490 [ -e "$devname" ] || continue
1492 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1494 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1495 devname="${loopdevname}"
1498 fstype=$(get_fstype "${devname}")
1500 if is_supported_fs ${fstype}
1502 devuid=$(blkid -o value -s UUID "$devname")
1503 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1504 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1505 [ -n "$devuid" ] && echo "$devuid" >> $tried
1507 if is_live_path ${mountpoint} && \
1508 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1513 umount ${mountpoint}
1517 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1519 losetup -d "${loopdevname}"
1529 # don't start autodetection before timeout has expired
1530 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1532 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1538 # first look at the one specified in the command line
1539 case "${LIVE_MEDIA}" in
1541 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1543 if [ "$(cat ${sysblock}/removable)" = "1" ]
1545 if readlink ${sysblock} | grep -q usb ||
1546 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1548 for dev in $(subdevices "${sysblock}")
1550 if check_dev "${dev}"
1562 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1564 if [ "$(cat ${sysblock}/removable)" = "1" ]
1566 for dev in $(subdevices "${sysblock}")
1568 if check_dev "${dev}"
1579 if [ ! -z "${LIVE_MEDIA}" ]
1581 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1589 # or do the scan of block devices
1590 # prefer removable devices over non-removable devices, so scan them first
1591 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1593 if [ "$(cat ${sysblock}/removable)" = "1" ]
1595 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1597 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1600 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1602 for sysblock in $devices_to_scan
1604 devname=$(sys2dev "${sysblock}")
1605 [ -e "$devname" ] || continue
1606 fstype=$(get_fstype "${devname}")
1608 if /lib/udev/cdrom_id ${devname} > /dev/null
1610 if check_dev "null" "${devname}"
1614 elif is_nice_device "${sysblock}"
1616 for dev in $(subdevices "${sysblock}")
1618 if check_dev "${dev}"
1623 elif [ "${fstype}" = "squashfs" -o \
1624 "${fstype}" = "ext2" -o \
1625 "${fstype}" = "ext3" -o \
1626 "${fstype}" = "ext4" -o \
1627 "${fstype}" = "jffs2" ]
1629 # This is an ugly hack situation, the block device has
1630 # an image directly on it. It's hopefully
1631 # live-boot, so take it and run with it.
1632 ln -s "${devname}" "${devname}.${fstype}"
1633 echo "${devname}.${fstype}"
1641 set_usplash_timeout ()
1643 if [ -x /sbin/usplash_write ]
1645 /sbin/usplash_write "TIMEOUT 120"
1646 else if [ -x /sbin/splashy_update ] ; then
1647 /sbin/splashy_update "TIMEOUT 120"
1653 media_mountpoint="${1}"
1655 log_begin_msg "Checking media integrity"
1657 cd ${media_mountpoint}
1658 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1663 if [ "${RC}" -eq 0 ]
1665 log_success_msg "Everything ok, will reboot in 10 seconds."
1668 umount ${media_mountpoint}
1670 echo u > /proc/sysrq-trigger
1671 echo b > /proc/sysrq-trigger
1673 panic "Not ok, a media defect is likely, switch to VT8 for details."
1677 start_usplash_pulse ()
1679 if [ -x /sbin/usplash_write ]
1681 /sbin/usplash_write "PULSELOGO"
1687 if [ -x /scripts/local-top/cryptroot ]; then
1688 /scripts/local-top/cryptroot
1695 tail -f live.log >&7 &
1698 # Ensure 'panic' function is overridden
1699 . /scripts/live-functions
1706 maybe_break live-premount
1707 log_begin_msg "Running /scripts/live-premount"
1708 run_scripts /scripts/live-premount
1711 # Needed here too because some things (*cough* udev *cough*)
1712 # changes the timeout
1716 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1720 livefs_root="${mountpoint}"
1722 panic "Unable to find a live file system on the network"
1725 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1727 # Do a local boot from hd
1730 # Scan local devices for the image
1732 while [ "$i" -lt 60 ]
1734 livefs_root=$(find_livefs ${i})
1736 if [ -n "${livefs_root}" ]
1747 if [ -z "${livefs_root}" ]
1749 panic "Unable to find a medium containing a live file system"
1752 if [ "${INTEGRITY_CHECK}" ]
1754 integrity_check "${livefs_root}"
1760 elif [ "${TODISK}" ]
1762 live_dest="${TODISK}"
1765 if [ "${live_dest}" ]
1767 log_begin_msg "Copying live media to ${live_dest}"
1768 copy_live_to "${livefs_root}" "${live_dest}"
1772 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1773 # because the mountpoint is left behind in /proc/mounts, so let's get
1774 # rid of it when running from RAM
1775 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1777 losetup -d /dev/loop0
1778 grep -q /isofrom /proc/mounts && umount /isofrom
1781 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1783 setup_unionfs "${livefs_root}" "${rootmnt}"
1786 mac="$(echo ${mac} | sed 's/-//g')"
1787 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1792 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1793 # live-bottom; udev's init script will take care of things after that
1794 if [ "${UNIONTYPE}" = unionfs-fuse ]
1796 mount -n -o bind /dev "${rootmnt}/dev"
1799 # Move to the new root filesystem so that programs there can get at it.
1800 if [ ! -d /root/live/image ]
1802 mkdir -p /root/live/image
1803 mount --move /live/image /root/live/image
1806 maybe_break live-bottom
1807 log_begin_msg "Running /scripts/live-bottom\n"
1809 run_scripts /scripts/live-bottom
1812 if [ "${UNIONFS}" = unionfs-fuse ]
1814 umount "${rootmnt}/dev"
1820 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1821 if [ -f /etc/live.conf ]
1823 cp /etc/live.conf "${rootmnt}/etc/"