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}" | egrep -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=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /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 [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
784 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
787 # if ethdevice was not specified on the kernel command line
788 # make sure we try to get a working network configuration
789 # for *every* present network device (except for loopback of course)
790 if [ -z "$ETHDEVICE" ] ; then
791 echo "If you want to boot from a specific device use bootoption ethdevice=..."
792 for device in /sys/class/net/*; do
794 if [ "$dev" != "lo" ] ; then
795 ETHDEVICE="$ETHDEVICE $dev"
800 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
801 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
802 devlist="$devlist $device"
805 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
806 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
808 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
809 # an endless loop; iff execution fails give it two further tries, that's
810 # why we use '$devlist $devlist $devlist' for the other for loop
811 for dev in $devlist $devlist $devlist ; do
812 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
813 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
815 sleep "$ETHDEV_TIMEOUT" ; sleep 1
816 if [ -r /proc/"$jobid"/status ] ; then
817 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
821 # if configuration of device worked we should have an assigned
822 # IP address, iff so let's use the according as $DEVICE for later usage
823 # simple and primitive approach which seems to work fine
824 if ifconfig $dev | grep -q 'inet.*addr:' ; then
831 ipconfig ${DEVICE} | tee /netboot.config
834 # source relevant ipconfig output
835 OLDHOSTNAME=${HOSTNAME}
836 . /tmp/net-${DEVICE}.conf
837 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
840 # Check if we have a network device at all
841 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
842 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
843 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
844 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
845 ! ls /sys/class/net/ra0 > /dev/null 2>&1
847 panic "No supported network device found, maybe a non-mainline driver is required."
850 if [ "${NFSROOT}" = "auto" ]
852 NFSROOT=${ROOTSERVER}:${ROOTPATH}
855 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
861 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
863 NFSROOT=${ROOTSERVER}:${NFSROOT}
866 log_begin_msg "Trying netboot from ${NFSROOT}"
868 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
885 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
886 mount -t ramfs ram "${mountpoint}"
889 for webfile in HTTPFS FTPFS FETCH
891 url="$(eval echo \"\$\{${webfile}\}\")"
892 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
896 case "${extension}" in
898 if [ "${webfile}" = "FETCH" ]
902 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
903 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
904 lfile="$(basename $url)"
905 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
906 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
910 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
911 wget "${url}" -O "${dest}/$(basename ${url})"
915 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
916 if [ "${webfile}" = "FTPFS" ]
918 FUSE_MOUNT="curlftpfs"
919 url="$(dirname ${url})"
924 $FUSE_MOUNT "${url}" "${dest}"
926 [ ${?} -eq 0 ] && rc=0
927 [ "${extension}" = "tgz" ] && live_dest="ram"
932 log_begin_msg "Unrecognized archive extension for ${url}"
940 umount "${mountpoint}"
952 if [ -z "${NFSOPTS}" ]
957 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
959 # FIXME: This while loop is an ugly HACK round an nfs bug
961 while [ "$i" -lt 60 ]
963 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
975 if [ -x "/sbin/mount.cifs" ]
977 if [ -z "${NFSOPTS}" ]
979 CIFSOPTS="-ouser=root,password="
981 CIFSOPTS="${NFSOPTS}"
984 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
987 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
1001 size=$(fs_size "${fromdev}" "" "used")
1003 if [ -b "${fromdev}" ]
1006 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
1008 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
1009 freespace=$(df -k | awk '/'${todev}'/{print $4}')
1011 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
1014 tomount="/mnt/tmpsnap"
1016 if [ ! -d "${tomount}" ]
1018 mkdir -p "${tomount}"
1021 fstype=$(get_fstype "${fromdev}")
1023 if [ -n "${fstype}" ]
1026 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1027 cp -a "${tomount}"/* ${todir}
1030 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1035 if echo ${fromdev} | grep -qs loop
1037 losetup -d "${fromdev}"
1044 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1050 # Look for ${snap_label}.* in block devices
1053 if [ "${PERSISTENT}" != "nofiles" ]
1055 # search for image files
1056 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")
1059 if [ -z "${snapdata}" ]
1061 snapdata=$(find_cow_device "${snap_label}")
1068 # copy the contents of previously found snapshot to ${snap_mount}
1069 # and remember the device and filename for resync on exit in live-initramfs.init
1075 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1077 log_success_msg "found snapshot: ${snapdata}"
1078 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1079 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1080 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1083 if ! try_mount "${snapdev}" "${snapback}" "ro"
1088 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1090 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1091 dev=$(get_backing_device "${snapback}/${snapfile}")
1093 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1098 # Unfortunately klibc's cpio is incompatible with the
1099 # rest of the world; everything else requires -u -d,
1100 # while klibc doesn't implement them. Try to detect
1101 # whether it's in use.
1102 cpiopath="$(which cpio)" || true
1103 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1107 cpioargs='--unconditional --make-directories'
1110 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1112 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1116 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1118 if [ "${RES}" != "0" ]
1120 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1123 elif [ -b "${snapdata}" ]
1125 # Try to find if it could be a snapshot partition
1127 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1128 if echo "${dev}" | grep -qs loop
1130 # strange things happens, user confused?
1131 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1132 snapfile=$(basename ${snaploop})
1133 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1138 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1140 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1143 if [ -n "${snapfile}" ]
1145 # it was a loop device, user confused
1150 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1154 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1160 image_directory="${1}"
1162 addimage_directory="${3}"
1164 case ${UNIONTYPE} in
1166 modprobe -q -b ${UNIONTYPE}
1168 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1170 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1171 echo "This might be really slow."
1173 UNIONTYPE="unionfs-fuse"
1178 if [ "${UNIONTYPE}" = unionfs-fuse ]
1183 # run-init can't deal with images in a subdir, but we're going to
1184 # move all of these away before it runs anyway. No, we're not,
1185 # put them in / since move-mounting them into / breaks mono and
1190 # Let's just mount the read-only file systems first
1194 if [ "${UNIONTYPE}" = "aufs" ]
1197 noxino_opt="noxino,"
1198 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1205 if [ -z "${PLAIN_ROOT}" ]
1207 # Read image names from ${MODULE}.module if it exists
1208 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1210 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1212 image_string="${image_string} ${image_directory}/${IMAGE}"
1214 elif [ -e "${image_directory}/${MODULE}.module" ]
1216 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1218 image_string="${image_string} ${image_directory}/${IMAGE}"
1221 # ${MODULE}.module does not exist, create a list of images
1222 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1224 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1226 if [ -e "${IMAGE}" ]
1228 image_string="${image_string} ${IMAGE}"
1233 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1235 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1237 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1239 if [ -e "${IMAGE}" ]
1241 image_string="${image_string} ${IMAGE}"
1248 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1251 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1255 for image in ${image_string}
1257 imagename=$(basename "${image}")
1259 export image devname
1260 maybe_break live-realpremount
1261 log_begin_msg "Running /scripts/live-realpremount"
1262 run_scripts /scripts/live-realpremount
1265 if [ -d "${image}" ]
1267 # it is a plain directory: do nothing
1268 rofsstring="${image}=${roopt}:${rofsstring}"
1269 rofslist="${image} ${rofslist}"
1270 elif [ -f "${image}" ]
1272 if losetup --help 2>&1 | grep -q -- "-r\b"
1274 backdev=$(get_backing_device "${image}" "-r")
1276 backdev=$(get_backing_device "${image}")
1278 fstype=$(get_fstype "${backdev}")
1280 if [ "${fstype}" = "unknown" ]
1282 panic "Unknown file system type on ${backdev} (${image})"
1285 if [ -z "${fstype}" ]
1287 fstype="${imagename##*.}"
1288 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1291 mkdir -p "${croot}/${imagename}"
1292 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1293 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}"
1298 # we have a plain root system
1299 mkdir -p "${croot}/filesystem"
1300 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1301 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}"
1303 mount -o bind ${croot}/filesystem $mountpoint
1307 rofsstring=${rofsstring%:}
1311 # Looking for "${root_persistence}" device or file
1312 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1314 if [ -z "${QUICKUSBMODULES}" ]
1317 num_block=$(ls -l /sys/block | wc -l)
1318 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1320 modprobe -q -b ${module}
1326 # For some reason, udevsettle does not block in this scenario,
1327 # so we sleep for a little while.
1329 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1330 for timeout in 5 4 3 2 1
1334 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1341 # search for label and files (this could be hugely optimized)
1342 cowprobe=$(find_cow_device "${root_persistence}")
1343 if [ -b "${cowprobe}" ]
1345 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1346 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1347 # snapshots to be sure to really store some e.g key config files,
1348 # but not on the same media
1349 blacklistdev="${cowprobe}"
1350 PERSISTENCE_IS_ON="1"
1351 export PERSISTENCE_IS_ON
1353 # homecow just mount something on /home, this should be generalized some way
1354 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1355 if [ -b "${homecow}" ]
1357 PERSISTENCE_IS_ON="1"
1358 export PERSISTENCE_IS_ON
1360 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1361 # This second type should be removed when snapshot will get smarter,
1362 # hence when "/etc/live-snapshot*list" will be supported also by
1363 # ext2|ext3|ext4|jffs2 snapshot types.
1364 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1366 if [ -b "${cowprobe}" ]
1368 cowdevice=${cowprobe}
1369 cow_fstype=$(get_fstype "${cowprobe}")
1370 cow_mountopt="rw,noatime"
1372 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1374 fsck -y ${cowdevice}
1377 log_warning_msg "Unable to find the persistent medium"
1380 cow_mountopt="rw,noatime,mode=755"
1382 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1384 # check if there are any nfs options
1385 if echo ${NFS_COW}|grep -q ','
1387 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1388 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1390 nfs_cow_opts="-o nolock"
1396 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1399 panic "unable to determine mac address"
1404 cow_mountopt="rw,noatime,mode=755"
1407 if [ "${cow_fstype}" = "nfs" ]
1410 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1411 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1412 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1414 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1415 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1418 rofscount=$(echo ${rofslist} |wc -w)
1420 if [ -n "${EXPOSED_ROOT}" ]
1422 if [ ${rofscount} -ne 1 ]
1424 panic "only one RO file system supported with exposedroot: ${rofslist}"
1426 exposedrootfs=${rofslist%% }
1428 mount --bind ${exposedrootfs} ${rootmnt} || \
1429 panic "bind mount of ${exposedrootfs} failed"
1431 if [ -z "${SKIP_UNION_MOUNTS}" ]
1433 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1438 for dir in ${cow_dirs}; do
1441 case "${UNIONTYPE}" in
1443 (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}")
1444 mkdir -p /dev/.initramfs/varrun
1445 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1449 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"
1454 case "${UNIONTYPE}" in
1456 (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}")
1457 mkdir -p /dev/.initramfs/varrun
1458 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1462 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}"
1467 # Correct the permissions of /:
1468 chmod 0755 "${rootmnt}"
1470 # tmpfs file systems
1472 mkdir -p "${rootmnt}/live"
1473 mount -t tmpfs tmpfs ${rootmnt}/live
1475 # Adding other custom mounts
1476 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1478 # directly mount /home
1479 # FIXME: add a custom mounts configurable system
1481 if [ -b "${homecow}" ]
1483 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1484 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1486 log_warning_msg "Unable to find the persistent home medium"
1489 # Look for other snapshots to copy in
1490 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1491 # This second type should be removed when snapshot grow smarter
1492 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1495 if [ -n "${SHOWMOUNTS}" ]
1497 for d in ${rofslist}
1499 mkdir -p "${rootmnt}/live/${d##*/}"
1503 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1507 case "${UNIONTYPE}" in
1509 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1513 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1521 # shows cow fs on /cow for use by live-snapshot
1522 mkdir -p "${rootmnt}/live/cow"
1523 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"
1530 skip_uuid_check="${3}"
1532 # support for fromiso=.../isofrom=....
1533 if [ -n "$FROMISO" ]
1535 ISO_DEVICE=$(dirname $FROMISO)
1536 if ! [ -b $ISO_DEVICE ]
1538 # to support unusual device names like /dev/cciss/c0d0p1
1539 # as well we have to identify the block device name, let's
1540 # do that for up to 15 levels
1542 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1544 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1545 [ -b "$ISO_DEVICE" ] && break
1550 if [ "$ISO_DEVICE" = "/" ]
1552 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1555 mount "$ISO_DEVICE" /isofrom
1556 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1557 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1558 devname="${loopdevname}"
1562 if [ -z "${devname}" ]
1564 devname=$(sys2dev "${sysdev}")
1567 if [ -d "${devname}" ]
1569 mount -o bind "${devname}" $mountpoint || continue
1571 if is_live_path $mountpoint
1579 [ -e "$devname" ] || continue
1581 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1583 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1584 devname="${loopdevname}"
1587 fstype=$(get_fstype "${devname}")
1589 if is_supported_fs ${fstype}
1591 devuid=$(blkid -o value -s UUID "$devname")
1592 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1593 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1594 [ -n "$devuid" ] && echo "$devuid" >> $tried
1596 if is_live_path ${mountpoint} && \
1597 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1602 umount ${mountpoint}
1606 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1608 losetup -d "${loopdevname}"
1618 # don't start autodetection before timeout has expired
1619 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1621 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1627 # first look at the one specified in the command line
1628 case "${LIVE_MEDIA}" in
1630 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1632 if [ "$(cat ${sysblock}/removable)" = "1" ]
1634 if readlink ${sysblock} | grep -q usb ||
1635 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1637 for dev in $(subdevices "${sysblock}")
1639 if check_dev "${dev}"
1651 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1653 if [ "$(cat ${sysblock}/removable)" = "1" ]
1655 for dev in $(subdevices "${sysblock}")
1657 if check_dev "${dev}"
1668 if [ ! -z "${LIVE_MEDIA}" ]
1670 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1678 # or do the scan of block devices
1679 # prefer removable devices over non-removable devices, so scan them first
1680 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1682 if [ "$(cat ${sysblock}/removable)" = "1" ]
1684 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1686 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1689 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1691 for sysblock in $devices_to_scan
1693 devname=$(sys2dev "${sysblock}")
1694 [ -e "$devname" ] || continue
1695 fstype=$(get_fstype "${devname}")
1697 if /lib/udev/cdrom_id ${devname} > /dev/null
1699 if check_dev "null" "${devname}"
1703 elif is_nice_device "${sysblock}"
1705 for dev in $(subdevices "${sysblock}")
1707 if check_dev "${dev}"
1712 elif [ "${fstype}" = "squashfs" -o \
1713 "${fstype}" = "ext2" -o \
1714 "${fstype}" = "ext3" -o \
1715 "${fstype}" = "ext4" -o \
1716 "${fstype}" = "jffs2" ]
1718 # This is an ugly hack situation, the block device has
1719 # an image directly on it. It's hopefully
1720 # live-initramfs, so take it and run with it.
1721 ln -s "${devname}" "${devname}.${fstype}"
1722 echo "${devname}.${fstype}"
1730 set_usplash_timeout ()
1732 if [ -x /sbin/usplash_write ]
1734 /sbin/usplash_write "TIMEOUT 120"
1735 else if [ -x /sbin/splashy_update ] ; then
1736 /sbin/splashy_update "TIMEOUT 120"
1742 media_mountpoint="${1}"
1744 log_begin_msg "Checking media integrity"
1746 cd ${media_mountpoint}
1747 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1752 if [ "${RC}" -eq 0 ]
1754 log_success_msg "Everything ok, will reboot in 10 seconds."
1757 umount ${media_mountpoint}
1759 echo u > /proc/sysrq-trigger
1760 echo b > /proc/sysrq-trigger
1762 panic "Not ok, a media defect is likely, switch to VT8 for details."
1766 start_usplash_pulse ()
1768 if [ -x /sbin/usplash_write ]
1770 /sbin/usplash_write "PULSELOGO"
1776 if [ -x /scripts/local-top/cryptroot ]; then
1777 /scripts/local-top/cryptroot
1784 tail -f live.log >&7 &
1787 # Ensure 'panic' function is overridden
1788 . /scripts/live-functions
1795 maybe_break live-premount
1796 log_begin_msg "Running /scripts/live-premount"
1797 run_scripts /scripts/live-premount
1800 # Needed here too because some things (*cough* udev *cough*)
1801 # changes the timeout
1805 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1809 livefs_root="${mountpoint}"
1811 panic "Unable to find a live file system on the network"
1814 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1816 # Do a local boot from hd
1819 # Scan local devices for the image
1821 while [ "$i" -lt 60 ]
1823 livefs_root=$(find_livefs ${i})
1825 if [ -n "${livefs_root}" ]
1836 if [ -z "${livefs_root}" ]
1838 panic "Unable to find a medium containing a live file system"
1841 if [ "${INTEGRITY_CHECK}" ]
1843 integrity_check "${livefs_root}"
1849 elif [ "${TODISK}" ]
1851 live_dest="${TODISK}"
1854 if [ "${live_dest}" ]
1856 log_begin_msg "Copying live media to ${live_dest}"
1857 copy_live_to "${livefs_root}" "${live_dest}"
1861 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1862 # because the mountpoint is left behind in /proc/mounts, so let's get
1863 # rid of it when running from RAM
1864 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1866 losetup -d /dev/loop0
1867 grep -q /isofrom /proc/mounts && umount /isofrom
1870 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1872 setup_unionfs "${livefs_root}" "${rootmnt}"
1875 mac="$(echo ${mac} | sed 's/-//g')"
1876 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1881 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1882 # live-bottom; udev's init script will take care of things after that
1883 if [ "${UNIONTYPE}" = unionfs-fuse ]
1885 mount -n -o bind /dev "${rootmnt}/dev"
1888 # Open up two fifo's fd's for debconf-communicate to use. Speeds up
1889 # the live-initramfs process considerably.
1890 log_begin_msg "Creating debconf-communicate fifo mechanism"
1891 mkfifo /tmp/debconf-in.fifo
1892 mkfifo /tmp/debconf-out.fifo
1894 chroot /root debconf-communicate -fnoninteractive live-initramfs > /tmp/debconf-out.fifo < /tmp/debconf-in.fifo &
1896 # Save the PID so it can be killed later.
1897 DEBCONF_COMMUNICATE_PID="$!"
1899 if [ ! -p /tmp/debconf-in.fifo ] || [ ! -p /tmp/debconf-out.fifo ]
1901 log_warning_msg "failed to setup debconf-communicate channel"
1906 # These file descriptors must stay open until we're finished with
1907 # debconf-communicate.
1908 exec 4</tmp/debconf-out.fifo 3>/tmp/debconf-in.fifo
1910 maybe_break live-bottom
1911 log_begin_msg "Running /scripts/live-bottom\n"
1913 run_scripts /scripts/live-bottom
1916 if [ "${UNIONFS}" = unionfs-fuse ]
1918 umount "${rootmnt}/dev"
1921 # Close the fd's associated with debconf-communicate
1923 rm -f /tmp/debconf-in.fifo
1924 rm -f /tmp/debconf-out.fifo
1929 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1930 if [ -f /etc/live.conf ]
1932 cp /etc/live.conf "${rootmnt}/etc/"