Adding upstream version 1.199.1.
[debian-live-boot/hramrach.git] / scripts / live
blob76b0be42b91ec3bf3805019c552c297cce91813d
1 #!/bin/sh
3 # set -e
5 export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
7 echo "/root/lib" >> /etc/ld.so.conf
8 echo "/root/usr/lib" >> /etc/ld.so.conf
10 mountpoint="/live/image"
11 LIVE_MEDIA_PATH="live"
13 root_persistence="live-rw"
14 home_persistence="home-rw"
15 root_snapshot_label="live-sn"
16 home_snapshot_label="home-sn"
18 USERNAME="user"
19 USERFULLNAME="Live user"
20 HOSTNAME="host"
22 mkdir -p "${mountpoint}"
23 tried="/tmp/tried"
25 # Create /etc/mtab for debug purpose and future syncs
26 if [ ! -d /etc ]
27 then
28 mkdir /etc/
31 if [ ! -f /etc/mtab ]
32 then
33 touch /etc/mtab
36 [ -f /etc/live.conf ] && . /etc/live.conf
37 export USERNAME USERFULLNAME HOSTNAME
39 . /scripts/live-helpers
41 if [ ! -f /live.vars ]
42 then
43 touch /live.vars
46 Arguments ()
48 PRESEEDS=""
50 for ARGUMENT in $(cat /proc/cmdline)
52 case "${ARGUMENT}" in
53 skipconfig)
54 NOACCESSIBILITY="Yes"
55 NOAPPARMOR="Yes"
56 NOAPTCDROM="Yes"
57 NOAUTOLOGIN="Yes"
58 NOCONSOLEKEYBOARD="Yes"
59 NOFASTBOOT="Yes"
60 NOFSTAB="Yes"
61 NOGNOMEPANEL="Yes"
62 NOHOSTS="Yes"
63 NOJOCKEY="Yes"
64 NOKPERSONALIZER="Yes"
65 NOLANGUAGESELECTOR="Yes"
66 NOLOCALES="Yes"
67 NONETWORKING="Yes"
68 NOPOLKITCONF="Yes"
69 NOPOWERMANAGEMENT="Yes"
70 NOPROGRAMCRASHES="Yes"
71 NOSUDO="Yes"
72 NOTIMEZONE="Yes"
73 NOUPDATENOTIFIER="Yes"
74 NOUSER="Yes"
75 NOXAUTOCONFIG="Yes"
76 NOXAUTOLOGIN="Yes"
77 NOXSCREENSAVER="Yes"
79 export NOACCESSIBILITY NOAPPARMOR NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOGNOMEPANEL NOHOSTS NOJOCKEY NOKPERSONALIZER NOLANGUAGESELECTOR NOLOCALES NONETWORKING NOPOLKITCONF NOPOWERMANAGEMENT NOPROGRAMCRASHES NOSUDO NOTIMEZONE NOUPDATENOTIFIER NOUSER NOXAUTOCONFIG NOXAUTOLOGIN NOXSCREENSAVER
82 access=*)
83 ACCESS="${ARGUMENT#access=}"
84 export ACCESS
87 console=*)
88 DEFCONSOLE="${ARGUMENT#*=}"
89 export DEFCONSOLE
92 debug)
93 DEBUG="Yes"
94 export DEBUG
96 set -x
99 ethdevice=*)
100 DEVICE="${ARGUMENT#ethdevice=}"
101 export DEVICE
104 ethdevice=*)
105 ETHDEVICE="${ARGUMENT#ethdevice=}"
106 export ETHDEVICE
109 ethdevice-timeout=*)
110 ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
111 export ETHDEV_TIMEOUT
114 fetch=*)
115 FETCH="${ARGUMENT#fetch=}"
116 export FETCH
119 forcepersistentfsck)
120 FORCEPERSISTENTFSCK="Yes"
121 export FORCEPERSISTENTFSCK
124 hook=*)
125 HOOK="${ARGUMENT#hook=}"
126 export HOOK
129 ftpfs=*)
130 FTPFS="${ARGUMENT#ftpfs=}"
131 export FTPFS
134 httpfs=*)
135 HTTPFS="${ARGUMENT#httpfs=}"
136 export HTTPFS
139 hostname=*)
140 HOSTNAME="${ARGUMENT#hostname=}"
141 LIVECONF="changed"
142 export HOSTNAME LIVECONF
145 isofrom=*|fromiso=*)
146 FROMISO="${ARGUMENT#*=}"
147 export FROMISO
150 username=*)
151 USERNAME="${ARGUMENT#username=}"
152 LIVECONF="changed"
153 export USERNAME LIVECONF
156 userfullname=*)
157 USERFULLNAME="${ARGUMENT#userfullname=}"
158 LIVECONF="changed"
159 export USERFULLNAME LIVECONF
162 ignore_uuid)
163 IGNORE_UUID="Yes"
164 export IGNORE_UUID
167 integrity-check)
168 INTEGRITY_CHECK="Yes"
169 export INTEGRITY_CHECK
172 ip=*)
173 STATICIP="${ARGUMENT#ip=}"
175 if [ -z "${STATICIP}" ]
176 then
177 STATICIP="frommedia"
180 export STATICIP
183 keyb=*|kbd-chooser/method=*)
184 KBD="${ARGUMENT#*=}"
185 export KBD
188 klayout=*|console-setup/layoutcode=*)
189 KLAYOUT="${ARGUMENT#*=}"
190 export KLAYOUT
193 kvariant=*|console-setup/variantcode=*)
194 KVARIANT="${ARGUMENT#*=}"
195 export KVARIANT
198 kmodel=*|console-setup/modelcode=*)
199 KMODEL="${ARGUMENT#*=}"
200 export KMODEL
203 koptions=*)
204 KOPTIONS="${ARGUMENT#koptions=}"
205 export KOPTIONS
208 live-getty)
209 LIVE_GETTY="1"
210 export LIVE_GETTY
213 live-media=*|bootfrom=*)
214 LIVE_MEDIA="${ARGUMENT#*=}"
215 export LIVE_MEDIA
218 live-media-encryption=*|encryption=*)
219 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
220 export LIVE_MEDIA_ENCRYPTION
223 live-media-offset=*)
224 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
225 export LIVE_MEDIA_OFFSET
228 live-media-path=*)
229 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
230 export LIVE_MEDIA_PATH
233 live-media-timeout=*)
234 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
235 export LIVE_MEDIA_TIMEOUT
238 language=*|debian-installer/language=*)
239 language=${x#debian-installer/language=}
240 locale="$(lang2locale "$language")"
241 set_locale="true"
244 locale=*|debian-installer/locale=*)
245 LOCALE="${ARGUMENT#*=}"
246 export LOCALE
249 module=*)
250 MODULE="${ARGUMENT#module=}"
251 export MODULE
254 netboot=*)
255 NETBOOT="${ARGUMENT#netboot=}"
256 export NETBOOT
259 nfsopts=*)
260 NFSOPTS="${ARGUMENT#nfsopts=}"
261 export NFSOPTS
264 nfscow=*)
265 NFS_COW="${ARGUMENT#nfscow=}"
266 export NFS_COW
269 noaccessibility)
270 NOACCESSIBILITY="Yes"
271 export NOACCESSIBILITY
274 noapparmor)
275 NOAPPARMOR="Yes"
276 export NOAPPARMOR
279 noaptcdrom)
280 NOAPTCDROM="Yes"
281 export NOAPTCDROM
284 noautologin)
285 NOAUTOLOGIN="Yes"
286 export NOAUTOLOGIN
289 noxautologin)
290 NOXAUTOLOGIN="Yes"
291 export NOXAUTOLOGIN
294 noconsolekeyboard)
295 NOCONSOLEKEYBOARD="Yes"
296 export NOCONSOLEKEYBOARD
299 nofastboot)
300 NOFASTBOOT="Yes"
301 export NOFASTBOOT
304 nofstab)
305 NOFSTAB="Yes"
306 export NOFSTAB
309 nognomepanel)
310 NOGNOMEPANEL="Yes"
311 export NOGNOMEPANEL
314 nohosts)
315 NOHOSTS="Yes"
316 export NOHOSTS
319 nokpersonalizer)
320 NOKPERSONALIZER="Yes"
321 export NOKPERSONALIZER
324 nolanguageselector)
325 NOLANGUAGESELECTOR="Yes"
326 export NOLANGUAGESELECTOR
329 nolocales)
330 NOLOCALES="Yes"
331 export NOLOCALES
334 nonetworking)
335 NONETWORKING="Yes"
336 export NONETWORKING
339 nopowermanagement)
340 NOPOWERMANAGEMENT="Yes"
341 export NOPOWERMANAGEMENT
344 noprogramcrashes)
345 NOPROGRAMCRASHES="Yes"
346 export NOPROGRAMCRASHES
349 nojockey)
350 NOJOCKEY="Yes"
351 export NOJOCKEY
354 nosudo)
355 NOSUDO="Yes"
356 export NOSUDO
359 swapon)
360 SWAPON="Yes"
361 export SWAPON
364 noupdatenotifier)
365 NOUPDATENOTIFIER="Yes"
366 export NOUPDATENOTIFIER
369 nouser)
370 NOUSER="Yes"
371 export NOUSER
374 noxautoconfig)
375 NOXAUTOCONFIG="Yes"
376 export NOXAUTOCONFIG
379 noxscreensaver)
380 NOXSCREENSAVER="Yes"
381 export NOXSCREENSAVER
384 persistent)
385 PERSISTENT="Yes"
386 export PERSISTENT
389 persistent=*)
390 PERSISTENT="${ARGUMENT#persistent=}"
391 if [ -z "${PERSISTENT}" ]
392 then
393 PERSISTENT="Yes"
395 export PERSISTENT
398 persistent-path=*)
399 PERSISTENT_PATH="${ARGUMENT#persistent-path=}"
400 export PERSISTENT_PATH
403 persistent-subtext=*)
404 root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
405 home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
406 root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}"
407 home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}"
410 nopersistent)
411 NOPERSISTENT="Yes"
412 export NOPERSISTENT
415 quickusbmodules)
416 QUICKUSBMODULES="Yes"
417 export QUICKUSBMODULES
420 preseed/file=*|file=*)
421 LOCATION="${ARGUMENT#*=}"
422 export LOCATION
425 nopreseed)
426 NOPRESEED="Yes"
427 export NOPRESEED
430 url=*)
431 location="${ARGUMENT#url=}"
433 mount -o bind /sys /root/sys
434 mount -o bind /proc /root/proc
435 mount -o bind /dev /root/dev
437 mkdir -p /root/var/run/network
438 [ "${NETBOOT}" ] || chroot /root dhclient eth0
439 chroot /root wget -P /tmp "${location}"
440 [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down
442 umount /root/sys
443 umount /root/proc
444 umount /root/dev
446 LOCATION="/tmp/$(basename "${location}")"
449 */*=*)
450 question="${ARGUMENT%%=*}"
451 value="${ARGUMENT#*=}"
452 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
453 export PRESEEDS
456 showmounts)
457 SHOWMOUNTS="Yes"
458 export SHOWMOUNTS
461 silent)
462 SILENT="Yes"
463 export SILENT
466 textonly)
467 TEXTONLY="Yes"
468 export TEXTONLY
471 timezone=*)
472 TIMEZONE="${ARGUMENT#timezone=}"
473 export TIMEZONE
476 notimezone)
477 NOTIMEZONE="Yes"
478 export NOTIMEZONE
481 todisk=*)
482 TODISK="${ARGUMENT#todisk=}"
483 export TODISK
486 toram)
487 TORAM="Yes"
488 export TORAM
491 toram=*)
492 TORAM="Yes"
493 MODULETORAM="${ARGUMENT#toram=}"
494 export TORAM MODULETORAM
497 exposedroot)
498 EXPOSED_ROOT="Yes"
499 export EXPOSED_ROOT
502 plainroot)
503 PLAIN_ROOT="Yes"
504 export PLAIN_ROOT
507 skipunion)
508 SKIP_UNION_MOUNTS="Yes"
509 export SKIP_UNION_MOUNTS
512 root=*)
513 ROOT="${ARGUMENT#root=}"
514 export ROOT
517 union=*)
518 UNIONTYPE="${ARGUMENT#union=}"
519 export UNIONTYPE
522 utc=*)
523 UTC="${ARGUMENT#utc=}"
524 export UTC
527 xdebconf)
528 XDEBCONF="Yes"
529 export XDEBCONF
532 xdriver=*)
533 XDRIVER="${ARGUMENT#xdriver=}"
534 export XDRIVER
537 xvideomode=*)
538 XVIDEOMODE="${ARGUMENT#xvideomode=}"
539 export XVIDEOMODE
541 esac
542 done
544 # sort of compatibility with netboot.h from linux docs
545 if [ -z "${NETBOOT}" ]
546 then
547 if [ "${ROOT}" = "/dev/nfs" ]
548 then
549 NETBOOT="nfs"
550 export NETBOOT
551 elif [ "${ROOT}" = "/dev/cifs" ]
552 then
553 NETBOOT="cifs"
554 export NETBOOT
558 if [ -z "${MODULE}" ]
559 then
560 MODULE="filesystem"
561 export MODULE
564 if [ -z "${UNIONTYPE}" ]
565 then
566 UNIONTYPE="aufs"
567 export UNIONTYPE
571 is_live_path ()
573 DIRECTORY="${1}"
575 if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
576 then
577 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2
579 if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
580 then
581 return 0
583 done
586 return 1
589 matches_uuid ()
591 if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
592 then
593 return 0
596 path="${1}"
597 uuid="$(cat /conf/uuid.conf)"
599 for try_uuid_file in "${path}/.disk/live-uuid"*
601 [ -e "${try_uuid_file}" ] || continue
603 try_uuid="$(cat "${try_uuid_file}")"
605 if [ "${uuid}" = "${try_uuid}" ]
606 then
607 return 0
609 done
611 return 1
614 get_backing_device ()
616 case "${1}" in
617 *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2)
618 echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
621 *.dir)
622 echo "directory"
626 panic "Unrecognized live filesystem: ${1}"
628 esac
631 match_files_in_dir ()
633 # Does any files match pattern ${1} ?
634 local pattern="${1}"
636 if [ "$(echo ${pattern})" != "${pattern}" ]
637 then
638 return 0
641 return 1
644 mount_images_in_directory ()
646 directory="${1}"
647 rootmnt="${2}"
648 mac="${3}"
651 if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
652 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
653 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
654 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" ||
655 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
656 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
657 then
658 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
659 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
660 else
661 panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}."
665 is_nice_device ()
667 sysfs_path="${1#/sys}"
669 if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
670 then
671 return 0
672 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
673 then
674 return 0
675 elif echo ${sysfs_path} | grep -q "^/block/dm-"
676 then
677 return 0
680 return 1
683 copy_live_to ()
685 copyfrom="${1}"
686 copytodev="${2}"
687 copyto="${copyfrom}_swap"
689 if [ -z "${MODULETORAM}" ]
690 then
691 size=$(fs_size "" ${copyfrom}/${LIVE_MEDIA_PATH} "used")
692 else
693 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
695 if [ -f "${MODULETORAMFILE}" ]
696 then
697 size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
698 else
699 log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
700 return 1
704 if [ "${copytodev}" = "ram" ]
705 then
706 # copying to ram:
707 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo ) )
708 mount_options="-o size=${size}k"
709 free_string="memory"
710 fstype="tmpfs"
711 dev="/dev/shm"
712 else
713 # it should be a writable block device
714 if [ -b "${copytodev}" ]
715 then
716 dev="${copytodev}"
717 free_string="space"
718 fstype=$(get_fstype "${dev}")
719 freespace=$(fs_size "${dev}")
720 else
721 log_warning_msg "${copytodev} is not a block device."
722 return 1
726 if [ "${freespace}" -lt "${size}" ]
727 then
728 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
729 return 1
732 # begin copying (or uncompressing)
733 mkdir "${copyto}"
734 log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
735 mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
737 if [ "${extension}" = "tgz" ]
738 then
739 cd "${copyto}"
740 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
741 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
742 mount -r -o move "${copyto}" "${rootmnt}"
743 cd "${OLDPWD}"
744 else
745 if [ -n "${MODULETORAMFILE}" ]
746 then
747 if [ -x /bin/rsync ]
748 then
749 echo " * Copying $MODULETORAMFILE to RAM" 1>/dev/console
750 rsync -a --progress ${MODULETORAMFILE} ${copyto} 1>/dev/console # copy only the filesystem module
751 else
752 cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
754 else
755 if [ -x /bin/rsync ]
756 then
757 echo " * Copying whole medium to RAM" 1>/dev/console
758 rsync -a --progress ${copyfrom}/* ${copyto} 1>/dev/console # "cp -a" from busybox also copies hidden files
759 else
760 mkdir -p ${copyto}/${LIVE_MEDIA_PATH}
761 cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} # "cp -a" from busybox also copies hidden files
765 umount ${copyfrom}
766 mount -r -o move ${copyto} ${copyfrom}
769 rmdir ${copyto}
770 return 0
773 do_netmount ()
775 rc=1
777 modprobe -q af_packet # For DHCP
779 udevadm trigger
780 udevadm settle
782 # if ethdevice was not specified on the kernel command line
783 # make sure we try to get a working network configuration
784 # for *every* present network device (except for loopback of course)
785 if [ -z "$ETHDEVICE" ] ; then
786 echo "If you want to boot from a specific device use bootoption ethdevice=..."
787 for device in /sys/class/net/*; do
788 dev=${device##*/} ;
789 if [ "$dev" != "lo" ] ; then
790 ETHDEVICE="$ETHDEVICE $dev"
792 done
795 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
796 for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
797 devlist="$devlist $device"
798 done
800 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
801 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
803 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
804 # an endless loop; iff execution fails give it two further tries, that's
805 # why we use '$devlist $devlist $devlist' for the other for loop
806 for dev in $devlist $devlist $devlist ; do
807 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
808 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
809 jobid=$!
810 sleep "$ETHDEV_TIMEOUT" ; sleep 1
811 if [ -r /proc/"$jobid"/status ] ; then
812 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
813 kill -9 $jobid
816 # if configuration of device worked we should have an assigned
817 # IP address, iff so let's use the according as $DEVICE for later usage
818 # simple and primitive approach which seems to work fine
819 if ifconfig $dev | grep -q 'inet.*addr:' ; then
820 export DEVICE="$dev"
821 break
823 done
825 # source relevant ipconfig output
826 OLDHOSTNAME=${HOSTNAME}
827 . /tmp/net-${DEVICE}.conf
828 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
829 export HOSTNAME
831 # Check if we have a network device at all
832 if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
833 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
834 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
835 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
836 ! ls /sys/class/net/ra0 > /dev/null 2>&1
837 then
838 panic "No supported network device found, maybe a non-mainline driver is required."
841 if [ "${NFSROOT}" = "auto" ]
842 then
843 NFSROOT=${ROOTSERVER}:${ROOTPATH}
846 if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
847 then
848 rc=0
849 return ${rc}
852 if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
853 then
854 NFSROOT=${ROOTSERVER}:${NFSROOT}
857 log_begin_msg "Trying netboot from ${NFSROOT}"
859 if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
860 then
861 rc=0
862 elif do_nfsmount
863 then
864 NETBOOT="nfs"
865 export NETBOOT
866 rc=0
869 log_end_msg
870 return ${rc}
873 do_httpmount ()
875 rc=1
876 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
877 mount -t ramfs ram "${mountpoint}"
878 mkdir -p "${dest}"
880 for webfile in HTTPFS FTPFS FETCH
882 url="$(eval echo \"\$\{${webfile}\}\")"
883 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
885 if [ -n "$url" ]
886 then
887 case "${extension}" in
888 squashfs|tgz|tar)
889 if [ "${webfile}" = "FETCH" ]
890 then
891 case "$url" in
892 tftp*)
893 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
894 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
895 lfile="$(basename $url)"
896 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
897 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
901 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
902 wget "${url}" -O "${dest}/$(basename ${url})"
904 esac
905 else
906 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
907 if [ "${webfile}" = "FTPFS" ]
908 then
909 FUSE_MOUNT="curlftpfs"
910 url="$(dirname ${url})"
911 else
912 FUSE_MOUNT="httpfs"
914 modprobe fuse
915 $FUSE_MOUNT "${url}" "${dest}"
917 [ ${?} -eq 0 ] && rc=0
918 [ "${extension}" = "tgz" ] && live_dest="ram"
919 break
923 log_begin_msg "Unrecognized archive extension for ${url}"
925 esac
927 done
929 if [ ${rc} != 0 ]
930 then
931 umount "${mountpoint}"
934 return ${rc}
937 do_nfsmount ()
939 rc=1
941 modprobe -q nfs
943 if [ -z "${NFSOPTS}" ]
944 then
945 NFSOPTS=""
948 log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
950 # FIXME: This while loop is an ugly HACK round an nfs bug
952 while [ "$i" -lt 60 ]
954 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
955 sleep 1
956 i="$(($i + 1))"
957 done
959 return ${rc}
962 do_cifsmount ()
964 rc=1
966 if [ -x "/sbin/mount.cifs" ]
967 then
968 if [ -z "${NFSOPTS}" ]
969 then
970 CIFSOPTS="-ouser=root,password="
971 else
972 CIFSOPTS="${NFSOPTS}"
975 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
976 modprobe -q cifs
978 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
979 then
980 rc=0
984 return ${rc}
987 do_snap_copy ()
989 fromdev="${1}"
990 todir="${2}"
991 snap_type="${3}"
992 size=$(fs_size "${fromdev}" "" "used")
994 if [ -b "${fromdev}" ]
995 then
996 # look for free mem
997 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
998 then
999 todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
1000 freespace=$(df -k | awk '/'${todev}'/{print $4}')
1001 else
1002 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /proc/meminfo))
1005 tomount="/mnt/tmpsnap"
1007 if [ ! -d "${tomount}" ]
1008 then
1009 mkdir -p "${tomount}"
1012 fstype=$(get_fstype "${fromdev}")
1014 if [ -n "${fstype}" ]
1015 then
1016 # Copying stuff...
1017 mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
1018 cp -a "${tomount}"/* ${todir}
1019 umount "${tomount}"
1020 else
1021 log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
1024 rmdir "${tomount}"
1026 if echo ${fromdev} | grep -qs loop
1027 then
1028 losetup -d "${fromdev}"
1031 return 0
1032 else
1033 return 1
1035 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
1039 find_snap ()
1041 # Look for ${snap_label}.* in block devices
1042 snap_label="${1}"
1044 if [ "${PERSISTENT}" != "nofiles" ]
1045 then
1046 # search for image files
1047 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")
1050 if [ -z "${snapdata}" ]
1051 then
1052 snapdata=$(find_cow_device "${snap_label}")
1054 echo "${snapdata}"
1057 try_snap ()
1059 # copy the contents of previously found snapshot to ${snap_mount}
1060 # and remember the device and filename for resync on exit in live-initramfs.init
1062 snapdata="${1}"
1063 snap_mount="${2}"
1064 snap_type="${3}"
1066 if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
1067 then
1068 log_success_msg "found snapshot: ${snapdata}"
1069 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
1070 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
1071 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
1073 RES=""
1074 if ! try_mount "${snapdev}" "${snapback}" "ro"
1075 then
1076 break
1079 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
1080 then
1081 # squashfs, jffs2 or ext2/ext3/ext4 snapshot
1082 dev=$(get_backing_device "${snapback}/${snapfile}")
1084 do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1085 RES=$?
1086 else
1087 # cpio.gz snapshot
1089 # Unfortunately klibc's cpio is incompatible with the
1090 # rest of the world; everything else requires -u -d,
1091 # while klibc doesn't implement them. Try to detect
1092 # whether it's in use.
1093 cpiopath="$(which cpio)" || true
1094 if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"
1095 then
1096 cpioargs=
1097 else
1098 cpioargs='--unconditional --make-directories'
1101 if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
1102 then
1103 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
1107 umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\""
1109 if [ "${RES}" != "0" ]
1110 then
1111 log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
1114 elif [ -b "${snapdata}" ]
1115 then
1116 # Try to find if it could be a snapshot partition
1117 dev="${snapdata}"
1118 log_success_msg "found snapshot ${snap_type} device on ${dev}"
1119 if echo "${dev}" | grep -qs loop
1120 then
1121 # strange things happens, user confused?
1122 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
1123 snapfile=$(basename ${snaploop})
1124 snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
1125 else
1126 snapdev="${dev}"
1129 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
1130 then
1131 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1132 return 1
1133 else
1134 if [ -n "${snapfile}" ]
1135 then
1136 # it was a loop device, user confused
1137 umount ${snapdev}
1140 else
1141 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
1142 return 1
1145 echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
1146 return 0
1149 setup_unionfs ()
1151 image_directory="${1}"
1152 rootmnt="${2}"
1153 addimage_directory="${3}"
1155 case ${UNIONTYPE} in
1156 aufs|unionfs)
1157 modprobe -q -b ${UNIONTYPE}
1159 if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ]
1160 then
1161 echo "${UNIONTYPE} not available, falling back to unionfs-fuse."
1162 echo "This might be really slow."
1164 UNIONTYPE="unionfs-fuse"
1167 esac
1169 if [ "${UNIONTYPE}" = unionfs-fuse ]
1170 then
1171 modprobe fuse
1174 # run-init can't deal with images in a subdir, but we're going to
1175 # move all of these away before it runs anyway. No, we're not,
1176 # put them in / since move-mounting them into / breaks mono and
1177 # some other apps.
1179 croot="/"
1181 # Let's just mount the read-only file systems first
1182 rofsstring=""
1183 rofslist=""
1185 if [ "${UNIONTYPE}" = "aufs" ]
1186 then
1187 roopt="rr"
1188 noxino_opt="noxino,"
1189 elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
1190 then
1191 roopt="RO"
1192 else
1193 roopt="ro"
1196 if [ -z "${PLAIN_ROOT}" ]
1197 then
1198 # Read image names from ${MODULE}.module if it exists
1199 if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1200 then
1201 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1203 image_string="${image_string} ${image_directory}/${IMAGE}"
1204 done
1205 elif [ -e "${image_directory}/${MODULE}.module" ]
1206 then
1207 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1209 image_string="${image_string} ${image_directory}/${IMAGE}"
1210 done
1211 else
1212 # ${MODULE}.module does not exist, create a list of images
1213 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1215 for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1217 if [ -e "${IMAGE}" ]
1218 then
1219 image_string="${image_string} ${IMAGE}"
1221 done
1222 done
1224 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1225 then
1226 for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
1228 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1230 if [ -e "${IMAGE}" ]
1231 then
1232 image_string="${image_string} ${IMAGE}"
1234 done
1235 done
1238 # Now sort the list
1239 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1242 [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1244 mkdir -p "${croot}"
1246 for image in ${image_string}
1248 imagename=$(basename "${image}")
1250 export image devname
1251 maybe_break live-realpremount
1252 log_begin_msg "Running /scripts/live-realpremount"
1253 run_scripts /scripts/live-realpremount
1254 log_end_msg
1256 if [ -d "${image}" ]
1257 then
1258 # it is a plain directory: do nothing
1259 rofsstring="${image}=${roopt}:${rofsstring}"
1260 rofslist="${image} ${rofslist}"
1261 elif [ -f "${image}" ]
1262 then
1263 if losetup --help 2>&1 | grep -q -- "-r\b"
1264 then
1265 backdev=$(get_backing_device "${image}" "-r")
1266 else
1267 backdev=$(get_backing_device "${image}")
1269 fstype=$(get_fstype "${backdev}")
1271 if [ "${fstype}" = "unknown" ]
1272 then
1273 panic "Unknown file system type on ${backdev} (${image})"
1276 if [ -z "${fstype}" ]
1277 then
1278 fstype="${imagename##*.}"
1279 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1282 mkdir -p "${croot}/${imagename}"
1283 log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1284 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}"
1285 log_end_msg
1287 done
1288 else
1289 # we have a plain root system
1290 mkdir -p "${croot}/filesystem"
1291 log_begin_msg "Mounting \"${image_directory}\" on \"${croot}/filesystem\""
1292 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}"
1293 # probably broken:
1294 mount -o bind ${croot}/filesystem $mountpoint
1295 log_end_msg
1298 rofsstring=${rofsstring%:}
1300 mkdir -p /cow
1302 # Looking for "${root_persistence}" device or file
1303 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1304 then
1305 if [ -z "${QUICKUSBMODULES}" ]
1306 then
1307 # Load USB modules
1308 num_block=$(ls -l /sys/block | wc -l)
1309 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1311 modprobe -q -b ${module}
1312 done
1314 udevadm trigger
1315 udevadm settle
1317 # For some reason, udevsettle does not block in this scenario,
1318 # so we sleep for a little while.
1320 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1321 for timeout in 5 4 3 2 1
1323 sleep 1
1325 if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1326 then
1327 break
1329 done
1332 # search for label and files (this could be hugely optimized)
1333 cowprobe=$(find_cow_device "${root_persistence}")
1334 if [ -b "${cowprobe}" ]
1335 then
1336 # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1337 # makes sense to have both persistence for /cow and /home mounted, maybe also with
1338 # snapshots to be sure to really store some e.g key config files,
1339 # but not on the same media
1340 blacklistdev="${cowprobe}"
1341 PERSISTENCE_IS_ON="1"
1342 export PERSISTENCE_IS_ON
1344 # homecow just mount something on /home, this should be generalized some way
1345 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1346 if [ -b "${homecow}" ]
1347 then
1348 PERSISTENCE_IS_ON="1"
1349 export PERSISTENCE_IS_ON
1351 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1352 # This second type should be removed when snapshot will get smarter,
1353 # hence when "/etc/live-snapshot*list" will be supported also by
1354 # ext2|ext3|ext4|jffs2 snapshot types.
1355 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1357 if [ -b "${cowprobe}" ]
1358 then
1359 cowdevice=${cowprobe}
1360 cow_fstype=$(get_fstype "${cowprobe}")
1361 cow_mountopt="rw,noatime"
1363 if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
1364 then
1365 fsck -y ${cowdevice}
1367 else
1368 log_warning_msg "Unable to find the persistent medium"
1369 cowdevice="tmpfs"
1370 cow_fstype="tmpfs"
1371 cow_mountopt="rw,noatime,mode=755"
1373 elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1374 then
1375 # check if there are any nfs options
1376 if echo ${NFS_COW}|grep -q ','
1377 then
1378 nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1379 nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1380 else
1381 nfs_cow_opts="-o nolock"
1382 nfs_cow=${NFS_COW}
1384 mac="$(get_mac)"
1385 if [ -n "${mac}" ]
1386 then
1387 cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1388 cow_fstype="nfs"
1389 else
1390 panic "unable to determine mac address"
1392 else
1393 cowdevice="tmpfs"
1394 cow_fstype="tmpfs"
1395 cow_mountopt="rw,noatime,mode=755"
1398 if [ "${cow_fstype}" = "nfs" ]
1399 then
1400 log_begin_msg \
1401 "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1402 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1403 panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1404 else
1405 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1406 panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1409 rofscount=$(echo ${rofslist} |wc -w)
1411 if [ -n "${EXPOSED_ROOT}" ]
1412 then
1413 if [ ${rofscount} -ne 1 ]
1414 then
1415 panic "only one RO file system supported with exposedroot: ${rofslist}"
1417 exposedrootfs=${rofslist%% }
1419 mount --bind ${exposedrootfs} ${rootmnt} || \
1420 panic "bind mount of ${exposedrootfs} failed"
1422 if [ -z "${SKIP_UNION_MOUNTS}" ]
1423 then
1424 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool /home /var/lib/live'
1425 else
1426 cow_dirs=''
1429 for dir in ${cow_dirs}; do
1430 mkdir -p /cow${dir}
1432 case "${UNIONTYPE}" in
1433 unionfs-fuse)
1434 (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}")
1435 mkdir -p /dev/.initramfs/varrun
1436 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1440 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"
1442 esac
1443 done
1444 else
1445 case "${UNIONTYPE}" in
1446 unionfs-fuse)
1447 (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}")
1448 mkdir -p /dev/.initramfs/varrun
1449 pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
1453 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}"
1455 esac
1458 # Correct the permissions of /:
1459 chmod 0755 "${rootmnt}"
1461 # tmpfs file systems
1462 touch /etc/fstab
1463 mkdir -p "${rootmnt}/live"
1464 mount -t tmpfs tmpfs ${rootmnt}/live
1466 # Adding other custom mounts
1467 if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1468 then
1469 # directly mount /home
1470 # FIXME: add a custom mounts configurable system
1472 if [ -b "${homecow}" ]
1473 then
1474 mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1475 export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1476 else
1477 log_warning_msg "Unable to find the persistent home medium"
1480 # Look for other snapshots to copy in
1481 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1482 # This second type should be removed when snapshot grow smarter
1483 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1486 if [ -n "${SHOWMOUNTS}" ]
1487 then
1488 for d in ${rofslist}
1490 mkdir -p "${rootmnt}/live/${d##*/}"
1492 case d in
1493 *.dir)
1494 # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1498 case "${UNIONTYPE}" in
1499 unionfs-fuse)
1500 mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1504 mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1506 esac
1508 esac
1509 done
1512 # shows cow fs on /cow for use by live-snapshot
1513 mkdir -p "${rootmnt}/live/cow"
1514 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"
1517 check_dev ()
1519 sysdev="${1}"
1520 devname="${2}"
1521 skip_uuid_check="${3}"
1523 # support for fromiso=.../isofrom=....
1524 if [ -n "$FROMISO" ]
1525 then
1526 ISO_DEVICE=$(dirname $FROMISO)
1527 if ! [ -b $ISO_DEVICE ]
1528 then
1529 # to support unusual device names like /dev/cciss/c0d0p1
1530 # as well we have to identify the block device name, let's
1531 # do that for up to 15 levels
1532 i=15
1533 while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ]
1535 ISO_DEVICE=$(dirname ${ISO_DEVICE})
1536 [ -b "$ISO_DEVICE" ] && break
1537 i=$(($i -1))
1538 done
1541 if [ "$ISO_DEVICE" = "/" ]
1542 then
1543 echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
1544 else
1545 mkdir /isofrom
1546 mount "$ISO_DEVICE" /isofrom
1547 ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
1548 loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
1549 devname="${loopdevname}"
1553 if [ -z "${devname}" ]
1554 then
1555 devname=$(sys2dev "${sysdev}")
1558 if [ -d "${devname}" ]
1559 then
1560 mount -o bind "${devname}" $mountpoint || continue
1562 if is_live_path $mountpoint
1563 then
1564 echo $mountpoint
1565 return 0
1566 else
1567 umount $mountpoint
1570 [ -e "$devname" ] || continue
1572 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1573 then
1574 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1575 devname="${loopdevname}"
1578 fstype=$(get_fstype "${devname}")
1580 if is_supported_fs ${fstype}
1581 then
1582 devuid=$(blkid -o value -s UUID "$devname")
1583 [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
1584 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1585 [ -n "$devuid" ] && echo "$devuid" >> $tried
1587 if is_live_path ${mountpoint} && \
1588 ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1589 then
1590 echo ${mountpoint}
1591 return 0
1592 else
1593 umount ${mountpoint}
1597 if [ -n "${LIVE_MEDIA_OFFSET}" ]
1598 then
1599 losetup -d "${loopdevname}"
1602 return 1
1605 find_livefs ()
1607 timeout="${1}"
1609 # don't start autodetection before timeout has expired
1610 if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1611 then
1612 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1613 then
1614 return 1
1618 # first look at the one specified in the command line
1619 case "${LIVE_MEDIA}" in
1620 removable-usb)
1621 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1623 if [ "$(cat ${sysblock}/removable)" = "1" ]
1624 then
1625 if readlink ${sysblock} | grep -q usb ||
1626 readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
1627 then
1628 for dev in $(subdevices "${sysblock}")
1630 if check_dev "${dev}"
1631 then
1632 return 0
1634 done
1637 done
1638 return 1
1641 removable)
1642 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1644 if [ "$(cat ${sysblock}/removable)" = "1" ]
1645 then
1646 for dev in $(subdevices "${sysblock}")
1648 if check_dev "${dev}"
1649 then
1650 return 0
1652 done
1654 done
1655 return 1
1659 if [ ! -z "${LIVE_MEDIA}" ]
1660 then
1661 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1662 then
1663 return 0
1667 esac
1669 # or do the scan of block devices
1670 # prefer removable devices over non-removable devices, so scan them first
1671 for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
1673 if [ "$(cat ${sysblock}/removable)" = "1" ]
1674 then
1675 removable_devices_to_scan="$removable_devices_to_scan $sysblock"
1676 else
1677 nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
1679 done
1680 devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
1682 for sysblock in $devices_to_scan
1684 devname=$(sys2dev "${sysblock}")
1685 [ -e "$devname" ] || continue
1686 fstype=$(get_fstype "${devname}")
1688 if /lib/udev/cdrom_id ${devname} > /dev/null
1689 then
1690 if check_dev "null" "${devname}"
1691 then
1692 return 0
1694 elif is_nice_device "${sysblock}"
1695 then
1696 for dev in $(subdevices "${sysblock}")
1698 if check_dev "${dev}"
1699 then
1700 return 0
1702 done
1703 elif [ "${fstype}" = "squashfs" -o \
1704 "${fstype}" = "ext2" -o \
1705 "${fstype}" = "ext3" -o \
1706 "${fstype}" = "ext4" -o \
1707 "${fstype}" = "jffs2" ]
1708 then
1709 # This is an ugly hack situation, the block device has
1710 # an image directly on it. It's hopefully
1711 # live-initramfs, so take it and run with it.
1712 ln -s "${devname}" "${devname}.${fstype}"
1713 echo "${devname}.${fstype}"
1714 return 0
1716 done
1718 return 1
1721 set_usplash_timeout ()
1723 if [ -x /sbin/usplash_write ]
1724 then
1725 /sbin/usplash_write "TIMEOUT 120"
1726 else if [ -x /sbin/splashy_update ] ; then
1727 /sbin/splashy_update "TIMEOUT 120"
1728 fi ; fi
1731 integrity_check ()
1733 media_mountpoint="${1}"
1735 log_begin_msg "Checking media integrity"
1737 cd ${media_mountpoint}
1738 /bin/md5sum -c md5sum.txt < /dev/tty8 > /dev/tty8
1739 RC="${?}"
1741 log_end_msg
1743 if [ "${RC}" -eq 0 ]
1744 then
1745 log_success_msg "Everything ok, will reboot in 10 seconds."
1746 sleep 10
1747 cd /
1748 umount ${media_mountpoint}
1749 sync
1750 echo u > /proc/sysrq-trigger
1751 echo b > /proc/sysrq-trigger
1752 else
1753 panic "Not ok, a media defect is likely, switch to VT8 for details."
1757 start_usplash_pulse ()
1759 if [ -x /sbin/usplash_write ]
1760 then
1761 /sbin/usplash_write "PULSELOGO"
1765 mountroot ()
1767 if [ -x /scripts/local-top/cryptroot ]; then
1768 /scripts/local-top/cryptroot
1771 exec 6>&1
1772 exec 7>&2
1773 exec > live.log
1774 exec 2>&1
1775 tail -f live.log >&7 &
1776 tailpid="${!}"
1778 # Ensure 'panic' function is overridden
1779 . /scripts/live-functions
1781 Arguments
1783 set_usplash_timeout
1784 start_usplash_pulse
1786 maybe_break live-premount
1787 log_begin_msg "Running /scripts/live-premount"
1788 run_scripts /scripts/live-premount
1789 log_end_msg
1791 # Needed here too because some things (*cough* udev *cough*)
1792 # changes the timeout
1794 set_usplash_timeout
1796 if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1797 then
1798 if do_netmount
1799 then
1800 livefs_root="${mountpoint}"
1801 else
1802 panic "Unable to find a live file system on the network"
1804 else
1805 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1806 then
1807 # Do a local boot from hd
1808 livefs_root=${ROOT}
1809 else
1810 # Scan local devices for the image
1812 while [ "$i" -lt 60 ]
1814 livefs_root=$(find_livefs ${i})
1816 if [ -n "${livefs_root}" ]
1817 then
1818 break
1821 sleep 1
1822 i="$(($i + 1))"
1823 done
1827 if [ -z "${livefs_root}" ]
1828 then
1829 panic "Unable to find a medium containing a live file system"
1832 if [ "${INTEGRITY_CHECK}" ]
1833 then
1834 integrity_check "${livefs_root}"
1837 if [ "${TORAM}" ]
1838 then
1839 live_dest="ram"
1840 elif [ "${TODISK}" ]
1841 then
1842 live_dest="${TODISK}"
1845 if [ "${live_dest}" ]
1846 then
1847 log_begin_msg "Copying live media to ${live_dest}"
1848 copy_live_to "${livefs_root}" "${live_dest}"
1849 log_end_msg
1852 # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
1853 # because the mountpoint is left behind in /proc/mounts, so let's get
1854 # rid of it when running from RAM
1855 if [ -n "$FROMISO" ] && [ "${TORAM}" ]
1856 then
1857 losetup -d /dev/loop0
1858 grep -q /isofrom /proc/mounts && umount /isofrom
1861 if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
1862 then
1863 setup_unionfs "${livefs_root}" "${rootmnt}"
1864 else
1865 mac="$(get_mac)"
1866 mac="$(echo ${mac} | sed 's/-//g')"
1867 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1870 log_end_msg
1872 # unionfs-fuse needs /dev to be bind-mounted for the duration of
1873 # live-bottom; udev's init script will take care of things after that
1874 if [ "${UNIONTYPE}" = unionfs-fuse ]
1875 then
1876 mount -n -o bind /dev "${rootmnt}/dev"
1879 maybe_break live-bottom
1880 log_begin_msg "Running /scripts/live-bottom\n"
1882 run_scripts /scripts/live-bottom
1883 log_end_msg
1885 if [ "${UNIONFS}" = unionfs-fuse ]
1886 then
1887 umount "${rootmnt}/dev"
1890 exec 1>&6 6>&-
1891 exec 2>&7 7>&-
1892 kill ${tailpid}
1893 [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
1894 if [ -f /etc/live.conf ]
1895 then
1896 cp /etc/live.conf "${rootmnt}/etc/"