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-)"
617 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
629 copyto="${copyfrom}_swap"
631 if [ -z "${MODULETORAM}" ]
633 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "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 log_begin_msg "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}" ]
691 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
692 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
694 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
699 echo " * Copying whole medium to RAM" 1>/dev/console
700 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
702 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
703 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} # "cp -a" from busybox also copies hidden files
708 mount -r -o move ${copyto} ${copyfrom}
719 modprobe -q af_packet # For DHCP
721 if [ -x /sbin/udevadm ]
732 ipconfig ${DEVICE} | tee /netboot.config
734 # source relevant ipconfig output
735 OLDHOSTNAME=${HOSTNAME}
736 . /tmp/net-${DEVICE}.conf
737 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
740 # Check if we have a network device at all
741 if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
742 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
743 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
744 ! ls /sys/class/net/ra0 > /dev/null 2>&1
746 panic "No supported network device found, maybe a non-mainline driver is required."
749 if [ "${NFSROOT}" = "auto" ]
751 NFSROOT=${ROOTSERVER}:${ROOTPATH}
754 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
760 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
762 NFSROOT=${ROOTSERVER}:${NFSROOT}
765 log_begin_msg "Trying netboot from ${NFSROOT}"
767 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
784 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
785 mount -t ramfs ram "${mountpoint}"
788 for webfile in HTTPFS FTPFS FETCH
790 url="$(eval echo \"\$\{${webfile}\}\")"
791 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
795 case "${extension}" in
797 if [ "${webfile}" = "FETCH" ]
801 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
802 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
803 lfile="$(basename $url)"
804 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
805 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
809 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
810 wget "${url}" -O "${dest}/$(basename ${url})"
814 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
815 if [ "${webfile}" = "FTPFS" ]
817 FUSE_MOUNT="curlftpfs"
818 url="$(dirname ${url})"
823 $FUSE_MOUNT "${url}" "${dest}"
825 [ ${?} -eq 0 ] && rc=0
826 [ "${extension}" = "tgz" ] && live_dest="ram"
831 log_begin_msg "Unrecognized archive extension for ${url}"
839 umount "${mountpoint}"
851 if [ -z "${NFSOPTS}" ]
856 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
858 # FIXME: This while loop is an ugly HACK round an nfs bug
860 while [ "$i" -lt 60 ]
862 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
874 if [ -x "/sbin/mount.cifs" ]
876 if [ -z "${NFSOPTS}" ]
878 CIFSOPTS="-ouser=root,password="
880 CIFSOPTS="${NFSOPTS}"
883 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
886 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
900 size=$(fs_size "${fromdev}" "" "used")
902 if [ -b "${fromdev}" ]
905 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
907 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
908 freespace=$(df -k | awk '/'${todev}'/{print $4}')
910 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo))
913 tomount="/mnt/tmpsnap"
915 if [ ! -d "${tomount}" ]
917 mkdir -p "${tomount}"
920 fstype=$(get_fstype "${fromdev}")
922 if [ -n "${fstype}" ]
925 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
926 cp -a "${tomount}"/* ${todir}
929 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
934 if echo ${fromdev} | grep -qs loop
936 losetup -d "${fromdev}"
943 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
949 # Look for ${snap_label}.* in block devices
952 if [ "${PERSISTENT}" != "nofiles" ]
954 # search for image files
955 snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3 ${snap_label}.ext4 ${snap_label}.jffs2")
958 if [ -z "${snapdata}" ]
960 snapdata=$(find_cow_device "${snap_label}")
967 # copy the contents of previously found snapshot to ${snap_mount}
968 # and remember the device and filename for resync on exit in live-initramfs.init
974 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
976 log_success_msg "found snapshot: ${snapdata}"
977 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
978 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
979 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
982 if ! try_mount "${snapdev}" "${snapback}" "ro"
987 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
989 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
990 dev=$(get_backing_device "${snapback}/${snapfile}")
992 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
997 zcat "${snapback}/${snapfile}" | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1
999 if [ "${RES}" != "0" ]
1001 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\""
1006 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1008 if [ "${RES}" != "0" ]
1010 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1013 elif [ -b "${snapdata}" ]
1015 # Try to find if it could be a snapshot partition
1017 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1018 if echo "${dev}" | grep -qs loop
1020 # strange things happens, user confused?
1021 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1022 snapfile=$(basename ${snaploop})
1023 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1028 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1030 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1033 if [ -n "${snapfile}" ]
1035 # it was a loop device, user confused
1040 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1044 echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1050 image_directory="${1}"
1052 addimage_directory="${3}"
1053 modprobe -q -b ${UNIONTYPE}
1055 # run-init can't deal with images in a subdir, but we're going to
1056 # move all of these away before it runs anyway. No, we're not,
1057 # put them in / since move-mounting them into / breaks mono and
1062 # Let's just mount the read-only file systems first
1065 minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
1067 if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
1069 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
1071 elif [ "${UNIONTYPE}" = "aufs" ]
1078 if [ -z "${PLAIN_ROOT}" ]
1080 # Read image names from ${MODULE}.module if it exists
1081 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1083 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1085 image_string="${image_string} ${image_directory}/${IMAGE}"
1087 elif [ -e "${image_directory}/${MODULE}.module" ]
1089 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1091 image_string="${image_string} ${image_directory}/${IMAGE}"
1094 # ${MODULE}.module does not exist, create a list of images
1095 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1097 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1099 if [ -e "${IMAGE}" ]
1101 image_string="${image_string} ${IMAGE}"
1106 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1108 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1110 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1112 if [ -e "${IMAGE}" ]
1114 image_string="${image_string} ${IMAGE}"
1121 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1124 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1128 for image in ${image_string}
1130 imagename=$(basename "${image}")
1132 export image devname
1133 maybe_break live-realpremount
1134 log_begin_msg "Running /scripts/live-realpremount"
1135 run_scripts /scripts/live-realpremount
1138 if [ -d "${image}" ]
1140 # it is a plain directory: do nothing
1141 rofsstring="${image}=${roopt}:${rofsstring}"
1142 rofslist="${image} ${rofslist}"
1143 elif [ -f "${image}" ]
1145 if losetup --help 2>&1 | grep -q -- "-r\b"
1147 backdev=$(get_backing_device "${image}" "-r")
1149 backdev=$(get_backing_device "${image}")
1151 fstype=$(get_fstype "${backdev}")
1153 if [ "${fstype}" = "unknown" ]
1155 panic "Unknown file system type on ${backdev} (${image})"
1158 if [ -z "${fstype}" ]
1160 fstype="${imagename##*.}"
1161 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1164 mkdir -p "${croot}/${imagename}"
1165 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1166 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}"
1171 # we have a plain root system
1172 mkdir -p "${croot}/filesystem"
1173 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1174 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}"
1176 mount -o bind ${croot}/filesystem $mountpoint
1180 rofsstring=${rofsstring%:}
1184 # Looking for "${root_persistence}" device or file
1185 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1188 num_block=$(ls -l /sys/block | wc -l)
1189 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1191 modprobe -q -b ${module}
1194 if [ -x /sbin/udevadm ]
1205 # For some reason, udevsettle does not block in this scenario,
1206 # so we sleep for a little while.
1208 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1209 for timeout in 5 4 3 2 1
1213 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1219 # search for label and files (this could be hugely optimized)
1220 cowprobe=$(find_cow_device "${root_persistence}")
1221 if [ -b "${cowprobe}" ]
1223 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1224 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1225 # snapshots to be sure to really store some e.g key config files,
1226 # but not on the same media
1227 blacklistdev="${cowprobe}"
1228 PERSISTENCE_IS_ON="1"
1229 export PERSISTENCE_IS_ON
1231 # homecow just mount something on /home, this should be generalized some way
1232 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1233 if [ -b "${homecow}" ]
1235 PERSISTENCE_IS_ON="1"
1236 export PERSISTENCE_IS_ON
1238 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1239 # This second type should be removed when snapshot will get smarter,
1240 # hence when "/etc/live-snapshot*list" will be supported also by
1241 # ext2|ext3|ext4|jffs2 snapshot types.
1242 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1244 if [ -b "${cowprobe}" ]
1246 cowdevice=${cowprobe}
1247 cow_fstype=$(get_fstype "${cowprobe}")
1248 cow_mountopt="rw,noatime"
1250 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1252 fsck -y ${cowdevice}
1255 log_warning_msg "Unable to find the persistent medium"
1258 cow_mountopt="rw,noatime,mode=755"
1260 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1262 # check if there are any nfs options
1263 if echo ${NFS_COW}|grep -q ','
1265 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1266 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1268 nfs_cow_opts="-o nolock"
1274 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1277 panic "unable to determine mac address"
1282 cow_mountopt="rw,noatime,mode=755"
1285 if [ "${cow_fstype}" = "nfs" ]
1288 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1289 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1290 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1292 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1293 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1296 rofscount=$(echo ${rofslist} |wc -w)
1298 if [ -n "${EXPOSED_ROOT}" ]
1300 if [ ${rofscount} -ne 1 ]
1302 panic "only one RO file system supported with exposedroot: ${rofslist}"
1304 exposedrootfs=${rofslist%% }
1306 mount --bind ${exposedrootfs} ${rootmnt} || \
1307 panic "bind mount of ${exposedrootfs} failed"
1309 if [ -z "${SKIP_UNION_MOUNTS}" ]
1311 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1316 for dir in ${cow_dirs}; do
1318 mount -t ${UNIONTYPE} \
1319 -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro \
1320 ${UNIONTYPE} "${rootmnt}${dir}" || \
1321 panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option \
1322 rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro"
1325 mount -t ${UNIONTYPE} -o noatime,dirs=/cow=rw:${rofsstring} \
1326 ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on \
1327 ${rootmnt} failed with option noatime,dirs=/cow=rw:${rofsstring}"
1330 # Correct the permissions of /:
1331 chmod 0755 "${rootmnt}"
1333 # tmpfs file systems
1335 mkdir -p "${rootmnt}/live"
1336 mount -t tmpfs tmpfs ${rootmnt}/live
1338 # Adding other custom mounts
1339 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1341 # directly mount /home
1342 # FIXME: add a custom mounts configurable system
1344 if [ -b "${homecow}" ]
1346 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1347 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1349 log_warning_msg "Unable to find the persistent home medium"
1352 # Look for other snapshots to copy in
1353 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1354 # This second type should be removed when snapshot grow smarter
1355 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1358 if [ -n "${SHOWMOUNTS}" ]
1360 for d in ${rofslist}
1362 mkdir -p "${rootmnt}/live/${d##*/}"
1366 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1370 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1376 # shows cow fs on /cow for use by live-snapshot
1377 mkdir -p "${rootmnt}/live/cow"
1378 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"
1385 skip_uuid_check="${3}"
1387 if [ -z "${devname}" ]
1389 devname=$(sys2dev "${sysdev}")
1392 if [ -d "${devname}" ]
1394 mount -o bind "${devname}" $mountpoint || continue
1396 if is_live_path $mountpoint
1405 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1407 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1408 devname="${loopdevname}"
1411 fstype=$(get_fstype "${devname}")
1413 if is_supported_fs ${fstype}
1415 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1417 if is_live_path ${mountpoint} && \
1418 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1423 umount ${mountpoint}
1427 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1429 losetup -d "${loopdevname}"
1439 # don't start autodetection before timeout has expired
1440 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1442 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1448 # first look at the one specified in the command line
1449 case "${LIVE_MEDIA}" in
1451 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1453 if [ "$(cat ${sysblock}/removable)" = "1" ]
1455 if readlink ${sysblock} | grep -q usb ||
1456 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1458 for dev in $(subdevices "${sysblock}")
1460 if check_dev "${dev}"
1471 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1473 if [ "$(cat ${sysblock}/removable)" = "1" ]
1475 for dev in $(subdevices "${sysblock}")
1477 if check_dev "${dev}"
1487 if [ ! -z "${LIVE_MEDIA}" ]
1489 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1497 # or do the scan of block devices
1498 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1500 devname=$(sys2dev "${sysblock}")
1501 fstype=$(get_fstype "${devname}")
1503 if /lib/udev/cdrom_id ${devname} > /dev/null
1505 if check_dev "null" "${devname}"
1509 elif is_nice_device "${sysblock}"
1511 for dev in $(subdevices "${sysblock}")
1513 if check_dev "${dev}"
1518 elif [ "${fstype}" = "squashfs" -o \
1519 "${fstype}" = "ext2" -o \
1520 "${fstype}" = "ext3" -o \
1521 "${fstype}" = "ext4" -o \
1522 "${fstype}" = "jffs2" ]
1524 # This is an ugly hack situation, the block device has
1525 # an image directly on it. It's hopefully
1526 # live-initramfs, so take it and run with it.
1527 ln -s "${devname}" "${devname}.${fstype}"
1528 echo "${devname}.${fstype}"
1536 set_usplash_timeout ()
1538 if [ -x /sbin/usplash_write ]
1540 /sbin/usplash_write "TIMEOUT 120"
1541 else if [ -x /sbin/splashy_update ] ; then
1542 /sbin/splashy_update "TIMEOUT 120"
1548 media_mountpoint="${1}"
1550 log_begin_msg "Checking media integrity"
1552 cd ${media_mountpoint}
1553 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1558 if [ "${RC}" -eq 0 ]
1560 log_success_msg "Everything ok, will reboot in 10 seconds."
1563 umount ${media_mountpoint}
1565 echo u > /proc/sysrq-trigger
1566 echo b > /proc/sysrq-trigger
1568 panic "Not ok, a media defect is likely, switch to VT8 for details."
1574 if [ -x /scripts/local-top/cryptroot ]; then
1575 /scripts/local-top/cryptroot
1582 tail -f live.log >&7 &
1585 # Ensure 'panic' function is overridden
1586 . /scripts/live-functions
1592 maybe_break live-premount
1593 log_begin_msg "Running /scripts/live-premount"
1594 run_scripts /scripts/live-premount
1597 # Needed here too because some things (*cough* udev *cough*)
1598 # changes the timeout
1602 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1606 livefs_root="${mountpoint}"
1608 panic "Unable to find a live file system on the network"
1611 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1613 # Do a local boot from hd
1616 # Scan local devices for the image
1618 while [ "$i" -lt 60 ]
1620 livefs_root=$(find_livefs ${i})
1622 if [ -n "${livefs_root}" ]
1633 if [ -z "${livefs_root}" ]
1635 panic "Unable to find a medium containing a live file system"
1638 if [ "${INTEGRITY_CHECK}" ]
1640 integrity_check "${livefs_root}"
1646 elif [ "${TODISK}" ]
1648 live_dest="${TODISK}"
1651 if [ "${live_dest}" ]
1653 log_begin_msg "Copying live media to ${live_dest}"
1654 copy_live_to "${livefs_root}" "${live_dest}"
1658 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1660 setup_unionfs "${livefs_root}" "${rootmnt}"
1663 mac="$(echo ${mac} | sed 's/-//g')"
1664 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1669 maybe_break live-bottom
1670 log_begin_msg "Running /scripts/live-bottom\n"
1672 run_scripts /scripts/live-bottom
1678 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null