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 . /scripts/live-helpers
40 if [ ! -f /live.vars ]
49 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
51 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
53 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
65 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
71 uuid="$(cat /conf/uuid.conf)"
73 for try_uuid_file in "${path}/.disk/live-uuid"*
75 [ -e "${try_uuid_file}" ] || continue
77 try_uuid="$(cat "${try_uuid_file}")"
79 if [ "${uuid}" = "${try_uuid}" ]
91 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
92 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
100 panic "Unrecognized live filesystem: ${1}"
105 match_files_in_dir ()
107 # Does any files match pattern ${1} ?
110 if [ "$(echo ${pattern})" != "${pattern}" ]
118 mount_images_in_directory ()
125 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
126 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
127 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
128 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
129 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
130 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
132 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
133 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
135 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
141 sysfs_path="${1#/sys}"
143 if [ -e /lib/udev/path_id ]
146 PATH_ID="/lib/udev/path_id"
148 # wheezy/sid (udev >= 174)
149 PATH_ID="/sbin/udevadm test-builtin path_id"
152 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)"
155 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
158 elif echo ${sysfs_path} | grep -q "^/block/dm-"
161 elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
173 skip_uuid_check="${3}"
175 # support for fromiso=.../isofrom=....
178 ISO_DEVICE=$(dirname $FROMISO)
179 if ! [ -b $ISO_DEVICE ]
181 # to support unusual device names like /dev/cciss/c0d0p1
182 # as well we have to identify the block device name, let's
183 # do that for up to 15 levels
185 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
187 ISO_DEVICE=$(dirname ${ISO_DEVICE})
188 [ -b "$ISO_DEVICE" ] && break
193 if [ "$ISO_DEVICE" = "/" ]
195 echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
197 fs_type=$(get_fstype "${ISO_DEVICE}")
198 if is_supported_fs ${fs_type}
201 mount -t $fs_type "$ISO_DEVICE" /live/fromiso
202 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
203 loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
204 devname="${loopdevname}"
206 echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
211 if [ -z "${devname}" ]
213 devname=$(sys2dev "${sysdev}")
216 if [ -d "${devname}" ]
218 mount -o bind "${devname}" $mountpoint || continue
220 if is_live_path $mountpoint
230 for device in ${devname}
235 if [ -x /scripts/local-top/lvm2 ]
237 ROOT="$device" resume="" /scripts/local-top/lvm2
242 # Adding raid support
243 if [ -x /scripts/local-top/mdadm ]
245 cp /conf/conf.d/md /conf/conf.d/md.orig
246 echo "MD_DEVS=$device " >> /conf/conf.d/md
247 /scripts/local-top/mdadm
248 mv /conf/conf.d/md.orig /conf/conf.d/md
255 [ -n "$device" ] && devname="$device"
257 [ -e "$devname" ] || continue
259 if [ -n "${LIVE_MEDIA_OFFSET}" ]
261 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
262 devname="${loopdevname}"
265 fstype=$(get_fstype "${devname}")
267 if is_supported_fs ${fstype}
269 devuid=$(blkid -o value -s UUID "$devname")
270 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
271 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
272 [ -n "$devuid" ] && echo "$devuid" >> $tried
274 if [ -n "${FINDISO}" ]
276 if [ -f ${mountpoint}/${FINDISO} ]
279 mkdir -p /live/findiso
280 mount -t ${fstype} -o ro,noatime "${devname}" /live/findiso
281 loopdevname=$(setup_loop "/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
282 devname="${loopdevname}"
283 mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint}
289 if is_live_path ${mountpoint} && \
290 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
295 umount ${mountpoint} 2>/dev/null
299 if [ -n "${LIVE_MEDIA_OFFSET}" ]
301 losetup -d "${loopdevname}"
311 # don't start autodetection before timeout has expired
312 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
314 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
320 # first look at the one specified in the command line
321 case "${LIVE_MEDIA}" in
323 for sysblock in $(removable_usb_dev "sys")
325 for dev in $(subdevices "${sysblock}")
327 if check_dev "${dev}"
337 for sysblock in $(removable_dev "sys")
339 for dev in $(subdevices "${sysblock}")
341 if check_dev "${dev}"
351 if [ ! -z "${LIVE_MEDIA}" ]
353 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
361 # or do the scan of block devices
362 # prefer removable devices over non-removable devices, so scan them first
363 devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
365 for sysblock in $devices_to_scan
367 devname=$(sys2dev "${sysblock}")
368 [ -e "$devname" ] || continue
369 fstype=$(get_fstype "${devname}")
371 if /lib/udev/cdrom_id ${devname} > /dev/null
373 if check_dev "null" "${devname}"
377 elif is_nice_device "${sysblock}"
379 for dev in $(subdevices "${sysblock}")
381 if check_dev "${dev}"
386 elif [ "${fstype}" = "squashfs" -o \
387 "${fstype}" = "btrfs" -o \
388 "${fstype}" = "ext2" -o \
389 "${fstype}" = "ext3" -o \
390 "${fstype}" = "ext4" -o \
391 "${fstype}" = "jffs2" ]
393 # This is an ugly hack situation, the block device has
394 # an image directly on it. It's hopefully
395 # live-boot, so take it and run with it.
396 ln -s "${devname}" "${devname}.${fstype}"
397 echo "${devname}.${fstype}"
407 media_mountpoint="${1}"
409 log_begin_msg "Checking media integrity"
411 cd ${media_mountpoint}
412 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
419 log_success_msg "Everything ok, will reboot in 10 seconds."
422 umount ${media_mountpoint}
424 echo u > /proc/sysrq-trigger
425 echo b > /proc/sysrq-trigger
427 panic "Not ok, a media defect is likely, switch to VT8 for details."
433 if [ -x /scripts/local-top/cryptroot ]; then
434 /scripts/local-top/cryptroot
441 tail -f boot.log >&7 &
444 # Ensure 'panic' function is overridden
445 . /scripts/live-functions
449 maybe_break live-premount
450 log_begin_msg "Running /scripts/live-premount"
451 run_scripts /scripts/live-premount
454 # Needed here too because some things (*cough* udev *cough*)
455 # changes the timeout
457 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
461 livefs_root="${mountpoint}"
463 panic "Unable to find a live file system on the network"
466 if [ -n "${ISCSI_PORTAL}" ]
468 do_iscsi && livefs_root="${mountpoint}"
469 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
471 # Do a local boot from hd
474 if [ -x /usr/bin/memdiskfind ]
476 MEMDISK=$(/usr/bin/memdiskfind)
480 # We found a memdisk, set up phram
481 modprobe phram phram=memdisk,${MEMDISK}
483 # Load mtdblock, the memdisk will be /dev/mtdblock0
488 # Scan local devices for the image
490 while [ "$i" -lt 60 ]
492 livefs_root=$(find_livefs ${i})
494 if [ -n "${livefs_root}" ]
505 if [ -z "${livefs_root}" ]
507 panic "Unable to find a medium containing a live file system"
510 if [ "${INTEGRITY_CHECK}" ]
512 integrity_check "${livefs_root}"
520 live_dest="${TODISK}"
523 if [ "${live_dest}" ]
525 log_begin_msg "Copying live media to ${live_dest}"
526 copy_live_to "${livefs_root}" "${live_dest}"
530 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
531 # because the mountpoint is left behind in /proc/mounts, so let's get
532 # rid of it when running from RAM
533 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
535 losetup -d /dev/loop0
537 if is_mountpoint /live/fromiso
540 rmdir --ignore-fail-on-non-empty /live/fromiso \
541 >/dev/null 2>&1 || true
545 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
547 setup_unionfs "${livefs_root}" "${rootmnt}"
550 mac="$(echo ${mac} | sed 's/-//g')"
551 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
555 if [ -n "${ROOT_PID}" ] ; then
556 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
561 # unionfs-fuse needs /dev to be bind-mounted for the duration of
562 # live-bottom; udev's init script will take care of things after that
563 if [ "${UNIONTYPE}" = unionfs-fuse ]
565 mount -n -o bind /dev "${rootmnt}/dev"
568 # Move to the new root filesystem so that programs there can get at it.
569 if [ ! -d /root/live/image ]
571 mkdir -p /root/live/image
572 mount --move /live/image /root/live/image
575 # aufs2 in kernel versions around 2.6.33 has a regression:
576 # directories can't be accessed when read for the first the time,
577 # causing a failure for example when accessing /var/lib/fai
578 # when booting FAI, this simple workaround solves it
579 ls /root/* >/dev/null 2>&1
581 # Move findiso directory to the new root filesystem so that programs there can get at it.
582 if [ -d /live/findiso ] && [ ! -d /root/live/findiso ]
584 mkdir -p /root/live/findiso
585 mount -n --move /live/findiso /root/live/findiso
588 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
589 # because the mountpoint is left behind in /proc/mounts, so let's get
590 # rid of it when running from RAM
591 if [ -n "$FINDISO" ] && [ "${TORAM}" ]
593 losetup -d /dev/loop0
595 if is_mountpoint /root/live/findiso
597 umount /root/live/findiso
598 rmdir --ignore-fail-on-non-empty /root/live/findiso \
599 >/dev/null 2>&1 || true
603 # copy snapshot configuration if exists
604 if [ -f snapshot.conf ]
606 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
607 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
609 mkdir -p "${rootmnt}/etc/live/boot.d"
611 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
615 if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
617 log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
618 cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
622 maybe_break live-bottom
623 log_begin_msg "Running /scripts/live-bottom\n"
625 run_scripts /scripts/live-bottom
628 if [ "${UNIONFS}" = unionfs-fuse ]
630 umount "${rootmnt}/dev"
636 [ -w "${rootmnt}/var/log/" ] && mkdir -p /var/log/live && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null