Releasing debian version 2.0~a4-1.
[debian-live-boot/hramrach.git] / scripts / live
blobafe0f4baa91c49486210b5c246ea7c48034e7e0c
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 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"
18 USERNAME="user"
19 USERFULLNAME="Live user"
20 HOSTNAME="host"
22 mkdir -p "${mountpoint}"
23 tried="/tmp/tried"
25 # Create /etc/mtab for debug purpose and future syncs
26 if [ ! -d /etc ]
27 then
28 mkdir /etc/
31 if [ ! -f /etc/mtab ]
32 then
33 touch /etc/mtab
36 [ -f /etc/live.conf ] && . /etc/live.conf
37 export USERNAME USERFULLNAME HOSTNAME
39 . /scripts/live-helpers
41 if [ ! -f /live.vars ]
42 then
43 touch /live.vars
46 Arguments ()
48 PRESEEDS=""
49 LOCATIONS=""
51 for ARGUMENT in $(cat /proc/cmdline)
53 case "${ARGUMENT}" in
54 skipconfig)
55 NOACCESSIBILITY="Yes"
56 NOAPTCDROM="Yes"
57 NOAUTOLOGIN="Yes"
58 NOCONSOLEKEYBOARD="Yes"
59 NOFASTBOOT="Yes"
60 NOFSTAB="Yes"
61 NOHOSTS="Yes"
62 NONETWORKING="Yes"
63 NOTIMEZONE="Yes"
64 NOXAUTOCONFIG="Yes"
65 NOXAUTOLOGIN="Yes"
67 export NOACCESSIBILITY NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOHOSTS NONETWORKING NOTIMEZONE NOXAUTOCONFIG NOXAUTOLOGIN
70 access=*)
71 ACCESS="${ARGUMENT#access=}"
72 export ACCESS
75 console=*)
76 DEFCONSOLE="${ARGUMENT#*=}"
77 export DEFCONSOLE
80 debug)
81 DEBUG="Yes"
82 export DEBUG
84 set -x
87 ethdevice=*)
88 DEVICE="${ARGUMENT#ethdevice=}"
89 export DEVICE
92 ethdevice=*)
93 ETHDEVICE="${ARGUMENT#ethdevice=}"
94 export ETHDEVICE
97 ethdevice-timeout=*)
98 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
99 export ETHDEV_TIMEOUT
102 fetch=*)
103 FETCH="${ARGUMENT#fetch=}"
104 export FETCH
107 forcepersistentfsck)
108 FORCEPERSISTENTFSCK="Yes"
109 export FORCEPERSISTENTFSCK
112 ftpfs=*)
113 FTPFS="${ARGUMENT#ftpfs=}"
114 export FTPFS
117 httpfs=*)
118 HTTPFS="${ARGUMENT#httpfs=}"
119 export HTTPFS
122 isofrom=*|fromiso=*)
123 FROMISO="${ARGUMENT#*=}"
124 export FROMISO
127 username=*)
128 USERNAME="${ARGUMENT#username=}"
129 LIVECONF="changed"
130 export USERNAME LIVECONF
133 userfullname=*)
134 USERFULLNAME="${ARGUMENT#userfullname=}"
135 LIVECONF="changed"
136 export USERFULLNAME LIVECONF
139 ignore_uuid)
140 IGNORE_UUID="Yes"
141 export IGNORE_UUID
144 integrity-check)
145 INTEGRITY_CHECK="Yes"
146 export INTEGRITY_CHECK
149 ip=*)
150 STATICIP="${ARGUMENT#ip=}"
152 if [ -z "${STATICIP}" ]
153 then
154 STATICIP="frommedia"
157 export STATICIP
160 keyb=*|kbd-chooser/method=*)
161 KBD="${ARGUMENT#*=}"
162 export KBD
165 klayout=*|console-setup/layoutcode=*)
166 KLAYOUT="${ARGUMENT#*=}"
167 export KLAYOUT
170 kvariant=*|console-setup/variantcode=*)
171 KVARIANT="${ARGUMENT#*=}"
172 export KVARIANT
175 kmodel=*|console-setup/modelcode=*)
176 KMODEL="${ARGUMENT#*=}"
177 export KMODEL
180 koptions=*)
181 KOPTIONS="${ARGUMENT#koptions=}"
182 export KOPTIONS
185 live-getty)
186 LIVE_GETTY="1"
187 export LIVE_GETTY
190 live-media=*|bootfrom=*)
191 LIVE_MEDIA="${ARGUMENT#*=}"
192 export LIVE_MEDIA
195 live-media-encryption=*|encryption=*)
196 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
197 export LIVE_MEDIA_ENCRYPTION
200 live-media-offset=*)
201 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
202 export LIVE_MEDIA_OFFSET
205 live-media-path=*)
206 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
207 export LIVE_MEDIA_PATH
210 live-media-timeout=*)
211 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
212 export LIVE_MEDIA_TIMEOUT
215 module=*)
216 MODULE="${ARGUMENT#module=}"
217 export MODULE
220 netboot=*)
221 NETBOOT="${ARGUMENT#netboot=}"
222 export NETBOOT
225 nfsopts=*)
226 NFSOPTS="${ARGUMENT#nfsopts=}"
227 export NFSOPTS
230 nfscow=*)
231 NFS_COW="${ARGUMENT#nfscow=}"
232 export NFS_COW
235 noaccessibility)
236 NOACCESSIBILITY="Yes"
237 export NOACCESSIBILITY
240 noaptcdrom)
241 NOAPTCDROM="Yes"
242 export NOAPTCDROM
245 noautologin)
246 NOAUTOLOGIN="Yes"
247 export NOAUTOLOGIN
250 noxautologin)
251 NOXAUTOLOGIN="Yes"
252 export NOXAUTOLOGIN
255 noconsolekeyboard)
256 NOCONSOLEKEYBOARD="Yes"
257 export NOCONSOLEKEYBOARD
260 nofastboot)
261 NOFASTBOOT="Yes"
262 export NOFASTBOOT
265 nofstab)
266 NOFSTAB="Yes"
267 export NOFSTAB
270 nohosts)
271 NOHOSTS="Yes"
272 export NOHOSTS
275 nonetworking)
276 NONETWORKING="Yes"
277 export NONETWORKING
280 swapon)
281 SWAPON="Yes"
282 export SWAPON
285 noxautoconfig)
286 NOXAUTOCONFIG="Yes"
287 export NOXAUTOCONFIG
290 noxscreensaver)
291 NOXSCREENSAVER="Yes"
292 export NOXSCREENSAVER
295 persistent)
296 PERSISTENT="Yes"
297 export PERSISTENT
300 persistent=*)
301 PERSISTENT="${ARGUMENT#persistent=}"
302 if [ -z "${PERSISTENT}" ]
303 then
304 PERSISTENT="Yes"
306 export PERSISTENT
309 persistent-path=*)
310 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
311 export PERSISTENT_PATH
314 persistent-subtext=*)
315 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
316 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
317 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
318 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
321 nopersistent)
322 NOPERSISTENT="Yes"
323 export NOPERSISTENT
326 quickusbmodules)
327 QUICKUSBMODULES="Yes"
328 export QUICKUSBMODULES
331 preseed/file=*|file=*)
332 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
333 export LOCATIONS
336 nopreseed)
337 NOPRESEED="Yes"
338 export NOPRESEED
341 url=*)
342 URL_LOCATION="${ARGUMENT#url=}"
344 mount -o bind /sys /root/sys
345 mount -o bind /proc /root/proc
346 mount -o bind /dev /root/dev
348 mkdir -p /root/var/run/network
349 [ "${NETBOOT}" ] || chroot /root dhclient eth0
350 chroot /root wget -P /tmp "${URL_LOCATION}"
351 [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down
353 umount /root/sys
354 umount /root/proc
355 umount /root/dev
357 LOCATIONS="/tmp/$(basename ${URL_LOCATION}) ${LOCATIONS}"
360 */*=*)
361 question="${ARGUMENT%%=*}"
362 value="${ARGUMENT#*=}"
363 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
364 export PRESEEDS
367 showmounts)
368 SHOWMOUNTS="Yes"
369 export SHOWMOUNTS
372 silent)
373 SILENT="Yes"
374 export SILENT
377 textonly)
378 TEXTONLY="Yes"
379 export TEXTONLY
382 timezone=*)
383 TIMEZONE="${ARGUMENT#timezone=}"
384 export TIMEZONE
387 notimezone)
388 NOTIMEZONE="Yes"
389 export NOTIMEZONE
392 todisk=*)
393 TODISK="${ARGUMENT#todisk=}"
394 export TODISK
397 toram)
398 TORAM="Yes"
399 export TORAM
402 toram=*)
403 TORAM="Yes"
404 MODULETORAM="${ARGUMENT#toram=}"
405 export TORAM MODULETORAM
408 exposedroot)
409 EXPOSED_ROOT="Yes"
410 export EXPOSED_ROOT
413 plainroot)
414 PLAIN_ROOT="Yes"
415 export PLAIN_ROOT
418 skipunion)
419 SKIP_UNION_MOUNTS="Yes"
420 export SKIP_UNION_MOUNTS
423 root=*)
424 ROOT="${ARGUMENT#root=}"
425 export ROOT
428 union=*)
429 UNIONTYPE="${ARGUMENT#union=}"
430 export UNIONTYPE
433 xdebconf)
434 XDEBCONF="Yes"
435 export XDEBCONF
438 xdriver=*)
439 XDRIVER="${ARGUMENT#xdriver=}"
440 export XDRIVER
443 xvideomode=*)
444 XVIDEOMODE="${ARGUMENT#xvideomode=}"
445 export XVIDEOMODE
447 esac
448 done
450 # sort of compatibility with netboot.h from linux docs
451 if [ -z "${NETBOOT}" ]
452 then
453 if [ "${ROOT}" = "/dev/nfs" ]
454 then
455 NETBOOT="nfs"
456 export NETBOOT
457 elif [ "${ROOT}" = "/dev/cifs" ]
458 then
459 NETBOOT="cifs"
460 export NETBOOT
464 if [ -z "${MODULE}" ]
465 then
466 MODULE="filesystem"
467 export MODULE
470 if [ -z "${UNIONTYPE}" ]
471 then
472 UNIONTYPE="aufs"
473 export UNIONTYPE
477 is_live_path ()
479 DIRECTORY="${1}"
481 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
482 then
483 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
485 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
486 then
487 return 0
489 done
492 return 1
495 matches_uuid ()
497 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
498 then
499 return 0
502 path="${1}"
503 uuid="$(cat /conf/uuid.conf)"
505 for try_uuid_file in "${path}/.disk/live-uuid"*
507 [ -e "${try_uuid_file}" ] || continue
509 try_uuid="$(cat "${try_uuid_file}")"
511 if [ "${uuid}" = "${try_uuid}" ]
512 then
513 return 0
515 done
517 return 1
520 get_backing_device ()
522 case "${1}" in
523 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
524 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
527 *.dir)
528 echo "directory"
532 panic "Unrecognized live filesystem: ${1}"
534 esac
537 match_files_in_dir ()
539 # Does any files match pattern ${1} ?
540 local pattern="${1}"
542 if [ "$(echo ${pattern})" != "${pattern}" ]
543 then
544 return 0
547 return 1
550 mount_images_in_directory ()
552 directory="${1}"
553 rootmnt="${2}"
554 mac="${3}"
557 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
558 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
559 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
560 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
561 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
562 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
563 then
564 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
565 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
566 else
567 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
571 is_nice_device ()
573 sysfs_path="${1#/sys}"
575 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
576 then
577 return 0
578 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
579 then
580 return 0
581 elif echo ${sysfs_path} | grep -q "^/block/dm-"
582 then
583 return 0
586 return 1
589 copy_live_to ()
591 copyfrom="${1}"
592 copytodev="${2}"
593 copyto="${copyfrom}_swap"
595 if [ -z "${MODULETORAM}" ]
596 then
597 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
598 else
599 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
601 if [ -f "${MODULETORAMFILE}" ]
602 then
603 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
604 else
605 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
606 return 1
610 if [ "${copytodev}" = "ram" ]
611 then
612 # copying to ram:
613 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
614 mount_options="-o size=${size}k"
615 free_string="memory"
616 fstype="tmpfs"
617 dev="/dev/shm"
618 else
619 # it should be a writable block device
620 if [ -b "${copytodev}" ]
621 then
622 dev="${copytodev}"
623 free_string="space"
624 fstype=$(get_fstype "${dev}")
625 freespace=$(fs_size "${dev}")
626 else
627 log_warning_msg "${copytodev} is not a block device."
628 return 1
632 if [ "${freespace}" -lt "${size}" ]
633 then
634 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
635 return 1
638 # begin copying (or uncompressing)
639 mkdir "${copyto}"
640 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
641 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
643 if [ "${extension}" = "tgz" ]
644 then
645 cd "${copyto}"
646 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
647 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
648 mount -r -o move "${copyto}" "${rootmnt}"
649 cd "${OLDPWD}"
650 else
651 if [ -n "${MODULETORAMFILE}" ]
652 then
653 if [ -x /bin/rsync ]
654 then
655 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
656 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
657 else
658 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
660 else
661 if [ -x /bin/rsync ]
662 then
663 echo " * Copying whole medium to RAM" 1>/dev/console
664 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
665 else
666 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
667 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
668 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
669 then
670 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
675 umount ${copyfrom}
676 mount -r -o move ${copyto} ${copyfrom}
679 rmdir ${copyto}
680 return 0
683 do_netmount ()
685 rc=1
687 modprobe -q af_packet # For DHCP
689 udevadm trigger
690 udevadm settle
692 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
693 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
694 then
696 # if ethdevice was not specified on the kernel command line
697 # make sure we try to get a working network configuration
698 # for *every* present network device (except for loopback of course)
699 if [ -z "$ETHDEVICE" ] ; then
700 echo "If you want to boot from a specific device use bootoption ethdevice=..."
701 for device in /sys/class/net/*; do
702 dev=${device##*/} ;
703 if [ "$dev" != "lo" ] ; then
704 ETHDEVICE="$ETHDEVICE $dev"
706 done
709 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
710 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
711 devlist="$devlist $device"
712 done
714 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
715 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
717 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
718 # an endless loop; iff execution fails give it two further tries, that's
719 # why we use '$devlist $devlist $devlist' for the other for loop
720 for dev in $devlist $devlist $devlist ; do
721 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
722 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
723 jobid=$!
724 sleep "$ETHDEV_TIMEOUT" ; sleep 1
725 if [ -r /proc/"$jobid"/status ] ; then
726 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
727 kill -9 $jobid
730 # if configuration of device worked we should have an assigned
731 # IP address, iff so let's use the according as $DEVICE for later usage
732 # simple and primitive approach which seems to work fine
733 if ifconfig $dev | grep -q 'inet.*addr:' ; then
734 export DEVICE="$dev"
735 break
737 done
739 else
740 ipconfig ${DEVICE} | tee /netboot.config
743 # source relevant ipconfig output
744 OLDHOSTNAME=${HOSTNAME}
745 . /tmp/net-${DEVICE}.conf
746 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
747 export HOSTNAME
749 # Check if we have a network device at all
750 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
751 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
752 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
753 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
754 ! ls /sys/class/net/ra0 > /dev/null 2>&1
755 then
756 panic "No supported network device found, maybe a non-mainline driver is required."
759 if [ "${NFSROOT}" = "auto" ]
760 then
761 NFSROOT=${ROOTSERVER}:${ROOTPATH}
764 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
765 then
766 rc=0
767 return ${rc}
770 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
771 then
772 NFSROOT=${ROOTSERVER}:${NFSROOT}
775 log_begin_msg "Trying netboot from ${NFSROOT}"
777 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
778 then
779 rc=0
780 elif do_nfsmount
781 then
782 NETBOOT="nfs"
783 export NETBOOT
784 rc=0
787 log_end_msg
788 return ${rc}
791 do_httpmount ()
793 rc=1
794 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
795 mount -t ramfs ram "${mountpoint}"
796 mkdir -p "${dest}"
798 for webfile in HTTPFS FTPFS FETCH
800 url="$(eval echo \"\$\{${webfile}\}\")"
801 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
803 if [ -n "$url" ]
804 then
805 case "${extension}" in
806 squashfs|tgz|tar)
807 if [ "${webfile}" = "FETCH" ]
808 then
809 case "$url" in
810 tftp*)
811 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
812 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
813 lfile="$(basename $url)"
814 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
815 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
819 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
820 wget "${url}" -O "${dest}/$(basename ${url})"
822 esac
823 else
824 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
825 if [ "${webfile}" = "FTPFS" ]
826 then
827 FUSE_MOUNT="curlftpfs"
828 url="$(dirname ${url})"
829 else
830 FUSE_MOUNT="httpfs"
832 modprobe fuse
833 $FUSE_MOUNT "${url}" "${dest}"
835 [ ${?} -eq 0 ] && rc=0
836 [ "${extension}" = "tgz" ] && live_dest="ram"
837 break
841 log_begin_msg "Unrecognized archive extension for ${url}"
843 esac
845 done
847 if [ ${rc} != 0 ]
848 then
849 umount "${mountpoint}"
852 return ${rc}
855 do_nfsmount ()
857 rc=1
859 modprobe -q nfs
861 if [ -z "${NFSOPTS}" ]
862 then
863 NFSOPTS=""
866 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
868 # FIXME: This while loop is an ugly HACK round an nfs bug
870 while [ "$i" -lt 60 ]
872 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
873 sleep 1
874 i="$(($i + 1))"
875 done
877 return ${rc}
880 do_cifsmount ()
882 rc=1
884 if [ -x "/sbin/mount.cifs" ]
885 then
886 if [ -z "${NFSOPTS}" ]
887 then
888 CIFSOPTS="-ouser=root,password="
889 else
890 CIFSOPTS="${NFSOPTS}"
893 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
894 modprobe -q cifs
896 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
897 then
898 rc=0
902 return ${rc}
905 do_snap_copy ()
907 fromdev="${1}"
908 todir="${2}"
909 snap_type="${3}"
910 size=$(fs_size "${fromdev}" "" "used")
912 if [ -b "${fromdev}" ]
913 then
914 # look for free mem
915 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
916 then
917 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
918 freespace=$(df -k | awk '/'${todev}'/{print $4}')
919 else
920 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
923 tomount="/mnt/tmpsnap"
925 if [ ! -d "${tomount}" ]
926 then
927 mkdir -p "${tomount}"
930 fstype=$(get_fstype "${fromdev}")
932 if [ -n "${fstype}" ]
933 then
934 # Copying stuff...
935 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
936 cp -a "${tomount}"/* ${todir}
937 umount "${tomount}"
938 else
939 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
942 rmdir "${tomount}"
944 if echo ${fromdev} | grep -qs loop
945 then
946 losetup -d "${fromdev}"
949 return 0
950 else
951 return 1
953 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
957 find_snap ()
959 # Look for ${snap_label}.* in block devices
960 snap_label="${1}"
962 if [ "${PERSISTENT}" != "nofiles" ]
963 then
964 # search for image files
965 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")
968 if [ -z "${snapdata}" ]
969 then
970 snapdata=$(find_cow_device "${snap_label}")
972 echo "${snapdata}"
975 try_snap ()
977 # copy the contents of previously found snapshot to ${snap_mount}
978 # and remember the device and filename for resync on exit in live-boot.init
980 snapdata="${1}"
981 snap_mount="${2}"
982 snap_type="${3}"
984 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
985 then
986 log_success_msg "found snapshot: ${snapdata}"
987 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
988 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
989 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
991 RES=""
992 if ! try_mount "${snapdev}" "${snapback}" "ro"
993 then
994 break
997 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
998 then
999 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1000 dev=$(get_backing_device "${snapback}/${snapfile}")
1002 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1003 RES=$?
1004 else
1005 # cpio.gz snapshot
1007 # Unfortunately klibc's cpio is incompatible with the
1008 # rest of the world; everything else requires -u -d,
1009 # while klibc doesn't implement them. Try to detect
1010 # whether it's in use.
1011 cpiopath="$(which cpio)" || true
1012 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1013 then
1014 cpioargs=
1015 else
1016 cpioargs='--unconditional --make-directories'
1019 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1020 then
1021 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1025 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1027 if [ "${RES}" != "0" ]
1028 then
1029 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1032 elif [ -b "${snapdata}" ]
1033 then
1034 # Try to find if it could be a snapshot partition
1035 dev="${snapdata}"
1036 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1037 if echo "${dev}" | grep -qs loop
1038 then
1039 # strange things happens, user confused?
1040 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1041 snapfile=$(basename ${snaploop})
1042 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1043 else
1044 snapdev="${dev}"
1047 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1048 then
1049 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1050 return 1
1051 else
1052 if [ -n "${snapfile}" ]
1053 then
1054 # it was a loop device, user confused
1055 umount ${snapdev}
1058 else
1059 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1060 return 1
1063 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1064 return 0
1067 setup_unionfs ()
1069 image_directory="${1}"
1070 rootmnt="${2}"
1071 addimage_directory="${3}"
1073 case ${UNIONTYPE} in
1074 aufs|unionfs)
1075 modprobe -q -b ${UNIONTYPE}
1077 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1078 then
1079 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1080 echo "This might be really slow."
1082 UNIONTYPE="unionfs-fuse"
1085 esac
1087 if [ "${UNIONTYPE}" = unionfs-fuse ]
1088 then
1089 modprobe fuse
1092 # run-init can't deal with images in a subdir, but we're going to
1093 # move all of these away before it runs anyway. No, we're not,
1094 # put them in / since move-mounting them into / breaks mono and
1095 # some other apps.
1097 croot="/"
1099 # Let's just mount the read-only file systems first
1100 rofsstring=""
1101 rofslist=""
1103 if [ "${UNIONTYPE}" = "aufs" ]
1104 then
1105 roopt="rr"
1106 noxino_opt="noxino,"
1107 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1108 then
1109 roopt="RO"
1110 else
1111 roopt="ro"
1114 if [ -z "${PLAIN_ROOT}" ]
1115 then
1116 # Read image names from ${MODULE}.module if it exists
1117 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1118 then
1119 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1121 image_string="${image_string} ${image_directory}/${IMAGE}"
1122 done
1123 elif [ -e "${image_directory}/${MODULE}.module" ]
1124 then
1125 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1127 image_string="${image_string} ${image_directory}/${IMAGE}"
1128 done
1129 else
1130 # ${MODULE}.module does not exist, create a list of images
1131 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1133 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1135 if [ -e "${IMAGE}" ]
1136 then
1137 image_string="${image_string} ${IMAGE}"
1139 done
1140 done
1142 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1143 then
1144 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1146 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1148 if [ -e "${IMAGE}" ]
1149 then
1150 image_string="${image_string} ${IMAGE}"
1152 done
1153 done
1156 # Now sort the list
1157 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1160 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1162 mkdir -p "${croot}"
1164 for image in ${image_string}
1166 imagename=$(basename "${image}")
1168 export image devname
1169 maybe_break live-realpremount
1170 log_begin_msg "Running /scripts/live-realpremount"
1171 run_scripts /scripts/live-realpremount
1172 log_end_msg
1174 if [ -d "${image}" ]
1175 then
1176 # it is a plain directory: do nothing
1177 rofsstring="${image}=${roopt}:${rofsstring}"
1178 rofslist="${image} ${rofslist}"
1179 elif [ -f "${image}" ]
1180 then
1181 if losetup --help 2>&1 | grep -q -- "-r\b"
1182 then
1183 backdev=$(get_backing_device "${image}" "-r")
1184 else
1185 backdev=$(get_backing_device "${image}")
1187 fstype=$(get_fstype "${backdev}")
1189 if [ "${fstype}" = "unknown" ]
1190 then
1191 panic "Unknown file system type on ${backdev} (${image})"
1194 if [ -z "${fstype}" ]
1195 then
1196 fstype="${imagename##*.}"
1197 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1200 mkdir -p "${croot}/${imagename}"
1201 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1202 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}"
1203 log_end_msg
1205 done
1206 else
1207 # we have a plain root system
1208 mkdir -p "${croot}/filesystem"
1209 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1210 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}"
1211 # probably broken:
1212 mount -o bind ${croot}/filesystem $mountpoint
1213 log_end_msg
1216 rofsstring=${rofsstring%:}
1218 mkdir -p /cow
1220 # Looking for "${root_persistence}" device or file
1221 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1222 then
1223 if [ -z "${QUICKUSBMODULES}" ]
1224 then
1225 # Load USB modules
1226 num_block=$(ls -l /sys/block | wc -l)
1227 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1229 modprobe -q -b ${module}
1230 done
1232 udevadm trigger
1233 udevadm settle
1235 # For some reason, udevsettle does not block in this scenario,
1236 # so we sleep for a little while.
1238 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1239 for timeout in 5 4 3 2 1
1241 sleep 1
1243 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1244 then
1245 break
1247 done
1250 # search for label and files (this could be hugely optimized)
1251 cowprobe=$(find_cow_device "${root_persistence}")
1252 if [ -b "${cowprobe}" ]
1253 then
1254 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1255 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1256 # snapshots to be sure to really store some e.g key config files,
1257 # but not on the same media
1258 blacklistdev="${cowprobe}"
1259 PERSISTENCE_IS_ON="1"
1260 export PERSISTENCE_IS_ON
1262 # homecow just mount something on /home, this should be generalized some way
1263 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1264 if [ -b "${homecow}" ]
1265 then
1266 PERSISTENCE_IS_ON="1"
1267 export PERSISTENCE_IS_ON
1269 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1270 # This second type should be removed when snapshot will get smarter,
1271 # hence when "/etc/live-snapshot*list" will be supported also by
1272 # ext2|ext3|ext4|jffs2 snapshot types.
1273 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1275 if [ -b "${cowprobe}" ]
1276 then
1277 cowdevice=${cowprobe}
1278 cow_fstype=$(get_fstype "${cowprobe}")
1279 cow_mountopt="rw,noatime"
1281 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1282 then
1283 fsck -y ${cowdevice}
1285 else
1286 log_warning_msg "Unable to find the persistent medium"
1287 cowdevice="tmpfs"
1288 cow_fstype="tmpfs"
1289 cow_mountopt="rw,noatime,mode=755"
1291 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1292 then
1293 # check if there are any nfs options
1294 if echo ${NFS_COW}|grep -q ','
1295 then
1296 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1297 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1298 else
1299 nfs_cow_opts="-o nolock"
1300 nfs_cow=${NFS_COW}
1302 mac="$(get_mac)"
1303 if [ -n "${mac}" ]
1304 then
1305 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1306 cow_fstype="nfs"
1307 else
1308 panic "unable to determine mac address"
1310 else
1311 cowdevice="tmpfs"
1312 cow_fstype="tmpfs"
1313 cow_mountopt="rw,noatime,mode=755"
1316 if [ "${cow_fstype}" = "nfs" ]
1317 then
1318 log_begin_msg \
1319 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1320 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1321 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1322 else
1323 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1324 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1327 rofscount=$(echo ${rofslist} |wc -w)
1329 if [ -n "${EXPOSED_ROOT}" ]
1330 then
1331 if [ ${rofscount} -ne 1 ]
1332 then
1333 panic "only one RO file system supported with exposedroot: ${rofslist}"
1335 exposedrootfs=${rofslist%% }
1337 mount --bind ${exposedrootfs} ${rootmnt} || \
1338 panic "bind mount of ${exposedrootfs} failed"
1340 if [ -z "${SKIP_UNION_MOUNTS}" ]
1341 then
1342 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1343 else
1344 cow_dirs=''
1347 for dir in ${cow_dirs}; do
1348 mkdir -p /cow${dir}
1350 case "${UNIONTYPE}" in
1351 unionfs-fuse)
1352 (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}")
1353 mkdir -p /dev/.initramfs/varrun
1354 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1358 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"
1360 esac
1361 done
1362 else
1363 case "${UNIONTYPE}" in
1364 unionfs-fuse)
1365 (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}")
1366 mkdir -p /dev/.initramfs/varrun
1367 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1371 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}"
1373 esac
1376 # Correct the permissions of /:
1377 chmod 0755 "${rootmnt}"
1379 # tmpfs file systems
1380 touch /etc/fstab
1381 mkdir -p "${rootmnt}/live"
1382 mount -t tmpfs tmpfs ${rootmnt}/live
1384 # Adding other custom mounts
1385 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1386 then
1387 # directly mount /home
1388 # FIXME: add a custom mounts configurable system
1390 if [ -b "${homecow}" ]
1391 then
1392 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1393 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1394 else
1395 log_warning_msg "Unable to find the persistent home medium"
1398 # Look for other snapshots to copy in
1399 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1400 # This second type should be removed when snapshot grow smarter
1401 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1404 if [ -n "${SHOWMOUNTS}" ]
1405 then
1406 for d in ${rofslist}
1408 mkdir -p "${rootmnt}/live/${d##*/}"
1410 case d in
1411 *.dir)
1412 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1416 case "${UNIONTYPE}" in
1417 unionfs-fuse)
1418 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1422 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1424 esac
1426 esac
1427 done
1430 # shows cow fs on /cow for use by live-snapshot
1431 mkdir -p "${rootmnt}/live/cow"
1432 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"
1435 check_dev ()
1437 sysdev="${1}"
1438 devname="${2}"
1439 skip_uuid_check="${3}"
1441 # support for fromiso=.../isofrom=....
1442 if [ -n "$FROMISO" ]
1443 then
1444 ISO_DEVICE=$(dirname $FROMISO)
1445 if ! [ -b $ISO_DEVICE ]
1446 then
1447 # to support unusual device names like /dev/cciss/c0d0p1
1448 # as well we have to identify the block device name, let's
1449 # do that for up to 15 levels
1450 i=15
1451 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1453 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1454 [ -b "$ISO_DEVICE" ] && break
1455 i=$(($i -1))
1456 done
1459 if [ "$ISO_DEVICE" = "/" ]
1460 then
1461 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1462 else
1463 mkdir /isofrom
1464 mount "$ISO_DEVICE" /isofrom
1465 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1466 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1467 devname="${loopdevname}"
1471 if [ -z "${devname}" ]
1472 then
1473 devname=$(sys2dev "${sysdev}")
1476 if [ -d "${devname}" ]
1477 then
1478 mount -o bind "${devname}" $mountpoint || continue
1480 if is_live_path $mountpoint
1481 then
1482 echo $mountpoint
1483 return 0
1484 else
1485 umount $mountpoint
1488 [ -e "$devname" ] || continue
1490 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1491 then
1492 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1493 devname="${loopdevname}"
1496 fstype=$(get_fstype "${devname}")
1498 if is_supported_fs ${fstype}
1499 then
1500 devuid=$(blkid -o value -s UUID "$devname")
1501 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1502 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1503 [ -n "$devuid" ] && echo "$devuid" >> $tried
1505 if is_live_path ${mountpoint} && \
1506 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1507 then
1508 echo ${mountpoint}
1509 return 0
1510 else
1511 umount ${mountpoint}
1515 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1516 then
1517 losetup -d "${loopdevname}"
1520 return 1
1523 find_livefs ()
1525 timeout="${1}"
1527 # don't start autodetection before timeout has expired
1528 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1529 then
1530 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1531 then
1532 return 1
1536 # first look at the one specified in the command line
1537 case "${LIVE_MEDIA}" in
1538 removable-usb)
1539 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1541 if [ "$(cat ${sysblock}/removable)" = "1" ]
1542 then
1543 if readlink ${sysblock} | grep -q usb ||
1544 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1545 then
1546 for dev in $(subdevices "${sysblock}")
1548 if check_dev "${dev}"
1549 then
1550 return 0
1552 done
1555 done
1556 return 1
1559 removable)
1560 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1562 if [ "$(cat ${sysblock}/removable)" = "1" ]
1563 then
1564 for dev in $(subdevices "${sysblock}")
1566 if check_dev "${dev}"
1567 then
1568 return 0
1570 done
1572 done
1573 return 1
1577 if [ ! -z "${LIVE_MEDIA}" ]
1578 then
1579 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1580 then
1581 return 0
1585 esac
1587 # or do the scan of block devices
1588 # prefer removable devices over non-removable devices, so scan them first
1589 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1591 if [ "$(cat ${sysblock}/removable)" = "1" ]
1592 then
1593 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1594 else
1595 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1597 done
1598 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1600 for sysblock in $devices_to_scan
1602 devname=$(sys2dev "${sysblock}")
1603 [ -e "$devname" ] || continue
1604 fstype=$(get_fstype "${devname}")
1606 if /lib/udev/cdrom_id ${devname} > /dev/null
1607 then
1608 if check_dev "null" "${devname}"
1609 then
1610 return 0
1612 elif is_nice_device "${sysblock}"
1613 then
1614 for dev in $(subdevices "${sysblock}")
1616 if check_dev "${dev}"
1617 then
1618 return 0
1620 done
1621 elif [ "${fstype}" = "squashfs" -o \
1622 "${fstype}" = "ext2" -o \
1623 "${fstype}" = "ext3" -o \
1624 "${fstype}" = "ext4" -o \
1625 "${fstype}" = "jffs2" ]
1626 then
1627 # This is an ugly hack situation, the block device has
1628 # an image directly on it. It's hopefully
1629 # live-boot, so take it and run with it.
1630 ln -s "${devname}" "${devname}.${fstype}"
1631 echo "${devname}.${fstype}"
1632 return 0
1634 done
1636 return 1
1639 set_usplash_timeout ()
1641 if [ -x /sbin/usplash_write ]
1642 then
1643 /sbin/usplash_write "TIMEOUT 120"
1644 else if [ -x /sbin/splashy_update ] ; then
1645 /sbin/splashy_update "TIMEOUT 120"
1646 fi ; fi
1649 integrity_check ()
1651 media_mountpoint="${1}"
1653 log_begin_msg "Checking media integrity"
1655 cd ${media_mountpoint}
1656 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1657 RC="${?}"
1659 log_end_msg
1661 if [ "${RC}" -eq 0 ]
1662 then
1663 log_success_msg "Everything ok, will reboot in 10 seconds."
1664 sleep 10
1665 cd /
1666 umount ${media_mountpoint}
1667 sync
1668 echo u > /proc/sysrq-trigger
1669 echo b > /proc/sysrq-trigger
1670 else
1671 panic "Not ok, a media defect is likely, switch to VT8 for details."
1675 start_usplash_pulse ()
1677 if [ -x /sbin/usplash_write ]
1678 then
1679 /sbin/usplash_write "PULSELOGO"
1683 mountroot ()
1685 if [ -x /scripts/local-top/cryptroot ]; then
1686 /scripts/local-top/cryptroot
1689 exec 6>&1
1690 exec 7>&2
1691 exec > live.log
1692 exec 2>&1
1693 tail -f live.log >&7 &
1694 tailpid="${!}"
1696 # Ensure 'panic' function is overridden
1697 . /scripts/live-functions
1699 Arguments
1701 set_usplash_timeout
1702 start_usplash_pulse
1704 maybe_break live-premount
1705 log_begin_msg "Running /scripts/live-premount"
1706 run_scripts /scripts/live-premount
1707 log_end_msg
1709 # Needed here too because some things (*cough* udev *cough*)
1710 # changes the timeout
1712 set_usplash_timeout
1714 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1715 then
1716 if do_netmount
1717 then
1718 livefs_root="${mountpoint}"
1719 else
1720 panic "Unable to find a live file system on the network"
1722 else
1723 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1724 then
1725 # Do a local boot from hd
1726 livefs_root=${ROOT}
1727 else
1728 # Scan local devices for the image
1730 while [ "$i" -lt 60 ]
1732 livefs_root=$(find_livefs ${i})
1734 if [ -n "${livefs_root}" ]
1735 then
1736 break
1739 sleep 1
1740 i="$(($i + 1))"
1741 done
1745 if [ -z "${livefs_root}" ]
1746 then
1747 panic "Unable to find a medium containing a live file system"
1750 if [ "${INTEGRITY_CHECK}" ]
1751 then
1752 integrity_check "${livefs_root}"
1755 if [ "${TORAM}" ]
1756 then
1757 live_dest="ram"
1758 elif [ "${TODISK}" ]
1759 then
1760 live_dest="${TODISK}"
1763 if [ "${live_dest}" ]
1764 then
1765 log_begin_msg "Copying live media to ${live_dest}"
1766 copy_live_to "${livefs_root}" "${live_dest}"
1767 log_end_msg
1770 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1771 # because the mountpoint is left behind in /proc/mounts, so let's get
1772 # rid of it when running from RAM
1773 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1774 then
1775 losetup -d /dev/loop0
1776 grep -q /isofrom /proc/mounts && umount /isofrom
1779 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1780 then
1781 setup_unionfs "${livefs_root}" "${rootmnt}"
1782 else
1783 mac="$(get_mac)"
1784 mac="$(echo ${mac} | sed 's/-//g')"
1785 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1788 log_end_msg
1790 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1791 # live-bottom; udev's init script will take care of things after that
1792 if [ "${UNIONTYPE}" = unionfs-fuse ]
1793 then
1794 mount -n -o bind /dev "${rootmnt}/dev"
1797 # Move to the new root filesystem so that programs there can get at it.
1798 if [ ! -d /root/live/image ]
1799 then
1800 mkdir -p /root/live/image
1801 mount --move /live/image /root/live/image
1804 maybe_break live-bottom
1805 log_begin_msg "Running /scripts/live-bottom\n"
1807 run_scripts /scripts/live-bottom
1808 log_end_msg
1810 if [ "${UNIONFS}" = unionfs-fuse ]
1811 then
1812 umount "${rootmnt}/dev"
1815 exec 1>&6 6>&-
1816 exec 2>&7 7>&-
1817 kill ${tailpid}
1818 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1819 if [ -f /etc/live.conf ]
1820 then
1821 cp /etc/live.conf "${rootmnt}/etc/"