5 export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
7 echo "/root/lib" >> /etc/ld.so.conf
8 echo "/root/usr/lib" >> /etc/ld.so.conf
10 mountpoint="/live/image"
11 LIVE_MEDIA_PATH="live"
13 root_persistence="live-rw"
14 home_persistence="home-rw"
15 root_snapshot_label="live-sn"
16 home_snapshot_label="home-sn"
19 USERFULLNAME="Live user"
22 mkdir -p "${mountpoint}"
25 # Create /etc/mtab for debug purpose and future syncs
36 [ -f /etc/live.conf ] && . /etc/live.conf
37 export USERNAME USERFULLNAME HOSTNAME
39 . /scripts/live-helpers
41 if [ ! -f /live.vars ]
51 for ARGUMENT in $(cat /proc/cmdline)
59 NOCONSOLEKEYBOARD="Yes"
66 NOLANGUAGESELECTOR="Yes"
70 NOPOWERMANAGEMENT="Yes"
71 NOPROGRAMCRASHES="Yes"
74 NOUPDATENOTIFIER="Yes"
80 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
84 ACCESS="${ARGUMENT#access=}"
89 DEFCONSOLE="${ARGUMENT#*=}"
101 DEVICE="${ARGUMENT#ethdevice=}"
106 ETHDEVICE="${ARGUMENT#ethdevice=}"
111 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
112 export ETHDEV_TIMEOUT
116 FETCH="${ARGUMENT#fetch=}"
121 FORCEPERSISTENTFSCK="Yes"
122 export FORCEPERSISTENTFSCK
126 HOOK="${ARGUMENT#hook=}"
131 FTPFS="${ARGUMENT#ftpfs=}"
136 HTTPFS="${ARGUMENT#httpfs=}"
141 HOSTNAME="${ARGUMENT#hostname=}"
143 export HOSTNAME LIVECONF
147 FROMISO="${ARGUMENT#*=}"
152 USERNAME="${ARGUMENT#username=}"
154 export USERNAME LIVECONF
158 USERFULLNAME="${ARGUMENT#userfullname=}"
160 export USERFULLNAME LIVECONF
169 INTEGRITY_CHECK="Yes"
170 export INTEGRITY_CHECK
174 STATICIP="${ARGUMENT#ip=}"
176 if [ -z "${STATICIP}" ]
184 keyb=*|kbd-chooser/method=*)
189 klayout=*|console-setup/layoutcode=*)
190 KLAYOUT="${ARGUMENT#*=}"
194 kvariant=*|console-setup/variantcode=*)
195 KVARIANT="${ARGUMENT#*=}"
199 kmodel=*|console-setup/modelcode=*)
200 KMODEL="${ARGUMENT#*=}"
205 KOPTIONS="${ARGUMENT#koptions=}"
214 live-media=*|bootfrom=*)
215 LIVE_MEDIA="${ARGUMENT#*=}"
219 live-media-encryption=*|encryption=*)
220 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
221 export LIVE_MEDIA_ENCRYPTION
225 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
226 export LIVE_MEDIA_OFFSET
230 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
231 export LIVE_MEDIA_PATH
234 live-media-timeout=*)
235 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
236 export LIVE_MEDIA_TIMEOUT
239 language=*|debian-installer/language=*)
240 language=${x#debian-installer/language=}
241 locale="$(lang2locale "$language")"
245 locale=*|debian-installer/locale=*)
246 LOCALE="${ARGUMENT#*=}"
251 MODULE="${ARGUMENT#module=}"
256 NETBOOT="${ARGUMENT#netboot=}"
261 NFSOPTS="${ARGUMENT#nfsopts=}"
266 NFS_COW="${ARGUMENT#nfscow=}"
271 NOACCESSIBILITY="Yes"
272 export NOACCESSIBILITY
296 NOCONSOLEKEYBOARD="Yes"
297 export NOCONSOLEKEYBOARD
321 NOKPERSONALIZER="Yes"
322 export NOKPERSONALIZER
326 NOLANGUAGESELECTOR="Yes"
327 export NOLANGUAGESELECTOR
341 NOPOWERMANAGEMENT="Yes"
342 export NOPOWERMANAGEMENT
346 NOPROGRAMCRASHES="Yes"
347 export NOPROGRAMCRASHES
366 NOUPDATENOTIFIER="Yes"
367 export NOUPDATENOTIFIER
382 export NOXSCREENSAVER
391 PERSISTENT="${ARGUMENT#persistent=}"
392 if [ -z "${PERSISTENT}" ]
400 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
401 export PERSISTENT_PATH
404 persistent-subtext=*)
405 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
406 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
407 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
408 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
417 QUICKUSBMODULES="Yes"
418 export QUICKUSBMODULES
421 preseed/file=*|file=*)
422 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
432 URL_LOCATION="${ARGUMENT#url=}"
434 mount -o bind /sys /root/sys
435 mount -o bind /proc /root/proc
436 mount -o bind /dev /root/dev
438 mkdir -p /root/var/run/network
439 [ "${NETBOOT}" ] || chroot /root dhclient eth0
440 chroot /root wget -P /tmp "${URL_LOCATION}"
441 [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down
447 LOCATIONS="/tmp/$(basename ${URL_LOCATION}) ${LOCATIONS}"
451 question="${ARGUMENT%%=*}"
452 value="${ARGUMENT#*=}"
453 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
473 TIMEZONE="${ARGUMENT#timezone=}"
483 TODISK="${ARGUMENT#todisk=}"
494 MODULETORAM="${ARGUMENT#toram=}"
495 export TORAM MODULETORAM
509 SKIP_UNION_MOUNTS="Yes"
510 export SKIP_UNION_MOUNTS
514 ROOT="${ARGUMENT#root=}"
519 UNIONTYPE="${ARGUMENT#union=}"
524 UTC="${ARGUMENT#utc=}"
534 XDRIVER="${ARGUMENT#xdriver=}"
539 XVIDEOMODE="${ARGUMENT#xvideomode=}"
545 # sort of compatibility with netboot.h from linux docs
546 if [ -z "${NETBOOT}" ]
548 if [ "${ROOT}" = "/dev/nfs" ]
552 elif [ "${ROOT}" = "/dev/cifs" ]
559 if [ -z "${MODULE}" ]
565 if [ -z "${UNIONTYPE}" ]
576 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
578 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
580 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
592 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
598 uuid="$(cat /conf/uuid.conf)"
600 for try_uuid_file in "${path}/.disk/live-uuid"*
602 [ -e "${try_uuid_file}" ] || continue
604 try_uuid="$(cat "${try_uuid_file}")"
606 if [ "${uuid}" = "${try_uuid}" ]
615 get_backing_device ()
618 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
619 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
627 panic "Unrecognized live filesystem: ${1}"
632 match_files_in_dir ()
634 # Does any files match pattern ${1} ?
637 if [ "$(echo ${pattern})" != "${pattern}" ]
645 mount_images_in_directory ()
652 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
653 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
654 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
655 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
656 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
657 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
659 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
660 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
662 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
668 sysfs_path="${1#/sys}"
670 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
673 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
676 elif echo ${sysfs_path} | grep -q "^/block/dm-"
688 copyto="${copyfrom}_swap"
690 if [ -z "${MODULETORAM}" ]
692 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
694 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
696 if [ -f "${MODULETORAMFILE}" ]
698 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
700 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
705 if [ "${copytodev}" = "ram" ]
708 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo ) )
709 mount_options="-o size=${size}k"
714 # it should be a writable block device
715 if [ -b "${copytodev}" ]
719 fstype=$(get_fstype "${dev}")
720 freespace=$(fs_size "${dev}")
722 log_warning_msg "${copytodev} is not a block device."
727 if [ "${freespace}" -lt "${size}" ]
729 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
733 # begin copying (or uncompressing)
735 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
736 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
738 if [ "${extension}" = "tgz" ]
741 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
742 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
743 mount -r -o move "${copyto}" "${rootmnt}"
746 if [ -n "${MODULETORAMFILE}" ]
750 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
751 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
753 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
758 echo " * Copying whole medium to RAM" 1>/dev/console
759 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
761 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
762 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} # "cp -a" from busybox also copies hidden files
767 mount -r -o move ${copyto} ${copyfrom}
778 modprobe -q af_packet # For DHCP
783 # if ethdevice was not specified on the kernel command line
784 # make sure we try to get a working network configuration
785 # for *every* present network device (except for loopback of course)
786 if [ -z "$ETHDEVICE" ] ; then
787 echo "If you want to boot from a specific device use bootoption ethdevice=..."
788 for device in /sys/class/net/*; do
790 if [ "$dev" != "lo" ] ; then
791 ETHDEVICE="$ETHDEVICE $dev"
796 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
797 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
798 devlist="$devlist $device"
801 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
802 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
804 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
805 # an endless loop; iff execution fails give it two further tries, that's
806 # why we use '$devlist $devlist $devlist' for the other for loop
807 for dev in $devlist $devlist $devlist ; do
808 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
809 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
811 sleep "$ETHDEV_TIMEOUT" ; sleep 1
812 if [ -r /proc/"$jobid"/status ] ; then
813 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
817 # if configuration of device worked we should have an assigned
818 # IP address, iff so let's use the according as $DEVICE for later usage
819 # simple and primitive approach which seems to work fine
820 if ifconfig $dev | grep -q 'inet.*addr:' ; then
826 # source relevant ipconfig output
827 OLDHOSTNAME=${HOSTNAME}
828 . /tmp/net-${DEVICE}.conf
829 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
832 # Check if we have a network device at all
833 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
834 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
835 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
836 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
837 ! ls /sys/class/net/ra0 > /dev/null 2>&1
839 panic "No supported network device found, maybe a non-mainline driver is required."
842 if [ "${NFSROOT}" = "auto" ]
844 NFSROOT=${ROOTSERVER}:${ROOTPATH}
847 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
853 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
855 NFSROOT=${ROOTSERVER}:${NFSROOT}
858 log_begin_msg "Trying netboot from ${NFSROOT}"
860 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
877 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
878 mount -t ramfs ram "${mountpoint}"
881 for webfile in HTTPFS FTPFS FETCH
883 url="$(eval echo \"\$\{${webfile}\}\")"
884 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
888 case "${extension}" in
890 if [ "${webfile}" = "FETCH" ]
894 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
895 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
896 lfile="$(basename $url)"
897 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
898 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
902 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
903 wget "${url}" -O "${dest}/$(basename ${url})"
907 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
908 if [ "${webfile}" = "FTPFS" ]
910 FUSE_MOUNT="curlftpfs"
911 url="$(dirname ${url})"
916 $FUSE_MOUNT "${url}" "${dest}"
918 [ ${?} -eq 0 ] && rc=0
919 [ "${extension}" = "tgz" ] && live_dest="ram"
924 log_begin_msg "Unrecognized archive extension for ${url}"
932 umount "${mountpoint}"
944 if [ -z "${NFSOPTS}" ]
949 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
951 # FIXME: This while loop is an ugly HACK round an nfs bug
953 while [ "$i" -lt 60 ]
955 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
967 if [ -x "/sbin/mount.cifs" ]
969 if [ -z "${NFSOPTS}" ]
971 CIFSOPTS="-ouser=root,password="
973 CIFSOPTS="${NFSOPTS}"
976 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
979 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
993 size=$(fs_size "${fromdev}" "" "used")
995 if [ -b "${fromdev}" ]
998 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
1000 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
1001 freespace=$(df -k | awk '/'${todev}'/{print $4}')
1003 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo))
1006 tomount="/mnt/tmpsnap"
1008 if [ ! -d "${tomount}" ]
1010 mkdir -p "${tomount}"
1013 fstype=$(get_fstype "${fromdev}")
1015 if [ -n "${fstype}" ]
1018 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1019 cp -a "${tomount}"/* ${todir}
1022 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1027 if echo ${fromdev} | grep -qs loop
1029 losetup -d "${fromdev}"
1036 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1042 # Look for ${snap_label}.* in block devices
1045 if [ "${PERSISTENT}" != "nofiles" ]
1047 # search for image files
1048 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")
1051 if [ -z "${snapdata}" ]
1053 snapdata=$(find_cow_device "${snap_label}")
1060 # copy the contents of previously found snapshot to ${snap_mount}
1061 # and remember the device and filename for resync on exit in live-initramfs.init
1067 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1069 log_success_msg "found snapshot: ${snapdata}"
1070 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1071 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1072 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1075 if ! try_mount "${snapdev}" "${snapback}" "ro"
1080 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1082 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1083 dev=$(get_backing_device "${snapback}/${snapfile}")
1085 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1090 # Unfortunately klibc's cpio is incompatible with the
1091 # rest of the world; everything else requires -u -d,
1092 # while klibc doesn't implement them. Try to detect
1093 # whether it's in use.
1094 cpiopath="$(which cpio)" || true
1095 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1099 cpioargs='--unconditional --make-directories'
1102 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1104 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1108 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1110 if [ "${RES}" != "0" ]
1112 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1115 elif [ -b "${snapdata}" ]
1117 # Try to find if it could be a snapshot partition
1119 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1120 if echo "${dev}" | grep -qs loop
1122 # strange things happens, user confused?
1123 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1124 snapfile=$(basename ${snaploop})
1125 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1130 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1132 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1135 if [ -n "${snapfile}" ]
1137 # it was a loop device, user confused
1142 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1146 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1152 image_directory="${1}"
1154 addimage_directory="${3}"
1156 case ${UNIONTYPE} in
1158 modprobe -q -b ${UNIONTYPE}
1160 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1162 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1163 echo "This might be really slow."
1165 UNIONTYPE="unionfs-fuse"
1170 if [ "${UNIONTYPE}" = unionfs-fuse ]
1175 # run-init can't deal with images in a subdir, but we're going to
1176 # move all of these away before it runs anyway. No, we're not,
1177 # put them in / since move-mounting them into / breaks mono and
1182 # Let's just mount the read-only file systems first
1186 if [ "${UNIONTYPE}" = "aufs" ]
1189 noxino_opt="noxino,"
1190 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1197 if [ -z "${PLAIN_ROOT}" ]
1199 # Read image names from ${MODULE}.module if it exists
1200 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1202 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1204 image_string="${image_string} ${image_directory}/${IMAGE}"
1206 elif [ -e "${image_directory}/${MODULE}.module" ]
1208 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1210 image_string="${image_string} ${image_directory}/${IMAGE}"
1213 # ${MODULE}.module does not exist, create a list of images
1214 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1216 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1218 if [ -e "${IMAGE}" ]
1220 image_string="${image_string} ${IMAGE}"
1225 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1227 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1229 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1231 if [ -e "${IMAGE}" ]
1233 image_string="${image_string} ${IMAGE}"
1240 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1243 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1247 for image in ${image_string}
1249 imagename=$(basename "${image}")
1251 export image devname
1252 maybe_break live-realpremount
1253 log_begin_msg "Running /scripts/live-realpremount"
1254 run_scripts /scripts/live-realpremount
1257 if [ -d "${image}" ]
1259 # it is a plain directory: do nothing
1260 rofsstring="${image}=${roopt}:${rofsstring}"
1261 rofslist="${image} ${rofslist}"
1262 elif [ -f "${image}" ]
1264 if losetup --help 2>&1 | grep -q -- "-r\b"
1266 backdev=$(get_backing_device "${image}" "-r")
1268 backdev=$(get_backing_device "${image}")
1270 fstype=$(get_fstype "${backdev}")
1272 if [ "${fstype}" = "unknown" ]
1274 panic "Unknown file system type on ${backdev} (${image})"
1277 if [ -z "${fstype}" ]
1279 fstype="${imagename##*.}"
1280 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1283 mkdir -p "${croot}/${imagename}"
1284 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1285 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}"
1290 # we have a plain root system
1291 mkdir -p "${croot}/filesystem"
1292 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1293 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}"
1295 mount -o bind ${croot}/filesystem $mountpoint
1299 rofsstring=${rofsstring%:}
1303 # Looking for "${root_persistence}" device or file
1304 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1306 if [ -z "${QUICKUSBMODULES}" ]
1309 num_block=$(ls -l /sys/block | wc -l)
1310 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1312 modprobe -q -b ${module}
1318 # For some reason, udevsettle does not block in this scenario,
1319 # so we sleep for a little while.
1321 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1322 for timeout in 5 4 3 2 1
1326 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1333 # search for label and files (this could be hugely optimized)
1334 cowprobe=$(find_cow_device "${root_persistence}")
1335 if [ -b "${cowprobe}" ]
1337 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1338 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1339 # snapshots to be sure to really store some e.g key config files,
1340 # but not on the same media
1341 blacklistdev="${cowprobe}"
1342 PERSISTENCE_IS_ON="1"
1343 export PERSISTENCE_IS_ON
1345 # homecow just mount something on /home, this should be generalized some way
1346 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1347 if [ -b "${homecow}" ]
1349 PERSISTENCE_IS_ON="1"
1350 export PERSISTENCE_IS_ON
1352 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1353 # This second type should be removed when snapshot will get smarter,
1354 # hence when "/etc/live-snapshot*list" will be supported also by
1355 # ext2|ext3|ext4|jffs2 snapshot types.
1356 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1358 if [ -b "${cowprobe}" ]
1360 cowdevice=${cowprobe}
1361 cow_fstype=$(get_fstype "${cowprobe}")
1362 cow_mountopt="rw,noatime"
1364 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1366 fsck -y ${cowdevice}
1369 log_warning_msg "Unable to find the persistent medium"
1372 cow_mountopt="rw,noatime,mode=755"
1374 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1376 # check if there are any nfs options
1377 if echo ${NFS_COW}|grep -q ','
1379 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1380 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1382 nfs_cow_opts="-o nolock"
1388 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1391 panic "unable to determine mac address"
1396 cow_mountopt="rw,noatime,mode=755"
1399 if [ "${cow_fstype}" = "nfs" ]
1402 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1403 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1404 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1406 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1407 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1410 rofscount=$(echo ${rofslist} |wc -w)
1412 if [ -n "${EXPOSED_ROOT}" ]
1414 if [ ${rofscount} -ne 1 ]
1416 panic "only one RO file system supported with exposedroot: ${rofslist}"
1418 exposedrootfs=${rofslist%% }
1420 mount --bind ${exposedrootfs} ${rootmnt} || \
1421 panic "bind mount of ${exposedrootfs} failed"
1423 if [ -z "${SKIP_UNION_MOUNTS}" ]
1425 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1430 for dir in ${cow_dirs}; do
1433 case "${UNIONTYPE}" in
1435 (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}")
1436 mkdir -p /dev/.initramfs/varrun
1437 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1441 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"
1446 case "${UNIONTYPE}" in
1448 (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}")
1449 mkdir -p /dev/.initramfs/varrun
1450 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1454 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}"
1459 # Correct the permissions of /:
1460 chmod 0755 "${rootmnt}"
1462 # tmpfs file systems
1464 mkdir -p "${rootmnt}/live"
1465 mount -t tmpfs tmpfs ${rootmnt}/live
1467 # Adding other custom mounts
1468 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1470 # directly mount /home
1471 # FIXME: add a custom mounts configurable system
1473 if [ -b "${homecow}" ]
1475 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1476 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1478 log_warning_msg "Unable to find the persistent home medium"
1481 # Look for other snapshots to copy in
1482 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1483 # This second type should be removed when snapshot grow smarter
1484 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1487 if [ -n "${SHOWMOUNTS}" ]
1489 for d in ${rofslist}
1491 mkdir -p "${rootmnt}/live/${d##*/}"
1495 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1499 case "${UNIONTYPE}" in
1501 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1505 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1513 # shows cow fs on /cow for use by live-snapshot
1514 mkdir -p "${rootmnt}/live/cow"
1515 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"
1522 skip_uuid_check="${3}"
1524 # support for fromiso=.../isofrom=....
1525 if [ -n "$FROMISO" ]
1527 ISO_DEVICE=$(dirname $FROMISO)
1528 if ! [ -b $ISO_DEVICE ]
1530 # to support unusual device names like /dev/cciss/c0d0p1
1531 # as well we have to identify the block device name, let's
1532 # do that for up to 15 levels
1534 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1536 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1537 [ -b "$ISO_DEVICE" ] && break
1542 if [ "$ISO_DEVICE" = "/" ]
1544 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1547 mount "$ISO_DEVICE" /isofrom
1548 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1549 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1550 devname="${loopdevname}"
1554 if [ -z "${devname}" ]
1556 devname=$(sys2dev "${sysdev}")
1559 if [ -d "${devname}" ]
1561 mount -o bind "${devname}" $mountpoint || continue
1563 if is_live_path $mountpoint
1571 [ -e "$devname" ] || continue
1573 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1575 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1576 devname="${loopdevname}"
1579 fstype=$(get_fstype "${devname}")
1581 if is_supported_fs ${fstype}
1583 devuid=$(blkid -o value -s UUID "$devname")
1584 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1585 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1586 [ -n "$devuid" ] && echo "$devuid" >> $tried
1588 if is_live_path ${mountpoint} && \
1589 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1594 umount ${mountpoint}
1598 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1600 losetup -d "${loopdevname}"
1610 # don't start autodetection before timeout has expired
1611 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1613 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1619 # first look at the one specified in the command line
1620 case "${LIVE_MEDIA}" in
1622 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1624 if [ "$(cat ${sysblock}/removable)" = "1" ]
1626 if readlink ${sysblock} | grep -q usb ||
1627 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1629 for dev in $(subdevices "${sysblock}")
1631 if check_dev "${dev}"
1643 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1645 if [ "$(cat ${sysblock}/removable)" = "1" ]
1647 for dev in $(subdevices "${sysblock}")
1649 if check_dev "${dev}"
1660 if [ ! -z "${LIVE_MEDIA}" ]
1662 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1670 # or do the scan of block devices
1671 # prefer removable devices over non-removable devices, so scan them first
1672 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1674 if [ "$(cat ${sysblock}/removable)" = "1" ]
1676 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1678 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1681 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1683 for sysblock in $devices_to_scan
1685 devname=$(sys2dev "${sysblock}")
1686 [ -e "$devname" ] || continue
1687 fstype=$(get_fstype "${devname}")
1689 if /lib/udev/cdrom_id ${devname} > /dev/null
1691 if check_dev "null" "${devname}"
1695 elif is_nice_device "${sysblock}"
1697 for dev in $(subdevices "${sysblock}")
1699 if check_dev "${dev}"
1704 elif [ "${fstype}" = "squashfs" -o \
1705 "${fstype}" = "ext2" -o \
1706 "${fstype}" = "ext3" -o \
1707 "${fstype}" = "ext4" -o \
1708 "${fstype}" = "jffs2" ]
1710 # This is an ugly hack situation, the block device has
1711 # an image directly on it. It's hopefully
1712 # live-initramfs, so take it and run with it.
1713 ln -s "${devname}" "${devname}.${fstype}"
1714 echo "${devname}.${fstype}"
1722 set_usplash_timeout ()
1724 if [ -x /sbin/usplash_write ]
1726 /sbin/usplash_write "TIMEOUT 120"
1727 else if [ -x /sbin/splashy_update ] ; then
1728 /sbin/splashy_update "TIMEOUT 120"
1734 media_mountpoint="${1}"
1736 log_begin_msg "Checking media integrity"
1738 cd ${media_mountpoint}
1739 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1744 if [ "${RC}" -eq 0 ]
1746 log_success_msg "Everything ok, will reboot in 10 seconds."
1749 umount ${media_mountpoint}
1751 echo u > /proc/sysrq-trigger
1752 echo b > /proc/sysrq-trigger
1754 panic "Not ok, a media defect is likely, switch to VT8 for details."
1758 start_usplash_pulse ()
1760 if [ -x /sbin/usplash_write ]
1762 /sbin/usplash_write "PULSELOGO"
1768 if [ -x /scripts/local-top/cryptroot ]; then
1769 /scripts/local-top/cryptroot
1776 tail -f live.log >&7 &
1779 # Ensure 'panic' function is overridden
1780 . /scripts/live-functions
1787 maybe_break live-premount
1788 log_begin_msg "Running /scripts/live-premount"
1789 run_scripts /scripts/live-premount
1792 # Needed here too because some things (*cough* udev *cough*)
1793 # changes the timeout
1797 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1801 livefs_root="${mountpoint}"
1803 panic "Unable to find a live file system on the network"
1806 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1808 # Do a local boot from hd
1811 # Scan local devices for the image
1813 while [ "$i" -lt 60 ]
1815 livefs_root=$(find_livefs ${i})
1817 if [ -n "${livefs_root}" ]
1828 if [ -z "${livefs_root}" ]
1830 panic "Unable to find a medium containing a live file system"
1833 if [ "${INTEGRITY_CHECK}" ]
1835 integrity_check "${livefs_root}"
1841 elif [ "${TODISK}" ]
1843 live_dest="${TODISK}"
1846 if [ "${live_dest}" ]
1848 log_begin_msg "Copying live media to ${live_dest}"
1849 copy_live_to "${livefs_root}" "${live_dest}"
1853 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1854 # because the mountpoint is left behind in /proc/mounts, so let's get
1855 # rid of it when running from RAM
1856 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1858 losetup -d /dev/loop0
1859 grep -q /isofrom /proc/mounts && umount /isofrom
1862 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1864 setup_unionfs "${livefs_root}" "${rootmnt}"
1867 mac="$(echo ${mac} | sed 's/-//g')"
1868 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1873 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1874 # live-bottom; udev's init script will take care of things after that
1875 if [ "${UNIONTYPE}" = unionfs-fuse ]
1877 mount -n -o bind /dev "${rootmnt}/dev"
1880 maybe_break live-bottom
1881 log_begin_msg "Running /scripts/live-bottom\n"
1883 run_scripts /scripts/live-bottom
1886 if [ "${UNIONFS}" = unionfs-fuse ]
1888 umount "${rootmnt}/dev"
1894 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1895 if [ -f /etc/live.conf ]
1897 cp /etc/live.conf "${rootmnt}/etc/"