Adding upstream version 3.0~a5.
[debian-live-boot.git] / scripts / live
blobd34279dee60c4485ab65f151eeb72f2c203114ba
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 BOOTIF=*)
72 BOOTIF="${x#BOOTIF=}"
75 debug)
76 DEBUG="Yes"
77 export DEBUG
79 set -x
82 dhcp)
83 # Force dhcp even while netbooting
84 # Use for debugging in case somebody works on fixing dhclient
85 DHCP="Force";
86 export DHCP
89 nodhcp)
90 unset DHCP
93 ethdevice=*)
94 DEVICE="${ARGUMENT#ethdevice=}"
95 ETHDEVICE="${DEVICE}"
96 export DEVICE ETHDEVICE
99 ethdevice-timeout=*)
100 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
101 export ETHDEV_TIMEOUT
104 fetch=*)
105 FETCH="${ARGUMENT#fetch=}"
106 export FETCH
109 forcepersistentfsck)
110 FORCEPERSISTENTFSCK="Yes"
111 export FORCEPERSISTENTFSCK
114 ftpfs=*)
115 FTPFS="${ARGUMENT#ftpfs=}"
116 export FTPFS
119 httpfs=*)
120 HTTPFS="${ARGUMENT#httpfs=}"
121 export HTTPFS
124 iscsi=*)
125 ISCSI="${ARGUMENT#iscsi=}"
126 #ip:port - separated by ;
127 ISCSI_PORTAL="${ISCSI%;*}"
128 if echo "${ISCSI_PORTAL}" | grep -q , ; then
129 ISCSI_SERVER="${ISCSI_PORTAL%,*}"
130 ISCSI_PORT="${ISCSI_PORTAL#*,}"
132 #target name
133 ISCSI_TARGET="${ISCSI#*;}"
134 export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT
137 isofrom=*|fromiso=*)
138 FROMISO="${ARGUMENT#*=}"
139 export FROMISO
142 ignore_uuid)
143 IGNORE_UUID="Yes"
144 export IGNORE_UUID
147 integrity-check)
148 INTEGRITY_CHECK="Yes"
149 export INTEGRITY_CHECK
152 ip=*)
153 STATICIP="${ARGUMENT#ip=}"
155 if [ -z "${STATICIP}" ]
156 then
157 STATICIP="frommedia"
160 export STATICIP
163 live-getty)
164 LIVE_GETTY="1"
165 export LIVE_GETTY
168 live-media=*|bootfrom=*)
169 LIVE_MEDIA="${ARGUMENT#*=}"
170 export LIVE_MEDIA
173 live-media-encryption=*|encryption=*)
174 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
175 export LIVE_MEDIA_ENCRYPTION
178 live-media-offset=*)
179 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
180 export LIVE_MEDIA_OFFSET
183 live-media-path=*)
184 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
185 export LIVE_MEDIA_PATH
188 live-media-timeout=*)
189 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
190 export LIVE_MEDIA_TIMEOUT
193 module=*)
194 MODULE="${ARGUMENT#module=}"
195 export MODULE
198 netboot=*)
199 NETBOOT="${ARGUMENT#netboot=}"
200 export NETBOOT
203 nfsopts=*)
204 NFSOPTS="${ARGUMENT#nfsopts=}"
205 export NFSOPTS
208 nfscow=*)
209 NFS_COW="${ARGUMENT#nfscow=}"
210 export NFS_COW
213 noaccessibility)
214 NOACCESSIBILITY="Yes"
215 export NOACCESSIBILITY
218 nofastboot)
219 NOFASTBOOT="Yes"
220 export NOFASTBOOT
223 nofstab)
224 NOFSTAB="Yes"
225 export NOFSTAB
228 nonetworking)
229 NONETWORKING="Yes"
230 export NONETWORKING
233 swapon)
234 SWAPON="Yes"
235 export SWAPON
238 persistent)
239 PERSISTENT="Yes"
240 export PERSISTENT
243 persistent=*)
244 PERSISTENT="${ARGUMENT#persistent=}"
245 if [ -z "${PERSISTENT}" ]
246 then
247 PERSISTENT="Yes"
249 export PERSISTENT
252 persistent-path=*)
253 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
254 export PERSISTENT_PATH
257 persistent-subtext=*)
258 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
259 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
260 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
261 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
264 nopersistent)
265 NOPERSISTENT="Yes"
266 export NOPERSISTENT
269 quickusbmodules)
270 QUICKUSBMODULES="Yes"
271 export QUICKUSBMODULES
274 preseed/file=*|file=*)
275 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
276 export LOCATIONS
279 nopreseed)
280 NOPRESEED="Yes"
281 export NOPRESEED
284 */*=*)
285 question="${ARGUMENT%%=*}"
286 value="${ARGUMENT#*=}"
287 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
288 export PRESEEDS
291 showmounts)
292 SHOWMOUNTS="Yes"
293 export SHOWMOUNTS
296 silent)
297 SILENT="Yes"
298 export SILENT
301 todisk=*)
302 TODISK="${ARGUMENT#todisk=}"
303 export TODISK
306 toram)
307 TORAM="Yes"
308 export TORAM
311 toram=*)
312 TORAM="Yes"
313 MODULETORAM="${ARGUMENT#toram=}"
314 export TORAM MODULETORAM
317 exposedroot)
318 EXPOSED_ROOT="Yes"
319 export EXPOSED_ROOT
322 plainroot)
323 PLAIN_ROOT="Yes"
324 export PLAIN_ROOT
327 skipunion)
328 SKIP_UNION_MOUNTS="Yes"
329 export SKIP_UNION_MOUNTS
332 root=*)
333 ROOT="${ARGUMENT#root=}"
334 export ROOT
337 union=*)
338 UNIONTYPE="${ARGUMENT#union=}"
339 export UNIONTYPE
341 esac
342 done
344 # sort of compatibility with netboot.h from linux docs
345 if [ -z "${NETBOOT}" ]
346 then
347 if [ "${ROOT}" = "/dev/nfs" ]
348 then
349 NETBOOT="nfs"
350 export NETBOOT
351 elif [ "${ROOT}" = "/dev/cifs" ]
352 then
353 NETBOOT="cifs"
354 export NETBOOT
358 if [ -z "${MODULE}" ]
359 then
360 MODULE="filesystem"
361 export MODULE
364 if [ -z "${UNIONTYPE}" ]
365 then
366 UNIONTYPE="aufs"
367 export UNIONTYPE
371 is_live_path ()
373 DIRECTORY="${1}"
375 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
376 then
377 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
379 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
380 then
381 return 0
383 done
386 return 1
389 matches_uuid ()
391 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
392 then
393 return 0
396 path="${1}"
397 uuid="$(cat /conf/uuid.conf)"
399 for try_uuid_file in "${path}/.disk/live-uuid"*
401 [ -e "${try_uuid_file}" ] || continue
403 try_uuid="$(cat "${try_uuid_file}")"
405 if [ "${uuid}" = "${try_uuid}" ]
406 then
407 return 0
409 done
411 return 1
414 get_backing_device ()
416 case "${1}" in
417 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
418 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
421 *.dir)
422 echo "directory"
426 panic "Unrecognized live filesystem: ${1}"
428 esac
431 match_files_in_dir ()
433 # Does any files match pattern ${1} ?
434 local pattern="${1}"
436 if [ "$(echo ${pattern})" != "${pattern}" ]
437 then
438 return 0
441 return 1
444 mount_images_in_directory ()
446 directory="${1}"
447 rootmnt="${2}"
448 mac="${3}"
451 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
452 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
453 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
454 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
455 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
456 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
457 then
458 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
459 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
460 else
461 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
465 is_nice_device ()
467 sysfs_path="${1#/sys}"
469 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
470 then
471 return 0
472 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
473 then
474 return 0
475 elif echo ${sysfs_path} | grep -q "^/block/dm-"
476 then
477 return 0
480 return 1
483 copy_live_to ()
485 copyfrom="${1}"
486 copytodev="${2}"
487 copyto="${copyfrom}_swap"
489 if [ -z "${MODULETORAM}" ]
490 then
491 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
492 else
493 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
495 if [ -f "${MODULETORAMFILE}" ]
496 then
497 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
498 else
499 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
500 return 1
504 if [ "${copytodev}" = "ram" ]
505 then
506 # copying to ram:
507 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
508 mount_options="-o size=${size}k"
509 free_string="memory"
510 fstype="tmpfs"
511 dev="/dev/shm"
512 else
513 # it should be a writable block device
514 if [ -b "${copytodev}" ]
515 then
516 dev="${copytodev}"
517 free_string="space"
518 fstype=$(get_fstype "${dev}")
519 freespace=$(fs_size "${dev}")
520 else
521 log_warning_msg "${copytodev} is not a block device."
522 return 1
526 if [ "${freespace}" -lt "${size}" ]
527 then
528 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
529 return 1
532 # begin copying (or uncompressing)
533 mkdir "${copyto}"
534 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
535 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
537 if [ "${extension}" = "tgz" ]
538 then
539 cd "${copyto}"
540 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
541 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
542 mount -r -o move "${copyto}" "${rootmnt}"
543 cd "${OLDPWD}"
544 else
545 if [ -n "${MODULETORAMFILE}" ]
546 then
547 if [ -x /bin/rsync ]
548 then
549 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
550 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
551 else
552 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
554 else
555 if [ -x /bin/rsync ]
556 then
557 echo " * Copying whole medium to RAM" 1>/dev/console
558 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
559 else
560 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
561 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
562 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
563 then
564 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
569 umount ${copyfrom}
570 mount -r -o move ${copyto} ${copyfrom}
573 rmdir ${copyto}
574 return 0
577 do_netsetup ()
579 modprobe -q af_packet # For DHCP
581 udevadm trigger
582 udevadm settle
584 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
585 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
587 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
588 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
589 then
592 # support for Syslinux IPAPPEND parameter
593 # it sets the BOOTIF variable on the kernel parameter
595 if [ -n "${BOOTIF}" ]
596 then
597 # pxelinux sets BOOTIF to a value based on the mac address of the
598 # network card used to PXE boot, so use this value for DEVICE rather
599 # than a hard-coded device name from initramfs.conf. this facilitates
600 # network booting when machines may have multiple network cards.
601 # pxelinux sets BOOTIF to 01-$mac_address
603 # strip off the leading "01-", which isn't part of the mac
604 # address
605 temp_mac=${BOOTIF#*-}
607 # convert to typical mac address format by replacing "-" with ":"
608 bootif_mac=""
609 IFS='-'
610 for x in $temp_mac
612 if [ -z "$bootif_mac" ]
613 then
614 bootif_mac="$x"
615 else
616 bootif_mac="$bootif_mac:$x"
618 done
619 unset IFS
621 # look for devices with matching mac address, and set DEVICE to
622 # appropriate value if match is found.
624 for device in /sys/class/net/*
626 if [ -f "$device/address" ]
627 then
628 current_mac=$(cat "$device/address")
630 if [ "$bootif_mac" = "$current_mac" ]
631 then
632 DEVICE=${device##*/}
633 break
636 done
639 # if ethdevice was not specified on the kernel command line
640 # make sure we try to get a working network configuration
641 # for *every* present network device (except for loopback of course)
642 if [ -z "$ETHDEVICE" ] ; then
643 echo "If you want to boot from a specific device use bootoption ethdevice=..."
644 for device in /sys/class/net/*; do
645 dev=${device##*/} ;
646 if [ "$dev" != "lo" ] ; then
647 ETHDEVICE="$ETHDEVICE $dev"
649 done
652 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
653 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
654 devlist="$devlist $device"
655 done
657 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
658 # an endless loop; iff execution fails give it two further tries, that's
659 # why we use '$devlist $devlist $devlist' for the other for loop
660 for dev in $devlist $devlist $devlist ; do
661 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
662 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
663 jobid=$!
664 sleep "$ETHDEV_TIMEOUT" ; sleep 1
665 if [ -r /proc/"$jobid"/status ] ; then
666 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
667 kill -9 $jobid
670 # if configuration of device worked we should have an assigned
671 # IP address, iff so let's use the according as $DEVICE for later usage
672 # simple and primitive approach which seems to work fine
673 if ifconfig $dev | grep -q 'inet.*addr:' ; then
674 export DEVICE="$dev"
675 break
677 done
679 else
680 for interface in ${DEVICE}; do
681 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
682 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
683 if [ "$IPV4ADDR" != "0.0.0.0" ]
684 then
685 break
687 done
690 for interface in ${DEVICE}; do
691 # source relevant ipconfig output
692 OLDHOSTNAME=${HOSTNAME}
693 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
694 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
695 export HOSTNAME
697 if [ -n "${interface}" ]
698 then
699 HWADDR="$(cat /sys/class/net/${interface}/address)"
702 if [ ! -e "/etc/resolv.conf" ]
703 then
704 echo "Creating /etc/resolv.conf"
706 if [ -n "${DNSDOMAIN}" ]
707 then
708 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
709 echo "search ${DNSDOMAIN}" > /etc/resolv.conf
712 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
714 echo "nameserver $i" >> /etc/resolv.conf
715 done
718 # Check if we have a network device at all
719 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
720 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
721 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
722 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
723 ! ls /sys/class/net/ra0 > /dev/null 2>&1
724 then
725 panic "No supported network device found, maybe a non-mainline driver is required."
727 done
730 do_netmount()
732 do_netsetup
734 if [ "${NFSROOT}" = "auto" ]
735 then
736 NFSROOT=${ROOTSERVER}:${ROOTPATH}
739 rc=1
741 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
742 then
743 do_httpmount
744 return $?
747 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
748 then
749 NFSROOT=${ROOTSERVER}:${NFSROOT}
752 log_begin_msg "Trying netboot from ${NFSROOT}"
754 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
755 then
756 rc=0
757 elif do_nfsmount
758 then
759 NETBOOT="nfs"
760 export NETBOOT
761 rc=0
764 log_end_msg
765 return ${rc}
768 do_iscsi()
770 do_netsetup
771 #modprobe ib_iser
772 modprobe iscsi_tcp
773 local debugopt=""
774 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
775 #FIXME this name is supposed to be unique - some date + ifconfig hash?
776 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
777 export ISCSI_INITIATORNAME
778 if [ -n "${ISCSI_SERVER}" ] ; then
779 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
780 else
781 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
783 if [ $? != 0 ]
784 then
785 panic "Failed to log into iscsi target"
787 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
788 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
789 if [ -n "${host}" ]
790 then
791 local devices=""
792 local i=0
793 while [ -z "${devices}" -a $i -lt 60 ]
795 sleep 1
796 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
797 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
798 i=$(expr $i + 1)
799 echo -ne $i\\r
800 done
801 for dev in $devices
803 if check_dev "null" "/dev/$dev"
804 then
805 NETBOOT="iscsi"
806 export NETBOOT
807 return 0;
809 done
810 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
811 else
812 panic "Failed to locate iSCSI host in /sys"
816 do_httpmount ()
818 rc=1
820 for webfile in HTTPFS FTPFS FETCH
822 local url="$(eval echo \"\$\{${webfile}\}\")"
823 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
825 if [ -n "$url" ]
826 then
827 case "${extension}" in
828 iso|squashfs|tgz|tar)
829 if [ "${extension}" = "iso" ]
830 then
831 mkdir -p "${alt_mountpoint}"
832 dest="${alt_mountpoint}"
833 else
834 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
835 mount -t ramfs ram "${mountpoint}"
836 mkdir -p "${dest}"
838 if [ "${webfile}" = "FETCH" ]
839 then
840 case "$url" in
841 tftp*)
842 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
843 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
844 lfile="$(basename $url)"
845 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
846 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
850 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
851 wget "${url}" -O "${dest}/$(basename ${url})"
853 esac
854 else
855 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
856 if [ "${webfile}" = "FTPFS" ]
857 then
858 FUSE_MOUNT="curlftpfs"
859 url="$(dirname ${url})"
860 else
861 FUSE_MOUNT="httpfs"
863 modprobe fuse
864 $FUSE_MOUNT "${url}" "${dest}"
865 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
867 [ ${?} -eq 0 ] && rc=0
868 [ "${extension}" = "tgz" ] && live_dest="ram"
869 if [ "${extension}" = "iso" ]
870 then
871 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
872 mount -t iso9660 "${isoloop}" "${mountpoint}"
873 rc=${?}
875 break
879 log_begin_msg "Unrecognized archive extension for ${url}"
881 esac
883 done
885 if [ ${rc} != 0 ]
886 then
887 if [ -d "${alt_mountpoint}" ]
888 then
889 umount "${alt_mountpoint}"
890 rmdir "${alt_mountpoint}"
892 umount "${mountpoint}"
893 elif [ "${webfile}" != "FETCH" ] ; then
894 NETBOOT="${webfile}"
895 export NETBOOT
898 return ${rc}
901 do_nfsmount ()
903 rc=1
905 modprobe -q nfs
907 if [ -z "${NFSOPTS}" ]
908 then
909 NFSOPTS=""
912 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
914 # FIXME: This while loop is an ugly HACK round an nfs bug
916 while [ "$i" -lt 60 ]
918 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
919 sleep 1
920 i="$(($i + 1))"
921 done
923 return ${rc}
926 do_cifsmount ()
928 rc=1
930 if [ -x "/sbin/mount.cifs" ]
931 then
932 if [ -z "${NFSOPTS}" ]
933 then
934 CIFSOPTS="-ouser=root,password="
935 else
936 CIFSOPTS="${NFSOPTS}"
939 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
940 modprobe -q cifs
942 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
943 then
944 rc=0
948 return ${rc}
951 do_snap_copy ()
953 fromdev="${1}"
954 todir="${2}"
955 snap_type="${3}"
956 size=$(fs_size "${fromdev}" "" "used")
958 if [ -b "${fromdev}" ]
959 then
960 # look for free mem
961 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
962 then
963 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
964 freespace=$(df -k | awk '/'${todev}'/{print $4}')
965 else
966 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
969 tomount="/mnt/tmpsnap"
971 if [ ! -d "${tomount}" ]
972 then
973 mkdir -p "${tomount}"
976 fstype=$(get_fstype "${fromdev}")
978 if [ -n "${fstype}" ]
979 then
980 # Copying stuff...
981 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
982 cp -a "${tomount}"/* ${todir}
983 umount "${tomount}"
984 else
985 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
988 rmdir "${tomount}"
990 if echo ${fromdev} | grep -qs loop
991 then
992 losetup -d "${fromdev}"
995 return 0
996 else
997 return 1
999 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1003 find_snap ()
1005 # Look for ${snap_label}.* in block devices
1006 snap_label="${1}"
1008 if [ "${PERSISTENT}" != "nofiles" ]
1009 then
1010 # search for image files
1011 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")
1014 if [ -z "${snapdata}" ]
1015 then
1016 snapdata=$(find_cow_device "${snap_label}")
1018 echo "${snapdata}"
1021 try_snap ()
1023 # copy the contents of previously found snapshot to ${snap_mount}
1024 # and remember the device and filename for resync on exit in live-boot.init
1026 snapdata="${1}"
1027 snap_mount="${2}"
1028 snap_type="${3}"
1030 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1031 then
1032 log_success_msg "found snapshot: ${snapdata}"
1033 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1034 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1035 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1037 if ! try_mount "${snapdev}" "${snapback}" "ro"
1038 then
1039 break
1042 RES="0"
1044 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1045 then
1046 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1047 dev=$(get_backing_device "${snapback}/${snapfile}")
1049 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1050 RES="$?"
1051 else
1052 # cpio.gz snapshot
1054 # Unfortunately klibc's cpio is incompatible with the
1055 # rest of the world; everything else requires -u -d,
1056 # while klibc doesn't implement them. Try to detect
1057 # whether it's in use.
1058 cpiopath="$(which cpio)" || true
1059 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1060 then
1061 cpioargs=
1062 else
1063 cpioargs='--unconditional --make-directories'
1066 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
1067 RES="$?"
1069 if [ "${RES}" != "0" ]
1070 then
1071 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1075 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1077 if [ "${RES}" != "0" ]
1078 then
1079 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1082 elif [ -b "${snapdata}" ]
1083 then
1084 # Try to find if it could be a snapshot partition
1085 dev="${snapdata}"
1086 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1087 if echo "${dev}" | grep -qs loop
1088 then
1089 # strange things happens, user confused?
1090 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1091 snapfile=$(basename ${snaploop})
1092 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1093 else
1094 snapdev="${dev}"
1097 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1098 then
1099 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1100 return 1
1101 else
1102 if [ -n "${snapfile}" ]
1103 then
1104 # it was a loop device, user confused
1105 umount ${snapdev}
1108 else
1109 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1110 return 1
1113 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1114 return 0
1117 setup_unionfs ()
1119 image_directory="${1}"
1120 rootmnt="${2}"
1121 addimage_directory="${3}"
1123 case ${UNIONTYPE} in
1124 aufs|unionfs)
1125 modprobe -q -b ${UNIONTYPE}
1127 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1128 then
1129 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1130 echo "This might be really slow."
1132 UNIONTYPE="unionfs-fuse"
1135 esac
1137 if [ "${UNIONTYPE}" = unionfs-fuse ]
1138 then
1139 modprobe fuse
1142 # run-init can't deal with images in a subdir, but we're going to
1143 # move all of these away before it runs anyway. No, we're not,
1144 # put them in / since move-mounting them into / breaks mono and
1145 # some other apps.
1147 croot="/"
1149 # Let's just mount the read-only file systems first
1150 rofsstring=""
1151 rofslist=""
1153 if [ "${UNIONTYPE}" = "aufs" ]
1154 then
1155 roopt="rr"
1156 noxino_opt="noxino,"
1157 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1158 then
1159 roopt="RO"
1160 else
1161 roopt="ro"
1164 if [ -z "${PLAIN_ROOT}" ]
1165 then
1166 # Read image names from ${MODULE}.module if it exists
1167 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1168 then
1169 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1171 image_string="${image_string} ${image_directory}/${IMAGE}"
1172 done
1173 elif [ -e "${image_directory}/${MODULE}.module" ]
1174 then
1175 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1177 image_string="${image_string} ${image_directory}/${IMAGE}"
1178 done
1179 else
1180 # ${MODULE}.module does not exist, create a list of images
1181 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1183 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1185 if [ -e "${IMAGE}" ]
1186 then
1187 image_string="${image_string} ${IMAGE}"
1189 done
1190 done
1192 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1193 then
1194 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1196 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1198 if [ -e "${IMAGE}" ]
1199 then
1200 image_string="${image_string} ${IMAGE}"
1202 done
1203 done
1206 # Now sort the list
1207 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1210 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1212 mkdir -p "${croot}"
1214 for image in ${image_string}
1216 imagename=$(basename "${image}")
1218 export image devname
1219 maybe_break live-realpremount
1220 log_begin_msg "Running /scripts/live-realpremount"
1221 run_scripts /scripts/live-realpremount
1222 log_end_msg
1224 if [ -d "${image}" ]
1225 then
1226 # it is a plain directory: do nothing
1227 rofsstring="${image}=${roopt}:${rofsstring}"
1228 rofslist="${image} ${rofslist}"
1229 elif [ -f "${image}" ]
1230 then
1231 if losetup --help 2>&1 | grep -q -- "-r\b"
1232 then
1233 backdev=$(get_backing_device "${image}" "-r")
1234 else
1235 backdev=$(get_backing_device "${image}")
1237 fstype=$(get_fstype "${backdev}")
1239 if [ "${fstype}" = "unknown" ]
1240 then
1241 panic "Unknown file system type on ${backdev} (${image})"
1244 if [ -z "${fstype}" ]
1245 then
1246 fstype="${imagename##*.}"
1247 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1250 mkdir -p "${croot}/${imagename}"
1251 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1252 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}"
1253 log_end_msg
1255 done
1256 else
1257 # we have a plain root system
1258 mkdir -p "${croot}/filesystem"
1259 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1260 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}"
1261 # probably broken:
1262 mount -o bind ${croot}/filesystem $mountpoint
1263 log_end_msg
1266 rofsstring=${rofsstring%:}
1268 mkdir -p /cow
1270 # Looking for "${root_persistence}" device or file
1271 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1272 then
1273 if [ -z "${QUICKUSBMODULES}" ]
1274 then
1275 # Load USB modules
1276 num_block=$(ls -l /sys/block | wc -l)
1277 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1279 modprobe -q -b ${module}
1280 done
1282 udevadm trigger
1283 udevadm settle
1285 # For some reason, udevsettle does not block in this scenario,
1286 # so we sleep for a little while.
1288 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1289 for timeout in 5 4 3 2 1
1291 sleep 1
1293 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1294 then
1295 break
1297 done
1300 # search for label and files (this could be hugely optimized)
1301 cowprobe=$(find_cow_device "${root_persistence}")
1302 if [ -b "${cowprobe}" ]
1303 then
1304 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1305 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1306 # snapshots to be sure to really store some e.g key config files,
1307 # but not on the same media
1308 blacklistdev="${cowprobe}"
1309 PERSISTENCE_IS_ON="1"
1310 export PERSISTENCE_IS_ON
1312 # homecow just mount something on /home, this should be generalized some way
1313 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1314 if [ -b "${homecow}" ]
1315 then
1316 PERSISTENCE_IS_ON="1"
1317 export PERSISTENCE_IS_ON
1319 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1320 # This second type should be removed when snapshot will get smarter,
1321 # hence when "/etc/live-snapshot*list" will be supported also by
1322 # ext2|ext3|ext4|jffs2 snapshot types.
1323 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1325 if [ -b "${cowprobe}" ]
1326 then
1327 cowdevice=${cowprobe}
1328 cow_fstype=$(get_fstype "${cowprobe}")
1329 cow_mountopt="rw,noatime"
1331 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1332 then
1333 fsck -y ${cowdevice}
1335 else
1336 log_warning_msg "Unable to find the persistent medium"
1337 cowdevice="tmpfs"
1338 cow_fstype="tmpfs"
1339 cow_mountopt="rw,noatime,mode=755"
1341 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1342 then
1343 # check if there are any nfs options
1344 if echo ${NFS_COW}|grep -q ','
1345 then
1346 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1347 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1348 else
1349 nfs_cow_opts="-o nolock"
1350 nfs_cow=${NFS_COW}
1352 mac="$(get_mac)"
1353 if [ -n "${mac}" ]
1354 then
1355 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1356 cow_fstype="nfs"
1357 else
1358 panic "unable to determine mac address"
1360 else
1361 cowdevice="tmpfs"
1362 cow_fstype="tmpfs"
1363 cow_mountopt="rw,noatime,mode=755"
1366 if [ "${cow_fstype}" = "nfs" ]
1367 then
1368 log_begin_msg \
1369 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1370 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1371 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1372 else
1373 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1374 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1377 rofscount=$(echo ${rofslist} |wc -w)
1379 if [ -n "${EXPOSED_ROOT}" ]
1380 then
1381 if [ ${rofscount} -ne 1 ]
1382 then
1383 panic "only one RO file system supported with exposedroot: ${rofslist}"
1385 exposedrootfs=${rofslist%% }
1387 mount --bind ${exposedrootfs} ${rootmnt} || \
1388 panic "bind mount of ${exposedrootfs} failed"
1390 if [ -z "${SKIP_UNION_MOUNTS}" ]
1391 then
1392 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1393 else
1394 cow_dirs=''
1397 for dir in ${cow_dirs}; do
1398 mkdir -p /cow${dir}
1400 case "${UNIONTYPE}" in
1401 unionfs-fuse)
1402 (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}")
1403 mkdir -p /dev/.initramfs/varrun
1404 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1408 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"
1410 esac
1411 done
1412 else
1413 case "${UNIONTYPE}" in
1414 unionfs-fuse)
1415 (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}")
1416 mkdir -p /dev/.initramfs/varrun
1417 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1421 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}"
1423 esac
1426 # Correct the permissions of /:
1427 chmod 0755 "${rootmnt}"
1429 # tmpfs file systems
1430 touch /etc/fstab
1431 mkdir -p "${rootmnt}/live"
1432 mount -t tmpfs tmpfs ${rootmnt}/live
1434 # Adding other custom mounts
1435 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1436 then
1437 # directly mount /home
1438 # FIXME: add a custom mounts configurable system
1440 if [ -b "${homecow}" ]
1441 then
1442 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1443 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1444 else
1445 log_warning_msg "Unable to find the persistent home medium"
1448 # Look for other snapshots to copy in
1449 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1450 # This second type should be removed when snapshot grow smarter
1451 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1454 if [ -n "${SHOWMOUNTS}" ]
1455 then
1456 for d in ${rofslist}
1458 mkdir -p "${rootmnt}/live/${d##*/}"
1460 case d in
1461 *.dir)
1462 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1466 case "${UNIONTYPE}" in
1467 unionfs-fuse)
1468 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1472 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1474 esac
1476 esac
1477 done
1480 # shows cow fs on /cow for use by live-snapshot
1481 mkdir -p "${rootmnt}/live/cow"
1482 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"
1485 check_dev ()
1487 sysdev="${1}"
1488 devname="${2}"
1489 skip_uuid_check="${3}"
1491 # support for fromiso=.../isofrom=....
1492 if [ -n "$FROMISO" ]
1493 then
1494 ISO_DEVICE=$(dirname $FROMISO)
1495 if ! [ -b $ISO_DEVICE ]
1496 then
1497 # to support unusual device names like /dev/cciss/c0d0p1
1498 # as well we have to identify the block device name, let's
1499 # do that for up to 15 levels
1500 i=15
1501 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1503 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1504 [ -b "$ISO_DEVICE" ] && break
1505 i=$(($i -1))
1506 done
1509 if [ "$ISO_DEVICE" = "/" ]
1510 then
1511 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1512 else
1513 mkdir /isofrom
1514 mount "$ISO_DEVICE" /isofrom
1515 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1516 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1517 devname="${loopdevname}"
1521 if [ -z "${devname}" ]
1522 then
1523 devname=$(sys2dev "${sysdev}")
1526 if [ -d "${devname}" ]
1527 then
1528 mount -o bind "${devname}" $mountpoint || continue
1530 if is_live_path $mountpoint
1531 then
1532 echo $mountpoint
1533 return 0
1534 else
1535 umount $mountpoint
1538 [ -e "$devname" ] || continue
1540 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1541 then
1542 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1543 devname="${loopdevname}"
1546 fstype=$(get_fstype "${devname}")
1548 if is_supported_fs ${fstype}
1549 then
1550 devuid=$(blkid -o value -s UUID "$devname")
1551 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1552 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1553 [ -n "$devuid" ] && echo "$devuid" >> $tried
1555 if is_live_path ${mountpoint} && \
1556 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1557 then
1558 echo ${mountpoint}
1559 return 0
1560 else
1561 umount ${mountpoint}
1565 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1566 then
1567 losetup -d "${loopdevname}"
1570 return 1
1573 find_livefs ()
1575 timeout="${1}"
1577 # don't start autodetection before timeout has expired
1578 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1579 then
1580 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1581 then
1582 return 1
1586 # first look at the one specified in the command line
1587 case "${LIVE_MEDIA}" in
1588 removable-usb)
1589 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1591 if [ "$(cat ${sysblock}/removable)" = "1" ]
1592 then
1593 if readlink ${sysblock} | grep -q usb ||
1594 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1595 then
1596 for dev in $(subdevices "${sysblock}")
1598 if check_dev "${dev}"
1599 then
1600 return 0
1602 done
1605 done
1606 return 1
1609 removable)
1610 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1612 if [ "$(cat ${sysblock}/removable)" = "1" ]
1613 then
1614 for dev in $(subdevices "${sysblock}")
1616 if check_dev "${dev}"
1617 then
1618 return 0
1620 done
1622 done
1623 return 1
1627 if [ ! -z "${LIVE_MEDIA}" ]
1628 then
1629 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1630 then
1631 return 0
1635 esac
1637 # or do the scan of block devices
1638 # prefer removable devices over non-removable devices, so scan them first
1639 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1641 if [ "$(cat ${sysblock}/removable)" = "1" ]
1642 then
1643 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1644 else
1645 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1647 done
1648 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1650 for sysblock in $devices_to_scan
1652 devname=$(sys2dev "${sysblock}")
1653 [ -e "$devname" ] || continue
1654 fstype=$(get_fstype "${devname}")
1656 if /lib/udev/cdrom_id ${devname} > /dev/null
1657 then
1658 if check_dev "null" "${devname}"
1659 then
1660 return 0
1662 elif is_nice_device "${sysblock}"
1663 then
1664 for dev in $(subdevices "${sysblock}")
1666 if check_dev "${dev}"
1667 then
1668 return 0
1670 done
1671 elif [ "${fstype}" = "squashfs" -o \
1672 "${fstype}" = "btrfs" -o \
1673 "${fstype}" = "ext2" -o \
1674 "${fstype}" = "ext3" -o \
1675 "${fstype}" = "ext4" -o \
1676 "${fstype}" = "jffs2" ]
1677 then
1678 # This is an ugly hack situation, the block device has
1679 # an image directly on it. It's hopefully
1680 # live-boot, so take it and run with it.
1681 ln -s "${devname}" "${devname}.${fstype}"
1682 echo "${devname}.${fstype}"
1683 return 0
1685 done
1687 return 1
1690 integrity_check ()
1692 media_mountpoint="${1}"
1694 log_begin_msg "Checking media integrity"
1696 cd ${media_mountpoint}
1697 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1698 RC="${?}"
1700 log_end_msg
1702 if [ "${RC}" -eq 0 ]
1703 then
1704 log_success_msg "Everything ok, will reboot in 10 seconds."
1705 sleep 10
1706 cd /
1707 umount ${media_mountpoint}
1708 sync
1709 echo u > /proc/sysrq-trigger
1710 echo b > /proc/sysrq-trigger
1711 else
1712 panic "Not ok, a media defect is likely, switch to VT8 for details."
1716 mountroot ()
1718 if [ -x /scripts/local-top/cryptroot ]; then
1719 /scripts/local-top/cryptroot
1722 exec 6>&1
1723 exec 7>&2
1724 exec > live.log
1725 exec 2>&1
1726 tail -f live.log >&7 &
1727 tailpid="${!}"
1729 # Ensure 'panic' function is overridden
1730 . /scripts/live-functions
1732 Arguments
1734 maybe_break live-premount
1735 log_begin_msg "Running /scripts/live-premount"
1736 run_scripts /scripts/live-premount
1737 log_end_msg
1739 # Needed here too because some things (*cough* udev *cough*)
1740 # changes the timeout
1742 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1743 then
1744 if do_netmount
1745 then
1746 livefs_root="${mountpoint}"
1747 else
1748 panic "Unable to find a live file system on the network"
1750 else
1751 if [ -n "${ISCSI_PORTAL}" ]
1752 then
1753 do_iscsi && livefs_root="${mountpoint}"
1754 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1755 then
1756 # Do a local boot from hd
1757 livefs_root=${ROOT}
1758 else
1759 if [ -x /usr/bin/memdiskfind ]
1760 then
1761 MEMDISK=$(/usr/bin/memdiskfind)
1763 if [ $? -eq 0 ]
1764 then
1765 # We found a memdisk, set up phram
1766 modprobe phram phram=memdisk,${MEMDISK}
1768 # Load mtdblock, the memdisk will be /dev/mtdblock0
1769 modprobe mtdblock
1773 # Scan local devices for the image
1775 while [ "$i" -lt 60 ]
1777 livefs_root=$(find_livefs ${i})
1779 if [ -n "${livefs_root}" ]
1780 then
1781 break
1784 sleep 1
1785 i="$(($i + 1))"
1786 done
1790 if [ -z "${livefs_root}" ]
1791 then
1792 panic "Unable to find a medium containing a live file system"
1795 if [ "${INTEGRITY_CHECK}" ]
1796 then
1797 integrity_check "${livefs_root}"
1800 if [ "${TORAM}" ]
1801 then
1802 live_dest="ram"
1803 elif [ "${TODISK}" ]
1804 then
1805 live_dest="${TODISK}"
1808 if [ "${live_dest}" ]
1809 then
1810 log_begin_msg "Copying live media to ${live_dest}"
1811 copy_live_to "${livefs_root}" "${live_dest}"
1812 log_end_msg
1815 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1816 # because the mountpoint is left behind in /proc/mounts, so let's get
1817 # rid of it when running from RAM
1818 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1819 then
1820 losetup -d /dev/loop0
1821 grep -q /isofrom /proc/mounts && umount /isofrom
1824 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1825 then
1826 setup_unionfs "${livefs_root}" "${rootmnt}"
1827 else
1828 mac="$(get_mac)"
1829 mac="$(echo ${mac} | sed 's/-//g')"
1830 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1834 if [ -n "${ROOT_PID}" ] ; then
1835 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1838 log_end_msg
1840 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1841 # live-bottom; udev's init script will take care of things after that
1842 if [ "${UNIONTYPE}" = unionfs-fuse ]
1843 then
1844 mount -n -o bind /dev "${rootmnt}/dev"
1847 # Move to the new root filesystem so that programs there can get at it.
1848 if [ ! -d /root/live/image ]
1849 then
1850 mkdir -p /root/live/image
1851 mount --move /live/image /root/live/image
1854 # aufs2 in kernel versions around 2.6.33 has a regression:
1855 # directories can't be accessed when read for the first the time,
1856 # causing a failure for example when accessing /var/lib/fai
1857 # when booting FAI, this simple workaround solves it
1858 ls /root/* >/dev/null 2>&1
1860 maybe_break live-bottom
1861 log_begin_msg "Running /scripts/live-bottom\n"
1863 run_scripts /scripts/live-bottom
1864 log_end_msg
1866 if [ "${UNIONFS}" = unionfs-fuse ]
1867 then
1868 umount "${rootmnt}/dev"
1871 exec 1>&6 6>&-
1872 exec 2>&7 7>&-
1873 kill ${tailpid}
1874 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null