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)
53 ACCESS="${ARGUMENT#access=}"
58 DEFCONSOLE="${ARGUMENT#*=}"
70 FETCH="${ARGUMENT#fetch=}"
75 FORCEPERSISTENTFSCK="Yes"
76 export FORCEPERSISTENTFSCK
80 HOOK="${ARGUMENT#hook=}"
85 FTPFS="${ARGUMENT#ftpfs=}"
90 HTTPFS="${ARGUMENT#httpfs=}"
95 HOSTNAME="${ARGUMENT#hostname=}"
97 export HOSTNAME LIVECONF
101 USERNAME="${ARGUMENT#username=}"
103 export USERNAME LIVECONF
107 USERFULLNAME="${ARGUMENT#userfullname=}"
109 export USERFULLNAME LIVECONF
118 INTEGRITY_CHECK="Yes"
119 export INTEGRITY_CHECK
123 STATICIP="${ARGUMENT#ip=}"
125 if [ -z "${STATICIP}" ]
133 keyb=*|kbd-chooser/method=*)
138 klayout=*|console-setup/layoutcode=*)
139 KLAYOUT="${ARGUMENT#*=}"
143 kvariant=*|console-setup/variantcode=*)
144 KVARIANT="${ARGUMENT#*=}"
148 kmodel=*|console-setup/modelcode=*)
149 KMODEL="${ARGUMENT#*=}"
154 KOPTIONS="${ARGUMENT#koptions=}"
163 live-media=*|bootfrom=*)
164 LIVE_MEDIA="${ARGUMENT#*=}"
168 live-media-encryption=*|encryption=*)
169 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
170 export LIVE_MEDIA_ENCRYPTION
174 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
175 export LIVE_MEDIA_OFFSET
179 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
180 export LIVE_MEDIA_PATH
183 live-media-timeout=*)
184 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
185 export LIVE_MEDIA_TIMEOUT
188 language=*|debian-installer/language=*)
189 language=${x#debian-installer/language=}
190 locale="$(lang2locale "$language")"
194 locale=*|debian-installer/locale=*)
195 LOCALE="${ARGUMENT#*=}"
200 MODULE="${ARGUMENT#module=}"
205 NETBOOT="${ARGUMENT#netboot=}"
210 NFSOPTS="${ARGUMENT#nfsopts=}"
215 NFS_COW="${ARGUMENT#nfscow=}"
220 NOACCESSIBILITY="Yes"
221 export NOACCESSIBILITY
245 NOCONSOLEKEYBOARD="Yes"
246 export NOCONSOLEKEYBOARD
270 NOKPERSONALIZER="Yes"
271 export NOKPERSONALIZER
275 NOLANGUAGESELECTOR="Yes"
276 export NOLANGUAGESELECTOR
290 NOPOWERMANAGEMENT="Yes"
291 export NOPOWERMANAGEMENT
295 NOPROGRAMCRASHES="Yes"
296 export NOPROGRAMCRASHES
315 NOUPDATENOTIFIER="Yes"
316 export NOUPDATENOTIFIER
331 export NOXSCREENSAVER
340 PERSISTENT="${ARGUMENT#persistent=}"
341 if [ -z "${PERSISTENT}" ]
349 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
350 export PERSISTENT_PATH
353 persistent-subtext=*)
354 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
355 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
356 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
357 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
365 preseed/file=*|file=*)
366 LOCATION="${ARGUMENT#*=}"
376 location="${ARGUMENT#url=}"
378 mount -o bind /sys /root/sys
379 mount -o bind /proc /root/proc
380 mount -o bind /dev /root/dev
382 mkdir -p /root/var/run/network
383 chroot /root dhclient eth0
384 chroot /root wget -P /tmp "${location}"
385 chroot /root ifconfig eth0 down
391 LOCATION="/tmp/$(basename "${location}")"
395 question="${ARGUMENT%%=*}"
396 value="${ARGUMENT#*=}"
397 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
417 TIMEZONE="${ARGUMENT#timezone=}"
427 TODISK="${ARGUMENT#todisk=}"
438 MODULETORAM="${ARGUMENT#toram=}"
439 export TORAM MODULETORAM
453 SKIP_UNION_MOUNTS="Yes"
454 export SKIP_UNION_MOUNTS
458 ROOT="${ARGUMENT#root=}"
463 UNIONTYPE="${ARGUMENT#union=}"
468 UTC="${ARGUMENT#utc=}"
478 XDRIVER="${ARGUMENT#xdriver=}"
483 XVIDEOMODE="${ARGUMENT#xvideomode=}"
489 # sort of compatibility with netboot.h from linux docs
490 if [ -z "${NETBOOT}" ]
492 if [ "${ROOT}" = "/dev/nfs" ]
496 elif [ "${ROOT}" = "/dev/cifs" ]
503 if [ -z "${MODULE}" ]
509 if [ -z "${UNIONTYPE}" ]
520 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
522 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
524 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
536 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
542 uuid="$(cat /conf/uuid.conf)"
544 for try_uuid_file in "${path}/.disk/live-uuid"*
546 [ -e "${try_uuid_file}" ] || continue
548 try_uuid="$(cat "${try_uuid_file}")"
550 if [ "${uuid}" = "${try_uuid}" ]
559 get_backing_device ()
562 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
563 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
571 panic "Unrecognized live filesystem: ${1}"
576 match_files_in_dir ()
578 # Does any files match pattern ${1} ?
581 if [ "$(echo ${pattern})" != "${pattern}" ]
589 mount_images_in_directory ()
596 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
597 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
598 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
599 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
600 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
601 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
603 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
604 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
606 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
612 sysfs_path="${1#/sys}"
614 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-(ide|scsi|usb))"
617 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
629 copyto="${copyfrom}_swap"
631 if [ -z "${MODULETORAM}" ]
633 size=$(fs_size "" ${copyfrom} "used")
635 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
637 if [ -f "${MODULETORAMFILE}" ]
639 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
641 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
646 if [ "${copytodev}" = "ram" ]
649 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo ) )
650 mount_options="-o size=${size}k"
655 # it should be a writable block device
656 if [ -b "${copytodev}" ]
660 fstype=$(get_fstype "${dev}")
661 freespace=$(fs_size "${dev}")
663 log_warning_msg "${copytodev} is not a block device."
668 if [ "${freespace}" -lt "${size}" ]
670 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
674 # begin copying (or uncompressing)
676 echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
677 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
679 if [ "${extension}" = "tgz" ]
682 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
683 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
684 mount -r -o move "${copyto}" "${rootmnt}"
687 if [ -n "${MODULETORAMFILE}" ]
689 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
691 cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
695 mount -r -o move ${copyto} ${copyfrom}
706 modprobe -q af_packet # For DHCP
708 if [ -x /sbin/udevadm ]
719 ipconfig ${DEVICE} | tee /netboot.config
721 # source relevant ipconfig output
722 OLDHOSTNAME=${HOSTNAME}
723 . /tmp/net-${DEVICE}.conf
724 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
727 # Check if we have a network device at all
728 if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
729 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
730 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
731 ! ls /sys/class/net/ra0 > /dev/null 2>&1
733 panic "No supported network device found, maybe a non-mainline driver is required."
736 if [ "${NFSROOT}" = "auto" ]
738 NFSROOT=${ROOTSERVER}:${ROOTPATH}
741 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
747 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
749 NFSROOT=${ROOTSERVER}:${NFSROOT}
752 log_begin_msg "Trying netboot from ${NFSROOT}"
754 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
771 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
772 mount -t ramfs ram "${mountpoint}"
775 for webfile in HTTPFS FTPFS FETCH
777 url="$(eval echo \"\$\{${webfile}\}\")"
778 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
782 case "${extension}" in
784 if [ "${webfile}" = "FETCH" ]
788 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
789 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
790 lfile="$(basename $url)"
791 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
792 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
796 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
797 wget "${url}" -O "${dest}/$(basename ${url})"
801 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
802 if [ "${webfile}" = "FTPFS" ]
804 FUSE_MOUNT="curlftpfs"
805 url="$(dirname ${url})"
810 $FUSE_MOUNT "${url}" "${dest}"
812 [ ${?} -eq 0 ] && rc=0
813 [ "${extension}" = "tgz" ] && live_dest="ram"
818 log_begin_msg "Unrecognized archive extension for ${url}"
826 umount "${mountpoint}"
838 if [ -z "${NFSOPTS}" ]
843 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
845 # FIXME: This while loop is an ugly HACK round an nfs bug
847 while [ "$i" -lt 60 ]
849 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
861 if [ -x "/sbin/mount.cifs" ]
863 if [ -z "${NFSOPTS}" ]
865 CIFSOPTS="-ouser=root,password="
867 CIFSOPTS="${NFSOPTS}"
870 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
873 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
887 size=$(fs_size "${fromdev}" "" "used")
889 if [ -b "${fromdev}" ]
892 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
894 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
895 freespace=$(df -k | awk '/'${todev}'/{print $4}')
897 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo))
900 tomount="/mnt/tmpsnap"
902 if [ ! -d "${tomount}" ]
904 mkdir -p "${tomount}"
907 fstype=$(get_fstype "${fromdev}")
909 if [ -n "${fstype}" ]
912 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
913 cp -a "${tomount}"/* ${todir}
916 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
921 if echo ${fromdev} | grep -qs loop
923 losetup -d "${fromdev}"
930 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
936 # Look for ${snap_label}.* in block devices
939 if [ "${PERSISTENT}" != "nofiles" ]
941 # search for image files
942 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3 ${snap_label}.ext4 ${snap_label}.jffs2")
945 if [ -z "${snapdata}" ]
947 snapdata=$(find_cow_device "${snap_label}")
954 # copy the contents of previously found snapshot to ${snap_mount}
955 # and remember the device and filename for resync on exit in live-initramfs.init
961 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
963 log_success_msg "found snapshot: ${snapdata}"
964 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
965 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
966 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
969 if ! try_mount "${snapdev}" "${snapback}" "ro"
974 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
976 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
977 dev=$(get_backing_device "${snapback}/${snapfile}")
979 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
984 zcat "${snapback}/${snapfile}" | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1
986 if [ "${RES}" != "0" ]
988 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\""
993 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
995 if [ "${RES}" != "0" ]
997 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1000 elif [ -b "${snapdata}" ]
1002 # Try to find if it could be a snapshot partition
1004 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1005 if echo "${dev}" | grep -qs loop
1007 # strange things happens, user confused?
1008 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1009 snapfile=$(basename ${snaploop})
1010 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1015 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1017 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1020 if [ -n "${snapfile}" ]
1022 # it was a loop device, user confused
1027 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1031 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1037 image_directory="${1}"
1039 addimage_directory="${3}"
1040 modprobe -q -b ${UNIONTYPE}
1042 # run-init can't deal with images in a subdir, but we're going to
1043 # move all of these away before it runs anyway. No, we're not,
1044 # put them in / since move-mounting them into / breaks mono and
1049 # Let's just mount the read-only file systems first
1052 minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
1054 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
1056 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
1058 elif [ "${UNIONTYPE}" = "aufs" ]
1065 if [ -z "${PLAIN_ROOT}" ]
1067 # Read image names from ${MODULE}.module if it exists
1068 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1070 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1072 image_string="${image_string} ${image_directory}/${IMAGE}"
1074 elif [ -e "${image_directory}/${MODULE}.module" ]
1076 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1078 image_string="${image_string} ${image_directory}/${IMAGE}"
1081 # ${MODULE}.module does not exist, create a list of images
1082 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1084 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1086 if [ -e "${IMAGE}" ]
1088 image_string="${image_string} ${IMAGE}"
1093 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1095 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1097 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1099 if [ -e "${IMAGE}" ]
1101 image_string="${image_string} ${IMAGE}"
1108 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1111 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1115 for image in ${image_string}
1117 imagename=$(basename "${image}")
1119 export image devname
1120 maybe_break live-realpremount
1121 log_begin_msg "Running /scripts/live-realpremount"
1122 run_scripts /scripts/live-realpremount
1125 if [ -d "${image}" ]
1127 # it is a plain directory: do nothing
1128 rofsstring="${image}=${roopt}:${rofsstring}"
1129 rofslist="${image} ${rofslist}"
1130 elif [ -f "${image}" ]
1132 if losetup --help 2>&1 | grep -q -- "-r\b"
1134 backdev=$(get_backing_device "${image}" "-r")
1136 backdev=$(get_backing_device "${image}")
1138 fstype=$(get_fstype "${backdev}")
1140 if [ "${fstype}" = "unknown" ]
1142 panic "Unknown file system type on ${backdev} (${image})"
1145 if [ -z "${fstype}" ]
1147 fstype="${imagename##*.}"
1148 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1151 mkdir -p "${croot}/${imagename}"
1152 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1153 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}"
1158 # we have a plain root system
1159 mkdir -p "${croot}/filesystem"
1160 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1161 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}"
1163 mount -o bind ${croot}/filesystem $mountpoint
1167 rofsstring=${rofsstring%:}
1171 # Looking for "${root_persistence}" device or file
1172 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1175 num_block=$(ls -l /sys/block | wc -l)
1176 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1178 modprobe -q -b ${module}
1181 if [ -x /sbin/udevadm ]
1192 # For some reason, udevsettle does not block in this scenario,
1193 # so we sleep for a little while.
1195 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1196 for timeout in 5 4 3 2 1
1200 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1206 # search for label and files (this could be hugely optimized)
1207 cowprobe=$(find_cow_device "${root_persistence}")
1208 if [ -b "${cowprobe}" ]
1210 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1211 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1212 # snapshots to be sure to really store some e.g key config files,
1213 # but not on the same media
1214 blacklistdev="${cowprobe}"
1215 PERSISTENCE_IS_ON="1"
1216 export PERSISTENCE_IS_ON
1218 # homecow just mount something on /home, this should be generalized some way
1219 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1220 if [ -b "${homecow}" ]
1222 PERSISTENCE_IS_ON="1"
1223 export PERSISTENCE_IS_ON
1225 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1226 # This second type should be removed when snapshot will get smarter,
1227 # hence when "/etc/live-snapshot*list" will be supported also by
1228 # ext2|ext3|ext4|jffs2 snapshot types.
1229 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1231 if [ -b "${cowprobe}" ]
1233 cowdevice=${cowprobe}
1234 cow_fstype=$(get_fstype "${cowprobe}")
1235 cow_mountopt="rw,noatime"
1237 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1239 fsck -y ${cowdevice}
1242 log_warning_msg "Unable to find the persistent medium"
1245 cow_mountopt="rw,noatime,mode=755"
1247 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1249 # check if there are any nfs options
1250 if echo ${NFS_COW}|grep -q ','
1252 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1253 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1255 nfs_cow_opts="-o nolock"
1261 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1264 panic "unable to determine mac address"
1269 cow_mountopt="rw,noatime,mode=755"
1272 if [ "${cow_fstype}" = "nfs" ]
1275 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1276 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1277 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1279 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1280 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1283 rofscount=$(echo ${rofslist} |wc -w)
1285 if [ -n "${EXPOSED_ROOT}" ]
1287 if [ ${rofscount} -ne 1 ]
1289 panic "only one RO file system supported with exposedroot: ${rofslist}"
1291 exposedrootfs=${rofslist%% }
1293 mount --bind ${exposedrootfs} ${rootmnt} || \
1294 panic "bind mount of ${exposedrootfs} failed"
1296 if [ -z "${SKIP_UNION_MOUNTS}" ]
1298 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1303 for dir in ${cow_dirs}; do
1305 mount -t ${UNIONTYPE} \
1306 -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro \
1307 ${UNIONTYPE} "${rootmnt}${dir}" || \
1308 panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option \
1309 rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro"
1312 mount -t ${UNIONTYPE} -o noatime,dirs=/cow=rw:${rofsstring} \
1313 ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on \
1314 ${rootmnt} failed with option noatime,dirs=/cow=rw:${rofsstring}"
1317 # Correct the permissions of /:
1318 chmod 0755 "${rootmnt}"
1320 # tmpfs file systems
1322 mkdir -p "${rootmnt}/live"
1323 mount -t tmpfs tmpfs ${rootmnt}/live
1325 # Adding other custom mounts
1326 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1328 # directly mount /home
1329 # FIXME: add a custom mounts configurable system
1331 if [ -b "${homecow}" ]
1333 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1334 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1336 log_warning_msg "Unable to find the persistent home medium"
1339 # Look for other snapshots to copy in
1340 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1341 # This second type should be removed when snapshot grow smarter
1342 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1345 if [ -n "${SHOWMOUNTS}" ]
1347 for d in ${rofslist}
1349 mkdir -p "${rootmnt}/live/${d##*/}"
1353 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1357 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1363 # shows cow fs on /cow for use by live-snapshot
1364 mkdir -p "${rootmnt}/live/cow"
1365 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"
1372 skip_uuid_check="${3}"
1374 if [ -z "${devname}" ]
1376 devname=$(sys2dev "${sysdev}")
1379 if [ -d "${devname}" ]
1381 mount -o bind "${devname}" $mountpoint || continue
1383 if is_live_path $mountpoint
1392 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1394 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1395 devname="${loopdevname}"
1398 fstype=$(get_fstype "${devname}")
1400 if is_supported_fs ${fstype}
1402 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1404 if is_live_path ${mountpoint} && \
1405 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1410 umount ${mountpoint}
1414 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1416 losetup -d "${loopdevname}"
1426 # don't start autodetection before timeout has expired
1427 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1429 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1435 # first look at the one specified in the command line
1436 case "${LIVE_MEDIA}" in
1438 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1440 if [ "$(cat ${sysblock}/removable)" = "1" ]
1442 if readlink ${sysblock} | grep -q usb ||
1443 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1445 for dev in $(subdevices "${sysblock}")
1447 if check_dev "${dev}"
1458 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1460 if [ "$(cat ${sysblock}/removable)" = "1" ]
1462 for dev in $(subdevices "${sysblock}")
1464 if check_dev "${dev}"
1474 if [ ! -z "${LIVE_MEDIA}" ]
1476 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1484 # or do the scan of block devices
1485 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1487 devname=$(sys2dev "${sysblock}")
1488 fstype=$(get_fstype "${devname}")
1490 if /lib/udev/cdrom_id ${devname} > /dev/null
1492 if check_dev "null" "${devname}"
1496 elif is_nice_device "${sysblock}"
1498 for dev in $(subdevices "${sysblock}")
1500 if check_dev "${dev}"
1505 elif [ "${fstype}" = "squashfs" -o \
1506 "${fstype}" = "ext2" -o \
1507 "${fstype}" = "ext3" -o \
1508 "${fstype}" = "ext4" -o \
1509 "${fstype}" = "jffs2" ]
1511 # This is an ugly hack situation, the block device has
1512 # an image directly on it. It's hopefully
1513 # live-initramfs, so take it and run with it.
1514 ln -s "${devname}" "${devname}.${fstype}"
1515 echo "${devname}.${fstype}"
1523 set_usplash_timeout ()
1525 if [ -x /sbin/usplash_write ]
1527 /sbin/usplash_write "TIMEOUT 120"
1528 else if [ -x /sbin/splashy_update ] ; then
1529 /sbin/splashy_update "TIMEOUT 120"
1535 media_mountpoint="${1}"
1537 log_begin_msg "Checking media integrity"
1539 cd ${media_mountpoint}
1540 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1545 if [ "${RC}" -eq 0 ]
1547 log_success_msg "Everything ok, will reboot in 10 seconds."
1550 umount ${media_mountpoint}
1552 echo u > /proc/sysrq-trigger
1553 echo b > /proc/sysrq-trigger
1555 panic "Not ok, a media defect is likely, switch to VT8 for details."
1561 if [ -x /scripts/local-top/cryptroot ]; then
1562 /scripts/local-top/cryptroot
1569 tail -f live.log >&7 &
1572 # Ensure 'panic' function is overridden
1573 . /scripts/live-functions
1579 maybe_break live-premount
1580 log_begin_msg "Running /scripts/live-premount"
1581 run_scripts /scripts/live-premount
1584 # Needed here too because some things (*cough* udev *cough*)
1585 # changes the timeout
1589 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1593 livefs_root="${mountpoint}"
1595 panic "Unable to find a live file system on the network"
1598 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1600 # Do a local boot from hd
1603 # Scan local devices for the image
1605 while [ "$i" -lt 60 ]
1607 livefs_root=$(find_livefs ${i})
1609 if [ -n "${livefs_root}" ]
1620 if [ -z "${livefs_root}" ]
1622 panic "Unable to find a medium containing a live file system"
1625 if [ "${INTEGRITY_CHECK}" ]
1627 integrity_check "${livefs_root}"
1633 elif [ "${TODISK}" ]
1635 live_dest="${TODISK}"
1638 if [ "${live_dest}" ]
1640 log_begin_msg "Copying live media to ${live_dest}"
1641 copy_live_to "${livefs_root}" "${live_dest}"
1645 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1647 setup_unionfs "${livefs_root}" "${rootmnt}"
1650 mac="$(echo ${mac} | sed 's/-//g')"
1651 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1656 maybe_break live-bottom
1657 log_begin_msg "Running /scripts/live-bottom\n"
1659 run_scripts /scripts/live-bottom
1665 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null