5 for _SCRIPT in /lib/live/boot/*
13 export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
15 echo "/root/lib" >> /etc/ld.so.conf
16 echo "/root/usr/lib" >> /etc/ld.so.conf
18 mountpoint="/live/image"
19 alt_mountpoint="/media"
20 LIVE_MEDIA_PATH="live"
24 mkdir -p "${mountpoint}"
27 # Create /etc/mtab for debug purpose and future syncs
38 if [ ! -x "/bin/fstype" ]
40 # klibc not in path -> not in initramfs
41 export PATH="${PATH}:/usr/lib/klibc/bin"
44 # handle upgrade path from old udev (using udevinfo) to
45 # recent versions of udev (using udevadm info)
46 if [ -x /sbin/udevadm ]
48 udevinfo='/sbin/udevadm info'
53 old_root_overlay_label="live-rw"
54 old_home_overlay_label="home-rw"
55 custom_overlay_label="custom-ov"
56 root_snapshot_label="live-sn"
57 old_root_snapshot_label="live-sn"
58 home_snapshot_label="home-sn"
59 persistence_list="live-persistence.conf"
61 if [ ! -f /live.vars ]
70 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
72 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
74 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
86 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
92 uuid="$(cat /conf/uuid.conf)"
94 for try_uuid_file in "${path}/.disk/live-uuid"*
96 [ -e "${try_uuid_file}" ] || continue
98 try_uuid="$(cat "${try_uuid_file}")"
100 if [ "${uuid}" = "${try_uuid}" ]
109 get_backing_device ()
112 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
113 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
121 panic "Unrecognized live filesystem: ${1}"
126 match_files_in_dir ()
128 # Does any files match pattern ${1} ?
131 if [ "$(echo ${pattern})" != "${pattern}" ]
139 mount_images_in_directory ()
146 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
147 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
148 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
149 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
150 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
151 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
153 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
154 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
156 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
162 sysfs_path="${1#/sys}"
164 if [ -e /lib/udev/path_id ]
167 PATH_ID="/lib/udev/path_id"
169 # wheezy/sid (udev >= 174)
170 PATH_ID="/sbin/udevadm test-builtin path_id"
173 if ${PATH_ID} "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)"
176 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
179 elif echo ${sysfs_path} | grep -q "^/block/dm-"
182 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
194 skip_uuid_check="${3}"
196 # support for fromiso=.../isofrom=....
199 ISO_DEVICE=$(dirname $FROMISO)
200 if ! [ -b $ISO_DEVICE ]
202 # to support unusual device names like /dev/cciss/c0d0p1
203 # as well we have to identify the block device name, let's
204 # do that for up to 15 levels
206 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
208 ISO_DEVICE=$(dirname ${ISO_DEVICE})
209 [ -b "$ISO_DEVICE" ] && break
214 if [ "$ISO_DEVICE" = "/" ]
216 echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
218 fs_type=$(get_fstype "${ISO_DEVICE}")
219 if is_supported_fs ${fs_type}
222 mount -t $fs_type "$ISO_DEVICE" /live/fromiso
223 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
224 loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
225 devname="${loopdevname}"
227 echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
232 if [ -z "${devname}" ]
234 devname=$(sys2dev "${sysdev}")
237 if [ -d "${devname}" ]
239 mount -o bind "${devname}" $mountpoint || continue
241 if is_live_path $mountpoint
251 for device in ${devname}
256 if [ -x /scripts/local-top/lvm2 ]
258 ROOT="$device" resume="" /scripts/local-top/lvm2
263 # Adding raid support
264 if [ -x /scripts/local-top/mdadm ]
266 cp /conf/conf.d/md /conf/conf.d/md.orig
267 echo "MD_DEVS=$device " >> /conf/conf.d/md
268 /scripts/local-top/mdadm
269 mv /conf/conf.d/md.orig /conf/conf.d/md
276 [ -n "$device" ] && devname="$device"
278 [ -e "$devname" ] || continue
280 if [ -n "${LIVE_MEDIA_OFFSET}" ]
282 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
283 devname="${loopdevname}"
286 fstype=$(get_fstype "${devname}")
288 if is_supported_fs ${fstype}
290 devuid=$(blkid -o value -s UUID "$devname")
291 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
292 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
293 [ -n "$devuid" ] && echo "$devuid" >> $tried
295 if [ -n "${FINDISO}" ]
297 if [ -f ${mountpoint}/${FINDISO} ]
300 mkdir -p /live/findiso
301 mount -t ${fstype} -o ro,noatime "${devname}" /live/findiso
302 loopdevname=$(setup_loop "/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
303 devname="${loopdevname}"
304 mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint}
310 if is_live_path ${mountpoint} && \
311 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
316 umount ${mountpoint} 2>/dev/null
320 if [ -n "${LIVE_MEDIA_OFFSET}" ]
322 losetup -d "${loopdevname}"
332 # don't start autodetection before timeout has expired
333 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
335 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
341 # first look at the one specified in the command line
342 case "${LIVE_MEDIA}" in
344 for sysblock in $(removable_usb_dev "sys")
346 for dev in $(subdevices "${sysblock}")
348 if check_dev "${dev}"
358 for sysblock in $(removable_dev "sys")
360 for dev in $(subdevices "${sysblock}")
362 if check_dev "${dev}"
372 if [ ! -z "${LIVE_MEDIA}" ]
374 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
382 # or do the scan of block devices
383 # prefer removable devices over non-removable devices, so scan them first
384 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
386 for sysblock in $devices_to_scan
388 devname=$(sys2dev "${sysblock}")
389 [ -e "$devname" ] || continue
390 fstype=$(get_fstype "${devname}")
392 if /lib/udev/cdrom_id ${devname} > /dev/null
394 if check_dev "null" "${devname}"
398 elif is_nice_device "${sysblock}"
400 for dev in $(subdevices "${sysblock}")
402 if check_dev "${dev}"
407 elif [ "${fstype}" = "squashfs" -o \
408 "${fstype}" = "btrfs" -o \
409 "${fstype}" = "ext2" -o \
410 "${fstype}" = "ext3" -o \
411 "${fstype}" = "ext4" -o \
412 "${fstype}" = "jffs2" ]
414 # This is an ugly hack situation, the block device has
415 # an image directly on it. It's hopefully
416 # live-boot, so take it and run with it.
417 ln -s "${devname}" "${devname}.${fstype}"
418 echo "${devname}.${fstype}"
428 media_mountpoint="${1}"
430 log_begin_msg "Checking media integrity"
432 cd ${media_mountpoint}
433 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
440 log_success_msg "Everything ok, will reboot in 10 seconds."
443 umount ${media_mountpoint}
445 echo u > /proc/sysrq-trigger
446 echo b > /proc/sysrq-trigger
448 panic "Not ok, a media defect is likely, switch to VT8 for details."
454 if [ -x /scripts/local-top/cryptroot ]; then
455 /scripts/local-top/cryptroot
462 tail -f boot.log >&7 &
465 # Ensure 'panic' function is overridden
466 . /scripts/live-functions
470 maybe_break live-premount
471 log_begin_msg "Running /scripts/live-premount"
472 run_scripts /scripts/live-premount
475 # Needed here too because some things (*cough* udev *cough*)
476 # changes the timeout
478 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
482 livefs_root="${mountpoint}"
484 panic "Unable to find a live file system on the network"
487 if [ -n "${ISCSI_PORTAL}" ]
489 do_iscsi && livefs_root="${mountpoint}"
490 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
492 # Do a local boot from hd
495 if [ -x /usr/bin/memdiskfind ]
497 MEMDISK=$(/usr/bin/memdiskfind)
501 # We found a memdisk, set up phram
502 modprobe phram phram=memdisk,${MEMDISK}
504 # Load mtdblock, the memdisk will be /dev/mtdblock0
509 # Scan local devices for the image
511 while [ "$i" -lt 60 ]
513 livefs_root=$(find_livefs ${i})
515 if [ -n "${livefs_root}" ]
526 if [ -z "${livefs_root}" ]
528 panic "Unable to find a medium containing a live file system"
531 if [ "${INTEGRITY_CHECK}" ]
533 integrity_check "${livefs_root}"
541 live_dest="${TODISK}"
544 if [ "${live_dest}" ]
546 log_begin_msg "Copying live media to ${live_dest}"
547 copy_live_to "${livefs_root}" "${live_dest}"
551 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
552 # because the mountpoint is left behind in /proc/mounts, so let's get
553 # rid of it when running from RAM
554 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
556 losetup -d /dev/loop0
558 if is_mountpoint /live/fromiso
561 rmdir --ignore-fail-on-non-empty /live/fromiso \
562 >/dev/null 2>&1 || true
566 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
568 setup_unionfs "${livefs_root}" "${rootmnt}"
571 mac="$(echo ${mac} | sed 's/-//g')"
572 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
576 if [ -n "${ROOT_PID}" ] ; then
577 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
582 # unionfs-fuse needs /dev to be bind-mounted for the duration of
583 # live-bottom; udev's init script will take care of things after that
584 if [ "${UNIONTYPE}" = unionfs-fuse ]
586 mount -n -o bind /dev "${rootmnt}/dev"
589 # Move to the new root filesystem so that programs there can get at it.
590 if [ ! -d /root/live/image ]
592 mkdir -p /root/live/image
593 mount --move /live/image /root/live/image
596 # aufs2 in kernel versions around 2.6.33 has a regression:
597 # directories can't be accessed when read for the first the time,
598 # causing a failure for example when accessing /var/lib/fai
599 # when booting FAI, this simple workaround solves it
600 ls /root/* >/dev/null 2>&1
602 # Move findiso directory to the new root filesystem so that programs there can get at it.
603 if [ -d /live/findiso ] && [ ! -d /root/live/findiso ]
605 mkdir -p /root/live/findiso
606 mount -n --move /live/findiso /root/live/findiso
609 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
610 # because the mountpoint is left behind in /proc/mounts, so let's get
611 # rid of it when running from RAM
612 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
614 losetup -d /dev/loop0
616 if is_mountpoint /root/live/findiso
618 umount /root/live/findiso
619 rmdir --ignore-fail-on-non-empty /root/live/findiso \
620 >/dev/null 2>&1 || true
624 # copy snapshot configuration if exists
625 if [ -f snapshot.conf ]
627 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
628 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
630 mkdir -p "${rootmnt}/etc/live/boot.d"
632 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
636 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
638 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
639 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
643 maybe_break live-bottom
644 log_begin_msg "Running /scripts/live-bottom\n"
646 run_scripts /scripts/live-bottom
649 if [ "${UNIONFS}" = unionfs-fuse ]
651 umount "${rootmnt}/dev"
657 [ -w "${rootmnt}/var/log/" ] && mkdir -p /var/log/live && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null