Adding upstream version 3.0~a13.
[debian-live-boot.git] / scripts / live
blob66f0db07061f1f339b69417da30d842d732291dd
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 ramdisk-size=*)
234 ramdisk_size="${ARGUMENT#ramdisk-size=}"
237 swapon)
238 SWAPON="Yes"
239 export SWAPON
242 persistent)
243 PERSISTENT="Yes"
244 export PERSISTENT
247 persistent=*)
248 PERSISTENT="${ARGUMENT#persistent=}"
249 if [ -z "${PERSISTENT}" ]
250 then
251 PERSISTENT="Yes"
253 export PERSISTENT
256 persistent-path=*)
257 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
258 export PERSISTENT_PATH
261 persistent-subtext=*)
262 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
263 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
264 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
265 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
268 nopersistent)
269 NOPERSISTENT="Yes"
270 export NOPERSISTENT
273 noprompt)
274 NOPROMPT="Yes"
275 export NOPROMPT
278 noprompt=*)
279 NOPROMPT="${ARGUMENT#noprompt=}"
280 export NOPROMPT
283 quickusbmodules)
284 QUICKUSBMODULES="Yes"
285 export QUICKUSBMODULES
288 preseed/file=*|file=*)
289 LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}"
290 export LOCATIONS
293 nopreseed)
294 NOPRESEED="Yes"
295 export NOPRESEED
298 */*=*)
299 question="${ARGUMENT%%=*}"
300 value="${ARGUMENT#*=}"
301 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
302 export PRESEEDS
305 showmounts)
306 SHOWMOUNTS="Yes"
307 export SHOWMOUNTS
310 silent)
311 SILENT="Yes"
312 export SILENT
315 todisk=*)
316 TODISK="${ARGUMENT#todisk=}"
317 export TODISK
320 toram)
321 TORAM="Yes"
322 export TORAM
325 toram=*)
326 TORAM="Yes"
327 MODULETORAM="${ARGUMENT#toram=}"
328 export TORAM MODULETORAM
331 exposedroot)
332 EXPOSED_ROOT="Yes"
333 export EXPOSED_ROOT
336 plainroot)
337 PLAIN_ROOT="Yes"
338 export PLAIN_ROOT
341 skipunion)
342 SKIP_UNION_MOUNTS="Yes"
343 export SKIP_UNION_MOUNTS
346 root=*)
347 ROOT="${ARGUMENT#root=}"
348 export ROOT
351 union=*)
352 UNIONTYPE="${ARGUMENT#union=}"
353 export UNIONTYPE
355 esac
356 done
358 # sort of compatibility with netboot.h from linux docs
359 if [ -z "${NETBOOT}" ]
360 then
361 if [ "${ROOT}" = "/dev/nfs" ]
362 then
363 NETBOOT="nfs"
364 export NETBOOT
365 elif [ "${ROOT}" = "/dev/cifs" ]
366 then
367 NETBOOT="cifs"
368 export NETBOOT
372 if [ -z "${MODULE}" ]
373 then
374 MODULE="filesystem"
375 export MODULE
378 if [ -z "${UNIONTYPE}" ]
379 then
380 UNIONTYPE="aufs"
381 export UNIONTYPE
385 is_live_path ()
387 DIRECTORY="${1}"
389 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
390 then
391 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
393 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
394 then
395 return 0
397 done
400 return 1
403 matches_uuid ()
405 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
406 then
407 return 0
410 path="${1}"
411 uuid="$(cat /conf/uuid.conf)"
413 for try_uuid_file in "${path}/.disk/live-uuid"*
415 [ -e "${try_uuid_file}" ] || continue
417 try_uuid="$(cat "${try_uuid_file}")"
419 if [ "${uuid}" = "${try_uuid}" ]
420 then
421 return 0
423 done
425 return 1
428 get_backing_device ()
430 case "${1}" in
431 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
432 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
435 *.dir)
436 echo "directory"
440 panic "Unrecognized live filesystem: ${1}"
442 esac
445 match_files_in_dir ()
447 # Does any files match pattern ${1} ?
448 local pattern="${1}"
450 if [ "$(echo ${pattern})" != "${pattern}" ]
451 then
452 return 0
455 return 1
458 mount_images_in_directory ()
460 directory="${1}"
461 rootmnt="${2}"
462 mac="${3}"
465 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
466 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
467 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
468 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
469 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
470 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
471 then
472 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
473 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
474 else
475 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
479 is_nice_device ()
481 sysfs_path="${1#/sys}"
483 if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
484 then
485 return 0
486 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
487 then
488 return 0
489 elif echo ${sysfs_path} | grep -q "^/block/dm-"
490 then
491 return 0
494 return 1
497 copy_live_to ()
499 copyfrom="${1}"
500 copytodev="${2}"
501 copyto="${copyfrom}_swap"
503 if [ -z "${MODULETORAM}" ]
504 then
505 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
506 else
507 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
509 if [ -f "${MODULETORAMFILE}" ]
510 then
511 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
512 else
513 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
514 return 1
518 if [ "${copytodev}" = "ram" ]
519 then
520 # copying to ram:
521 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
522 mount_options="-o size=${size}k"
523 free_string="memory"
524 fstype="tmpfs"
525 dev="/dev/shm"
526 else
527 # it should be a writable block device
528 if [ -b "${copytodev}" ]
529 then
530 dev="${copytodev}"
531 free_string="space"
532 fstype=$(get_fstype "${dev}")
533 freespace=$(fs_size "${dev}")
534 else
535 log_warning_msg "${copytodev} is not a block device."
536 return 1
540 if [ "${freespace}" -lt "${size}" ]
541 then
542 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
543 return 1
546 # Custom ramdisk size
547 if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ]
548 then
549 # FIXME: should check for wrong values
550 mount_options="-o size=${ramdisk_size}"
553 # begin copying (or uncompressing)
554 mkdir "${copyto}"
555 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
556 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
558 if [ "${extension}" = "tgz" ]
559 then
560 cd "${copyto}"
561 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
562 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
563 mount -r -o move "${copyto}" "${rootmnt}"
564 cd "${OLDPWD}"
565 else
566 if [ -n "${MODULETORAMFILE}" ]
567 then
568 if [ -x /bin/rsync ]
569 then
570 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
571 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
572 else
573 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
575 else
576 if [ -x /bin/rsync ]
577 then
578 echo " * Copying whole medium to RAM" 1>/dev/console
579 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
580 else
581 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
582 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH}
583 if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ]
584 then
585 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto}
590 umount ${copyfrom}
591 mount -r -o move ${copyto} ${copyfrom}
594 rmdir ${copyto}
595 return 0
598 do_netsetup ()
600 modprobe -q af_packet # For DHCP
602 udevadm trigger
603 udevadm settle
605 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
606 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
608 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
609 [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
610 then
613 # support for Syslinux IPAPPEND parameter
614 # it sets the BOOTIF variable on the kernel parameter
616 if [ -n "${BOOTIF}" ]
617 then
618 # pxelinux sets BOOTIF to a value based on the mac address of the
619 # network card used to PXE boot, so use this value for DEVICE rather
620 # than a hard-coded device name from initramfs.conf. this facilitates
621 # network booting when machines may have multiple network cards.
622 # pxelinux sets BOOTIF to 01-$mac_address
624 # strip off the leading "01-", which isn't part of the mac
625 # address
626 temp_mac=${BOOTIF#*-}
628 # convert to typical mac address format by replacing "-" with ":"
629 bootif_mac=""
630 IFS='-'
631 for x in $temp_mac
633 if [ -z "$bootif_mac" ]
634 then
635 bootif_mac="$x"
636 else
637 bootif_mac="$bootif_mac:$x"
639 done
640 unset IFS
642 # look for devices with matching mac address, and set DEVICE to
643 # appropriate value if match is found.
645 for device in /sys/class/net/*
647 if [ -f "$device/address" ]
648 then
649 current_mac=$(cat "$device/address")
651 if [ "$bootif_mac" = "$current_mac" ]
652 then
653 DEVICE=${device##*/}
654 break
657 done
660 # if ethdevice was not specified on the kernel command line
661 # make sure we try to get a working network configuration
662 # for *every* present network device (except for loopback of course)
663 if [ -z "$ETHDEVICE" ] ; then
664 echo "If you want to boot from a specific device use bootoption ethdevice=..."
665 for device in /sys/class/net/*; do
666 dev=${device##*/} ;
667 if [ "$dev" != "lo" ] ; then
668 ETHDEVICE="$ETHDEVICE $dev"
670 done
673 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
674 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
675 devlist="$devlist $device"
676 done
678 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
679 # an endless loop; iff execution fails give it two further tries, that's
680 # why we use '$devlist $devlist $devlist' for the other for loop
681 for dev in $devlist $devlist $devlist ; do
682 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
683 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
684 jobid=$!
685 sleep "$ETHDEV_TIMEOUT" ; sleep 1
686 if [ -r /proc/"$jobid"/status ] ; then
687 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
688 kill -9 $jobid
691 # if configuration of device worked we should have an assigned
692 # IP address, iff so let's use the according as $DEVICE for later usage
693 # simple and primitive approach which seems to work fine
694 if ifconfig $dev | grep -q 'inet.*addr:' ; then
695 export DEVICE="$dev"
696 break
698 done
700 else
701 for interface in ${DEVICE}; do
702 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
703 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
704 if [ "$IPV4ADDR" != "0.0.0.0" ]
705 then
706 break
708 done
711 for interface in ${DEVICE}; do
712 # source relevant ipconfig output
713 OLDHOSTNAME=${HOSTNAME}
714 [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
715 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
716 export HOSTNAME
718 if [ -n "${interface}" ]
719 then
720 HWADDR="$(cat /sys/class/net/${interface}/address)"
723 if [ ! -e "/etc/resolv.conf" ]
724 then
725 echo "Creating /etc/resolv.conf"
727 if [ -n "${DNSDOMAIN}" ]
728 then
729 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
730 echo "search ${DNSDOMAIN}" > /etc/resolv.conf
733 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
735 echo "nameserver $i" >> /etc/resolv.conf
736 done
739 # Check if we have a network device at all
740 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
741 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
742 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
743 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
744 ! ls /sys/class/net/ra0 > /dev/null 2>&1
745 then
746 panic "No supported network device found, maybe a non-mainline driver is required."
748 done
751 do_netmount()
753 do_netsetup
755 if [ "${NFSROOT}" = "auto" ]
756 then
757 NFSROOT=${ROOTSERVER}:${ROOTPATH}
760 rc=1
762 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
763 then
764 do_httpmount
765 return $?
768 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
769 then
770 NFSROOT=${ROOTSERVER}:${NFSROOT}
773 log_begin_msg "Trying netboot from ${NFSROOT}"
775 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
776 then
777 rc=0
778 elif do_nfsmount
779 then
780 NETBOOT="nfs"
781 export NETBOOT
782 rc=0
785 log_end_msg
786 return ${rc}
789 do_iscsi()
791 do_netsetup
792 #modprobe ib_iser
793 modprobe iscsi_tcp
794 local debugopt=""
795 [ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
796 #FIXME this name is supposed to be unique - some date + ifconfig hash?
797 ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)"
798 export ISCSI_INITIATORNAME
799 if [ -n "${ISCSI_SERVER}" ] ; then
800 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}"
801 else
802 iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260
804 if [ $? != 0 ]
805 then
806 panic "Failed to log into iscsi target"
808 local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \
809 /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')"
810 if [ -n "${host}" ]
811 then
812 local devices=""
813 local i=0
814 while [ -z "${devices}" -a $i -lt 60 ]
816 sleep 1
817 devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \
818 /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')"
819 i=$(expr $i + 1)
820 echo -ne $i\\r
821 done
822 for dev in $devices
824 if check_dev "null" "/dev/$dev"
825 then
826 NETBOOT="iscsi"
827 export NETBOOT
828 return 0;
830 done
831 panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
832 else
833 panic "Failed to locate iSCSI host in /sys"
837 do_httpmount ()
839 rc=1
841 for webfile in HTTPFS FTPFS FETCH
843 local url="$(eval echo \"\$\{${webfile}\}\")"
844 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
846 if [ -n "$url" ]
847 then
848 case "${extension}" in
849 iso|squashfs|tgz|tar)
850 if [ "${extension}" = "iso" ]
851 then
852 mkdir -p "${alt_mountpoint}"
853 dest="${alt_mountpoint}"
854 else
855 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
856 mount -t ramfs ram "${mountpoint}"
857 mkdir -p "${dest}"
859 if [ "${webfile}" = "FETCH" ]
860 then
861 case "$url" in
862 tftp*)
863 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
864 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
865 lfile="$(basename $url)"
866 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
867 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
871 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
872 wget "${url}" -O "${dest}/$(basename ${url})"
874 esac
875 else
876 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
877 if [ "${webfile}" = "FTPFS" ]
878 then
879 FUSE_MOUNT="curlftpfs"
880 url="$(dirname ${url})"
881 else
882 FUSE_MOUNT="httpfs"
884 modprobe fuse
885 $FUSE_MOUNT "${url}" "${dest}"
886 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
888 [ ${?} -eq 0 ] && rc=0
889 [ "${extension}" = "tgz" ] && live_dest="ram"
890 if [ "${extension}" = "iso" ]
891 then
892 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
893 mount -t iso9660 "${isoloop}" "${mountpoint}"
894 rc=${?}
896 break
900 log_begin_msg "Unrecognized archive extension for ${url}"
902 esac
904 done
906 if [ ${rc} != 0 ]
907 then
908 if [ -d "${alt_mountpoint}" ]
909 then
910 umount "${alt_mountpoint}"
911 rmdir "${alt_mountpoint}"
913 umount "${mountpoint}"
914 elif [ "${webfile}" != "FETCH" ] ; then
915 NETBOOT="${webfile}"
916 export NETBOOT
919 return ${rc}
922 do_nfsmount ()
924 rc=1
926 modprobe -q nfs
928 if [ -z "${NFSOPTS}" ]
929 then
930 NFSOPTS=""
933 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
935 # FIXME: This while loop is an ugly HACK round an nfs bug
937 while [ "$i" -lt 60 ]
939 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
940 sleep 1
941 i="$(($i + 1))"
942 done
944 return ${rc}
947 do_cifsmount ()
949 rc=1
951 if [ -x "/sbin/mount.cifs" ]
952 then
953 if [ -z "${NFSOPTS}" ]
954 then
955 CIFSOPTS="-ouser=root,password="
956 else
957 CIFSOPTS="${NFSOPTS}"
960 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
961 modprobe -q cifs
963 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
964 then
965 rc=0
969 return ${rc}
972 do_snap_copy ()
974 fromdev="${1}"
975 todir="${2}"
976 snap_type="${3}"
977 size=$(fs_size "${fromdev}" "" "used")
979 if [ -b "${fromdev}" ]
980 then
981 log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
983 # look for free mem
984 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
985 then
986 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
987 freespace=$(df -k | awk '/'${todev}'/{print $4}')
988 else
989 freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
992 tomount="/mnt/tmpsnap"
994 if [ ! -d "${tomount}" ]
995 then
996 mkdir -p "${tomount}"
999 fstype=$(get_fstype "${fromdev}")
1001 if [ -n "${fstype}" ]
1002 then
1003 # Copying stuff...
1004 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1005 cp -a "${tomount}"/* ${todir}
1006 umount "${tomount}"
1007 else
1008 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1011 rmdir "${tomount}"
1013 if echo ${fromdev} | grep -qs loop
1014 then
1015 losetup -d "${fromdev}"
1018 return 0
1019 else
1020 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1021 return 1
1025 find_snap ()
1027 # Look for ${snap_label}.* in block devices
1028 snap_label="${1}"
1029 black_listed_devices="${2}"
1031 if [ "${PERSISTENT}" != "nofiles" ]
1032 then
1033 # search for image files
1034 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" "${black_listed_devices}")
1037 if [ -z "${snapdata}" ]
1038 then
1039 snapdata=$(find_cow_device "${snap_label}" "${black_listed_devices}")
1041 echo "${snapdata}"
1044 try_snap ()
1046 # copy the contents of previously found snapshot to ${snap_mount}
1047 # and remember the device and filename for resync on exit in live-boot.init
1049 snapdata="${1}"
1050 snap_mount="${2}"
1051 snap_type="${3}"
1052 snap_relpath="${4}"
1054 if [ -z "${snap_relpath}" ]
1055 then
1056 # root snapshot, default usage
1057 snap_relpath="/"
1058 else
1059 # relative snapshot (actually used just for "/home" snapshots)
1060 snap_mount="${2}${snap_relpath}"
1063 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1064 then
1065 log_success_msg "found snapshot: ${snapdata}"
1066 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1067 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1068 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1070 if ! try_mount "${snapdev}" "${snapback}" "ro"
1071 then
1072 break
1075 RES="0"
1077 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1078 then
1079 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1080 dev=$(get_backing_device "${snapback}/${snapfile}")
1082 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1083 RES="$?"
1084 else
1085 # cpio.gz snapshot
1087 # Unfortunately klibc's cpio is incompatible with the
1088 # rest of the world; everything else requires -u -d,
1089 # while klibc doesn't implement them. Try to detect
1090 # whether it's in use.
1091 cpiopath="$(which cpio)" || true
1092 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1093 then
1094 cpioargs=
1095 else
1096 cpioargs='--unconditional --make-directories'
1099 if [ -s "${snapback}/${snapfile}" ]
1100 then
1101 BEFOREDIR="$(pwd)"
1102 cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
1103 RES="$?"
1104 cd "${BEFOREDIR}"
1105 else
1106 log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
1107 RES="0"
1110 if [ "${RES}" != "0" ]
1111 then
1112 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1116 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1118 if [ "${RES}" != "0" ]
1119 then
1120 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1123 elif [ -b "${snapdata}" ]
1124 then
1125 # Try to find if it could be a snapshot partition
1126 dev="${snapdata}"
1127 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1128 if echo "${dev}" | grep -qs loop
1129 then
1130 # strange things happens, user confused?
1131 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1132 snapfile=$(basename ${snaploop})
1133 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1134 else
1135 snapdev="${dev}"
1138 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1139 then
1140 log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
1141 return 1
1142 else
1143 if [ -n "${snapfile}" ]
1144 then
1145 # it was a loop device, user confused
1146 umount ${snapdev}
1149 else
1150 log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
1151 return 1
1154 echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
1155 return 0
1158 setup_unionfs ()
1160 image_directory="${1}"
1161 rootmnt="${2}"
1162 addimage_directory="${3}"
1164 case ${UNIONTYPE} in
1165 aufs|unionfs)
1166 modprobe -q -b ${UNIONTYPE}
1168 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1169 then
1170 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1171 echo "This might be really slow."
1173 UNIONTYPE="unionfs-fuse"
1176 esac
1178 if [ "${UNIONTYPE}" = unionfs-fuse ]
1179 then
1180 modprobe fuse
1183 # run-init can't deal with images in a subdir, but we're going to
1184 # move all of these away before it runs anyway. No, we're not,
1185 # put them in / since move-mounting them into / breaks mono and
1186 # some other apps.
1188 croot="/"
1190 # Let's just mount the read-only file systems first
1191 rofsstring=""
1192 rofslist=""
1194 if [ "${UNIONTYPE}" = "aufs" ]
1195 then
1196 roopt="rr"
1197 noxino_opt="noxino,"
1198 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1199 then
1200 roopt="RO"
1201 else
1202 roopt="ro"
1205 if [ -z "${PLAIN_ROOT}" ]
1206 then
1207 # Read image names from ${MODULE}.module if it exists
1208 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1209 then
1210 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1212 image_string="${image_string} ${image_directory}/${IMAGE}"
1213 done
1214 elif [ -e "${image_directory}/${MODULE}.module" ]
1215 then
1216 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1218 image_string="${image_string} ${image_directory}/${IMAGE}"
1219 done
1220 else
1221 # ${MODULE}.module does not exist, create a list of images
1222 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1224 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1226 if [ -e "${IMAGE}" ]
1227 then
1228 image_string="${image_string} ${IMAGE}"
1230 done
1231 done
1233 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1234 then
1235 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1237 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1239 if [ -e "${IMAGE}" ]
1240 then
1241 image_string="${image_string} ${IMAGE}"
1243 done
1244 done
1247 # Now sort the list
1248 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1251 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1253 mkdir -p "${croot}"
1255 for image in ${image_string}
1257 imagename=$(basename "${image}")
1259 export image devname
1260 maybe_break live-realpremount
1261 log_begin_msg "Running /scripts/live-realpremount"
1262 run_scripts /scripts/live-realpremount
1263 log_end_msg
1265 if [ -d "${image}" ]
1266 then
1267 # it is a plain directory: do nothing
1268 rofsstring="${image}=${roopt}:${rofsstring}"
1269 rofslist="${image} ${rofslist}"
1270 elif [ -f "${image}" ]
1271 then
1272 if losetup --help 2>&1 | grep -q -- "-r\b"
1273 then
1274 backdev=$(get_backing_device "${image}" "-r")
1275 else
1276 backdev=$(get_backing_device "${image}")
1278 fstype=$(get_fstype "${backdev}")
1280 if [ "${fstype}" = "unknown" ]
1281 then
1282 panic "Unknown file system type on ${backdev} (${image})"
1285 if [ -z "${fstype}" ]
1286 then
1287 fstype="${imagename##*.}"
1288 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1291 if [ "${UNIONTYPE}" != "unionmount" ]
1292 then
1293 mpoint="${croot}/${imagename}"
1294 rofsstring="${mpoint}=${roopt}:${rofsstring}" && rofslist="${mpoint} ${rofslist}"
1295 else
1296 mpoint="${rootmnt}"
1298 mkdir -p "${mpoint}"
1299 log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
1300 mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
1301 log_end_msg
1303 done
1304 else
1305 # we have a plain root system
1306 mkdir -p "${croot}/filesystem"
1307 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1308 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}"
1309 # probably broken:
1310 mount -o bind ${croot}/filesystem $mountpoint
1311 log_end_msg
1314 rofsstring=${rofsstring%:}
1316 mkdir -p /cow
1318 # Looking for "${root_persistence}" device or file
1319 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1320 then
1321 if [ -z "${QUICKUSBMODULES}" ]
1322 then
1323 # Load USB modules
1324 num_block=$(ls -l /sys/block | wc -l)
1325 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1327 modprobe -q -b ${module}
1328 done
1330 udevadm trigger
1331 udevadm settle
1333 # For some reason, udevsettle does not block in this scenario,
1334 # so we sleep for a little while.
1336 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1337 for timeout in 5 4 3 2 1
1339 sleep 1
1341 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1342 then
1343 break
1345 done
1348 # search for label and files (this could be hugely optimized)
1349 cowprobe=$(find_cow_device "${root_persistence}")
1350 if [ -b "${cowprobe}" ]
1351 then
1352 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1353 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1354 # snapshots to be sure to really store some e.g key config files,
1355 # but not on the same media
1356 blacklistdev="${cowprobe}"
1357 PERSISTENCE_IS_ON="1"
1358 export PERSISTENCE_IS_ON
1360 # homecow just mount something on /home, this should be generalized some way
1361 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1362 if [ -b "${homecow}" ]
1363 then
1364 PERSISTENCE_IS_ON="1"
1365 export PERSISTENCE_IS_ON
1367 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1368 # This second type should be removed when snapshot will get smarter,
1369 # hence when "/etc/live-snapshot*list" will be supported also by
1370 # ext2|ext3|ext4|jffs2 snapshot types.
1371 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1373 if [ -b "${cowprobe}" ]
1374 then
1375 cowdevice=${cowprobe}
1376 cow_fstype=$(get_fstype "${cowprobe}")
1377 cow_mountopt="rw,noatime"
1379 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1380 then
1381 fsck -y ${cowdevice}
1383 else
1384 log_warning_msg "Unable to find the persistent medium"
1385 cowdevice="tmpfs"
1386 cow_fstype="tmpfs"
1387 cow_mountopt="rw,noatime,mode=755"
1389 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1390 then
1391 # check if there are any nfs options
1392 if echo ${NFS_COW}|grep -q ','
1393 then
1394 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1395 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1396 else
1397 nfs_cow_opts="-o nolock"
1398 nfs_cow=${NFS_COW}
1400 mac="$(get_mac)"
1401 if [ -n "${mac}" ]
1402 then
1403 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1404 cow_fstype="nfs"
1405 else
1406 panic "unable to determine mac address"
1408 else
1409 cowdevice="tmpfs"
1410 cow_fstype="tmpfs"
1411 cow_mountopt="rw,noatime,mode=755"
1414 if [ "${UNIONTYPE}" != "unionmount" ]
1415 then
1417 if [ "${cow_fstype}" = "nfs" ]
1418 then
1419 log_begin_msg \
1420 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1421 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1422 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1423 else
1424 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1425 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1429 rofscount=$(echo ${rofslist} |wc -w)
1431 if [ -n "${EXPOSED_ROOT}" ]
1432 then
1433 if [ ${rofscount} -ne 1 ]
1434 then
1435 panic "only one RO file system supported with exposedroot: ${rofslist}"
1437 exposedrootfs=${rofslist%% }
1439 mount --bind ${exposedrootfs} ${rootmnt} || \
1440 panic "bind mount of ${exposedrootfs} failed"
1442 if [ -z "${SKIP_UNION_MOUNTS}" ]
1443 then
1444 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1445 else
1446 cow_dirs=''
1449 for dir in ${cow_dirs}; do
1450 mkdir -p /cow${dir}
1452 case "${UNIONTYPE}" in
1453 unionfs-fuse)
1454 (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}")
1455 mkdir -p /dev/.initramfs/varrun
1456 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1460 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"
1462 esac
1463 done
1464 else
1465 case "${UNIONTYPE}" in
1466 unionfs-fuse)
1467 (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}")
1468 mkdir -p /dev/.initramfs/varrun
1469 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1472 unionmount)
1473 mount_full -t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice} "${rootmnt}" || panic "${UNIONTYPE} ${cowdevice} on ${rootmnt} failed with option noatime,union,${cow_mountopt}"
1477 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}"
1479 esac
1482 # Correct the permissions of /:
1483 chmod 0755 "${rootmnt}"
1485 # tmpfs file systems
1486 touch /etc/fstab
1487 mkdir -p "${rootmnt}/live"
1488 mount -t tmpfs tmpfs ${rootmnt}/live
1490 # Adding other custom mounts
1491 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1492 then
1493 # directly mount /home
1494 # FIXME: add a custom mounts configurable system
1496 if [ -b "${homecow}" ]
1497 then
1498 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1499 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1500 else
1501 log_warning_msg "Unable to find the persistent home medium"
1504 # Look for other snapshots to copy in
1505 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1506 # This second type should be removed when snapshot grow smarter
1507 try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
1510 if [ -n "${SHOWMOUNTS}" ]
1511 then
1512 for d in ${rofslist}
1514 mkdir -p "${rootmnt}/live/${d##*/}"
1516 case d in
1517 *.dir)
1518 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1522 case "${UNIONTYPE}" in
1523 unionfs-fuse)
1524 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1528 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1530 esac
1532 esac
1533 done
1536 # shows cow fs on /cow for use by live-snapshot
1537 mkdir -p "${rootmnt}/live/cow"
1538 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"
1541 check_dev ()
1543 sysdev="${1}"
1544 devname="${2}"
1545 skip_uuid_check="${3}"
1547 # support for fromiso=.../isofrom=....
1548 if [ -n "$FROMISO" ]
1549 then
1550 ISO_DEVICE=$(dirname $FROMISO)
1551 if ! [ -b $ISO_DEVICE ]
1552 then
1553 # to support unusual device names like /dev/cciss/c0d0p1
1554 # as well we have to identify the block device name, let's
1555 # do that for up to 15 levels
1556 i=15
1557 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1559 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1560 [ -b "$ISO_DEVICE" ] && break
1561 i=$(($i -1))
1562 done
1565 if [ "$ISO_DEVICE" = "/" ]
1566 then
1567 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live-boot.log
1568 else
1569 mkdir /isofrom
1570 mount -t auto "$ISO_DEVICE" /isofrom
1571 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1572 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1573 devname="${loopdevname}"
1577 if [ -z "${devname}" ]
1578 then
1579 devname=$(sys2dev "${sysdev}")
1582 if [ -d "${devname}" ]
1583 then
1584 mount -o bind "${devname}" $mountpoint || continue
1586 if is_live_path $mountpoint
1587 then
1588 echo $mountpoint
1589 return 0
1590 else
1591 umount $mountpoint
1594 [ -e "$devname" ] || continue
1596 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1597 then
1598 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1599 devname="${loopdevname}"
1602 fstype=$(get_fstype "${devname}")
1604 if is_supported_fs ${fstype}
1605 then
1606 devuid=$(blkid -o value -s UUID "$devname")
1607 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1608 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1609 [ -n "$devuid" ] && echo "$devuid" >> $tried
1611 if is_live_path ${mountpoint} && \
1612 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1613 then
1614 echo ${mountpoint}
1615 return 0
1616 else
1617 umount ${mountpoint}
1621 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1622 then
1623 losetup -d "${loopdevname}"
1626 return 1
1629 find_livefs ()
1631 timeout="${1}"
1633 # don't start autodetection before timeout has expired
1634 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1635 then
1636 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1637 then
1638 return 1
1642 # first look at the one specified in the command line
1643 case "${LIVE_MEDIA}" in
1644 removable-usb)
1645 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1647 if [ "$(cat ${sysblock}/removable)" = "1" ]
1648 then
1649 if readlink ${sysblock} | grep -q usb
1650 then
1651 for dev in $(subdevices "${sysblock}")
1653 if check_dev "${dev}"
1654 then
1655 return 0
1657 done
1660 done
1661 return 1
1664 removable)
1665 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1667 if [ "$(cat ${sysblock}/removable)" = "1" ]
1668 then
1669 for dev in $(subdevices "${sysblock}")
1671 if check_dev "${dev}"
1672 then
1673 return 0
1675 done
1677 done
1678 return 1
1682 if [ ! -z "${LIVE_MEDIA}" ]
1683 then
1684 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1685 then
1686 return 0
1690 esac
1692 # or do the scan of block devices
1693 # prefer removable devices over non-removable devices, so scan them first
1694 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
1696 if [ "$(cat ${sysblock}/removable)" = "1" ]
1697 then
1698 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1699 else
1700 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1702 done
1703 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1705 for sysblock in $devices_to_scan
1707 devname=$(sys2dev "${sysblock}")
1708 [ -e "$devname" ] || continue
1709 fstype=$(get_fstype "${devname}")
1711 if /lib/udev/cdrom_id ${devname} > /dev/null
1712 then
1713 if check_dev "null" "${devname}"
1714 then
1715 return 0
1717 elif is_nice_device "${sysblock}"
1718 then
1719 for dev in $(subdevices "${sysblock}")
1721 if check_dev "${dev}"
1722 then
1723 return 0
1725 done
1726 elif [ "${fstype}" = "squashfs" -o \
1727 "${fstype}" = "btrfs" -o \
1728 "${fstype}" = "ext2" -o \
1729 "${fstype}" = "ext3" -o \
1730 "${fstype}" = "ext4" -o \
1731 "${fstype}" = "jffs2" ]
1732 then
1733 # This is an ugly hack situation, the block device has
1734 # an image directly on it. It's hopefully
1735 # live-boot, so take it and run with it.
1736 ln -s "${devname}" "${devname}.${fstype}"
1737 echo "${devname}.${fstype}"
1738 return 0
1740 done
1742 return 1
1745 integrity_check ()
1747 media_mountpoint="${1}"
1749 log_begin_msg "Checking media integrity"
1751 cd ${media_mountpoint}
1752 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1753 RC="${?}"
1755 log_end_msg
1757 if [ "${RC}" -eq 0 ]
1758 then
1759 log_success_msg "Everything ok, will reboot in 10 seconds."
1760 sleep 10
1761 cd /
1762 umount ${media_mountpoint}
1763 sync
1764 echo u > /proc/sysrq-trigger
1765 echo b > /proc/sysrq-trigger
1766 else
1767 panic "Not ok, a media defect is likely, switch to VT8 for details."
1771 mountroot ()
1773 if [ -x /scripts/local-top/cryptroot ]; then
1774 /scripts/local-top/cryptroot
1777 exec 6>&1
1778 exec 7>&2
1779 exec > live-boot.log
1780 exec 2>&1
1781 tail -f live-boot.log >&7 &
1782 tailpid="${!}"
1784 # Ensure 'panic' function is overridden
1785 . /scripts/live-functions
1787 Arguments
1789 maybe_break live-premount
1790 log_begin_msg "Running /scripts/live-premount"
1791 run_scripts /scripts/live-premount
1792 log_end_msg
1794 # Needed here too because some things (*cough* udev *cough*)
1795 # changes the timeout
1797 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1798 then
1799 if do_netmount
1800 then
1801 livefs_root="${mountpoint}"
1802 else
1803 panic "Unable to find a live file system on the network"
1805 else
1806 if [ -n "${ISCSI_PORTAL}" ]
1807 then
1808 do_iscsi && livefs_root="${mountpoint}"
1809 elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1810 then
1811 # Do a local boot from hd
1812 livefs_root=${ROOT}
1813 else
1814 if [ -x /usr/bin/memdiskfind ]
1815 then
1816 MEMDISK=$(/usr/bin/memdiskfind)
1818 if [ $? -eq 0 ]
1819 then
1820 # We found a memdisk, set up phram
1821 modprobe phram phram=memdisk,${MEMDISK}
1823 # Load mtdblock, the memdisk will be /dev/mtdblock0
1824 modprobe mtdblock
1828 # Scan local devices for the image
1830 while [ "$i" -lt 60 ]
1832 livefs_root=$(find_livefs ${i})
1834 if [ -n "${livefs_root}" ]
1835 then
1836 break
1839 sleep 1
1840 i="$(($i + 1))"
1841 done
1845 if [ -z "${livefs_root}" ]
1846 then
1847 panic "Unable to find a medium containing a live file system"
1850 if [ "${INTEGRITY_CHECK}" ]
1851 then
1852 integrity_check "${livefs_root}"
1855 if [ "${TORAM}" ]
1856 then
1857 live_dest="ram"
1858 elif [ "${TODISK}" ]
1859 then
1860 live_dest="${TODISK}"
1863 if [ "${live_dest}" ]
1864 then
1865 log_begin_msg "Copying live media to ${live_dest}"
1866 copy_live_to "${livefs_root}" "${live_dest}"
1867 log_end_msg
1870 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1871 # because the mountpoint is left behind in /proc/mounts, so let's get
1872 # rid of it when running from RAM
1873 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1874 then
1875 losetup -d /dev/loop0
1876 grep -q /isofrom /proc/mounts && umount /isofrom
1879 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1880 then
1881 setup_unionfs "${livefs_root}" "${rootmnt}"
1882 else
1883 mac="$(get_mac)"
1884 mac="$(echo ${mac} | sed 's/-//g')"
1885 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1889 if [ -n "${ROOT_PID}" ] ; then
1890 echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid
1893 log_end_msg
1895 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1896 # live-bottom; udev's init script will take care of things after that
1897 if [ "${UNIONTYPE}" = unionfs-fuse ]
1898 then
1899 mount -n -o bind /dev "${rootmnt}/dev"
1902 # Move to the new root filesystem so that programs there can get at it.
1903 if [ ! -d /root/live/image ]
1904 then
1905 mkdir -p /root/live/image
1906 mount --move /live/image /root/live/image
1909 # aufs2 in kernel versions around 2.6.33 has a regression:
1910 # directories can't be accessed when read for the first the time,
1911 # causing a failure for example when accessing /var/lib/fai
1912 # when booting FAI, this simple workaround solves it
1913 ls /root/* >/dev/null 2>&1
1915 # copy snapshot configuration if exists
1916 if [ -f snapshot.conf ]
1917 then
1918 log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
1919 if [ ! -d "${rootmnt}/etc/live/boot.d" ]
1920 then
1921 mkdir -p "${rootmnt}/etc/live/boot.d"
1923 cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
1924 log_end_msg
1927 maybe_break live-bottom
1928 log_begin_msg "Running /scripts/live-bottom\n"
1930 run_scripts /scripts/live-bottom
1931 log_end_msg
1933 if [ "${UNIONFS}" = unionfs-fuse ]
1934 then
1935 umount "${rootmnt}/dev"
1938 exec 1>&6 6>&-
1939 exec 2>&7 7>&-
1940 kill ${tailpid}
1941 [ -w "${rootmnt}/var/log/" ] && cp live-boot.log "${rootmnt}/var/log/" 2>/dev/null