Adding upstream version 2.0~a5.
[debian-live-boot.git] / scripts / live
blob3e604f6162ecbe25c7cba758b4db44d6255e1510
1 #!/bin/sh
3 # set -e
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 alt_mountpoint="/media"
12 LIVE_MEDIA_PATH="live"
14 root_persistence="live-rw"
15 home_persistence="home-rw"
16 root_snapshot_label="live-sn"
17 home_snapshot_label="home-sn"
19 USERNAME="user"
20 USERFULLNAME="Live user"
21 HOSTNAME="host"
23 mkdir -p "${mountpoint}"
24 tried="/tmp/tried"
26 # Create /etc/mtab for debug purpose and future syncs
27 if [ ! -d /etc ]
28 then
29 mkdir /etc/
32 if [ ! -f /etc/mtab ]
33 then
34 touch /etc/mtab
37 . /scripts/live-helpers
39 if [ ! -f /live.vars ]
40 then
41 touch /live.vars
44 Arguments ()
46 PRESEEDS=""
47 LOCATIONS=""
49 for ARGUMENT in $(cat /proc/cmdline)
51 case "${ARGUMENT}" in
52 skipconfig)
53 NOACCESSIBILITY="Yes"
54 NOAUTOLOGIN="Yes"
55 NOCONSOLEKEYBOARD="Yes"
56 NOFASTBOOT="Yes"
57 NOFSTAB="Yes"
58 NONETWORKING="Yes"
59 NOXAUTOCONFIG="Yes"
61 export NOACCESSIBILITY NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NONETWORKING NOXAUTOCONFIG
64 access=*)
65 ACCESS="${ARGUMENT#access=}"
66 export ACCESS
69 console=*)
70 DEFCONSOLE="${ARGUMENT#*=}"
71 export DEFCONSOLE
74 debug)
75 DEBUG="Yes"
76 export DEBUG
78 set -x
81 dhcp)
82 # Force dhcp even while netbooting
83 # Use for debugging in case somebody works on fixing dhclient
84 DHCP="Force";
85 export DHCP
88 nodhcp)
89 unset DHCP
92 ethdevice=*)
93 DEVICE="${ARGUMENT#ethdevice=}"
94 export DEVICE
97 ethdevice=*)
98 ETHDEVICE="${ARGUMENT#ethdevice=}"
99 export ETHDEVICE
102 ethdevice-timeout=*)
103 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
104 export ETHDEV_TIMEOUT
107 fetch=*)
108 FETCH="${ARGUMENT#fetch=}"
109 export FETCH
112 forcepersistentfsck)
113 FORCEPERSISTENTFSCK="Yes"
114 export FORCEPERSISTENTFSCK
117 ftpfs=*)
118 FTPFS="${ARGUMENT#ftpfs=}"
119 export FTPFS
122 httpfs=*)
123 HTTPFS="${ARGUMENT#httpfs=}"
124 export HTTPFS
127 isofrom=*|fromiso=*)
128 FROMISO="${ARGUMENT#*=}"
129 export FROMISO
132 ignore_uuid)
133 IGNORE_UUID="Yes"
134 export IGNORE_UUID
137 integrity-check)
138 INTEGRITY_CHECK="Yes"
139 export INTEGRITY_CHECK
142 ip=*)
143 STATICIP="${ARGUMENT#ip=}"
145 if [ -z "${STATICIP}" ]
146 then
147 STATICIP="frommedia"
150 export STATICIP
153 keyb=*|kbd-chooser/method=*)
154 KBD="${ARGUMENT#*=}"
155 export KBD
158 klayout=*|console-setup/layoutcode=*)
159 KLAYOUT="${ARGUMENT#*=}"
160 export KLAYOUT
163 kvariant=*|console-setup/variantcode=*)
164 KVARIANT="${ARGUMENT#*=}"
165 export KVARIANT
168 kmodel=*|console-setup/modelcode=*)
169 KMODEL="${ARGUMENT#*=}"
170 export KMODEL
173 koptions=*)
174 KOPTIONS="${ARGUMENT#koptions=}"
175 export KOPTIONS
178 live-getty)
179 LIVE_GETTY="1"
180 export LIVE_GETTY
183 live-media=*|bootfrom=*)
184 LIVE_MEDIA="${ARGUMENT#*=}"
185 export LIVE_MEDIA
188 live-media-encryption=*|encryption=*)
189 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
190 export LIVE_MEDIA_ENCRYPTION
193 live-media-offset=*)
194 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
195 export LIVE_MEDIA_OFFSET
198 live-media-path=*)
199 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
200 export LIVE_MEDIA_PATH
203 live-media-timeout=*)
204 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
205 export LIVE_MEDIA_TIMEOUT
208 module=*)
209 MODULE="${ARGUMENT#module=}"
210 export MODULE
213 netboot=*)
214 NETBOOT="${ARGUMENT#netboot=}"
215 export NETBOOT
218 nfsopts=*)
219 NFSOPTS="${ARGUMENT#nfsopts=}"
220 export NFSOPTS
223 nfscow=*)
224 NFS_COW="${ARGUMENT#nfscow=}"
225 export NFS_COW
228 noaccessibility)
229 NOACCESSIBILITY="Yes"
230 export NOACCESSIBILITY
233 noautologin)
234 NOAUTOLOGIN="Yes"
235 export NOAUTOLOGIN
238 noconsolekeyboard)
239 NOCONSOLEKEYBOARD="Yes"
240 export NOCONSOLEKEYBOARD
243 nofastboot)
244 NOFASTBOOT="Yes"
245 export NOFASTBOOT
248 nofstab)
249 NOFSTAB="Yes"
250 export NOFSTAB
253 nonetworking)
254 NONETWORKING="Yes"
255 export NONETWORKING
258 swapon)
259 SWAPON="Yes"
260 export SWAPON
263 noxautoconfig)
264 NOXAUTOCONFIG="Yes"
265 export NOXAUTOCONFIG
268 persistent)
269 PERSISTENT="Yes"
270 export PERSISTENT
273 persistent=*)
274 PERSISTENT="${ARGUMENT#persistent=}"
275 if [ -z "${PERSISTENT}" ]
276 then
277 PERSISTENT="Yes"
279 export PERSISTENT
282 persistent-path=*)
283 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
284 export PERSISTENT_PATH
287 persistent-subtext=*)
288 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
289 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
290 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
291 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
294 nopersistent)
295 NOPERSISTENT="Yes"
296 export NOPERSISTENT
299 quickusbmodules)
300 QUICKUSBMODULES="Yes"
301 export QUICKUSBMODULES
304 preseed/file=*|file=*)
305 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
306 export LOCATIONS
309 nopreseed)
310 NOPRESEED="Yes"
311 export NOPRESEED
314 */*=*)
315 question="${ARGUMENT%%=*}"
316 value="${ARGUMENT#*=}"
317 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
318 export PRESEEDS
321 showmounts)
322 SHOWMOUNTS="Yes"
323 export SHOWMOUNTS
326 silent)
327 SILENT="Yes"
328 export SILENT
331 todisk=*)
332 TODISK="${ARGUMENT#todisk=}"
333 export TODISK
336 toram)
337 TORAM="Yes"
338 export TORAM
341 toram=*)
342 TORAM="Yes"
343 MODULETORAM="${ARGUMENT#toram=}"
344 export TORAM MODULETORAM
347 exposedroot)
348 EXPOSED_ROOT="Yes"
349 export EXPOSED_ROOT
352 plainroot)
353 PLAIN_ROOT="Yes"
354 export PLAIN_ROOT
357 skipunion)
358 SKIP_UNION_MOUNTS="Yes"
359 export SKIP_UNION_MOUNTS
362 root=*)
363 ROOT="${ARGUMENT#root=}"
364 export ROOT
367 union=*)
368 UNIONTYPE="${ARGUMENT#union=}"
369 export UNIONTYPE
372 xdebconf)
373 XDEBCONF="Yes"
374 export XDEBCONF
377 xdriver=*)
378 XDRIVER="${ARGUMENT#xdriver=}"
379 export XDRIVER
382 xvideomode=*)
383 XVIDEOMODE="${ARGUMENT#xvideomode=}"
384 export XVIDEOMODE
386 esac
387 done
389 # sort of compatibility with netboot.h from linux docs
390 if [ -z "${NETBOOT}" ]
391 then
392 if [ "${ROOT}" = "/dev/nfs" ]
393 then
394 NETBOOT="nfs"
395 export NETBOOT
396 elif [ "${ROOT}" = "/dev/cifs" ]
397 then
398 NETBOOT="cifs"
399 export NETBOOT
403 if [ -z "${MODULE}" ]
404 then
405 MODULE="filesystem"
406 export MODULE
409 if [ -z "${UNIONTYPE}" ]
410 then
411 UNIONTYPE="aufs"
412 export UNIONTYPE
416 is_live_path ()
418 DIRECTORY="${1}"
420 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
421 then
422 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
424 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
425 then
426 return 0
428 done
431 return 1
434 matches_uuid ()
436 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
437 then
438 return 0
441 path="${1}"
442 uuid="$(cat /conf/uuid.conf)"
444 for try_uuid_file in "${path}/.disk/live-uuid"*
446 [ -e "${try_uuid_file}" ] || continue
448 try_uuid="$(cat "${try_uuid_file}")"
450 if [ "${uuid}" = "${try_uuid}" ]
451 then
452 return 0
454 done
456 return 1
459 get_backing_device ()
461 case "${1}" in
462 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
463 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
466 *.dir)
467 echo "directory"
471 panic "Unrecognized live filesystem: ${1}"
473 esac
476 match_files_in_dir ()
478 # Does any files match pattern ${1} ?
479 local pattern="${1}"
481 if [ "$(echo ${pattern})" != "${pattern}" ]
482 then
483 return 0
486 return 1
489 mount_images_in_directory ()
491 directory="${1}"
492 rootmnt="${2}"
493 mac="${3}"
496 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
497 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
498 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
499 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
500 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
501 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
502 then
503 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
504 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
505 else
506 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
510 is_nice_device ()
512 sysfs_path="${1#/sys}"
514 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
515 then
516 return 0
517 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
518 then
519 return 0
520 elif echo ${sysfs_path} | grep -q "^/block/dm-"
521 then
522 return 0
525 return 1
528 copy_live_to ()
530 copyfrom="${1}"
531 copytodev="${2}"
532 copyto="${copyfrom}_swap"
534 if [ -z "${MODULETORAM}" ]
535 then
536 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
537 else
538 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
540 if [ -f "${MODULETORAMFILE}" ]
541 then
542 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
543 else
544 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
545 return 1
549 if [ "${copytodev}" = "ram" ]
550 then
551 # copying to ram:
552 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
553 mount_options="-o size=${size}k"
554 free_string="memory"
555 fstype="tmpfs"
556 dev="/dev/shm"
557 else
558 # it should be a writable block device
559 if [ -b "${copytodev}" ]
560 then
561 dev="${copytodev}"
562 free_string="space"
563 fstype=$(get_fstype "${dev}")
564 freespace=$(fs_size "${dev}")
565 else
566 log_warning_msg "${copytodev} is not a block device."
567 return 1
571 if [ "${freespace}" -lt "${size}" ]
572 then
573 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
574 return 1
577 # begin copying (or uncompressing)
578 mkdir "${copyto}"
579 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
580 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
582 if [ "${extension}" = "tgz" ]
583 then
584 cd "${copyto}"
585 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
586 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
587 mount -r -o move "${copyto}" "${rootmnt}"
588 cd "${OLDPWD}"
589 else
590 if [ -n "${MODULETORAMFILE}" ]
591 then
592 if [ -x /bin/rsync ]
593 then
594 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
595 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
596 else
597 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
599 else
600 if [ -x /bin/rsync ]
601 then
602 echo " * Copying whole medium to RAM" 1>/dev/console
603 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
604 else
605 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
606 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
607 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
608 then
609 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
614 umount ${copyfrom}
615 mount -r -o move ${copyto} ${copyfrom}
618 rmdir ${copyto}
619 return 0
622 do_netmount ()
624 modprobe -q af_packet # For DHCP
626 udevadm trigger
627 udevadm settle
629 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
630 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
631 then
633 # if ethdevice was not specified on the kernel command line
634 # make sure we try to get a working network configuration
635 # for *every* present network device (except for loopback of course)
636 if [ -z "$ETHDEVICE" ] ; then
637 echo "If you want to boot from a specific device use bootoption ethdevice=..."
638 for device in /sys/class/net/*; do
639 dev=${device##*/} ;
640 if [ "$dev" != "lo" ] ; then
641 ETHDEVICE="$ETHDEVICE $dev"
643 done
646 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
647 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
648 devlist="$devlist $device"
649 done
651 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
652 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
654 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
655 # an endless loop; iff execution fails give it two further tries, that's
656 # why we use '$devlist $devlist $devlist' for the other for loop
657 for dev in $devlist $devlist $devlist ; do
658 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
659 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
660 jobid=$!
661 sleep "$ETHDEV_TIMEOUT" ; sleep 1
662 if [ -r /proc/"$jobid"/status ] ; then
663 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
664 kill -9 $jobid
667 # if configuration of device worked we should have an assigned
668 # IP address, iff so let's use the according as $DEVICE for later usage
669 # simple and primitive approach which seems to work fine
670 if ifconfig $dev | grep -q 'inet.*addr:' ; then
671 export DEVICE="$dev"
672 break
674 done
676 else
677 ipconfig ${DEVICE} | tee /netboot.config
680 # source relevant ipconfig output
681 OLDHOSTNAME=${HOSTNAME}
682 . /tmp/net-${DEVICE}.conf
683 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
684 export HOSTNAME
686 # Check if we have a network device at all
687 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
688 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
689 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
690 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
691 ! ls /sys/class/net/ra0 > /dev/null 2>&1
692 then
693 panic "No supported network device found, maybe a non-mainline driver is required."
696 if [ "${NFSROOT}" = "auto" ]
697 then
698 NFSROOT=${ROOTSERVER}:${ROOTPATH}
701 rc=1
703 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
704 then
705 do_httpmount
706 return $?
709 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
710 then
711 NFSROOT=${ROOTSERVER}:${NFSROOT}
714 log_begin_msg "Trying netboot from ${NFSROOT}"
716 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
717 then
718 rc=0
719 elif do_nfsmount
720 then
721 NETBOOT="nfs"
722 export NETBOOT
723 rc=0
726 log_end_msg
727 return ${rc}
730 do_httpmount ()
732 rc=1
734 for webfile in HTTPFS FTPFS FETCH
736 local url="$(eval echo \"\$\{${webfile}\}\")"
737 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
739 if [ -n "$url" ]
740 then
741 case "${extension}" in
742 iso|squashfs|tgz|tar)
743 if [ "${extension}" = "iso" ]
744 then
745 mkdir -p "${alt_mountpoint}"
746 dest="${alt_mountpoint}"
747 else
748 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
749 mount -t ramfs ram "${mountpoint}"
750 mkdir -p "${dest}"
752 if [ "${webfile}" = "FETCH" ]
753 then
754 case "$url" in
755 tftp*)
756 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
757 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
758 lfile="$(basename $url)"
759 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
760 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
764 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
765 wget "${url}" -O "${dest}/$(basename ${url})"
767 esac
768 else
769 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
770 if [ "${webfile}" = "FTPFS" ]
771 then
772 FUSE_MOUNT="curlftpfs"
773 url="$(dirname ${url})"
774 else
775 FUSE_MOUNT="httpfs"
777 modprobe fuse
778 $FUSE_MOUNT "${url}" "${dest}"
780 [ ${?} -eq 0 ] && rc=0
781 [ "${extension}" = "tgz" ] && live_dest="ram"
782 if [ "${extension}" = "iso" ]
783 then
784 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
785 mount -t iso9660 "${isoloop}" "${mountpoint}"
786 rc=${?}
788 break
792 log_begin_msg "Unrecognized archive extension for ${url}"
794 esac
796 done
798 if [ ${rc} != 0 ]
799 then
800 if [ -d "${alt_mountpoint}" ]
801 then
802 umount "${alt_mountpoint}"
803 rmdir "${alt_mountpoint}"
805 umount "${mountpoint}"
806 elif [ "${webfile}" != "FETCH" ] ; then
807 NETBOOT="${webfile}"
808 export NETBOOT
811 return ${rc}
814 do_nfsmount ()
816 rc=1
818 modprobe -q nfs
820 if [ -z "${NFSOPTS}" ]
821 then
822 NFSOPTS=""
825 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
827 # FIXME: This while loop is an ugly HACK round an nfs bug
829 while [ "$i" -lt 60 ]
831 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
832 sleep 1
833 i="$(($i + 1))"
834 done
836 return ${rc}
839 do_cifsmount ()
841 rc=1
843 if [ -x "/sbin/mount.cifs" ]
844 then
845 if [ -z "${NFSOPTS}" ]
846 then
847 CIFSOPTS="-ouser=root,password="
848 else
849 CIFSOPTS="${NFSOPTS}"
852 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
853 modprobe -q cifs
855 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
856 then
857 rc=0
861 return ${rc}
864 do_snap_copy ()
866 fromdev="${1}"
867 todir="${2}"
868 snap_type="${3}"
869 size=$(fs_size "${fromdev}" "" "used")
871 if [ -b "${fromdev}" ]
872 then
873 # look for free mem
874 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
875 then
876 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
877 freespace=$(df -k | awk '/'${todev}'/{print $4}')
878 else
879 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
882 tomount="/mnt/tmpsnap"
884 if [ ! -d "${tomount}" ]
885 then
886 mkdir -p "${tomount}"
889 fstype=$(get_fstype "${fromdev}")
891 if [ -n "${fstype}" ]
892 then
893 # Copying stuff...
894 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
895 cp -a "${tomount}"/* ${todir}
896 umount "${tomount}"
897 else
898 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
901 rmdir "${tomount}"
903 if echo ${fromdev} | grep -qs loop
904 then
905 losetup -d "${fromdev}"
908 return 0
909 else
910 return 1
912 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
916 find_snap ()
918 # Look for ${snap_label}.* in block devices
919 snap_label="${1}"
921 if [ "${PERSISTENT}" != "nofiles" ]
922 then
923 # search for image files
924 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")
927 if [ -z "${snapdata}" ]
928 then
929 snapdata=$(find_cow_device "${snap_label}")
931 echo "${snapdata}"
934 try_snap ()
936 # copy the contents of previously found snapshot to ${snap_mount}
937 # and remember the device and filename for resync on exit in live-boot.init
939 snapdata="${1}"
940 snap_mount="${2}"
941 snap_type="${3}"
943 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
944 then
945 log_success_msg "found snapshot: ${snapdata}"
946 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
947 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
948 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
950 RES=""
951 if ! try_mount "${snapdev}" "${snapback}" "ro"
952 then
953 break
956 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
957 then
958 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
959 dev=$(get_backing_device "${snapback}/${snapfile}")
961 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
962 RES=$?
963 else
964 # cpio.gz snapshot
966 # Unfortunately klibc's cpio is incompatible with the
967 # rest of the world; everything else requires -u -d,
968 # while klibc doesn't implement them. Try to detect
969 # whether it's in use.
970 cpiopath="$(which cpio)" || true
971 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
972 then
973 cpioargs=
974 else
975 cpioargs='--unconditional --make-directories'
978 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
979 then
980 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
984 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
986 if [ "${RES}" != "0" ]
987 then
988 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
991 elif [ -b "${snapdata}" ]
992 then
993 # Try to find if it could be a snapshot partition
994 dev="${snapdata}"
995 log_success_msg "found snapshot ${snap_type} device on ${dev}"
996 if echo "${dev}" | grep -qs loop
997 then
998 # strange things happens, user confused?
999 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1000 snapfile=$(basename ${snaploop})
1001 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1002 else
1003 snapdev="${dev}"
1006 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1007 then
1008 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1009 return 1
1010 else
1011 if [ -n "${snapfile}" ]
1012 then
1013 # it was a loop device, user confused
1014 umount ${snapdev}
1017 else
1018 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1019 return 1
1022 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1023 return 0
1026 setup_unionfs ()
1028 image_directory="${1}"
1029 rootmnt="${2}"
1030 addimage_directory="${3}"
1032 case ${UNIONTYPE} in
1033 aufs|unionfs)
1034 modprobe -q -b ${UNIONTYPE}
1036 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1037 then
1038 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1039 echo "This might be really slow."
1041 UNIONTYPE="unionfs-fuse"
1044 esac
1046 if [ "${UNIONTYPE}" = unionfs-fuse ]
1047 then
1048 modprobe fuse
1051 # run-init can't deal with images in a subdir, but we're going to
1052 # move all of these away before it runs anyway. No, we're not,
1053 # put them in / since move-mounting them into / breaks mono and
1054 # some other apps.
1056 croot="/"
1058 # Let's just mount the read-only file systems first
1059 rofsstring=""
1060 rofslist=""
1062 if [ "${UNIONTYPE}" = "aufs" ]
1063 then
1064 roopt="rr"
1065 noxino_opt="noxino,"
1066 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1067 then
1068 roopt="RO"
1069 else
1070 roopt="ro"
1073 if [ -z "${PLAIN_ROOT}" ]
1074 then
1075 # Read image names from ${MODULE}.module if it exists
1076 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1077 then
1078 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1080 image_string="${image_string} ${image_directory}/${IMAGE}"
1081 done
1082 elif [ -e "${image_directory}/${MODULE}.module" ]
1083 then
1084 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1086 image_string="${image_string} ${image_directory}/${IMAGE}"
1087 done
1088 else
1089 # ${MODULE}.module does not exist, create a list of images
1090 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1092 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1094 if [ -e "${IMAGE}" ]
1095 then
1096 image_string="${image_string} ${IMAGE}"
1098 done
1099 done
1101 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1102 then
1103 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1105 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1107 if [ -e "${IMAGE}" ]
1108 then
1109 image_string="${image_string} ${IMAGE}"
1111 done
1112 done
1115 # Now sort the list
1116 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1119 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1121 mkdir -p "${croot}"
1123 for image in ${image_string}
1125 imagename=$(basename "${image}")
1127 export image devname
1128 maybe_break live-realpremount
1129 log_begin_msg "Running /scripts/live-realpremount"
1130 run_scripts /scripts/live-realpremount
1131 log_end_msg
1133 if [ -d "${image}" ]
1134 then
1135 # it is a plain directory: do nothing
1136 rofsstring="${image}=${roopt}:${rofsstring}"
1137 rofslist="${image} ${rofslist}"
1138 elif [ -f "${image}" ]
1139 then
1140 if losetup --help 2>&1 | grep -q -- "-r\b"
1141 then
1142 backdev=$(get_backing_device "${image}" "-r")
1143 else
1144 backdev=$(get_backing_device "${image}")
1146 fstype=$(get_fstype "${backdev}")
1148 if [ "${fstype}" = "unknown" ]
1149 then
1150 panic "Unknown file system type on ${backdev} (${image})"
1153 if [ -z "${fstype}" ]
1154 then
1155 fstype="${imagename##*.}"
1156 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1159 mkdir -p "${croot}/${imagename}"
1160 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1161 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}"
1162 log_end_msg
1164 done
1165 else
1166 # we have a plain root system
1167 mkdir -p "${croot}/filesystem"
1168 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1169 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}"
1170 # probably broken:
1171 mount -o bind ${croot}/filesystem $mountpoint
1172 log_end_msg
1175 rofsstring=${rofsstring%:}
1177 mkdir -p /cow
1179 # Looking for "${root_persistence}" device or file
1180 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1181 then
1182 if [ -z "${QUICKUSBMODULES}" ]
1183 then
1184 # Load USB modules
1185 num_block=$(ls -l /sys/block | wc -l)
1186 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1188 modprobe -q -b ${module}
1189 done
1191 udevadm trigger
1192 udevadm settle
1194 # For some reason, udevsettle does not block in this scenario,
1195 # so we sleep for a little while.
1197 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1198 for timeout in 5 4 3 2 1
1200 sleep 1
1202 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1203 then
1204 break
1206 done
1209 # search for label and files (this could be hugely optimized)
1210 cowprobe=$(find_cow_device "${root_persistence}")
1211 if [ -b "${cowprobe}" ]
1212 then
1213 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1214 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1215 # snapshots to be sure to really store some e.g key config files,
1216 # but not on the same media
1217 blacklistdev="${cowprobe}"
1218 PERSISTENCE_IS_ON="1"
1219 export PERSISTENCE_IS_ON
1221 # homecow just mount something on /home, this should be generalized some way
1222 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1223 if [ -b "${homecow}" ]
1224 then
1225 PERSISTENCE_IS_ON="1"
1226 export PERSISTENCE_IS_ON
1228 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1229 # This second type should be removed when snapshot will get smarter,
1230 # hence when "/etc/live-snapshot*list" will be supported also by
1231 # ext2|ext3|ext4|jffs2 snapshot types.
1232 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1234 if [ -b "${cowprobe}" ]
1235 then
1236 cowdevice=${cowprobe}
1237 cow_fstype=$(get_fstype "${cowprobe}")
1238 cow_mountopt="rw,noatime"
1240 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1241 then
1242 fsck -y ${cowdevice}
1244 else
1245 log_warning_msg "Unable to find the persistent medium"
1246 cowdevice="tmpfs"
1247 cow_fstype="tmpfs"
1248 cow_mountopt="rw,noatime,mode=755"
1250 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1251 then
1252 # check if there are any nfs options
1253 if echo ${NFS_COW}|grep -q ','
1254 then
1255 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1256 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1257 else
1258 nfs_cow_opts="-o nolock"
1259 nfs_cow=${NFS_COW}
1261 mac="$(get_mac)"
1262 if [ -n "${mac}" ]
1263 then
1264 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1265 cow_fstype="nfs"
1266 else
1267 panic "unable to determine mac address"
1269 else
1270 cowdevice="tmpfs"
1271 cow_fstype="tmpfs"
1272 cow_mountopt="rw,noatime,mode=755"
1275 if [ "${cow_fstype}" = "nfs" ]
1276 then
1277 log_begin_msg \
1278 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1279 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1280 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1281 else
1282 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1283 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1286 rofscount=$(echo ${rofslist} |wc -w)
1288 if [ -n "${EXPOSED_ROOT}" ]
1289 then
1290 if [ ${rofscount} -ne 1 ]
1291 then
1292 panic "only one RO file system supported with exposedroot: ${rofslist}"
1294 exposedrootfs=${rofslist%% }
1296 mount --bind ${exposedrootfs} ${rootmnt} || \
1297 panic "bind mount of ${exposedrootfs} failed"
1299 if [ -z "${SKIP_UNION_MOUNTS}" ]
1300 then
1301 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1302 else
1303 cow_dirs=''
1306 for dir in ${cow_dirs}; do
1307 mkdir -p /cow${dir}
1309 case "${UNIONTYPE}" in
1310 unionfs-fuse)
1311 (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}")
1312 mkdir -p /dev/.initramfs/varrun
1313 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1317 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"
1319 esac
1320 done
1321 else
1322 case "${UNIONTYPE}" in
1323 unionfs-fuse)
1324 (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}")
1325 mkdir -p /dev/.initramfs/varrun
1326 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1330 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}"
1332 esac
1335 # Correct the permissions of /:
1336 chmod 0755 "${rootmnt}"
1338 # tmpfs file systems
1339 touch /etc/fstab
1340 mkdir -p "${rootmnt}/live"
1341 mount -t tmpfs tmpfs ${rootmnt}/live
1343 # Adding other custom mounts
1344 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1345 then
1346 # directly mount /home
1347 # FIXME: add a custom mounts configurable system
1349 if [ -b "${homecow}" ]
1350 then
1351 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1352 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1353 else
1354 log_warning_msg "Unable to find the persistent home medium"
1357 # Look for other snapshots to copy in
1358 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1359 # This second type should be removed when snapshot grow smarter
1360 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1363 if [ -n "${SHOWMOUNTS}" ]
1364 then
1365 for d in ${rofslist}
1367 mkdir -p "${rootmnt}/live/${d##*/}"
1369 case d in
1370 *.dir)
1371 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1375 case "${UNIONTYPE}" in
1376 unionfs-fuse)
1377 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1381 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1383 esac
1385 esac
1386 done
1389 # shows cow fs on /cow for use by live-snapshot
1390 mkdir -p "${rootmnt}/live/cow"
1391 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"
1394 check_dev ()
1396 sysdev="${1}"
1397 devname="${2}"
1398 skip_uuid_check="${3}"
1400 # support for fromiso=.../isofrom=....
1401 if [ -n "$FROMISO" ]
1402 then
1403 ISO_DEVICE=$(dirname $FROMISO)
1404 if ! [ -b $ISO_DEVICE ]
1405 then
1406 # to support unusual device names like /dev/cciss/c0d0p1
1407 # as well we have to identify the block device name, let's
1408 # do that for up to 15 levels
1409 i=15
1410 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1412 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1413 [ -b "$ISO_DEVICE" ] && break
1414 i=$(($i -1))
1415 done
1418 if [ "$ISO_DEVICE" = "/" ]
1419 then
1420 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1421 else
1422 mkdir /isofrom
1423 mount "$ISO_DEVICE" /isofrom
1424 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1425 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1426 devname="${loopdevname}"
1430 if [ -z "${devname}" ]
1431 then
1432 devname=$(sys2dev "${sysdev}")
1435 if [ -d "${devname}" ]
1436 then
1437 mount -o bind "${devname}" $mountpoint || continue
1439 if is_live_path $mountpoint
1440 then
1441 echo $mountpoint
1442 return 0
1443 else
1444 umount $mountpoint
1447 [ -e "$devname" ] || continue
1449 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1450 then
1451 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1452 devname="${loopdevname}"
1455 fstype=$(get_fstype "${devname}")
1457 if is_supported_fs ${fstype}
1458 then
1459 devuid=$(blkid -o value -s UUID "$devname")
1460 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1461 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1462 [ -n "$devuid" ] && echo "$devuid" >> $tried
1464 if is_live_path ${mountpoint} && \
1465 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1466 then
1467 echo ${mountpoint}
1468 return 0
1469 else
1470 umount ${mountpoint}
1474 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1475 then
1476 losetup -d "${loopdevname}"
1479 return 1
1482 find_livefs ()
1484 timeout="${1}"
1486 # don't start autodetection before timeout has expired
1487 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1488 then
1489 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1490 then
1491 return 1
1495 # first look at the one specified in the command line
1496 case "${LIVE_MEDIA}" in
1497 removable-usb)
1498 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1500 if [ "$(cat ${sysblock}/removable)" = "1" ]
1501 then
1502 if readlink ${sysblock} | grep -q usb ||
1503 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1504 then
1505 for dev in $(subdevices "${sysblock}")
1507 if check_dev "${dev}"
1508 then
1509 return 0
1511 done
1514 done
1515 return 1
1518 removable)
1519 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1521 if [ "$(cat ${sysblock}/removable)" = "1" ]
1522 then
1523 for dev in $(subdevices "${sysblock}")
1525 if check_dev "${dev}"
1526 then
1527 return 0
1529 done
1531 done
1532 return 1
1536 if [ ! -z "${LIVE_MEDIA}" ]
1537 then
1538 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1539 then
1540 return 0
1544 esac
1546 # or do the scan of block devices
1547 # prefer removable devices over non-removable devices, so scan them first
1548 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1550 if [ "$(cat ${sysblock}/removable)" = "1" ]
1551 then
1552 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1553 else
1554 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1556 done
1557 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1559 for sysblock in $devices_to_scan
1561 devname=$(sys2dev "${sysblock}")
1562 [ -e "$devname" ] || continue
1563 fstype=$(get_fstype "${devname}")
1565 if /lib/udev/cdrom_id ${devname} > /dev/null
1566 then
1567 if check_dev "null" "${devname}"
1568 then
1569 return 0
1571 elif is_nice_device "${sysblock}"
1572 then
1573 for dev in $(subdevices "${sysblock}")
1575 if check_dev "${dev}"
1576 then
1577 return 0
1579 done
1580 elif [ "${fstype}" = "squashfs" -o \
1581 "${fstype}" = "ext2" -o \
1582 "${fstype}" = "ext3" -o \
1583 "${fstype}" = "ext4" -o \
1584 "${fstype}" = "jffs2" ]
1585 then
1586 # This is an ugly hack situation, the block device has
1587 # an image directly on it. It's hopefully
1588 # live-boot, so take it and run with it.
1589 ln -s "${devname}" "${devname}.${fstype}"
1590 echo "${devname}.${fstype}"
1591 return 0
1593 done
1595 return 1
1598 set_usplash_timeout ()
1600 if [ -x /sbin/usplash_write ]
1601 then
1602 /sbin/usplash_write "TIMEOUT 120"
1603 else if [ -x /sbin/splashy_update ] ; then
1604 /sbin/splashy_update "TIMEOUT 120"
1605 fi ; fi
1608 integrity_check ()
1610 media_mountpoint="${1}"
1612 log_begin_msg "Checking media integrity"
1614 cd ${media_mountpoint}
1615 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1616 RC="${?}"
1618 log_end_msg
1620 if [ "${RC}" -eq 0 ]
1621 then
1622 log_success_msg "Everything ok, will reboot in 10 seconds."
1623 sleep 10
1624 cd /
1625 umount ${media_mountpoint}
1626 sync
1627 echo u > /proc/sysrq-trigger
1628 echo b > /proc/sysrq-trigger
1629 else
1630 panic "Not ok, a media defect is likely, switch to VT8 for details."
1634 start_usplash_pulse ()
1636 if [ -x /sbin/usplash_write ]
1637 then
1638 /sbin/usplash_write "PULSELOGO"
1642 mountroot ()
1644 if [ -x /scripts/local-top/cryptroot ]; then
1645 /scripts/local-top/cryptroot
1648 exec 6>&1
1649 exec 7>&2
1650 exec > live.log
1651 exec 2>&1
1652 tail -f live.log >&7 &
1653 tailpid="${!}"
1655 # Ensure 'panic' function is overridden
1656 . /scripts/live-functions
1658 Arguments
1660 set_usplash_timeout
1661 start_usplash_pulse
1663 maybe_break live-premount
1664 log_begin_msg "Running /scripts/live-premount"
1665 run_scripts /scripts/live-premount
1666 log_end_msg
1668 # Needed here too because some things (*cough* udev *cough*)
1669 # changes the timeout
1671 set_usplash_timeout
1673 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1674 then
1675 if do_netmount
1676 then
1677 livefs_root="${mountpoint}"
1678 else
1679 panic "Unable to find a live file system on the network"
1681 else
1682 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1683 then
1684 # Do a local boot from hd
1685 livefs_root=${ROOT}
1686 else
1687 # Scan local devices for the image
1689 while [ "$i" -lt 60 ]
1691 livefs_root=$(find_livefs ${i})
1693 if [ -n "${livefs_root}" ]
1694 then
1695 break
1698 sleep 1
1699 i="$(($i + 1))"
1700 done
1704 if [ -z "${livefs_root}" ]
1705 then
1706 panic "Unable to find a medium containing a live file system"
1709 if [ "${INTEGRITY_CHECK}" ]
1710 then
1711 integrity_check "${livefs_root}"
1714 if [ "${TORAM}" ]
1715 then
1716 live_dest="ram"
1717 elif [ "${TODISK}" ]
1718 then
1719 live_dest="${TODISK}"
1722 if [ "${live_dest}" ]
1723 then
1724 log_begin_msg "Copying live media to ${live_dest}"
1725 copy_live_to "${livefs_root}" "${live_dest}"
1726 log_end_msg
1729 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1730 # because the mountpoint is left behind in /proc/mounts, so let's get
1731 # rid of it when running from RAM
1732 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1733 then
1734 losetup -d /dev/loop0
1735 grep -q /isofrom /proc/mounts && umount /isofrom
1738 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1739 then
1740 setup_unionfs "${livefs_root}" "${rootmnt}"
1741 else
1742 mac="$(get_mac)"
1743 mac="$(echo ${mac} | sed 's/-//g')"
1744 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1747 log_end_msg
1749 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1750 # live-bottom; udev's init script will take care of things after that
1751 if [ "${UNIONTYPE}" = unionfs-fuse ]
1752 then
1753 mount -n -o bind /dev "${rootmnt}/dev"
1756 # Move to the new root filesystem so that programs there can get at it.
1757 if [ ! -d /root/live/image ]
1758 then
1759 mkdir -p /root/live/image
1760 mount --move /live/image /root/live/image
1763 maybe_break live-bottom
1764 log_begin_msg "Running /scripts/live-bottom\n"
1766 run_scripts /scripts/live-bottom
1767 log_end_msg
1769 if [ "${UNIONFS}" = unionfs-fuse ]
1770 then
1771 umount "${rootmnt}/dev"
1774 exec 1>&6 6>&-
1775 exec 2>&7 7>&-
1776 kill ${tailpid}
1777 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null