Dropping /etc/live.conf, replaced mostly by /etc/live/config.conf of live-config.
[debian-live-boot/hramrach.git] / scripts / live
blob4eaf3a687999a20fc44518817e7bc9c983eae421
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 NOAPTCDROM="Yes"
55 NOAUTOLOGIN="Yes"
56 NOCONSOLEKEYBOARD="Yes"
57 NOFASTBOOT="Yes"
58 NOFSTAB="Yes"
59 NOHOSTS="Yes"
60 NONETWORKING="Yes"
61 NOTIMEZONE="Yes"
62 NOXAUTOCONFIG="Yes"
63 NOXAUTOLOGIN="Yes"
65 export NOACCESSIBILITY NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOHOSTS NONETWORKING NOTIMEZONE NOXAUTOCONFIG NOXAUTOLOGIN
68 access=*)
69 ACCESS="${ARGUMENT#access=}"
70 export ACCESS
73 console=*)
74 DEFCONSOLE="${ARGUMENT#*=}"
75 export DEFCONSOLE
78 debug)
79 DEBUG="Yes"
80 export DEBUG
82 set -x
85 dhcp)
86 # Force dhcp even while netbooting
87 # Use for debugging in case somebody works on fixing dhclient
88 DHCP="Force";
89 export DHCP
92 nodhcp)
93 unset DHCP
96 ethdevice=*)
97 DEVICE="${ARGUMENT#ethdevice=}"
98 export DEVICE
101 ethdevice=*)
102 ETHDEVICE="${ARGUMENT#ethdevice=}"
103 export ETHDEVICE
106 ethdevice-timeout=*)
107 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
108 export ETHDEV_TIMEOUT
111 fetch=*)
112 FETCH="${ARGUMENT#fetch=}"
113 export FETCH
116 forcepersistentfsck)
117 FORCEPERSISTENTFSCK="Yes"
118 export FORCEPERSISTENTFSCK
121 ftpfs=*)
122 FTPFS="${ARGUMENT#ftpfs=}"
123 export FTPFS
126 httpfs=*)
127 HTTPFS="${ARGUMENT#httpfs=}"
128 export HTTPFS
131 isofrom=*|fromiso=*)
132 FROMISO="${ARGUMENT#*=}"
133 export FROMISO
136 username=*)
137 USERNAME="${ARGUMENT#username=}"
138 LIVECONF="changed"
139 export USERNAME LIVECONF
142 userfullname=*)
143 USERFULLNAME="${ARGUMENT#userfullname=}"
144 LIVECONF="changed"
145 export USERFULLNAME LIVECONF
148 ignore_uuid)
149 IGNORE_UUID="Yes"
150 export IGNORE_UUID
153 integrity-check)
154 INTEGRITY_CHECK="Yes"
155 export INTEGRITY_CHECK
158 ip=*)
159 STATICIP="${ARGUMENT#ip=}"
161 if [ -z "${STATICIP}" ]
162 then
163 STATICIP="frommedia"
166 export STATICIP
169 keyb=*|kbd-chooser/method=*)
170 KBD="${ARGUMENT#*=}"
171 export KBD
174 klayout=*|console-setup/layoutcode=*)
175 KLAYOUT="${ARGUMENT#*=}"
176 export KLAYOUT
179 kvariant=*|console-setup/variantcode=*)
180 KVARIANT="${ARGUMENT#*=}"
181 export KVARIANT
184 kmodel=*|console-setup/modelcode=*)
185 KMODEL="${ARGUMENT#*=}"
186 export KMODEL
189 koptions=*)
190 KOPTIONS="${ARGUMENT#koptions=}"
191 export KOPTIONS
194 live-getty)
195 LIVE_GETTY="1"
196 export LIVE_GETTY
199 live-media=*|bootfrom=*)
200 LIVE_MEDIA="${ARGUMENT#*=}"
201 export LIVE_MEDIA
204 live-media-encryption=*|encryption=*)
205 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
206 export LIVE_MEDIA_ENCRYPTION
209 live-media-offset=*)
210 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
211 export LIVE_MEDIA_OFFSET
214 live-media-path=*)
215 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
216 export LIVE_MEDIA_PATH
219 live-media-timeout=*)
220 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
221 export LIVE_MEDIA_TIMEOUT
224 module=*)
225 MODULE="${ARGUMENT#module=}"
226 export MODULE
229 netboot=*)
230 NETBOOT="${ARGUMENT#netboot=}"
231 export NETBOOT
234 nfsopts=*)
235 NFSOPTS="${ARGUMENT#nfsopts=}"
236 export NFSOPTS
239 nfscow=*)
240 NFS_COW="${ARGUMENT#nfscow=}"
241 export NFS_COW
244 noaccessibility)
245 NOACCESSIBILITY="Yes"
246 export NOACCESSIBILITY
249 noaptcdrom)
250 NOAPTCDROM="Yes"
251 export NOAPTCDROM
254 noautologin)
255 NOAUTOLOGIN="Yes"
256 export NOAUTOLOGIN
259 noxautologin)
260 NOXAUTOLOGIN="Yes"
261 export NOXAUTOLOGIN
264 noconsolekeyboard)
265 NOCONSOLEKEYBOARD="Yes"
266 export NOCONSOLEKEYBOARD
269 nofastboot)
270 NOFASTBOOT="Yes"
271 export NOFASTBOOT
274 nofstab)
275 NOFSTAB="Yes"
276 export NOFSTAB
279 nohosts)
280 NOHOSTS="Yes"
281 export NOHOSTS
284 nonetworking)
285 NONETWORKING="Yes"
286 export NONETWORKING
289 swapon)
290 SWAPON="Yes"
291 export SWAPON
294 noxautoconfig)
295 NOXAUTOCONFIG="Yes"
296 export NOXAUTOCONFIG
299 noxscreensaver)
300 NOXSCREENSAVER="Yes"
301 export NOXSCREENSAVER
304 persistent)
305 PERSISTENT="Yes"
306 export PERSISTENT
309 persistent=*)
310 PERSISTENT="${ARGUMENT#persistent=}"
311 if [ -z "${PERSISTENT}" ]
312 then
313 PERSISTENT="Yes"
315 export PERSISTENT
318 persistent-path=*)
319 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
320 export PERSISTENT_PATH
323 persistent-subtext=*)
324 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
325 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
326 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
327 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
330 nopersistent)
331 NOPERSISTENT="Yes"
332 export NOPERSISTENT
335 quickusbmodules)
336 QUICKUSBMODULES="Yes"
337 export QUICKUSBMODULES
340 preseed/file=*|file=*)
341 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
342 export LOCATIONS
345 nopreseed)
346 NOPRESEED="Yes"
347 export NOPRESEED
350 */*=*)
351 question="${ARGUMENT%%=*}"
352 value="${ARGUMENT#*=}"
353 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
354 export PRESEEDS
357 showmounts)
358 SHOWMOUNTS="Yes"
359 export SHOWMOUNTS
362 silent)
363 SILENT="Yes"
364 export SILENT
367 textonly)
368 TEXTONLY="Yes"
369 export TEXTONLY
372 timezone=*)
373 TIMEZONE="${ARGUMENT#timezone=}"
374 export TIMEZONE
377 notimezone)
378 NOTIMEZONE="Yes"
379 export NOTIMEZONE
382 todisk=*)
383 TODISK="${ARGUMENT#todisk=}"
384 export TODISK
387 toram)
388 TORAM="Yes"
389 export TORAM
392 toram=*)
393 TORAM="Yes"
394 MODULETORAM="${ARGUMENT#toram=}"
395 export TORAM MODULETORAM
398 exposedroot)
399 EXPOSED_ROOT="Yes"
400 export EXPOSED_ROOT
403 plainroot)
404 PLAIN_ROOT="Yes"
405 export PLAIN_ROOT
408 skipunion)
409 SKIP_UNION_MOUNTS="Yes"
410 export SKIP_UNION_MOUNTS
413 root=*)
414 ROOT="${ARGUMENT#root=}"
415 export ROOT
418 union=*)
419 UNIONTYPE="${ARGUMENT#union=}"
420 export UNIONTYPE
423 xdebconf)
424 XDEBCONF="Yes"
425 export XDEBCONF
428 xdriver=*)
429 XDRIVER="${ARGUMENT#xdriver=}"
430 export XDRIVER
433 xvideomode=*)
434 XVIDEOMODE="${ARGUMENT#xvideomode=}"
435 export XVIDEOMODE
437 esac
438 done
440 # sort of compatibility with netboot.h from linux docs
441 if [ -z "${NETBOOT}" ]
442 then
443 if [ "${ROOT}" = "/dev/nfs" ]
444 then
445 NETBOOT="nfs"
446 export NETBOOT
447 elif [ "${ROOT}" = "/dev/cifs" ]
448 then
449 NETBOOT="cifs"
450 export NETBOOT
454 if [ -z "${MODULE}" ]
455 then
456 MODULE="filesystem"
457 export MODULE
460 if [ -z "${UNIONTYPE}" ]
461 then
462 UNIONTYPE="aufs"
463 export UNIONTYPE
467 is_live_path ()
469 DIRECTORY="${1}"
471 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
472 then
473 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
475 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
476 then
477 return 0
479 done
482 return 1
485 matches_uuid ()
487 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
488 then
489 return 0
492 path="${1}"
493 uuid="$(cat /conf/uuid.conf)"
495 for try_uuid_file in "${path}/.disk/live-uuid"*
497 [ -e "${try_uuid_file}" ] || continue
499 try_uuid="$(cat "${try_uuid_file}")"
501 if [ "${uuid}" = "${try_uuid}" ]
502 then
503 return 0
505 done
507 return 1
510 get_backing_device ()
512 case "${1}" in
513 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
514 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
517 *.dir)
518 echo "directory"
522 panic "Unrecognized live filesystem: ${1}"
524 esac
527 match_files_in_dir ()
529 # Does any files match pattern ${1} ?
530 local pattern="${1}"
532 if [ "$(echo ${pattern})" != "${pattern}" ]
533 then
534 return 0
537 return 1
540 mount_images_in_directory ()
542 directory="${1}"
543 rootmnt="${2}"
544 mac="${3}"
547 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
548 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
549 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
550 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
551 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
552 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
553 then
554 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
555 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
556 else
557 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
561 is_nice_device ()
563 sysfs_path="${1#/sys}"
565 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
566 then
567 return 0
568 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
569 then
570 return 0
571 elif echo ${sysfs_path} | grep -q "^/block/dm-"
572 then
573 return 0
576 return 1
579 copy_live_to ()
581 copyfrom="${1}"
582 copytodev="${2}"
583 copyto="${copyfrom}_swap"
585 if [ -z "${MODULETORAM}" ]
586 then
587 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
588 else
589 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
591 if [ -f "${MODULETORAMFILE}" ]
592 then
593 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
594 else
595 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
596 return 1
600 if [ "${copytodev}" = "ram" ]
601 then
602 # copying to ram:
603 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
604 mount_options="-o size=${size}k"
605 free_string="memory"
606 fstype="tmpfs"
607 dev="/dev/shm"
608 else
609 # it should be a writable block device
610 if [ -b "${copytodev}" ]
611 then
612 dev="${copytodev}"
613 free_string="space"
614 fstype=$(get_fstype "${dev}")
615 freespace=$(fs_size "${dev}")
616 else
617 log_warning_msg "${copytodev} is not a block device."
618 return 1
622 if [ "${freespace}" -lt "${size}" ]
623 then
624 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
625 return 1
628 # begin copying (or uncompressing)
629 mkdir "${copyto}"
630 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
631 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
633 if [ "${extension}" = "tgz" ]
634 then
635 cd "${copyto}"
636 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
637 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
638 mount -r -o move "${copyto}" "${rootmnt}"
639 cd "${OLDPWD}"
640 else
641 if [ -n "${MODULETORAMFILE}" ]
642 then
643 if [ -x /bin/rsync ]
644 then
645 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
646 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
647 else
648 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
650 else
651 if [ -x /bin/rsync ]
652 then
653 echo " * Copying whole medium to RAM" 1>/dev/console
654 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
655 else
656 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
657 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
658 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
659 then
660 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
665 umount ${copyfrom}
666 mount -r -o move ${copyto} ${copyfrom}
669 rmdir ${copyto}
670 return 0
673 do_netmount ()
675 modprobe -q af_packet # For DHCP
677 udevadm trigger
678 udevadm settle
680 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
681 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
682 then
684 # if ethdevice was not specified on the kernel command line
685 # make sure we try to get a working network configuration
686 # for *every* present network device (except for loopback of course)
687 if [ -z "$ETHDEVICE" ] ; then
688 echo "If you want to boot from a specific device use bootoption ethdevice=..."
689 for device in /sys/class/net/*; do
690 dev=${device##*/} ;
691 if [ "$dev" != "lo" ] ; then
692 ETHDEVICE="$ETHDEVICE $dev"
694 done
697 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
698 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
699 devlist="$devlist $device"
700 done
702 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
703 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
705 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
706 # an endless loop; iff execution fails give it two further tries, that's
707 # why we use '$devlist $devlist $devlist' for the other for loop
708 for dev in $devlist $devlist $devlist ; do
709 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
710 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
711 jobid=$!
712 sleep "$ETHDEV_TIMEOUT" ; sleep 1
713 if [ -r /proc/"$jobid"/status ] ; then
714 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
715 kill -9 $jobid
718 # if configuration of device worked we should have an assigned
719 # IP address, iff so let's use the according as $DEVICE for later usage
720 # simple and primitive approach which seems to work fine
721 if ifconfig $dev | grep -q 'inet.*addr:' ; then
722 export DEVICE="$dev"
723 break
725 done
727 else
728 ipconfig ${DEVICE} | tee /netboot.config
731 # source relevant ipconfig output
732 OLDHOSTNAME=${HOSTNAME}
733 . /tmp/net-${DEVICE}.conf
734 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
735 export HOSTNAME
737 # Check if we have a network device at all
738 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
739 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
740 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
741 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
742 ! ls /sys/class/net/ra0 > /dev/null 2>&1
743 then
744 panic "No supported network device found, maybe a non-mainline driver is required."
747 if [ "${NFSROOT}" = "auto" ]
748 then
749 NFSROOT=${ROOTSERVER}:${ROOTPATH}
752 rc=1
754 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
755 then
756 do_httpmount
757 return $?
760 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
761 then
762 NFSROOT=${ROOTSERVER}:${NFSROOT}
765 log_begin_msg "Trying netboot from ${NFSROOT}"
767 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
768 then
769 rc=0
770 elif do_nfsmount
771 then
772 NETBOOT="nfs"
773 export NETBOOT
774 rc=0
777 log_end_msg
778 return ${rc}
781 do_httpmount ()
783 rc=1
785 for webfile in HTTPFS FTPFS FETCH
787 local url="$(eval echo \"\$\{${webfile}\}\")"
788 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
790 if [ -n "$url" ]
791 then
792 case "${extension}" in
793 iso|squashfs|tgz|tar)
794 if [ "${extension}" = "iso" ]
795 then
796 mkdir -p "${alt_mountpoint}"
797 dest="${alt_mountpoint}"
798 else
799 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
800 mount -t ramfs ram "${mountpoint}"
801 mkdir -p "${dest}"
803 if [ "${webfile}" = "FETCH" ]
804 then
805 case "$url" in
806 tftp*)
807 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
808 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
809 lfile="$(basename $url)"
810 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
811 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
815 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
816 wget "${url}" -O "${dest}/$(basename ${url})"
818 esac
819 else
820 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
821 if [ "${webfile}" = "FTPFS" ]
822 then
823 FUSE_MOUNT="curlftpfs"
824 url="$(dirname ${url})"
825 else
826 FUSE_MOUNT="httpfs"
828 modprobe fuse
829 $FUSE_MOUNT "${url}" "${dest}"
831 [ ${?} -eq 0 ] && rc=0
832 [ "${extension}" = "tgz" ] && live_dest="ram"
833 if [ "${extension}" = "iso" ]
834 then
835 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
836 mount -t iso9660 "${isoloop}" "${mountpoint}"
837 rc=${?}
839 break
843 log_begin_msg "Unrecognized archive extension for ${url}"
845 esac
847 done
849 if [ ${rc} != 0 ]
850 then
851 if [ -d "${alt_mountpoint}" ]
852 then
853 umount "${alt_mountpoint}"
854 rmdir "${alt_mountpoint}"
856 umount "${mountpoint}"
857 elif [ "${webfile}" != "FETCH" ] ; then
858 NETBOOT="${webfile}"
859 export NETBOOT
862 return ${rc}
865 do_nfsmount ()
867 rc=1
869 modprobe -q nfs
871 if [ -z "${NFSOPTS}" ]
872 then
873 NFSOPTS=""
876 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
878 # FIXME: This while loop is an ugly HACK round an nfs bug
880 while [ "$i" -lt 60 ]
882 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
883 sleep 1
884 i="$(($i + 1))"
885 done
887 return ${rc}
890 do_cifsmount ()
892 rc=1
894 if [ -x "/sbin/mount.cifs" ]
895 then
896 if [ -z "${NFSOPTS}" ]
897 then
898 CIFSOPTS="-ouser=root,password="
899 else
900 CIFSOPTS="${NFSOPTS}"
903 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
904 modprobe -q cifs
906 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
907 then
908 rc=0
912 return ${rc}
915 do_snap_copy ()
917 fromdev="${1}"
918 todir="${2}"
919 snap_type="${3}"
920 size=$(fs_size "${fromdev}" "" "used")
922 if [ -b "${fromdev}" ]
923 then
924 # look for free mem
925 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
926 then
927 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
928 freespace=$(df -k | awk '/'${todev}'/{print $4}')
929 else
930 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
933 tomount="/mnt/tmpsnap"
935 if [ ! -d "${tomount}" ]
936 then
937 mkdir -p "${tomount}"
940 fstype=$(get_fstype "${fromdev}")
942 if [ -n "${fstype}" ]
943 then
944 # Copying stuff...
945 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
946 cp -a "${tomount}"/* ${todir}
947 umount "${tomount}"
948 else
949 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
952 rmdir "${tomount}"
954 if echo ${fromdev} | grep -qs loop
955 then
956 losetup -d "${fromdev}"
959 return 0
960 else
961 return 1
963 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
967 find_snap ()
969 # Look for ${snap_label}.* in block devices
970 snap_label="${1}"
972 if [ "${PERSISTENT}" != "nofiles" ]
973 then
974 # search for image files
975 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")
978 if [ -z "${snapdata}" ]
979 then
980 snapdata=$(find_cow_device "${snap_label}")
982 echo "${snapdata}"
985 try_snap ()
987 # copy the contents of previously found snapshot to ${snap_mount}
988 # and remember the device and filename for resync on exit in live-boot.init
990 snapdata="${1}"
991 snap_mount="${2}"
992 snap_type="${3}"
994 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
995 then
996 log_success_msg "found snapshot: ${snapdata}"
997 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
998 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
999 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1001 RES=""
1002 if ! try_mount "${snapdev}" "${snapback}" "ro"
1003 then
1004 break
1007 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1008 then
1009 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1010 dev=$(get_backing_device "${snapback}/${snapfile}")
1012 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1013 RES=$?
1014 else
1015 # cpio.gz snapshot
1017 # Unfortunately klibc's cpio is incompatible with the
1018 # rest of the world; everything else requires -u -d,
1019 # while klibc doesn't implement them. Try to detect
1020 # whether it's in use.
1021 cpiopath="$(which cpio)" || true
1022 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1023 then
1024 cpioargs=
1025 else
1026 cpioargs='--unconditional --make-directories'
1029 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1030 then
1031 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1035 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1037 if [ "${RES}" != "0" ]
1038 then
1039 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1042 elif [ -b "${snapdata}" ]
1043 then
1044 # Try to find if it could be a snapshot partition
1045 dev="${snapdata}"
1046 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1047 if echo "${dev}" | grep -qs loop
1048 then
1049 # strange things happens, user confused?
1050 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1051 snapfile=$(basename ${snaploop})
1052 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1053 else
1054 snapdev="${dev}"
1057 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1058 then
1059 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1060 return 1
1061 else
1062 if [ -n "${snapfile}" ]
1063 then
1064 # it was a loop device, user confused
1065 umount ${snapdev}
1068 else
1069 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1070 return 1
1073 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1074 return 0
1077 setup_unionfs ()
1079 image_directory="${1}"
1080 rootmnt="${2}"
1081 addimage_directory="${3}"
1083 case ${UNIONTYPE} in
1084 aufs|unionfs)
1085 modprobe -q -b ${UNIONTYPE}
1087 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1088 then
1089 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1090 echo "This might be really slow."
1092 UNIONTYPE="unionfs-fuse"
1095 esac
1097 if [ "${UNIONTYPE}" = unionfs-fuse ]
1098 then
1099 modprobe fuse
1102 # run-init can't deal with images in a subdir, but we're going to
1103 # move all of these away before it runs anyway. No, we're not,
1104 # put them in / since move-mounting them into / breaks mono and
1105 # some other apps.
1107 croot="/"
1109 # Let's just mount the read-only file systems first
1110 rofsstring=""
1111 rofslist=""
1113 if [ "${UNIONTYPE}" = "aufs" ]
1114 then
1115 roopt="rr"
1116 noxino_opt="noxino,"
1117 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1118 then
1119 roopt="RO"
1120 else
1121 roopt="ro"
1124 if [ -z "${PLAIN_ROOT}" ]
1125 then
1126 # Read image names from ${MODULE}.module if it exists
1127 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1128 then
1129 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1131 image_string="${image_string} ${image_directory}/${IMAGE}"
1132 done
1133 elif [ -e "${image_directory}/${MODULE}.module" ]
1134 then
1135 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1137 image_string="${image_string} ${image_directory}/${IMAGE}"
1138 done
1139 else
1140 # ${MODULE}.module does not exist, create a list of images
1141 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1143 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1145 if [ -e "${IMAGE}" ]
1146 then
1147 image_string="${image_string} ${IMAGE}"
1149 done
1150 done
1152 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1153 then
1154 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1156 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1158 if [ -e "${IMAGE}" ]
1159 then
1160 image_string="${image_string} ${IMAGE}"
1162 done
1163 done
1166 # Now sort the list
1167 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1170 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1172 mkdir -p "${croot}"
1174 for image in ${image_string}
1176 imagename=$(basename "${image}")
1178 export image devname
1179 maybe_break live-realpremount
1180 log_begin_msg "Running /scripts/live-realpremount"
1181 run_scripts /scripts/live-realpremount
1182 log_end_msg
1184 if [ -d "${image}" ]
1185 then
1186 # it is a plain directory: do nothing
1187 rofsstring="${image}=${roopt}:${rofsstring}"
1188 rofslist="${image} ${rofslist}"
1189 elif [ -f "${image}" ]
1190 then
1191 if losetup --help 2>&1 | grep -q -- "-r\b"
1192 then
1193 backdev=$(get_backing_device "${image}" "-r")
1194 else
1195 backdev=$(get_backing_device "${image}")
1197 fstype=$(get_fstype "${backdev}")
1199 if [ "${fstype}" = "unknown" ]
1200 then
1201 panic "Unknown file system type on ${backdev} (${image})"
1204 if [ -z "${fstype}" ]
1205 then
1206 fstype="${imagename##*.}"
1207 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1210 mkdir -p "${croot}/${imagename}"
1211 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1212 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}"
1213 log_end_msg
1215 done
1216 else
1217 # we have a plain root system
1218 mkdir -p "${croot}/filesystem"
1219 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1220 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}"
1221 # probably broken:
1222 mount -o bind ${croot}/filesystem $mountpoint
1223 log_end_msg
1226 rofsstring=${rofsstring%:}
1228 mkdir -p /cow
1230 # Looking for "${root_persistence}" device or file
1231 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1232 then
1233 if [ -z "${QUICKUSBMODULES}" ]
1234 then
1235 # Load USB modules
1236 num_block=$(ls -l /sys/block | wc -l)
1237 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1239 modprobe -q -b ${module}
1240 done
1242 udevadm trigger
1243 udevadm settle
1245 # For some reason, udevsettle does not block in this scenario,
1246 # so we sleep for a little while.
1248 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1249 for timeout in 5 4 3 2 1
1251 sleep 1
1253 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1254 then
1255 break
1257 done
1260 # search for label and files (this could be hugely optimized)
1261 cowprobe=$(find_cow_device "${root_persistence}")
1262 if [ -b "${cowprobe}" ]
1263 then
1264 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1265 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1266 # snapshots to be sure to really store some e.g key config files,
1267 # but not on the same media
1268 blacklistdev="${cowprobe}"
1269 PERSISTENCE_IS_ON="1"
1270 export PERSISTENCE_IS_ON
1272 # homecow just mount something on /home, this should be generalized some way
1273 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1274 if [ -b "${homecow}" ]
1275 then
1276 PERSISTENCE_IS_ON="1"
1277 export PERSISTENCE_IS_ON
1279 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1280 # This second type should be removed when snapshot will get smarter,
1281 # hence when "/etc/live-snapshot*list" will be supported also by
1282 # ext2|ext3|ext4|jffs2 snapshot types.
1283 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1285 if [ -b "${cowprobe}" ]
1286 then
1287 cowdevice=${cowprobe}
1288 cow_fstype=$(get_fstype "${cowprobe}")
1289 cow_mountopt="rw,noatime"
1291 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1292 then
1293 fsck -y ${cowdevice}
1295 else
1296 log_warning_msg "Unable to find the persistent medium"
1297 cowdevice="tmpfs"
1298 cow_fstype="tmpfs"
1299 cow_mountopt="rw,noatime,mode=755"
1301 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1302 then
1303 # check if there are any nfs options
1304 if echo ${NFS_COW}|grep -q ','
1305 then
1306 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1307 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1308 else
1309 nfs_cow_opts="-o nolock"
1310 nfs_cow=${NFS_COW}
1312 mac="$(get_mac)"
1313 if [ -n "${mac}" ]
1314 then
1315 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1316 cow_fstype="nfs"
1317 else
1318 panic "unable to determine mac address"
1320 else
1321 cowdevice="tmpfs"
1322 cow_fstype="tmpfs"
1323 cow_mountopt="rw,noatime,mode=755"
1326 if [ "${cow_fstype}" = "nfs" ]
1327 then
1328 log_begin_msg \
1329 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1330 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1331 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1332 else
1333 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1334 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1337 rofscount=$(echo ${rofslist} |wc -w)
1339 if [ -n "${EXPOSED_ROOT}" ]
1340 then
1341 if [ ${rofscount} -ne 1 ]
1342 then
1343 panic "only one RO file system supported with exposedroot: ${rofslist}"
1345 exposedrootfs=${rofslist%% }
1347 mount --bind ${exposedrootfs} ${rootmnt} || \
1348 panic "bind mount of ${exposedrootfs} failed"
1350 if [ -z "${SKIP_UNION_MOUNTS}" ]
1351 then
1352 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1353 else
1354 cow_dirs=''
1357 for dir in ${cow_dirs}; do
1358 mkdir -p /cow${dir}
1360 case "${UNIONTYPE}" in
1361 unionfs-fuse)
1362 (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}")
1363 mkdir -p /dev/.initramfs/varrun
1364 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1368 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"
1370 esac
1371 done
1372 else
1373 case "${UNIONTYPE}" in
1374 unionfs-fuse)
1375 (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}")
1376 mkdir -p /dev/.initramfs/varrun
1377 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1381 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}"
1383 esac
1386 # Correct the permissions of /:
1387 chmod 0755 "${rootmnt}"
1389 # tmpfs file systems
1390 touch /etc/fstab
1391 mkdir -p "${rootmnt}/live"
1392 mount -t tmpfs tmpfs ${rootmnt}/live
1394 # Adding other custom mounts
1395 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1396 then
1397 # directly mount /home
1398 # FIXME: add a custom mounts configurable system
1400 if [ -b "${homecow}" ]
1401 then
1402 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1403 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1404 else
1405 log_warning_msg "Unable to find the persistent home medium"
1408 # Look for other snapshots to copy in
1409 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1410 # This second type should be removed when snapshot grow smarter
1411 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1414 if [ -n "${SHOWMOUNTS}" ]
1415 then
1416 for d in ${rofslist}
1418 mkdir -p "${rootmnt}/live/${d##*/}"
1420 case d in
1421 *.dir)
1422 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1426 case "${UNIONTYPE}" in
1427 unionfs-fuse)
1428 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1432 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1434 esac
1436 esac
1437 done
1440 # shows cow fs on /cow for use by live-snapshot
1441 mkdir -p "${rootmnt}/live/cow"
1442 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"
1445 check_dev ()
1447 sysdev="${1}"
1448 devname="${2}"
1449 skip_uuid_check="${3}"
1451 # support for fromiso=.../isofrom=....
1452 if [ -n "$FROMISO" ]
1453 then
1454 ISO_DEVICE=$(dirname $FROMISO)
1455 if ! [ -b $ISO_DEVICE ]
1456 then
1457 # to support unusual device names like /dev/cciss/c0d0p1
1458 # as well we have to identify the block device name, let's
1459 # do that for up to 15 levels
1460 i=15
1461 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1463 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1464 [ -b "$ISO_DEVICE" ] && break
1465 i=$(($i -1))
1466 done
1469 if [ "$ISO_DEVICE" = "/" ]
1470 then
1471 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1472 else
1473 mkdir /isofrom
1474 mount "$ISO_DEVICE" /isofrom
1475 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1476 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1477 devname="${loopdevname}"
1481 if [ -z "${devname}" ]
1482 then
1483 devname=$(sys2dev "${sysdev}")
1486 if [ -d "${devname}" ]
1487 then
1488 mount -o bind "${devname}" $mountpoint || continue
1490 if is_live_path $mountpoint
1491 then
1492 echo $mountpoint
1493 return 0
1494 else
1495 umount $mountpoint
1498 [ -e "$devname" ] || continue
1500 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1501 then
1502 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1503 devname="${loopdevname}"
1506 fstype=$(get_fstype "${devname}")
1508 if is_supported_fs ${fstype}
1509 then
1510 devuid=$(blkid -o value -s UUID "$devname")
1511 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1512 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1513 [ -n "$devuid" ] && echo "$devuid" >> $tried
1515 if is_live_path ${mountpoint} && \
1516 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1517 then
1518 echo ${mountpoint}
1519 return 0
1520 else
1521 umount ${mountpoint}
1525 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1526 then
1527 losetup -d "${loopdevname}"
1530 return 1
1533 find_livefs ()
1535 timeout="${1}"
1537 # don't start autodetection before timeout has expired
1538 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1539 then
1540 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1541 then
1542 return 1
1546 # first look at the one specified in the command line
1547 case "${LIVE_MEDIA}" in
1548 removable-usb)
1549 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1551 if [ "$(cat ${sysblock}/removable)" = "1" ]
1552 then
1553 if readlink ${sysblock} | grep -q usb ||
1554 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1555 then
1556 for dev in $(subdevices "${sysblock}")
1558 if check_dev "${dev}"
1559 then
1560 return 0
1562 done
1565 done
1566 return 1
1569 removable)
1570 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1572 if [ "$(cat ${sysblock}/removable)" = "1" ]
1573 then
1574 for dev in $(subdevices "${sysblock}")
1576 if check_dev "${dev}"
1577 then
1578 return 0
1580 done
1582 done
1583 return 1
1587 if [ ! -z "${LIVE_MEDIA}" ]
1588 then
1589 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1590 then
1591 return 0
1595 esac
1597 # or do the scan of block devices
1598 # prefer removable devices over non-removable devices, so scan them first
1599 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1601 if [ "$(cat ${sysblock}/removable)" = "1" ]
1602 then
1603 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1604 else
1605 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1607 done
1608 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1610 for sysblock in $devices_to_scan
1612 devname=$(sys2dev "${sysblock}")
1613 [ -e "$devname" ] || continue
1614 fstype=$(get_fstype "${devname}")
1616 if /lib/udev/cdrom_id ${devname} > /dev/null
1617 then
1618 if check_dev "null" "${devname}"
1619 then
1620 return 0
1622 elif is_nice_device "${sysblock}"
1623 then
1624 for dev in $(subdevices "${sysblock}")
1626 if check_dev "${dev}"
1627 then
1628 return 0
1630 done
1631 elif [ "${fstype}" = "squashfs" -o \
1632 "${fstype}" = "ext2" -o \
1633 "${fstype}" = "ext3" -o \
1634 "${fstype}" = "ext4" -o \
1635 "${fstype}" = "jffs2" ]
1636 then
1637 # This is an ugly hack situation, the block device has
1638 # an image directly on it. It's hopefully
1639 # live-boot, so take it and run with it.
1640 ln -s "${devname}" "${devname}.${fstype}"
1641 echo "${devname}.${fstype}"
1642 return 0
1644 done
1646 return 1
1649 set_usplash_timeout ()
1651 if [ -x /sbin/usplash_write ]
1652 then
1653 /sbin/usplash_write "TIMEOUT 120"
1654 else if [ -x /sbin/splashy_update ] ; then
1655 /sbin/splashy_update "TIMEOUT 120"
1656 fi ; fi
1659 integrity_check ()
1661 media_mountpoint="${1}"
1663 log_begin_msg "Checking media integrity"
1665 cd ${media_mountpoint}
1666 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1667 RC="${?}"
1669 log_end_msg
1671 if [ "${RC}" -eq 0 ]
1672 then
1673 log_success_msg "Everything ok, will reboot in 10 seconds."
1674 sleep 10
1675 cd /
1676 umount ${media_mountpoint}
1677 sync
1678 echo u > /proc/sysrq-trigger
1679 echo b > /proc/sysrq-trigger
1680 else
1681 panic "Not ok, a media defect is likely, switch to VT8 for details."
1685 start_usplash_pulse ()
1687 if [ -x /sbin/usplash_write ]
1688 then
1689 /sbin/usplash_write "PULSELOGO"
1693 mountroot ()
1695 if [ -x /scripts/local-top/cryptroot ]; then
1696 /scripts/local-top/cryptroot
1699 exec 6>&1
1700 exec 7>&2
1701 exec > live.log
1702 exec 2>&1
1703 tail -f live.log >&7 &
1704 tailpid="${!}"
1706 # Ensure 'panic' function is overridden
1707 . /scripts/live-functions
1709 Arguments
1711 set_usplash_timeout
1712 start_usplash_pulse
1714 maybe_break live-premount
1715 log_begin_msg "Running /scripts/live-premount"
1716 run_scripts /scripts/live-premount
1717 log_end_msg
1719 # Needed here too because some things (*cough* udev *cough*)
1720 # changes the timeout
1722 set_usplash_timeout
1724 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1725 then
1726 if do_netmount
1727 then
1728 livefs_root="${mountpoint}"
1729 else
1730 panic "Unable to find a live file system on the network"
1732 else
1733 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1734 then
1735 # Do a local boot from hd
1736 livefs_root=${ROOT}
1737 else
1738 # Scan local devices for the image
1740 while [ "$i" -lt 60 ]
1742 livefs_root=$(find_livefs ${i})
1744 if [ -n "${livefs_root}" ]
1745 then
1746 break
1749 sleep 1
1750 i="$(($i + 1))"
1751 done
1755 if [ -z "${livefs_root}" ]
1756 then
1757 panic "Unable to find a medium containing a live file system"
1760 if [ "${INTEGRITY_CHECK}" ]
1761 then
1762 integrity_check "${livefs_root}"
1765 if [ "${TORAM}" ]
1766 then
1767 live_dest="ram"
1768 elif [ "${TODISK}" ]
1769 then
1770 live_dest="${TODISK}"
1773 if [ "${live_dest}" ]
1774 then
1775 log_begin_msg "Copying live media to ${live_dest}"
1776 copy_live_to "${livefs_root}" "${live_dest}"
1777 log_end_msg
1780 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1781 # because the mountpoint is left behind in /proc/mounts, so let's get
1782 # rid of it when running from RAM
1783 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1784 then
1785 losetup -d /dev/loop0
1786 grep -q /isofrom /proc/mounts && umount /isofrom
1789 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1790 then
1791 setup_unionfs "${livefs_root}" "${rootmnt}"
1792 else
1793 mac="$(get_mac)"
1794 mac="$(echo ${mac} | sed 's/-//g')"
1795 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1798 log_end_msg
1800 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1801 # live-bottom; udev's init script will take care of things after that
1802 if [ "${UNIONTYPE}" = unionfs-fuse ]
1803 then
1804 mount -n -o bind /dev "${rootmnt}/dev"
1807 # Move to the new root filesystem so that programs there can get at it.
1808 if [ ! -d /root/live/image ]
1809 then
1810 mkdir -p /root/live/image
1811 mount --move /live/image /root/live/image
1814 maybe_break live-bottom
1815 log_begin_msg "Running /scripts/live-bottom\n"
1817 run_scripts /scripts/live-bottom
1818 log_end_msg
1820 if [ "${UNIONFS}" = unionfs-fuse ]
1821 then
1822 umount "${rootmnt}/dev"
1825 exec 1>&6 6>&-
1826 exec 2>&7 7>&-
1827 kill ${tailpid}
1828 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null