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 ext_mountpoint="/ext_volume"
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 URL_LOCATION="${ARGUMENT#url=}"
345 mount -o bind /sys /root/sys
346 mount -o bind /proc /root/proc
347 mount -o bind /dev /root/dev
349 mkdir -p /root/var/run/network
350 [ "${NETBOOT}" ] || chroot /root dhclient eth0
351 chroot /root wget -P /tmp "${URL_LOCATION}"
352 [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down
358 LOCATIONS="/tmp/$(basename ${URL_LOCATION}) ${LOCATIONS}"
362 question="${ARGUMENT%%=*}"
363 value="${ARGUMENT#*=}"
364 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
384 TIMEZONE="${ARGUMENT#timezone=}"
394 TODISK="${ARGUMENT#todisk=}"
405 MODULETORAM="${ARGUMENT#toram=}"
406 export TORAM MODULETORAM
420 SKIP_UNION_MOUNTS="Yes"
421 export SKIP_UNION_MOUNTS
425 ROOT="${ARGUMENT#root=}"
430 UNIONTYPE="${ARGUMENT#union=}"
440 XDRIVER="${ARGUMENT#xdriver=}"
445 XVIDEOMODE="${ARGUMENT#xvideomode=}"
451 # sort of compatibility with netboot.h from linux docs
452 if [ -z "${NETBOOT}" ]
454 if [ "${ROOT}" = "/dev/nfs" ]
458 elif [ "${ROOT}" = "/dev/cifs" ]
465 if [ -z "${MODULE}" ]
471 if [ -z "${UNIONTYPE}" ]
482 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
484 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
486 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
498 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
504 uuid="$(cat /conf/uuid.conf)"
506 for try_uuid_file in "${path}/.disk/live-uuid"*
508 [ -e "${try_uuid_file}" ] || continue
510 try_uuid="$(cat "${try_uuid_file}")"
512 if [ "${uuid}" = "${try_uuid}" ]
521 get_backing_device ()
524 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
525 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
533 panic "Unrecognized live filesystem: ${1}"
538 match_files_in_dir ()
540 # Does any files match pattern ${1} ?
543 if [ "$(echo ${pattern})" != "${pattern}" ]
551 mount_images_in_directory ()
558 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
559 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
560 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
561 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
562 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
563 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
565 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
566 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
568 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
574 sysfs_path="${1#/sys}"
576 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
579 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
582 elif echo ${sysfs_path} | grep -q "^/block/dm-"
594 copyto="${copyfrom}_swap"
596 if [ -z "${MODULETORAM}" ]
598 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
600 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
602 if [ -f "${MODULETORAMFILE}" ]
604 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
606 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
611 if [ "${copytodev}" = "ram" ]
614 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
615 mount_options="-o size=${size}k"
620 # it should be a writable block device
621 if [ -b "${copytodev}" ]
625 fstype=$(get_fstype "${dev}")
626 freespace=$(fs_size "${dev}")
628 log_warning_msg "${copytodev} is not a block device."
633 if [ "${freespace}" -lt "${size}" ]
635 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
639 # begin copying (or uncompressing)
641 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
642 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
644 if [ "${extension}" = "tgz" ]
647 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
648 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
649 mount -r -o move "${copyto}" "${rootmnt}"
652 if [ -n "${MODULETORAMFILE}" ]
656 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
657 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
659 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
664 echo " * Copying whole medium to RAM" 1>/dev/console
665 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
667 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
668 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
669 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
671 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
677 mount -r -o move ${copyto} ${copyfrom}
686 modprobe -q af_packet # For DHCP
691 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
692 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
695 # if ethdevice was not specified on the kernel command line
696 # make sure we try to get a working network configuration
697 # for *every* present network device (except for loopback of course)
698 if [ -z "$ETHDEVICE" ] ; then
699 echo "If you want to boot from a specific device use bootoption ethdevice=..."
700 for device in /sys/class/net/*; do
702 if [ "$dev" != "lo" ] ; then
703 ETHDEVICE="$ETHDEVICE $dev"
708 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
709 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
710 devlist="$devlist $device"
713 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
714 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
716 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
717 # an endless loop; iff execution fails give it two further tries, that's
718 # why we use '$devlist $devlist $devlist' for the other for loop
719 for dev in $devlist $devlist $devlist ; do
720 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
721 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
723 sleep "$ETHDEV_TIMEOUT" ; sleep 1
724 if [ -r /proc/"$jobid"/status ] ; then
725 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
729 # if configuration of device worked we should have an assigned
730 # IP address, iff so let's use the according as $DEVICE for later usage
731 # simple and primitive approach which seems to work fine
732 if ifconfig $dev | grep -q 'inet.*addr:' ; then
739 ipconfig ${DEVICE} | tee /netboot.config
742 # source relevant ipconfig output
743 OLDHOSTNAME=${HOSTNAME}
744 . /tmp/net-${DEVICE}.conf
745 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
748 # Check if we have a network device at all
749 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
750 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
751 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
752 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
753 ! ls /sys/class/net/ra0 > /dev/null 2>&1
755 panic "No supported network device found, maybe a non-mainline driver is required."
758 if [ "${NFSROOT}" = "auto" ]
760 NFSROOT=${ROOTSERVER}:${ROOTPATH}
765 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
771 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
773 NFSROOT=${ROOTSERVER}:${NFSROOT}
776 log_begin_msg "Trying netboot from ${NFSROOT}"
778 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
796 for webfile in HTTPFS FTPFS FETCH
798 local url="$(eval echo \"\$\{${webfile}\}\")"
799 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
803 case "${extension}" in
804 iso|squashfs|tgz|tar)
805 if [ "${extension}" = "iso" ]
807 mkdir -p "${ext_mountpoint}"
808 dest="${ext_mountpoint}"
810 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
811 mount -t ramfs ram "${mountpoint}"
814 if [ "${webfile}" = "FETCH" ]
818 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
819 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
820 lfile="$(basename $url)"
821 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
822 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
826 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
827 wget "${url}" -O "${dest}/$(basename ${url})"
831 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
832 if [ "${webfile}" = "FTPFS" ]
834 FUSE_MOUNT="curlftpfs"
835 url="$(dirname ${url})"
840 $FUSE_MOUNT "${url}" "${dest}"
842 [ ${?} -eq 0 ] && rc=0
843 [ "${extension}" = "tgz" ] && live_dest="ram"
844 if [ "${extension}" = "iso" ]
846 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
847 mount -t iso9660 "${isoloop}" "${mountpoint}"
854 log_begin_msg "Unrecognized archive extension for ${url}"
862 if [ -d "${ext_mountpoint}" ]
864 umount "${ext_mountpoint}"
865 rmdir "${ext_mountpoint}"
867 umount "${mountpoint}"
868 elif [ "${webfile}" != "FETCH" ] ; then
882 if [ -z "${NFSOPTS}" ]
887 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
889 # FIXME: This while loop is an ugly HACK round an nfs bug
891 while [ "$i" -lt 60 ]
893 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
905 if [ -x "/sbin/mount.cifs" ]
907 if [ -z "${NFSOPTS}" ]
909 CIFSOPTS="-ouser=root,password="
911 CIFSOPTS="${NFSOPTS}"
914 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
917 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
931 size=$(fs_size "${fromdev}" "" "used")
933 if [ -b "${fromdev}" ]
936 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
938 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
939 freespace=$(df -k | awk '/'${todev}'/{print $4}')
941 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
944 tomount="/mnt/tmpsnap"
946 if [ ! -d "${tomount}" ]
948 mkdir -p "${tomount}"
951 fstype=$(get_fstype "${fromdev}")
953 if [ -n "${fstype}" ]
956 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
957 cp -a "${tomount}"/* ${todir}
960 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
965 if echo ${fromdev} | grep -qs loop
967 losetup -d "${fromdev}"
974 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
980 # Look for ${snap_label}.* in block devices
983 if [ "${PERSISTENT}" != "nofiles" ]
985 # search for image files
986 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")
989 if [ -z "${snapdata}" ]
991 snapdata=$(find_cow_device "${snap_label}")
998 # copy the contents of previously found snapshot to ${snap_mount}
999 # and remember the device and filename for resync on exit in live-boot.init
1005 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1007 log_success_msg "found snapshot: ${snapdata}"
1008 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1009 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1010 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1013 if ! try_mount "${snapdev}" "${snapback}" "ro"
1018 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1020 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1021 dev=$(get_backing_device "${snapback}/${snapfile}")
1023 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1028 # Unfortunately klibc's cpio is incompatible with the
1029 # rest of the world; everything else requires -u -d,
1030 # while klibc doesn't implement them. Try to detect
1031 # whether it's in use.
1032 cpiopath="$(which cpio)" || true
1033 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1037 cpioargs='--unconditional --make-directories'
1040 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1042 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1046 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1048 if [ "${RES}" != "0" ]
1050 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1053 elif [ -b "${snapdata}" ]
1055 # Try to find if it could be a snapshot partition
1057 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1058 if echo "${dev}" | grep -qs loop
1060 # strange things happens, user confused?
1061 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1062 snapfile=$(basename ${snaploop})
1063 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1068 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1070 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1073 if [ -n "${snapfile}" ]
1075 # it was a loop device, user confused
1080 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1084 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1090 image_directory="${1}"
1092 addimage_directory="${3}"
1094 case ${UNIONTYPE} in
1096 modprobe -q -b ${UNIONTYPE}
1098 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1100 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1101 echo "This might be really slow."
1103 UNIONTYPE="unionfs-fuse"
1108 if [ "${UNIONTYPE}" = unionfs-fuse ]
1113 # run-init can't deal with images in a subdir, but we're going to
1114 # move all of these away before it runs anyway. No, we're not,
1115 # put them in / since move-mounting them into / breaks mono and
1120 # Let's just mount the read-only file systems first
1124 if [ "${UNIONTYPE}" = "aufs" ]
1127 noxino_opt="noxino,"
1128 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1135 if [ -z "${PLAIN_ROOT}" ]
1137 # Read image names from ${MODULE}.module if it exists
1138 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1140 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1142 image_string="${image_string} ${image_directory}/${IMAGE}"
1144 elif [ -e "${image_directory}/${MODULE}.module" ]
1146 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1148 image_string="${image_string} ${image_directory}/${IMAGE}"
1151 # ${MODULE}.module does not exist, create a list of images
1152 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1154 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1156 if [ -e "${IMAGE}" ]
1158 image_string="${image_string} ${IMAGE}"
1163 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1165 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1167 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1169 if [ -e "${IMAGE}" ]
1171 image_string="${image_string} ${IMAGE}"
1178 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1181 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1185 for image in ${image_string}
1187 imagename=$(basename "${image}")
1189 export image devname
1190 maybe_break live-realpremount
1191 log_begin_msg "Running /scripts/live-realpremount"
1192 run_scripts /scripts/live-realpremount
1195 if [ -d "${image}" ]
1197 # it is a plain directory: do nothing
1198 rofsstring="${image}=${roopt}:${rofsstring}"
1199 rofslist="${image} ${rofslist}"
1200 elif [ -f "${image}" ]
1202 if losetup --help 2>&1 | grep -q -- "-r\b"
1204 backdev=$(get_backing_device "${image}" "-r")
1206 backdev=$(get_backing_device "${image}")
1208 fstype=$(get_fstype "${backdev}")
1210 if [ "${fstype}" = "unknown" ]
1212 panic "Unknown file system type on ${backdev} (${image})"
1215 if [ -z "${fstype}" ]
1217 fstype="${imagename##*.}"
1218 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1221 mkdir -p "${croot}/${imagename}"
1222 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1223 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}"
1228 # we have a plain root system
1229 mkdir -p "${croot}/filesystem"
1230 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1231 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}"
1233 mount -o bind ${croot}/filesystem $mountpoint
1237 rofsstring=${rofsstring%:}
1241 # Looking for "${root_persistence}" device or file
1242 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1244 if [ -z "${QUICKUSBMODULES}" ]
1247 num_block=$(ls -l /sys/block | wc -l)
1248 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1250 modprobe -q -b ${module}
1256 # For some reason, udevsettle does not block in this scenario,
1257 # so we sleep for a little while.
1259 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1260 for timeout in 5 4 3 2 1
1264 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1271 # search for label and files (this could be hugely optimized)
1272 cowprobe=$(find_cow_device "${root_persistence}")
1273 if [ -b "${cowprobe}" ]
1275 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1276 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1277 # snapshots to be sure to really store some e.g key config files,
1278 # but not on the same media
1279 blacklistdev="${cowprobe}"
1280 PERSISTENCE_IS_ON="1"
1281 export PERSISTENCE_IS_ON
1283 # homecow just mount something on /home, this should be generalized some way
1284 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1285 if [ -b "${homecow}" ]
1287 PERSISTENCE_IS_ON="1"
1288 export PERSISTENCE_IS_ON
1290 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1291 # This second type should be removed when snapshot will get smarter,
1292 # hence when "/etc/live-snapshot*list" will be supported also by
1293 # ext2|ext3|ext4|jffs2 snapshot types.
1294 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1296 if [ -b "${cowprobe}" ]
1298 cowdevice=${cowprobe}
1299 cow_fstype=$(get_fstype "${cowprobe}")
1300 cow_mountopt="rw,noatime"
1302 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1304 fsck -y ${cowdevice}
1307 log_warning_msg "Unable to find the persistent medium"
1310 cow_mountopt="rw,noatime,mode=755"
1312 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1314 # check if there are any nfs options
1315 if echo ${NFS_COW}|grep -q ','
1317 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1318 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1320 nfs_cow_opts="-o nolock"
1326 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1329 panic "unable to determine mac address"
1334 cow_mountopt="rw,noatime,mode=755"
1337 if [ "${cow_fstype}" = "nfs" ]
1340 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1341 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1342 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1344 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1345 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1348 rofscount=$(echo ${rofslist} |wc -w)
1350 if [ -n "${EXPOSED_ROOT}" ]
1352 if [ ${rofscount} -ne 1 ]
1354 panic "only one RO file system supported with exposedroot: ${rofslist}"
1356 exposedrootfs=${rofslist%% }
1358 mount --bind ${exposedrootfs} ${rootmnt} || \
1359 panic "bind mount of ${exposedrootfs} failed"
1361 if [ -z "${SKIP_UNION_MOUNTS}" ]
1363 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1368 for dir in ${cow_dirs}; do
1371 case "${UNIONTYPE}" in
1373 (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}")
1374 mkdir -p /dev/.initramfs/varrun
1375 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1379 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"
1384 case "${UNIONTYPE}" in
1386 (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}")
1387 mkdir -p /dev/.initramfs/varrun
1388 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1392 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}"
1397 # Correct the permissions of /:
1398 chmod 0755 "${rootmnt}"
1400 # tmpfs file systems
1402 mkdir -p "${rootmnt}/live"
1403 mount -t tmpfs tmpfs ${rootmnt}/live
1405 # Adding other custom mounts
1406 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1408 # directly mount /home
1409 # FIXME: add a custom mounts configurable system
1411 if [ -b "${homecow}" ]
1413 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1414 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1416 log_warning_msg "Unable to find the persistent home medium"
1419 # Look for other snapshots to copy in
1420 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1421 # This second type should be removed when snapshot grow smarter
1422 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1425 if [ -n "${SHOWMOUNTS}" ]
1427 for d in ${rofslist}
1429 mkdir -p "${rootmnt}/live/${d##*/}"
1433 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1437 case "${UNIONTYPE}" in
1439 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1443 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1451 # shows cow fs on /cow for use by live-snapshot
1452 mkdir -p "${rootmnt}/live/cow"
1453 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"
1460 skip_uuid_check="${3}"
1462 # support for fromiso=.../isofrom=....
1463 if [ -n "$FROMISO" ]
1465 ISO_DEVICE=$(dirname $FROMISO)
1466 if ! [ -b $ISO_DEVICE ]
1468 # to support unusual device names like /dev/cciss/c0d0p1
1469 # as well we have to identify the block device name, let's
1470 # do that for up to 15 levels
1472 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1474 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1475 [ -b "$ISO_DEVICE" ] && break
1480 if [ "$ISO_DEVICE" = "/" ]
1482 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1485 mount "$ISO_DEVICE" /isofrom
1486 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1487 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1488 devname="${loopdevname}"
1492 if [ -z "${devname}" ]
1494 devname=$(sys2dev "${sysdev}")
1497 if [ -d "${devname}" ]
1499 mount -o bind "${devname}" $mountpoint || continue
1501 if is_live_path $mountpoint
1509 [ -e "$devname" ] || continue
1511 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1513 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1514 devname="${loopdevname}"
1517 fstype=$(get_fstype "${devname}")
1519 if is_supported_fs ${fstype}
1521 devuid=$(blkid -o value -s UUID "$devname")
1522 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1523 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1524 [ -n "$devuid" ] && echo "$devuid" >> $tried
1526 if is_live_path ${mountpoint} && \
1527 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1532 umount ${mountpoint}
1536 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1538 losetup -d "${loopdevname}"
1548 # don't start autodetection before timeout has expired
1549 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1551 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1557 # first look at the one specified in the command line
1558 case "${LIVE_MEDIA}" in
1560 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1562 if [ "$(cat ${sysblock}/removable)" = "1" ]
1564 if readlink ${sysblock} | grep -q usb ||
1565 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1567 for dev in $(subdevices "${sysblock}")
1569 if check_dev "${dev}"
1581 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1583 if [ "$(cat ${sysblock}/removable)" = "1" ]
1585 for dev in $(subdevices "${sysblock}")
1587 if check_dev "${dev}"
1598 if [ ! -z "${LIVE_MEDIA}" ]
1600 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1608 # or do the scan of block devices
1609 # prefer removable devices over non-removable devices, so scan them first
1610 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1612 if [ "$(cat ${sysblock}/removable)" = "1" ]
1614 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1616 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1619 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1621 for sysblock in $devices_to_scan
1623 devname=$(sys2dev "${sysblock}")
1624 [ -e "$devname" ] || continue
1625 fstype=$(get_fstype "${devname}")
1627 if /lib/udev/cdrom_id ${devname} > /dev/null
1629 if check_dev "null" "${devname}"
1633 elif is_nice_device "${sysblock}"
1635 for dev in $(subdevices "${sysblock}")
1637 if check_dev "${dev}"
1642 elif [ "${fstype}" = "squashfs" -o \
1643 "${fstype}" = "ext2" -o \
1644 "${fstype}" = "ext3" -o \
1645 "${fstype}" = "ext4" -o \
1646 "${fstype}" = "jffs2" ]
1648 # This is an ugly hack situation, the block device has
1649 # an image directly on it. It's hopefully
1650 # live-boot, so take it and run with it.
1651 ln -s "${devname}" "${devname}.${fstype}"
1652 echo "${devname}.${fstype}"
1660 set_usplash_timeout ()
1662 if [ -x /sbin/usplash_write ]
1664 /sbin/usplash_write "TIMEOUT 120"
1665 else if [ -x /sbin/splashy_update ] ; then
1666 /sbin/splashy_update "TIMEOUT 120"
1672 media_mountpoint="${1}"
1674 log_begin_msg "Checking media integrity"
1676 cd ${media_mountpoint}
1677 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1682 if [ "${RC}" -eq 0 ]
1684 log_success_msg "Everything ok, will reboot in 10 seconds."
1687 umount ${media_mountpoint}
1689 echo u > /proc/sysrq-trigger
1690 echo b > /proc/sysrq-trigger
1692 panic "Not ok, a media defect is likely, switch to VT8 for details."
1696 start_usplash_pulse ()
1698 if [ -x /sbin/usplash_write ]
1700 /sbin/usplash_write "PULSELOGO"
1706 if [ -x /scripts/local-top/cryptroot ]; then
1707 /scripts/local-top/cryptroot
1714 tail -f live.log >&7 &
1717 # Ensure 'panic' function is overridden
1718 . /scripts/live-functions
1725 maybe_break live-premount
1726 log_begin_msg "Running /scripts/live-premount"
1727 run_scripts /scripts/live-premount
1730 # Needed here too because some things (*cough* udev *cough*)
1731 # changes the timeout
1735 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1739 livefs_root="${mountpoint}"
1741 panic "Unable to find a live file system on the network"
1744 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1746 # Do a local boot from hd
1749 # Scan local devices for the image
1751 while [ "$i" -lt 60 ]
1753 livefs_root=$(find_livefs ${i})
1755 if [ -n "${livefs_root}" ]
1766 if [ -z "${livefs_root}" ]
1768 panic "Unable to find a medium containing a live file system"
1771 if [ "${INTEGRITY_CHECK}" ]
1773 integrity_check "${livefs_root}"
1779 elif [ "${TODISK}" ]
1781 live_dest="${TODISK}"
1784 if [ "${live_dest}" ]
1786 log_begin_msg "Copying live media to ${live_dest}"
1787 copy_live_to "${livefs_root}" "${live_dest}"
1791 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1792 # because the mountpoint is left behind in /proc/mounts, so let's get
1793 # rid of it when running from RAM
1794 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1796 losetup -d /dev/loop0
1797 grep -q /isofrom /proc/mounts && umount /isofrom
1800 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1802 setup_unionfs "${livefs_root}" "${rootmnt}"
1805 mac="$(echo ${mac} | sed 's/-//g')"
1806 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1811 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1812 # live-bottom; udev's init script will take care of things after that
1813 if [ "${UNIONTYPE}" = unionfs-fuse ]
1815 mount -n -o bind /dev "${rootmnt}/dev"
1818 # Move to the new root filesystem so that programs there can get at it.
1819 if [ ! -d /root/live/image ]
1821 mkdir -p /root/live/image
1822 mount --move /live/image /root/live/image
1825 maybe_break live-bottom
1826 log_begin_msg "Running /scripts/live-bottom\n"
1828 run_scripts /scripts/live-bottom
1831 if [ "${UNIONFS}" = unionfs-fuse ]
1833 umount "${rootmnt}/dev"
1839 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1840 if [ -f /etc/live.conf ]
1842 cp /etc/live.conf "${rootmnt}/etc/"