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}"
24 # Create /etc/mtab for debug purpose and future syncs
35 [ -f /etc/live.conf ] && . /etc/live.conf
36 export USERNAME USERFULLNAME HOSTNAME
38 . /scripts/live-helpers
40 if [ ! -f /live.vars ]
49 for ARGUMENT in $(cat /proc/cmdline)
57 NOCONSOLEKEYBOARD="Yes"
64 NOLANGUAGESELECTOR="Yes"
68 NOPOWERMANAGEMENT="Yes"
69 NOPROGRAMCRASHES="Yes"
72 NOUPDATENOTIFIER="Yes"
78 export NOACCESSIBILITY NOAPPARMOR NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOGNOMEPANEL NOHOSTS NOJOCKEY NOKPERSONALIZER NOLANGUAGESELECTOR NOLOCALES NONETWORKING NOPOLKITCONF NOPOWERMANAGEMENT NOPROGRAMCRASHES NOSUDO NOTIMEZONE NOUPDATENOTIFIER NOUSER NOXAUTOCONFIG NOXAUTOLOGIN NOXSCREENSAVER
82 ACCESS="${ARGUMENT#access=}"
87 DEFCONSOLE="${ARGUMENT#*=}"
99 DEVICE="${ARGUMENT#ethdevice=}"
104 ETHDEVICE="${ARGUMENT#ethdevice=}"
109 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
110 export ETHDEV_TIMEOUT
114 FETCH="${ARGUMENT#fetch=}"
119 FORCEPERSISTENTFSCK="Yes"
120 export FORCEPERSISTENTFSCK
124 HOOK="${ARGUMENT#hook=}"
129 FTPFS="${ARGUMENT#ftpfs=}"
134 HTTPFS="${ARGUMENT#httpfs=}"
139 HOSTNAME="${ARGUMENT#hostname=}"
141 export HOSTNAME LIVECONF
145 FROMISO="${ARGUMENT#*=}"
150 USERNAME="${ARGUMENT#username=}"
152 export USERNAME LIVECONF
156 USERFULLNAME="${ARGUMENT#userfullname=}"
158 export USERFULLNAME LIVECONF
167 INTEGRITY_CHECK="Yes"
168 export INTEGRITY_CHECK
172 STATICIP="${ARGUMENT#ip=}"
174 if [ -z "${STATICIP}" ]
182 keyb=*|kbd-chooser/method=*)
187 klayout=*|console-setup/layoutcode=*)
188 KLAYOUT="${ARGUMENT#*=}"
192 kvariant=*|console-setup/variantcode=*)
193 KVARIANT="${ARGUMENT#*=}"
197 kmodel=*|console-setup/modelcode=*)
198 KMODEL="${ARGUMENT#*=}"
203 KOPTIONS="${ARGUMENT#koptions=}"
212 live-media=*|bootfrom=*)
213 LIVE_MEDIA="${ARGUMENT#*=}"
217 live-media-encryption=*|encryption=*)
218 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
219 export LIVE_MEDIA_ENCRYPTION
223 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
224 export LIVE_MEDIA_OFFSET
228 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
229 export LIVE_MEDIA_PATH
232 live-media-timeout=*)
233 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
234 export LIVE_MEDIA_TIMEOUT
237 language=*|debian-installer/language=*)
238 language=${x#debian-installer/language=}
239 locale="$(lang2locale "$language")"
243 locale=*|debian-installer/locale=*)
244 LOCALE="${ARGUMENT#*=}"
249 MODULE="${ARGUMENT#module=}"
254 NETBOOT="${ARGUMENT#netboot=}"
259 NFSOPTS="${ARGUMENT#nfsopts=}"
264 NFS_COW="${ARGUMENT#nfscow=}"
269 NOACCESSIBILITY="Yes"
270 export NOACCESSIBILITY
294 NOCONSOLEKEYBOARD="Yes"
295 export NOCONSOLEKEYBOARD
319 NOKPERSONALIZER="Yes"
320 export NOKPERSONALIZER
324 NOLANGUAGESELECTOR="Yes"
325 export NOLANGUAGESELECTOR
339 NOPOWERMANAGEMENT="Yes"
340 export NOPOWERMANAGEMENT
344 NOPROGRAMCRASHES="Yes"
345 export NOPROGRAMCRASHES
364 NOUPDATENOTIFIER="Yes"
365 export NOUPDATENOTIFIER
380 export NOXSCREENSAVER
389 PERSISTENT="${ARGUMENT#persistent=}"
390 if [ -z "${PERSISTENT}" ]
398 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
399 export PERSISTENT_PATH
402 persistent-subtext=*)
403 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
404 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
405 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
406 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
415 QUICKUSBMODULES="Yes"
416 export QUICKUSBMODULES
419 preseed/file=*|file=*)
420 LOCATION="${ARGUMENT#*=}"
430 location="${ARGUMENT#url=}"
432 mount -o bind /sys /root/sys
433 mount -o bind /proc /root/proc
434 mount -o bind /dev /root/dev
436 mkdir -p /root/var/run/network
437 [ "${NETBOOT}" ] || chroot /root dhclient eth0
438 chroot /root wget -P /tmp "${location}"
439 [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down
445 LOCATION="/tmp/$(basename "${location}")"
449 question="${ARGUMENT%%=*}"
450 value="${ARGUMENT#*=}"
451 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
471 TIMEZONE="${ARGUMENT#timezone=}"
481 TODISK="${ARGUMENT#todisk=}"
492 MODULETORAM="${ARGUMENT#toram=}"
493 export TORAM MODULETORAM
507 SKIP_UNION_MOUNTS="Yes"
508 export SKIP_UNION_MOUNTS
512 ROOT="${ARGUMENT#root=}"
517 UNIONTYPE="${ARGUMENT#union=}"
522 UTC="${ARGUMENT#utc=}"
532 XDRIVER="${ARGUMENT#xdriver=}"
537 XVIDEOMODE="${ARGUMENT#xvideomode=}"
543 # sort of compatibility with netboot.h from linux docs
544 if [ -z "${NETBOOT}" ]
546 if [ "${ROOT}" = "/dev/nfs" ]
550 elif [ "${ROOT}" = "/dev/cifs" ]
557 if [ -z "${MODULE}" ]
563 if [ -z "${UNIONTYPE}" ]
574 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
576 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
578 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
590 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
596 uuid="$(cat /conf/uuid.conf)"
598 for try_uuid_file in "${path}/.disk/live-uuid"*
600 [ -e "${try_uuid_file}" ] || continue
602 try_uuid="$(cat "${try_uuid_file}")"
604 if [ "${uuid}" = "${try_uuid}" ]
613 get_backing_device ()
616 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
617 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
625 panic "Unrecognized live filesystem: ${1}"
630 match_files_in_dir ()
632 # Does any files match pattern ${1} ?
635 if [ "$(echo ${pattern})" != "${pattern}" ]
643 mount_images_in_directory ()
650 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
651 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
652 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
653 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
654 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
655 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
657 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
658 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
660 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
666 sysfs_path="${1#/sys}"
668 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-|platform-mmc)"
671 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
683 copyto="${copyfrom}_swap"
685 if [ -z "${MODULETORAM}" ]
687 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
689 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
691 if [ -f "${MODULETORAMFILE}" ]
693 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
695 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
700 if [ "${copytodev}" = "ram" ]
703 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo ) )
704 mount_options="-o size=${size}k"
709 # it should be a writable block device
710 if [ -b "${copytodev}" ]
714 fstype=$(get_fstype "${dev}")
715 freespace=$(fs_size "${dev}")
717 log_warning_msg "${copytodev} is not a block device."
722 if [ "${freespace}" -lt "${size}" ]
724 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
728 # begin copying (or uncompressing)
730 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
731 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
733 if [ "${extension}" = "tgz" ]
736 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
737 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
738 mount -r -o move "${copyto}" "${rootmnt}"
741 if [ -n "${MODULETORAMFILE}" ]
745 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
746 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
748 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
753 echo " * Copying whole medium to RAM" 1>/dev/console
754 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
756 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
757 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} # "cp -a" from busybox also copies hidden files
762 mount -r -o move ${copyto} ${copyfrom}
773 modprobe -q af_packet # For DHCP
778 # if ethdevice was not specified on the kernel command line
779 # make sure we try to get a working network configuration
780 # for *every* present network device (except for loopback of course)
781 if [ -z "$ETHDEVICE" ] ; then
782 echo "If you want to boot from a specific device use bootoption ethdevice=..."
783 for device in /sys/class/net/*; do
785 if [ "$dev" != "lo" ] ; then
786 ETHDEVICE="$ETHDEVICE $dev"
791 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
792 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
793 devlist="$devlist $device"
796 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
797 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
799 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
800 # an endless loop; iff execution fails give it two further tries, that's
801 # why we use '$devlist $devlist $devlist' for the other for loop
802 for dev in $devlist $devlist $devlist ; do
803 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
804 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
806 sleep "$ETHDEV_TIMEOUT" ; sleep 1
807 if [ -r /proc/"$jobid"/status ] ; then
808 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
812 # if configuration of device worked we should have an assigned
813 # IP address, iff so let's use the according as $DEVICE for later usage
814 # simple and primitive approach which seems to work fine
815 if ifconfig $dev | grep -q 'inet.*addr:' ; then
821 # source relevant ipconfig output
822 OLDHOSTNAME=${HOSTNAME}
823 . /tmp/net-${DEVICE}.conf
824 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
827 # Check if we have a network device at all
828 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
829 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
830 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
831 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
832 ! ls /sys/class/net/ra0 > /dev/null 2>&1
834 panic "No supported network device found, maybe a non-mainline driver is required."
837 if [ "${NFSROOT}" = "auto" ]
839 NFSROOT=${ROOTSERVER}:${ROOTPATH}
842 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
848 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
850 NFSROOT=${ROOTSERVER}:${NFSROOT}
853 log_begin_msg "Trying netboot from ${NFSROOT}"
855 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
872 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
873 mount -t ramfs ram "${mountpoint}"
876 for webfile in HTTPFS FTPFS FETCH
878 url="$(eval echo \"\$\{${webfile}\}\")"
879 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
883 case "${extension}" in
885 if [ "${webfile}" = "FETCH" ]
889 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
890 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
891 lfile="$(basename $url)"
892 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
893 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
897 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
898 wget "${url}" -O "${dest}/$(basename ${url})"
902 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
903 if [ "${webfile}" = "FTPFS" ]
905 FUSE_MOUNT="curlftpfs"
906 url="$(dirname ${url})"
911 $FUSE_MOUNT "${url}" "${dest}"
913 [ ${?} -eq 0 ] && rc=0
914 [ "${extension}" = "tgz" ] && live_dest="ram"
919 log_begin_msg "Unrecognized archive extension for ${url}"
927 umount "${mountpoint}"
939 if [ -z "${NFSOPTS}" ]
944 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
946 # FIXME: This while loop is an ugly HACK round an nfs bug
948 while [ "$i" -lt 60 ]
950 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
962 if [ -x "/sbin/mount.cifs" ]
964 if [ -z "${NFSOPTS}" ]
966 CIFSOPTS="-ouser=root,password="
968 CIFSOPTS="${NFSOPTS}"
971 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
974 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
988 size=$(fs_size "${fromdev}" "" "used")
990 if [ -b "${fromdev}" ]
993 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
995 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
996 freespace=$(df -k | awk '/'${todev}'/{print $4}')
998 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo))
1001 tomount="/mnt/tmpsnap"
1003 if [ ! -d "${tomount}" ]
1005 mkdir -p "${tomount}"
1008 fstype=$(get_fstype "${fromdev}")
1010 if [ -n "${fstype}" ]
1013 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1014 cp -a "${tomount}"/* ${todir}
1017 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1022 if echo ${fromdev} | grep -qs loop
1024 losetup -d "${fromdev}"
1031 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1037 # Look for ${snap_label}.* in block devices
1040 if [ "${PERSISTENT}" != "nofiles" ]
1042 # search for image files
1043 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")
1046 if [ -z "${snapdata}" ]
1048 snapdata=$(find_cow_device "${snap_label}")
1055 # copy the contents of previously found snapshot to ${snap_mount}
1056 # and remember the device and filename for resync on exit in live-initramfs.init
1062 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1064 log_success_msg "found snapshot: ${snapdata}"
1065 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1066 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1067 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1070 if ! try_mount "${snapdev}" "${snapback}" "ro"
1075 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1077 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1078 dev=$(get_backing_device "${snapback}/${snapfile}")
1080 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1085 zcat "${snapback}/${snapfile}" | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1
1087 if [ "${RES}" != "0" ]
1089 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\""
1094 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1096 if [ "${RES}" != "0" ]
1098 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1101 elif [ -b "${snapdata}" ]
1103 # Try to find if it could be a snapshot partition
1105 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1106 if echo "${dev}" | grep -qs loop
1108 # strange things happens, user confused?
1109 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1110 snapfile=$(basename ${snaploop})
1111 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1116 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1118 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1121 if [ -n "${snapfile}" ]
1123 # it was a loop device, user confused
1128 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1132 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1138 image_directory="${1}"
1140 addimage_directory="${3}"
1142 case ${UNIONTYPE} in
1144 modprobe -q -b ${UNIONTYPE}
1146 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1148 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1149 echo "This might be really slow."
1151 UNIONTYPE="unionfs-fuse"
1156 if [ "${UNIONTYPE}" = unionfs-fuse ]
1161 # run-init can't deal with images in a subdir, but we're going to
1162 # move all of these away before it runs anyway. No, we're not,
1163 # put them in / since move-mounting them into / breaks mono and
1168 # Let's just mount the read-only file systems first
1172 if [ "${UNIONTYPE}" = "aufs" ]
1175 noxino_opt="noxino,"
1176 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1183 if [ -z "${PLAIN_ROOT}" ]
1185 # Read image names from ${MODULE}.module if it exists
1186 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1188 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1190 image_string="${image_string} ${image_directory}/${IMAGE}"
1192 elif [ -e "${image_directory}/${MODULE}.module" ]
1194 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1196 image_string="${image_string} ${image_directory}/${IMAGE}"
1199 # ${MODULE}.module does not exist, create a list of images
1200 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1202 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1204 if [ -e "${IMAGE}" ]
1206 image_string="${image_string} ${IMAGE}"
1211 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1213 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1215 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1217 if [ -e "${IMAGE}" ]
1219 image_string="${image_string} ${IMAGE}"
1226 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1229 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1233 for image in ${image_string}
1235 imagename=$(basename "${image}")
1237 export image devname
1238 maybe_break live-realpremount
1239 log_begin_msg "Running /scripts/live-realpremount"
1240 run_scripts /scripts/live-realpremount
1243 if [ -d "${image}" ]
1245 # it is a plain directory: do nothing
1246 rofsstring="${image}=${roopt}:${rofsstring}"
1247 rofslist="${image} ${rofslist}"
1248 elif [ -f "${image}" ]
1250 if losetup --help 2>&1 | grep -q -- "-r\b"
1252 backdev=$(get_backing_device "${image}" "-r")
1254 backdev=$(get_backing_device "${image}")
1256 fstype=$(get_fstype "${backdev}")
1258 if [ "${fstype}" = "unknown" ]
1260 panic "Unknown file system type on ${backdev} (${image})"
1263 if [ -z "${fstype}" ]
1265 fstype="${imagename##*.}"
1266 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1269 mkdir -p "${croot}/${imagename}"
1270 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1271 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}"
1276 # we have a plain root system
1277 mkdir -p "${croot}/filesystem"
1278 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1279 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}"
1281 mount -o bind ${croot}/filesystem $mountpoint
1285 rofsstring=${rofsstring%:}
1289 # Looking for "${root_persistence}" device or file
1290 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1292 if [ -z "${QUICKUSBMODULES}" ]
1295 num_block=$(ls -l /sys/block | wc -l)
1296 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1298 modprobe -q -b ${module}
1304 # For some reason, udevsettle does not block in this scenario,
1305 # so we sleep for a little while.
1307 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1308 for timeout in 5 4 3 2 1
1312 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1319 # search for label and files (this could be hugely optimized)
1320 cowprobe=$(find_cow_device "${root_persistence}")
1321 if [ -b "${cowprobe}" ]
1323 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1324 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1325 # snapshots to be sure to really store some e.g key config files,
1326 # but not on the same media
1327 blacklistdev="${cowprobe}"
1328 PERSISTENCE_IS_ON="1"
1329 export PERSISTENCE_IS_ON
1331 # homecow just mount something on /home, this should be generalized some way
1332 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1333 if [ -b "${homecow}" ]
1335 PERSISTENCE_IS_ON="1"
1336 export PERSISTENCE_IS_ON
1338 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1339 # This second type should be removed when snapshot will get smarter,
1340 # hence when "/etc/live-snapshot*list" will be supported also by
1341 # ext2|ext3|ext4|jffs2 snapshot types.
1342 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1344 if [ -b "${cowprobe}" ]
1346 cowdevice=${cowprobe}
1347 cow_fstype=$(get_fstype "${cowprobe}")
1348 cow_mountopt="rw,noatime"
1350 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1352 fsck -y ${cowdevice}
1355 log_warning_msg "Unable to find the persistent medium"
1358 cow_mountopt="rw,noatime,mode=755"
1360 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1362 # check if there are any nfs options
1363 if echo ${NFS_COW}|grep -q ','
1365 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1366 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1368 nfs_cow_opts="-o nolock"
1374 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1377 panic "unable to determine mac address"
1382 cow_mountopt="rw,noatime,mode=755"
1385 if [ "${cow_fstype}" = "nfs" ]
1388 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1389 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1390 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1392 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1393 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1396 rofscount=$(echo ${rofslist} |wc -w)
1398 if [ -n "${EXPOSED_ROOT}" ]
1400 if [ ${rofscount} -ne 1 ]
1402 panic "only one RO file system supported with exposedroot: ${rofslist}"
1404 exposedrootfs=${rofslist%% }
1406 mount --bind ${exposedrootfs} ${rootmnt} || \
1407 panic "bind mount of ${exposedrootfs} failed"
1409 if [ -z "${SKIP_UNION_MOUNTS}" ]
1411 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1416 for dir in ${cow_dirs}; do
1419 case "${UNIONTYPE}" in
1421 (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}")
1425 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"
1430 case "${UNIONTYPE}" in
1432 (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}")
1436 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}"
1441 # Correct the permissions of /:
1442 chmod 0755 "${rootmnt}"
1444 # tmpfs file systems
1446 mkdir -p "${rootmnt}/live"
1447 mount -t tmpfs tmpfs ${rootmnt}/live
1449 # Adding other custom mounts
1450 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1452 # directly mount /home
1453 # FIXME: add a custom mounts configurable system
1455 if [ -b "${homecow}" ]
1457 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1458 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1460 log_warning_msg "Unable to find the persistent home medium"
1463 # Look for other snapshots to copy in
1464 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1465 # This second type should be removed when snapshot grow smarter
1466 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1469 if [ -n "${SHOWMOUNTS}" ]
1471 for d in ${rofslist}
1473 mkdir -p "${rootmnt}/live/${d##*/}"
1477 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1481 case "${UNIONTYPE}" in
1483 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1487 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1495 # shows cow fs on /cow for use by live-snapshot
1496 mkdir -p "${rootmnt}/live/cow"
1497 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"
1504 skip_uuid_check="${3}"
1506 # support for fromiso=.../isofrom=....
1507 if [ -n "$FROMISO" ]
1510 ISO_DEVICE="$(echo $FROMISO | sed 's|\(/dev/[a-z]*[0-9]*\).*|\1|')"
1511 mount "$ISO_DEVICE" /isofrom
1512 ISO_NAME="$(echo $FROMISO | sed 's|/dev/[a-z]*[0-9]*/||')"
1513 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1514 devname="${loopdevname}"
1517 if [ -z "${devname}" ]
1519 devname=$(sys2dev "${sysdev}")
1522 if [ -d "${devname}" ]
1524 mount -o bind "${devname}" $mountpoint || continue
1526 if is_live_path $mountpoint
1535 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1537 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1538 devname="${loopdevname}"
1541 fstype=$(get_fstype "${devname}")
1543 if is_supported_fs ${fstype}
1545 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1547 if is_live_path ${mountpoint} && \
1548 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1553 umount ${mountpoint}
1557 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1559 losetup -d "${loopdevname}"
1569 # don't start autodetection before timeout has expired
1570 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1572 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1578 # first look at the one specified in the command line
1579 case "${LIVE_MEDIA}" in
1581 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1583 if [ "$(cat ${sysblock}/removable)" = "1" ]
1585 if readlink ${sysblock} | grep -q usb ||
1586 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1588 for dev in $(subdevices "${sysblock}")
1590 if check_dev "${dev}"
1602 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1604 if [ "$(cat ${sysblock}/removable)" = "1" ]
1606 for dev in $(subdevices "${sysblock}")
1608 if check_dev "${dev}"
1619 if [ ! -z "${LIVE_MEDIA}" ]
1621 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1629 # or do the scan of block devices
1630 # prefer removable devices over non-removable devices, so scan them first
1631 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1633 if [ "$(cat ${sysblock}/removable)" = "1" ]
1635 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1637 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1640 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1642 for sysblock in $devices_to_scan
1644 devname=$(sys2dev "${sysblock}")
1645 fstype=$(get_fstype "${devname}")
1647 if /lib/udev/cdrom_id ${devname} > /dev/null
1649 if check_dev "null" "${devname}"
1653 elif is_nice_device "${sysblock}"
1655 for dev in $(subdevices "${sysblock}")
1657 if check_dev "${dev}"
1662 elif [ "${fstype}" = "squashfs" -o \
1663 "${fstype}" = "ext2" -o \
1664 "${fstype}" = "ext3" -o \
1665 "${fstype}" = "ext4" -o \
1666 "${fstype}" = "jffs2" ]
1668 # This is an ugly hack situation, the block device has
1669 # an image directly on it. It's hopefully
1670 # live-initramfs, so take it and run with it.
1671 ln -s "${devname}" "${devname}.${fstype}"
1672 echo "${devname}.${fstype}"
1680 set_usplash_timeout ()
1682 if [ -x /sbin/usplash_write ]
1684 /sbin/usplash_write "TIMEOUT 120"
1685 else if [ -x /sbin/splashy_update ] ; then
1686 /sbin/splashy_update "TIMEOUT 120"
1692 media_mountpoint="${1}"
1694 log_begin_msg "Checking media integrity"
1696 cd ${media_mountpoint}
1697 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1702 if [ "${RC}" -eq 0 ]
1704 log_success_msg "Everything ok, will reboot in 10 seconds."
1707 umount ${media_mountpoint}
1709 echo u > /proc/sysrq-trigger
1710 echo b > /proc/sysrq-trigger
1712 panic "Not ok, a media defect is likely, switch to VT8 for details."
1718 if [ -x /scripts/local-top/cryptroot ]; then
1719 /scripts/local-top/cryptroot
1726 tail -f live.log >&7 &
1729 # Ensure 'panic' function is overridden
1730 . /scripts/live-functions
1736 maybe_break live-premount
1737 log_begin_msg "Running /scripts/live-premount"
1738 run_scripts /scripts/live-premount
1741 # Needed here too because some things (*cough* udev *cough*)
1742 # changes the timeout
1746 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1750 livefs_root="${mountpoint}"
1752 panic "Unable to find a live file system on the network"
1755 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1757 # Do a local boot from hd
1760 # Scan local devices for the image
1762 while [ "$i" -lt 60 ]
1764 livefs_root=$(find_livefs ${i})
1766 if [ -n "${livefs_root}" ]
1777 if [ -z "${livefs_root}" ]
1779 panic "Unable to find a medium containing a live file system"
1782 if [ "${INTEGRITY_CHECK}" ]
1784 integrity_check "${livefs_root}"
1790 elif [ "${TODISK}" ]
1792 live_dest="${TODISK}"
1795 if [ "${live_dest}" ]
1797 log_begin_msg "Copying live media to ${live_dest}"
1798 copy_live_to "${livefs_root}" "${live_dest}"
1802 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1803 # because the mountpoint is left behind in /proc/mounts, so let's get
1804 # rid of it when running from RAM
1805 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1807 losetup -d /dev/loop0
1808 grep -q /isofrom /proc/mounts && umount /isofrom
1811 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1813 setup_unionfs "${livefs_root}" "${rootmnt}"
1816 mac="$(echo ${mac} | sed 's/-//g')"
1817 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1822 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1823 # live-bottom; udev's init script will take care of things after that
1824 if [ "${UNIONTYPE}" = unionfs-fuse ]
1826 mount -n -o bind /dev "${rootmnt}/dev"
1829 maybe_break live-bottom
1830 log_begin_msg "Running /scripts/live-bottom\n"
1832 run_scripts /scripts/live-bottom
1835 if [ "${UNIONFS}" = unionfs-fuse ]
1837 umount "${rootmnt}/dev"
1843 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null