Adding upstream version 2.0~a15.
[debian-live-boot/hramrach.git] / scripts / live
blobf5f4ad28a007cecd48dfcf2db404af56787ae465
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 NOFASTBOOT="Yes"
55 NOFSTAB="Yes"
56 NONETWORKING="Yes"
58 export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
61 access=*)
62 ACCESS="${ARGUMENT#access=}"
63 export ACCESS
66 console=*)
67 DEFCONSOLE="${ARGUMENT#*=}"
68 export DEFCONSOLE
71 debug)
72 DEBUG="Yes"
73 export DEBUG
75 set -x
78 dhcp)
79 # Force dhcp even while netbooting
80 # Use for debugging in case somebody works on fixing dhclient
81 DHCP="Force";
82 export DHCP
85 nodhcp)
86 unset DHCP
89 ethdevice=*)
90 DEVICE="${ARGUMENT#ethdevice=}"
91 ETHDEVICE="${DEVICE}"
92 export DEVICE ETHDEVICE
95 ethdevice-timeout=*)
96 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
97 export ETHDEV_TIMEOUT
100 fetch=*)
101 FETCH="${ARGUMENT#fetch=}"
102 export FETCH
105 forcepersistentfsck)
106 FORCEPERSISTENTFSCK="Yes"
107 export FORCEPERSISTENTFSCK
110 ftpfs=*)
111 FTPFS="${ARGUMENT#ftpfs=}"
112 export FTPFS
115 httpfs=*)
116 HTTPFS="${ARGUMENT#httpfs=}"
117 export HTTPFS
120 iscsi=*)
121 ISCSI="${ARGUMENT#iscsi=}"
122 #ip:port - separated by ;
123 ISCSI_PORTAL="${ISCSI%;*}"
124 if echo "${ISCSI_PORTAL}" | grep -q , ; then
125 ISCSI_SERVER="${ISCSI_PORTAL%,*}"
126 ISCSI_PORT="${ISCSI_PORTAL#*,}"
128 #target name
129 ISCSI_TARGET="${ISCSI#*;}"
130 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
133 isofrom=*|fromiso=*)
134 FROMISO="${ARGUMENT#*=}"
135 export FROMISO
138 ignore_uuid)
139 IGNORE_UUID="Yes"
140 export IGNORE_UUID
143 integrity-check)
144 INTEGRITY_CHECK="Yes"
145 export INTEGRITY_CHECK
148 ip=*)
149 STATICIP="${ARGUMENT#ip=}"
151 if [ -z "${STATICIP}" ]
152 then
153 STATICIP="frommedia"
156 export STATICIP
159 live-getty)
160 LIVE_GETTY="1"
161 export LIVE_GETTY
164 live-media=*|bootfrom=*)
165 LIVE_MEDIA="${ARGUMENT#*=}"
166 export LIVE_MEDIA
169 live-media-encryption=*|encryption=*)
170 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
171 export LIVE_MEDIA_ENCRYPTION
174 live-media-offset=*)
175 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
176 export LIVE_MEDIA_OFFSET
179 live-media-path=*)
180 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
181 export LIVE_MEDIA_PATH
184 live-media-timeout=*)
185 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
186 export LIVE_MEDIA_TIMEOUT
189 module=*)
190 MODULE="${ARGUMENT#module=}"
191 export MODULE
194 netboot=*)
195 NETBOOT="${ARGUMENT#netboot=}"
196 export NETBOOT
199 nfsopts=*)
200 NFSOPTS="${ARGUMENT#nfsopts=}"
201 export NFSOPTS
204 nfscow=*)
205 NFS_COW="${ARGUMENT#nfscow=}"
206 export NFS_COW
209 noaccessibility)
210 NOACCESSIBILITY="Yes"
211 export NOACCESSIBILITY
214 nofastboot)
215 NOFASTBOOT="Yes"
216 export NOFASTBOOT
219 nofstab)
220 NOFSTAB="Yes"
221 export NOFSTAB
224 nonetworking)
225 NONETWORKING="Yes"
226 export NONETWORKING
229 swapon)
230 SWAPON="Yes"
231 export SWAPON
234 persistent)
235 PERSISTENT="Yes"
236 export PERSISTENT
239 persistent=*)
240 PERSISTENT="${ARGUMENT#persistent=}"
241 if [ -z "${PERSISTENT}" ]
242 then
243 PERSISTENT="Yes"
245 export PERSISTENT
248 persistent-path=*)
249 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
250 export PERSISTENT_PATH
253 persistent-subtext=*)
254 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
255 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
256 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
257 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
260 nopersistent)
261 NOPERSISTENT="Yes"
262 export NOPERSISTENT
265 quickusbmodules)
266 QUICKUSBMODULES="Yes"
267 export QUICKUSBMODULES
270 preseed/file=*|file=*)
271 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
272 export LOCATIONS
275 nopreseed)
276 NOPRESEED="Yes"
277 export NOPRESEED
280 */*=*)
281 question="${ARGUMENT%%=*}"
282 value="${ARGUMENT#*=}"
283 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
284 export PRESEEDS
287 showmounts)
288 SHOWMOUNTS="Yes"
289 export SHOWMOUNTS
292 silent)
293 SILENT="Yes"
294 export SILENT
297 todisk=*)
298 TODISK="${ARGUMENT#todisk=}"
299 export TODISK
302 toram)
303 TORAM="Yes"
304 export TORAM
307 toram=*)
308 TORAM="Yes"
309 MODULETORAM="${ARGUMENT#toram=}"
310 export TORAM MODULETORAM
313 exposedroot)
314 EXPOSED_ROOT="Yes"
315 export EXPOSED_ROOT
318 plainroot)
319 PLAIN_ROOT="Yes"
320 export PLAIN_ROOT
323 skipunion)
324 SKIP_UNION_MOUNTS="Yes"
325 export SKIP_UNION_MOUNTS
328 root=*)
329 ROOT="${ARGUMENT#root=}"
330 export ROOT
333 union=*)
334 UNIONTYPE="${ARGUMENT#union=}"
335 export UNIONTYPE
337 esac
338 done
340 # sort of compatibility with netboot.h from linux docs
341 if [ -z "${NETBOOT}" ]
342 then
343 if [ "${ROOT}" = "/dev/nfs" ]
344 then
345 NETBOOT="nfs"
346 export NETBOOT
347 elif [ "${ROOT}" = "/dev/cifs" ]
348 then
349 NETBOOT="cifs"
350 export NETBOOT
354 if [ -z "${MODULE}" ]
355 then
356 MODULE="filesystem"
357 export MODULE
360 if [ -z "${UNIONTYPE}" ]
361 then
362 UNIONTYPE="aufs"
363 export UNIONTYPE
367 is_live_path ()
369 DIRECTORY="${1}"
371 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
372 then
373 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
375 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
376 then
377 return 0
379 done
382 return 1
385 matches_uuid ()
387 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
388 then
389 return 0
392 path="${1}"
393 uuid="$(cat /conf/uuid.conf)"
395 for try_uuid_file in "${path}/.disk/live-uuid"*
397 [ -e "${try_uuid_file}" ] || continue
399 try_uuid="$(cat "${try_uuid_file}")"
401 if [ "${uuid}" = "${try_uuid}" ]
402 then
403 return 0
405 done
407 return 1
410 get_backing_device ()
412 case "${1}" in
413 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
414 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
417 *.dir)
418 echo "directory"
422 panic "Unrecognized live filesystem: ${1}"
424 esac
427 match_files_in_dir ()
429 # Does any files match pattern ${1} ?
430 local pattern="${1}"
432 if [ "$(echo ${pattern})" != "${pattern}" ]
433 then
434 return 0
437 return 1
440 mount_images_in_directory ()
442 directory="${1}"
443 rootmnt="${2}"
444 mac="${3}"
447 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
448 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
449 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
450 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
451 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
452 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
453 then
454 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
455 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
456 else
457 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
461 is_nice_device ()
463 sysfs_path="${1#/sys}"
465 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
466 then
467 return 0
468 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
469 then
470 return 0
471 elif echo ${sysfs_path} | grep -q "^/block/dm-"
472 then
473 return 0
476 return 1
479 copy_live_to ()
481 copyfrom="${1}"
482 copytodev="${2}"
483 copyto="${copyfrom}_swap"
485 if [ -z "${MODULETORAM}" ]
486 then
487 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
488 else
489 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
491 if [ -f "${MODULETORAMFILE}" ]
492 then
493 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
494 else
495 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
496 return 1
500 if [ "${copytodev}" = "ram" ]
501 then
502 # copying to ram:
503 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
504 mount_options="-o size=${size}k"
505 free_string="memory"
506 fstype="tmpfs"
507 dev="/dev/shm"
508 else
509 # it should be a writable block device
510 if [ -b "${copytodev}" ]
511 then
512 dev="${copytodev}"
513 free_string="space"
514 fstype=$(get_fstype "${dev}")
515 freespace=$(fs_size "${dev}")
516 else
517 log_warning_msg "${copytodev} is not a block device."
518 return 1
522 if [ "${freespace}" -lt "${size}" ]
523 then
524 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
525 return 1
528 # begin copying (or uncompressing)
529 mkdir "${copyto}"
530 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
531 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
533 if [ "${extension}" = "tgz" ]
534 then
535 cd "${copyto}"
536 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
537 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
538 mount -r -o move "${copyto}" "${rootmnt}"
539 cd "${OLDPWD}"
540 else
541 if [ -n "${MODULETORAMFILE}" ]
542 then
543 if [ -x /bin/rsync ]
544 then
545 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
546 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
547 else
548 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
550 else
551 if [ -x /bin/rsync ]
552 then
553 echo " * Copying whole medium to RAM" 1>/dev/console
554 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
555 else
556 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
557 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
558 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
559 then
560 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
565 umount ${copyfrom}
566 mount -r -o move ${copyto} ${copyfrom}
569 rmdir ${copyto}
570 return 0
573 do_netsetup ()
575 modprobe -q af_packet # For DHCP
577 udevadm trigger
578 udevadm settle
580 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
581 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
582 then
584 # if ethdevice was not specified on the kernel command line
585 # make sure we try to get a working network configuration
586 # for *every* present network device (except for loopback of course)
587 if [ -z "$ETHDEVICE" ] ; then
588 echo "If you want to boot from a specific device use bootoption ethdevice=..."
589 for device in /sys/class/net/*; do
590 dev=${device##*/} ;
591 if [ "$dev" != "lo" ] ; then
592 ETHDEVICE="$ETHDEVICE $dev"
594 done
597 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
598 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
599 devlist="$devlist $device"
600 done
602 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
603 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
605 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
606 # an endless loop; iff execution fails give it two further tries, that's
607 # why we use '$devlist $devlist $devlist' for the other for loop
608 for dev in $devlist $devlist $devlist ; do
609 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
610 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
611 jobid=$!
612 sleep "$ETHDEV_TIMEOUT" ; sleep 1
613 if [ -r /proc/"$jobid"/status ] ; then
614 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
615 kill -9 $jobid
618 # if configuration of device worked we should have an assigned
619 # IP address, iff so let's use the according as $DEVICE for later usage
620 # simple and primitive approach which seems to work fine
621 if ifconfig $dev | grep -q 'inet.*addr:' ; then
622 export DEVICE="$dev"
623 break
625 done
627 else
628 ipconfig ${DEVICE} | tee /netboot.config
631 # source relevant ipconfig output
632 OLDHOSTNAME=${HOSTNAME}
633 . /tmp/net-${DEVICE}.conf
634 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
635 export HOSTNAME
637 if [ -n "${DEVICE}" ]
638 then
639 HWADDR="$(cat /sys/class/net/${DEVICE}/address)"
642 # Check if we have a network device at all
643 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
644 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
645 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
646 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
647 ! ls /sys/class/net/ra0 > /dev/null 2>&1
648 then
649 panic "No supported network device found, maybe a non-mainline driver is required."
653 do_netmount()
655 do_netsetup
657 if [ "${NFSROOT}" = "auto" ]
658 then
659 NFSROOT=${ROOTSERVER}:${ROOTPATH}
662 rc=1
664 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
665 then
666 do_httpmount
667 return $?
670 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
671 then
672 NFSROOT=${ROOTSERVER}:${NFSROOT}
675 log_begin_msg "Trying netboot from ${NFSROOT}"
677 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
678 then
679 rc=0
680 elif do_nfsmount
681 then
682 NETBOOT="nfs"
683 export NETBOOT
684 rc=0
687 log_end_msg
688 return ${rc}
691 do_iscsi()
693 do_netsetup
694 #modprobe ib_iser
695 modprobe iscsi_tcp
696 local debugopt=""
697 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
698 #FIXME this name is supposed to be unique - some date + ifconfig hash?
699 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
700 export ISCSI_INITIATORNAME
701 if [ -n "${ISCSI_SERVER}" ] ; then
702 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
703 else
704 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
706 if [ $? != 0 ]
707 then
708 panic "Failed to log into iscsi target"
710 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
711 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
712 if [ -n "${host}" ]
713 then
714 local devices=""
715 local i=0
716 while [ -z "${devices}" -a $i -lt 60 ]
718 sleep 1
719 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
720 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
721 i=$(expr $i + 1)
722 echo -ne $i\\r
723 done
724 for dev in $devices
726 if check_dev "null" "/dev/$dev"
727 then
728 NETBOOT="iscsi"
729 export NETBOOT
730 return 0;
732 done
733 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
734 else
735 panic "Failed to locate iSCSI host in /sys"
739 do_httpmount ()
741 rc=1
743 for webfile in HTTPFS FTPFS FETCH
745 local url="$(eval echo \"\$\{${webfile}\}\")"
746 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
748 if [ -n "$url" ]
749 then
750 case "${extension}" in
751 iso|squashfs|tgz|tar)
752 if [ "${extension}" = "iso" ]
753 then
754 mkdir -p "${alt_mountpoint}"
755 dest="${alt_mountpoint}"
756 else
757 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
758 mount -t ramfs ram "${mountpoint}"
759 mkdir -p "${dest}"
761 if [ "${webfile}" = "FETCH" ]
762 then
763 case "$url" in
764 tftp*)
765 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
766 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
767 lfile="$(basename $url)"
768 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
769 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
773 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
774 wget "${url}" -O "${dest}/$(basename ${url})"
776 esac
777 else
778 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
779 if [ "${webfile}" = "FTPFS" ]
780 then
781 FUSE_MOUNT="curlftpfs"
782 url="$(dirname ${url})"
783 else
784 FUSE_MOUNT="httpfs"
786 modprobe fuse
787 $FUSE_MOUNT "${url}" "${dest}"
788 FUSE_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
790 [ ${?} -eq 0 ] && rc=0
791 [ "${extension}" = "tgz" ] && live_dest="ram"
792 if [ "${extension}" = "iso" ]
793 then
794 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
795 mount -t iso9660 "${isoloop}" "${mountpoint}"
796 rc=${?}
798 break
802 log_begin_msg "Unrecognized archive extension for ${url}"
804 esac
806 done
808 if [ ${rc} != 0 ]
809 then
810 if [ -d "${alt_mountpoint}" ]
811 then
812 umount "${alt_mountpoint}"
813 rmdir "${alt_mountpoint}"
815 umount "${mountpoint}"
816 elif [ "${webfile}" != "FETCH" ] ; then
817 NETBOOT="${webfile}"
818 export NETBOOT
819 if [ -n "${FUSE_PID}" ] ; then
820 echo "${FUSE_PID}" > ${mountpoint}/root.pid
824 return ${rc}
827 do_nfsmount ()
829 rc=1
831 modprobe -q nfs
833 if [ -z "${NFSOPTS}" ]
834 then
835 NFSOPTS=""
838 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
840 # FIXME: This while loop is an ugly HACK round an nfs bug
842 while [ "$i" -lt 60 ]
844 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
845 sleep 1
846 i="$(($i + 1))"
847 done
849 return ${rc}
852 do_cifsmount ()
854 rc=1
856 if [ -x "/sbin/mount.cifs" ]
857 then
858 if [ -z "${NFSOPTS}" ]
859 then
860 CIFSOPTS="-ouser=root,password="
861 else
862 CIFSOPTS="${NFSOPTS}"
865 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
866 modprobe -q cifs
868 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
869 then
870 rc=0
874 return ${rc}
877 do_snap_copy ()
879 fromdev="${1}"
880 todir="${2}"
881 snap_type="${3}"
882 size=$(fs_size "${fromdev}" "" "used")
884 if [ -b "${fromdev}" ]
885 then
886 # look for free mem
887 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
888 then
889 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
890 freespace=$(df -k | awk '/'${todev}'/{print $4}')
891 else
892 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
895 tomount="/mnt/tmpsnap"
897 if [ ! -d "${tomount}" ]
898 then
899 mkdir -p "${tomount}"
902 fstype=$(get_fstype "${fromdev}")
904 if [ -n "${fstype}" ]
905 then
906 # Copying stuff...
907 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
908 cp -a "${tomount}"/* ${todir}
909 umount "${tomount}"
910 else
911 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
914 rmdir "${tomount}"
916 if echo ${fromdev} | grep -qs loop
917 then
918 losetup -d "${fromdev}"
921 return 0
922 else
923 return 1
925 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
929 find_snap ()
931 # Look for ${snap_label}.* in block devices
932 snap_label="${1}"
934 if [ "${PERSISTENT}" != "nofiles" ]
935 then
936 # search for image files
937 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")
940 if [ -z "${snapdata}" ]
941 then
942 snapdata=$(find_cow_device "${snap_label}")
944 echo "${snapdata}"
947 try_snap ()
949 # copy the contents of previously found snapshot to ${snap_mount}
950 # and remember the device and filename for resync on exit in live-boot.init
952 snapdata="${1}"
953 snap_mount="${2}"
954 snap_type="${3}"
956 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
957 then
958 log_success_msg "found snapshot: ${snapdata}"
959 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
960 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
961 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
963 if ! try_mount "${snapdev}" "${snapback}" "ro"
964 then
965 break
968 RES="0"
970 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
971 then
972 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
973 dev=$(get_backing_device "${snapback}/${snapfile}")
975 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
976 RES="$?"
977 else
978 # cpio.gz snapshot
980 # Unfortunately klibc's cpio is incompatible with the
981 # rest of the world; everything else requires -u -d,
982 # while klibc doesn't implement them. Try to detect
983 # whether it's in use.
984 cpiopath="$(which cpio)" || true
985 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
986 then
987 cpioargs=
988 else
989 cpioargs='--unconditional --make-directories'
992 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
993 RES="$?"
995 if [ "${RES}" != "0" ]
996 then
997 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1001 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1003 if [ "${RES}" != "0" ]
1004 then
1005 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1008 elif [ -b "${snapdata}" ]
1009 then
1010 # Try to find if it could be a snapshot partition
1011 dev="${snapdata}"
1012 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1013 if echo "${dev}" | grep -qs loop
1014 then
1015 # strange things happens, user confused?
1016 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1017 snapfile=$(basename ${snaploop})
1018 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1019 else
1020 snapdev="${dev}"
1023 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1024 then
1025 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1026 return 1
1027 else
1028 if [ -n "${snapfile}" ]
1029 then
1030 # it was a loop device, user confused
1031 umount ${snapdev}
1034 else
1035 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1036 return 1
1039 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1040 return 0
1043 setup_unionfs ()
1045 image_directory="${1}"
1046 rootmnt="${2}"
1047 addimage_directory="${3}"
1049 case ${UNIONTYPE} in
1050 aufs|unionfs)
1051 modprobe -q -b ${UNIONTYPE}
1053 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1054 then
1055 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1056 echo "This might be really slow."
1058 UNIONTYPE="unionfs-fuse"
1061 esac
1063 if [ "${UNIONTYPE}" = unionfs-fuse ]
1064 then
1065 modprobe fuse
1068 # run-init can't deal with images in a subdir, but we're going to
1069 # move all of these away before it runs anyway. No, we're not,
1070 # put them in / since move-mounting them into / breaks mono and
1071 # some other apps.
1073 croot="/"
1075 # Let's just mount the read-only file systems first
1076 rofsstring=""
1077 rofslist=""
1079 if [ "${UNIONTYPE}" = "aufs" ]
1080 then
1081 roopt="rr"
1082 noxino_opt="noxino,"
1083 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1084 then
1085 roopt="RO"
1086 else
1087 roopt="ro"
1090 if [ -z "${PLAIN_ROOT}" ]
1091 then
1092 # Read image names from ${MODULE}.module if it exists
1093 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1094 then
1095 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1097 image_string="${image_string} ${image_directory}/${IMAGE}"
1098 done
1099 elif [ -e "${image_directory}/${MODULE}.module" ]
1100 then
1101 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1103 image_string="${image_string} ${image_directory}/${IMAGE}"
1104 done
1105 else
1106 # ${MODULE}.module does not exist, create a list of images
1107 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1109 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1111 if [ -e "${IMAGE}" ]
1112 then
1113 image_string="${image_string} ${IMAGE}"
1115 done
1116 done
1118 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1119 then
1120 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1122 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1124 if [ -e "${IMAGE}" ]
1125 then
1126 image_string="${image_string} ${IMAGE}"
1128 done
1129 done
1132 # Now sort the list
1133 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1136 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1138 mkdir -p "${croot}"
1140 for image in ${image_string}
1142 imagename=$(basename "${image}")
1144 export image devname
1145 maybe_break live-realpremount
1146 log_begin_msg "Running /scripts/live-realpremount"
1147 run_scripts /scripts/live-realpremount
1148 log_end_msg
1150 if [ -d "${image}" ]
1151 then
1152 # it is a plain directory: do nothing
1153 rofsstring="${image}=${roopt}:${rofsstring}"
1154 rofslist="${image} ${rofslist}"
1155 elif [ -f "${image}" ]
1156 then
1157 if losetup --help 2>&1 | grep -q -- "-r\b"
1158 then
1159 backdev=$(get_backing_device "${image}" "-r")
1160 else
1161 backdev=$(get_backing_device "${image}")
1163 fstype=$(get_fstype "${backdev}")
1165 if [ "${fstype}" = "unknown" ]
1166 then
1167 panic "Unknown file system type on ${backdev} (${image})"
1170 if [ -z "${fstype}" ]
1171 then
1172 fstype="${imagename##*.}"
1173 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1176 mkdir -p "${croot}/${imagename}"
1177 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1178 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}"
1179 log_end_msg
1181 done
1182 else
1183 # we have a plain root system
1184 mkdir -p "${croot}/filesystem"
1185 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1186 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}"
1187 # probably broken:
1188 mount -o bind ${croot}/filesystem $mountpoint
1189 log_end_msg
1192 rofsstring=${rofsstring%:}
1194 mkdir -p /cow
1196 # Looking for "${root_persistence}" device or file
1197 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1198 then
1199 if [ -z "${QUICKUSBMODULES}" ]
1200 then
1201 # Load USB modules
1202 num_block=$(ls -l /sys/block | wc -l)
1203 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1205 modprobe -q -b ${module}
1206 done
1208 udevadm trigger
1209 udevadm settle
1211 # For some reason, udevsettle does not block in this scenario,
1212 # so we sleep for a little while.
1214 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1215 for timeout in 5 4 3 2 1
1217 sleep 1
1219 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1220 then
1221 break
1223 done
1226 # search for label and files (this could be hugely optimized)
1227 cowprobe=$(find_cow_device "${root_persistence}")
1228 if [ -b "${cowprobe}" ]
1229 then
1230 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1231 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1232 # snapshots to be sure to really store some e.g key config files,
1233 # but not on the same media
1234 blacklistdev="${cowprobe}"
1235 PERSISTENCE_IS_ON="1"
1236 export PERSISTENCE_IS_ON
1238 # homecow just mount something on /home, this should be generalized some way
1239 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1240 if [ -b "${homecow}" ]
1241 then
1242 PERSISTENCE_IS_ON="1"
1243 export PERSISTENCE_IS_ON
1245 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1246 # This second type should be removed when snapshot will get smarter,
1247 # hence when "/etc/live-snapshot*list" will be supported also by
1248 # ext2|ext3|ext4|jffs2 snapshot types.
1249 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1251 if [ -b "${cowprobe}" ]
1252 then
1253 cowdevice=${cowprobe}
1254 cow_fstype=$(get_fstype "${cowprobe}")
1255 cow_mountopt="rw,noatime"
1257 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1258 then
1259 fsck -y ${cowdevice}
1261 else
1262 log_warning_msg "Unable to find the persistent medium"
1263 cowdevice="tmpfs"
1264 cow_fstype="tmpfs"
1265 cow_mountopt="rw,noatime,mode=755"
1267 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1268 then
1269 # check if there are any nfs options
1270 if echo ${NFS_COW}|grep -q ','
1271 then
1272 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1273 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1274 else
1275 nfs_cow_opts="-o nolock"
1276 nfs_cow=${NFS_COW}
1278 mac="$(get_mac)"
1279 if [ -n "${mac}" ]
1280 then
1281 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1282 cow_fstype="nfs"
1283 else
1284 panic "unable to determine mac address"
1286 else
1287 cowdevice="tmpfs"
1288 cow_fstype="tmpfs"
1289 cow_mountopt="rw,noatime,mode=755"
1292 if [ "${cow_fstype}" = "nfs" ]
1293 then
1294 log_begin_msg \
1295 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1296 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1297 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1298 else
1299 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1300 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1303 rofscount=$(echo ${rofslist} |wc -w)
1305 if [ -n "${EXPOSED_ROOT}" ]
1306 then
1307 if [ ${rofscount} -ne 1 ]
1308 then
1309 panic "only one RO file system supported with exposedroot: ${rofslist}"
1311 exposedrootfs=${rofslist%% }
1313 mount --bind ${exposedrootfs} ${rootmnt} || \
1314 panic "bind mount of ${exposedrootfs} failed"
1316 if [ -z "${SKIP_UNION_MOUNTS}" ]
1317 then
1318 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1319 else
1320 cow_dirs=''
1323 for dir in ${cow_dirs}; do
1324 mkdir -p /cow${dir}
1326 case "${UNIONTYPE}" in
1327 unionfs-fuse)
1328 (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}")
1329 mkdir -p /dev/.initramfs/varrun
1330 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1334 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"
1336 esac
1337 done
1338 else
1339 case "${UNIONTYPE}" in
1340 unionfs-fuse)
1341 (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}")
1342 mkdir -p /dev/.initramfs/varrun
1343 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1347 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}"
1349 esac
1352 # Correct the permissions of /:
1353 chmod 0755 "${rootmnt}"
1355 # tmpfs file systems
1356 touch /etc/fstab
1357 mkdir -p "${rootmnt}/live"
1358 mount -t tmpfs tmpfs ${rootmnt}/live
1360 # Adding other custom mounts
1361 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1362 then
1363 # directly mount /home
1364 # FIXME: add a custom mounts configurable system
1366 if [ -b "${homecow}" ]
1367 then
1368 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1369 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1370 else
1371 log_warning_msg "Unable to find the persistent home medium"
1374 # Look for other snapshots to copy in
1375 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1376 # This second type should be removed when snapshot grow smarter
1377 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1380 if [ -n "${SHOWMOUNTS}" ]
1381 then
1382 for d in ${rofslist}
1384 mkdir -p "${rootmnt}/live/${d##*/}"
1386 case d in
1387 *.dir)
1388 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1392 case "${UNIONTYPE}" in
1393 unionfs-fuse)
1394 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1398 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1400 esac
1402 esac
1403 done
1406 # shows cow fs on /cow for use by live-snapshot
1407 mkdir -p "${rootmnt}/live/cow"
1408 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"
1411 check_dev ()
1413 sysdev="${1}"
1414 devname="${2}"
1415 skip_uuid_check="${3}"
1417 # support for fromiso=.../isofrom=....
1418 if [ -n "$FROMISO" ]
1419 then
1420 ISO_DEVICE=$(dirname $FROMISO)
1421 if ! [ -b $ISO_DEVICE ]
1422 then
1423 # to support unusual device names like /dev/cciss/c0d0p1
1424 # as well we have to identify the block device name, let's
1425 # do that for up to 15 levels
1426 i=15
1427 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1429 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1430 [ -b "$ISO_DEVICE" ] && break
1431 i=$(($i -1))
1432 done
1435 if [ "$ISO_DEVICE" = "/" ]
1436 then
1437 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1438 else
1439 mkdir /isofrom
1440 mount "$ISO_DEVICE" /isofrom
1441 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1442 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1443 devname="${loopdevname}"
1447 if [ -z "${devname}" ]
1448 then
1449 devname=$(sys2dev "${sysdev}")
1452 if [ -d "${devname}" ]
1453 then
1454 mount -o bind "${devname}" $mountpoint || continue
1456 if is_live_path $mountpoint
1457 then
1458 echo $mountpoint
1459 return 0
1460 else
1461 umount $mountpoint
1464 [ -e "$devname" ] || continue
1466 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1467 then
1468 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1469 devname="${loopdevname}"
1472 fstype=$(get_fstype "${devname}")
1474 if is_supported_fs ${fstype}
1475 then
1476 devuid=$(blkid -o value -s UUID "$devname")
1477 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1478 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1479 [ -n "$devuid" ] && echo "$devuid" >> $tried
1481 if is_live_path ${mountpoint} && \
1482 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1483 then
1484 echo ${mountpoint}
1485 return 0
1486 else
1487 umount ${mountpoint}
1491 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1492 then
1493 losetup -d "${loopdevname}"
1496 return 1
1499 find_livefs ()
1501 timeout="${1}"
1503 # don't start autodetection before timeout has expired
1504 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1505 then
1506 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1507 then
1508 return 1
1512 # first look at the one specified in the command line
1513 case "${LIVE_MEDIA}" in
1514 removable-usb)
1515 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1517 if [ "$(cat ${sysblock}/removable)" = "1" ]
1518 then
1519 if readlink ${sysblock} | grep -q usb ||
1520 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1521 then
1522 for dev in $(subdevices "${sysblock}")
1524 if check_dev "${dev}"
1525 then
1526 return 0
1528 done
1531 done
1532 return 1
1535 removable)
1536 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1538 if [ "$(cat ${sysblock}/removable)" = "1" ]
1539 then
1540 for dev in $(subdevices "${sysblock}")
1542 if check_dev "${dev}"
1543 then
1544 return 0
1546 done
1548 done
1549 return 1
1553 if [ ! -z "${LIVE_MEDIA}" ]
1554 then
1555 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1556 then
1557 return 0
1561 esac
1563 # or do the scan of block devices
1564 # prefer removable devices over non-removable devices, so scan them first
1565 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1567 if [ "$(cat ${sysblock}/removable)" = "1" ]
1568 then
1569 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1570 else
1571 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1573 done
1574 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1576 for sysblock in $devices_to_scan
1578 devname=$(sys2dev "${sysblock}")
1579 [ -e "$devname" ] || continue
1580 fstype=$(get_fstype "${devname}")
1582 if /lib/udev/cdrom_id ${devname} > /dev/null
1583 then
1584 if check_dev "null" "${devname}"
1585 then
1586 return 0
1588 elif is_nice_device "${sysblock}"
1589 then
1590 for dev in $(subdevices "${sysblock}")
1592 if check_dev "${dev}"
1593 then
1594 return 0
1596 done
1597 elif [ "${fstype}" = "squashfs" -o \
1598 "${fstype}" = "btrfs" -o \
1599 "${fstype}" = "ext2" -o \
1600 "${fstype}" = "ext3" -o \
1601 "${fstype}" = "ext4" -o \
1602 "${fstype}" = "jffs2" ]
1603 then
1604 # This is an ugly hack situation, the block device has
1605 # an image directly on it. It's hopefully
1606 # live-boot, so take it and run with it.
1607 ln -s "${devname}" "${devname}.${fstype}"
1608 echo "${devname}.${fstype}"
1609 return 0
1611 done
1613 return 1
1616 set_usplash_timeout ()
1618 if [ -x /sbin/usplash_write ]
1619 then
1620 /sbin/usplash_write "TIMEOUT 120"
1621 else if [ -x /sbin/splashy_update ] ; then
1622 /sbin/splashy_update "TIMEOUT 120"
1623 fi ; fi
1626 integrity_check ()
1628 media_mountpoint="${1}"
1630 log_begin_msg "Checking media integrity"
1632 cd ${media_mountpoint}
1633 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1634 RC="${?}"
1636 log_end_msg
1638 if [ "${RC}" -eq 0 ]
1639 then
1640 log_success_msg "Everything ok, will reboot in 10 seconds."
1641 sleep 10
1642 cd /
1643 umount ${media_mountpoint}
1644 sync
1645 echo u > /proc/sysrq-trigger
1646 echo b > /proc/sysrq-trigger
1647 else
1648 panic "Not ok, a media defect is likely, switch to VT8 for details."
1652 start_usplash_pulse ()
1654 if [ -x /sbin/usplash_write ]
1655 then
1656 /sbin/usplash_write "PULSELOGO"
1660 mountroot ()
1662 if [ -x /scripts/local-top/cryptroot ]; then
1663 /scripts/local-top/cryptroot
1666 exec 6>&1
1667 exec 7>&2
1668 exec > live.log
1669 exec 2>&1
1670 tail -f live.log >&7 &
1671 tailpid="${!}"
1673 # Ensure 'panic' function is overridden
1674 . /scripts/live-functions
1676 Arguments
1678 set_usplash_timeout
1679 start_usplash_pulse
1681 maybe_break live-premount
1682 log_begin_msg "Running /scripts/live-premount"
1683 run_scripts /scripts/live-premount
1684 log_end_msg
1686 # Needed here too because some things (*cough* udev *cough*)
1687 # changes the timeout
1689 set_usplash_timeout
1691 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1692 then
1693 if do_netmount
1694 then
1695 livefs_root="${mountpoint}"
1696 else
1697 panic "Unable to find a live file system on the network"
1699 else
1700 if [ -n "${ISCSI_PORTAL}" ]
1701 then
1702 do_iscsi && livefs_root="${mountpoint}"
1703 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1704 then
1705 # Do a local boot from hd
1706 livefs_root=${ROOT}
1707 else
1708 if [ -x /usr/bin/memdiskfind ]
1709 then
1710 MEMDISK=$(/usr/bin/memdiskfind)
1712 if [ $? -eq 0 ]
1713 then
1714 # We found a memdisk, set up phram
1715 modprobe phram phram=memdisk,${MEMDISK}
1717 # Load mtdblock, the memdisk will be /dev/mtdblock0
1718 modprobe mtdblock
1722 # Scan local devices for the image
1724 while [ "$i" -lt 60 ]
1726 livefs_root=$(find_livefs ${i})
1728 if [ -n "${livefs_root}" ]
1729 then
1730 break
1733 sleep 1
1734 i="$(($i + 1))"
1735 done
1739 if [ -z "${livefs_root}" ]
1740 then
1741 panic "Unable to find a medium containing a live file system"
1744 if [ "${INTEGRITY_CHECK}" ]
1745 then
1746 integrity_check "${livefs_root}"
1749 if [ "${TORAM}" ]
1750 then
1751 live_dest="ram"
1752 elif [ "${TODISK}" ]
1753 then
1754 live_dest="${TODISK}"
1757 if [ "${live_dest}" ]
1758 then
1759 log_begin_msg "Copying live media to ${live_dest}"
1760 copy_live_to "${livefs_root}" "${live_dest}"
1761 log_end_msg
1764 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1765 # because the mountpoint is left behind in /proc/mounts, so let's get
1766 # rid of it when running from RAM
1767 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1768 then
1769 losetup -d /dev/loop0
1770 grep -q /isofrom /proc/mounts && umount /isofrom
1773 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1774 then
1775 setup_unionfs "${livefs_root}" "${rootmnt}"
1776 else
1777 mac="$(get_mac)"
1778 mac="$(echo ${mac} | sed 's/-//g')"
1779 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1782 log_end_msg
1784 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1785 # live-bottom; udev's init script will take care of things after that
1786 if [ "${UNIONTYPE}" = unionfs-fuse ]
1787 then
1788 mount -n -o bind /dev "${rootmnt}/dev"
1791 # Move to the new root filesystem so that programs there can get at it.
1792 if [ ! -d /root/live/image ]
1793 then
1794 mkdir -p /root/live/image
1795 mount --move /live/image /root/live/image
1798 maybe_break live-bottom
1799 log_begin_msg "Running /scripts/live-bottom\n"
1801 run_scripts /scripts/live-bottom
1802 log_end_msg
1804 if [ "${UNIONFS}" = unionfs-fuse ]
1805 then
1806 umount "${rootmnt}/dev"
1809 exec 1>&6 6>&-
1810 exec 2>&7 7>&-
1811 kill ${tailpid}
1812 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null