Adding live-initramfs 1.91.3-1.
[live-boot-grml.git] / scripts / live
1 #!/bin/sh
2
3 # set -e
4
5 export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin
6
7 echo "/root/lib" >> /etc/ld.so.conf
8 echo "/root/usr/lib" >> /etc/ld.so.conf
9
10 mountpoint=/live_media
11
12 root_persistence="live-rw"
13 home_persistence="home-rw"
14 root_snapshot_label="live-sn"
15 home_snapshot_label="home-sn"
16
17 USERNAME=user
18 USERFULLNAME="Live user"
19 HOSTNAME=host
20 BUILD_SYSTEM=Custom
21
22 mkdir -p $mountpoint
23
24 [ -f /etc/live.conf ] && . /etc/live.conf
25 export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
26
27 . /scripts/live-helpers
28
29 if [ ! -f /live.vars ]; then
30     touch /live.vars
31 fi
32
33 parse_cmdline ()
34 {
35         PRESEEDS=
36
37         # looking for live-initramfs specifics options as kernel parameters
38
39         for x in $(cat /proc/cmdline)
40         do
41                 case $x in
42                         access=*)
43                                 ACCESS=${x#access=}
44                                 export ACCESS
45                                 ;;
46
47                         console=*)
48                                 DEFCONSOLE="${x#*=}"
49                                 export DEFCONFSOLE
50                                 ;;
51
52                         hostname=*)
53                                 HOSTNAME=${x#hostname=}
54                                 LIVECONF="changed"
55                                 export HOSTNAME LIVECONF
56                                 ;;
57
58                         username=*)
59                                 USERNAME=${x#username=}
60                                 LIVECONF="changed"
61                                 export USERNAME LIVECONF
62                                 ;;
63
64                         userfullname=*)
65                                 USERFULLNAME=${x#userfullname=}
66                                 LIVECONF="changed"
67                                 export USERFULLNAME LIVECONF
68                                 ;;
69
70                         ip*)
71                                 STATICIP=${x#ip=}
72
73                                 if [ -z "${STATICIP}" ]
74                                 then
75                                         STATICIP="frommedia"
76                                 fi
77
78                                 export STATICIP
79                                 ;;
80
81                         keyb=*|kbd-chooser/method=*)
82                                 KBD=${x#*=}
83                                 export KBD
84                                 ;;
85
86                         klayout=*|console-setup/layoutcode=*)
87                                 KLAYOUT=${x#*=}
88                                 export KLAYOUT
89                                 ;;
90
91                         kvariant=*|console-setup/variantcode=*)
92                                 KVARIANT=${x#*=}
93                                 export KVARIANT
94                                 ;;
95
96                         kmodel=*|console-setup/modelcode=*)
97                                 KMODEL=${x#*=}
98                                 export KMODEL
99                                 ;;
100
101                         koptions=*)
102                                 KOPTIONS=${x#koptions=}
103                                 export KOPTIONS
104                                 ;;
105
106                         live-getty)
107                                 LIVE_GETTY=1
108                                 export LIVE_GETTY
109                                 ;;
110
111                         live-media=*|bootfrom=*)
112                                 LIVE_MEDIA=${x#*=}
113                                 export LIVE_MEDIA
114                                 ;;
115
116                         live-media-encryption=*|encryption=*)
117                                 LIVE_MEDIA_ENCRYPTION=${x#*=}
118                                 export LIVE_MEDIA_ENCRYPTION
119                                 ;;
120
121                         live-media-offset=*)
122                                 LIVE_MEDIA_OFFSET=${x#live-media-offset=}
123                                 export LIVE_MEDIA_OFFSET
124                                 ;;
125
126                         live-media-timeout=*)
127                                 LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=}
128                                 export LIVE_MEDIA_TIMEOUT
129                                 ;;
130
131                         locale=*|debian-installer/locale=*)
132                                 LOCALE=${x#*=}
133                                 export LOCALE
134                                 ;;
135
136                         module=*)
137                                 MODULE=${x#module=}
138                                 export MODULE
139                                 ;;
140
141                         netboot*)
142                                 NETBOOT=${x#netboot=}
143                                 export NETBOOT
144                                 ;;
145
146                         nfsopts=)
147                                 NFSOPTS=${x#nfsopts=}
148                                 export NFSOPTS
149                                 ;;
150
151                         noautologin)
152                                 NOAUTOLOGIN="Yes"
153                                 export NOAUTOLOGIN
154                                 ;;
155
156                         noxautologin)
157                                 NOXAUTOLOGIN="Yes"
158                                 export NOXAUTOLOGIN
159                                 ;;
160
161                         nofastboot)
162                                 NOFASTBOOT="Yes"
163                                 export NOFASTBOOT
164                                 ;;
165
166                         nopersistent)
167                                 PERSISTENT=""
168                                 export PERSISTENT
169                                 ;;
170
171                         nosudo)
172                                 NOSUDO="Yes"
173                                 export NOSUDO
174                                 ;;
175
176                         noswap)
177                                 NOSWAP="Yes"
178                                 export NOSWAP
179                                 ;;
180
181                         persistent)
182                                 PERSISTENT="Yes"
183                                 export PERSISTENT
184                                 ;;
185
186                         preseed/file=*|file=*)
187                                 LOCATION="${x#*=}"
188                                 export LOCATION
189                                 ;;
190
191                         */*=*)
192                                 question="${x%%=*}"
193                                 value="${x#*=}"
194                                 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
195
196                                 export PRESEEDS
197                                 ;;
198
199                         showmounts)
200                                 SHOWMOUNTS="Yes"
201                                 export SHOWMOUNTS
202                                 ;;
203
204                        timezone=*)
205                                 TIMEZONE="${x#timezone=}"
206                                 export TIMEZONE
207                                 ;;
208
209                         todisk=*)
210                                 TODISK=${x#todisk=}
211                                 export TODISK
212                                 ;;
213
214                         toram)
215                                 TORAM="Yes"
216                                 export TORAM
217                                 ;;
218
219                         union=*)
220                                 UNIONTYPE="${x#union=}"
221                                 export UNIONTYPE
222                                 ;;
223
224                         xdebconf)
225                                 XDEBCONF="Yes"
226                                 export XDEBCONF
227                                 ;;
228
229                         xvideomode=*)
230                                 XVIDEOMODE="${x#xvideomode=}"
231                                 export XVIDEOMODE
232                                 ;;
233                 esac
234         done
235
236         # sort of compatibility with netboot.h from linux docs
237         if [ -z "${NETBOOT}" ]
238         then
239                 if [ "${ROOT}" = "/dev/nfs" ]
240                 then
241                         NETBOOT="nfs"
242                         export NETBOOT
243                 elif [ "${ROOT}" = "/dev/cifs" ]
244                 then
245                         NETBOOT="cifs"
246                         export NETBOOT
247                 fi
248         fi
249
250         if [ -z "${MODULE}" ]
251         then
252                 MODULE="filesystem"
253                 export MODULE
254         fi
255
256         if [ -z "${UNIONTYPE}" ]
257         then
258                 UNIONTYPE="unionfs"
259                 export UNIONTYPE
260         fi
261 }
262
263 is_live_path()
264 {
265         DIRECTORY="${1}"
266
267         if [ -d "${DIRECTORY}"/live ]
268         then
269                 for FILESYSTEM in squashfs ext2 ext3 xfs dir
270                 do
271                         if [ "`echo ${DIRECTORY}/live/*.${FILESYSTEM}`" != "${DIRECTORY}/live/*.${FILESYSTEM}" ]
272                         then
273                                 return 0
274                         fi
275                 done
276         fi
277
278         return 1
279 }
280
281 get_backing_device() {
282     case "$1" in
283         *.squashfs|*.ext2|*.ext3)
284             echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}")
285             ;;
286         *.dir)
287             echo "directory"
288             ;;
289         *)
290             panic "Unrecognized live filesystem: $1"
291             ;;
292     esac
293 }
294
295 match_files_in_dir() {
296     # Does any files match pattern $1 ?
297
298     local pattern="$1"
299     if [ "$(echo $pattern)" != "$pattern" ]; then
300         return 0
301     fi
302     return 1
303 }
304
305 mount_images_in_directory() {
306     directory="$1"
307     rootmnt="$2"
308     if match_files_in_dir "$directory/live/*.squashfs" ||
309         match_files_in_dir "$directory/live/*.ext2" ||
310         match_files_in_dir "$directory/live/*.ext3" ||
311         match_files_in_dir "$directory/live/*.dir"; then
312         setup_unionfs "$directory/live" "$rootmnt"
313     else
314         :
315     fi
316 }
317
318 is_nice_device() {
319     sysfs_path="${1#/sys}"
320     if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
321         return 0
322     fi
323     return 1
324 }
325
326 is_supported_fs () {
327     # FIXME: do something better like the scan of supported filesystems
328     fstype="${1}"
329     case ${fstype} in
330         vfat|iso9660|udf|ext2|ext3|ntfs)
331             return 0
332             ;;
333     esac
334     return 1
335 }
336
337 copy_live_to() {
338     copyfrom="${1}"
339     copytodev="${2}"
340     copyto="${copyfrom}_swap"
341
342     size=$(fs_size "" ${copyfrom} "used")
343
344     if [ "${copytodev}" = "ram" ]; then
345         # copying to ram:
346         freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
347         mount_options="-o size=${size}k"
348         free_string="memory"
349         fstype="tmpfs"
350         dev="/dev/shm"
351     else
352         # it should be a writable block device
353         if [ -b "${copytodev}" ]; then
354             dev="${copytodev}"
355             free_string="space"
356             fstype=$(get_fstype "${dev}")
357             freespace=$(fs_size "${dev}")
358         else
359             [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
360             return 1
361         fi
362     fi
363     if [ "${freespace}" -lt "${size}" ] ; then
364         [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
365         return 1
366     fi
367
368     # begin copying..
369     mkdir "${copyto}"
370     echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
371     mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
372     cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
373     umount ${copyfrom}
374     mount -r --move ${copyto} ${copyfrom}
375     rmdir ${copyto}
376     return 0
377 }
378
379 do_netmount() {
380     rc=1
381
382     modprobe "${MP_QUIET}" af_packet # For DHCP
383
384     udevtrigger
385     udevsettle
386
387     ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
388
389     if [ "${NFSROOT}" = "auto" ]; then
390         NFSROOT=${ROOTSERVER}:${ROOTPATH}
391     fi
392
393     [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
394
395     if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
396         rc=0
397     elif do_nfsmount ; then
398         NETBOOT="nfs"
399         export NETBOOT
400         rc=0
401     fi
402
403     [ "$quiet" != "y" ] && log_end_msg
404     return ${rc}
405 }
406
407 do_nfsmount() {
408     rc=1
409     modprobe "${MP_QUIET}" nfs
410     if [ -z "${NFSOPTS}" ]; then
411         NFSOPTS=""
412     fi
413
414     [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
415     # FIXME: This for loop is an ugly HACK round an nfs bug
416     for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
417         nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
418         sleep 1
419     done
420     return ${rc}
421 }
422
423 do_cifsmount() {
424     rc=1
425     if [ -x "/sbin/mount.cifs" ]; then
426         if [ -z "${NFSOPTS}" ]; then
427             CIFSOPTS="-ouser=root,password="
428         else
429             CIFSOPTS="${NFSOPTS}"
430         fi
431
432         [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
433         modprobe "${MP_QUIET}" cifs
434
435         if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
436             rc=0
437         fi
438     fi
439     return ${rc}
440 }
441
442 do_snap_copy ()
443 {
444     fromdev="${1}"
445     todir="${2}"
446     snap_type="${3}"
447
448     size=$(fs_size "${fromdev}" "" "used")
449
450     if [ -b "${fromdev}" ]; then
451         # look for free mem
452         if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
453             todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
454             freespace=$(df -k  | grep -s ${todev} | awk '{print $4}')
455         else
456             freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
457         fi
458
459         tomount="/mnt/tmpsnap"
460         if [ ! -d "${tomount}" ] ; then
461             mkdir -p "${tomount}"
462         fi
463
464         fstype=$(get_fstype "${fromdev}")
465         if [ -n "${fstype}" ]; then
466             # Copying stuff...
467             mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
468             cp -a "${tomount}"/* ${todir}
469             umount "${tomount}"
470         else
471             log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
472         fi
473
474         rmdir "${tomount}"
475         if echo ${fromdev} | grep -qs loop; then
476            losetup -d "${fromdev}"
477         fi
478         return 0
479     else
480         return 1
481         [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
482     fi
483 }
484
485 try_snap ()
486 {
487     # Look for $snap_label.* in block devices and copy the contents to $snap_mount
488     #   and remember the device and filename for resync on exit in live-initramfs.init
489
490     snap_label="${1}"
491     snap_mount="${2}"
492     snap_type="${3}"
493
494     snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
495     if [ ! -z "${snapdata}" ]; then
496         snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
497         snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
498         snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
499         if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
500             # squashfs or ext2/ext3 snapshot
501             dev=$(get_backing_device "${snapback}/${snapfile}")
502             if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
503                  log_warning_msg "Impossible to include the ${snapfile} Snapshot"
504                  return 1
505             fi
506         else
507             # cpio.gz snapshot
508             if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
509                 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
510                 return 1
511             fi
512         fi
513         umount "${snapback}"
514     else
515         dev=$(find_cow_device "${snap_label}")
516         if [ -b ${dev} ]; then
517             if echo "${dev}" | grep -qs loop; then
518                 # strange things happens, user confused?
519                 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
520                 snapfile=$(basename ${snaploop})
521                 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
522             else
523                 snapdev="${dev}"
524             fi
525             if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
526                 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
527                 return 1
528             else
529                 if [ -n "${snapfile}" ]; then
530                      # it was a loop device, user confused
531                      umount ${snapdev}
532                 fi
533             fi
534         else
535             log_warning_msg "Impossible to include the ${snap_label} Snapshot"
536             return 1
537         fi
538     fi
539     echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
540     return 0
541 }
542
543 setup_unionfs() {
544     image_directory="$1"
545     rootmnt="$2"
546
547     modprobe "${MP_QUIET}" -b ${UNIONTYPE}
548
549     # run-init can't deal with images in a subdir, but we're going to
550     # move all of these away before it runs anyway.  No, we're not,
551     # put them in / since move-mounting them into / breaks mono and
552     # some other apps.
553
554     croot="/"
555
556     # Let's just mount the read-only file systems first
557     rofsstring=""
558     rofslist=""
559     if [ "${NETBOOT}" = "nfs" ] ; then
560         roopt="nfsro" # go aroung a bug in nfs-unionfs locking
561     else
562         roopt="ro"
563     fi
564
565         # Read image names from ${MODULE}.module if it exists
566         if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
567         then
568                 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
569                 do
570                         image_string="${image_string} ${image_directory}/${image}"
571                 done
572         elif [ -e "${image_directory}/${MODULE}.module" ]
573         then
574                 for IMAGE in `cat ${image_directory}/${MODULE}.module`
575                 do
576                         image_string="${image_string} ${image_directory}/${image}"
577                 done
578         else
579                 # ${MODULE}.module does not exist, create a list of images
580                 for FILESYSTEM in squashfs ext2 ext3 xfs dir
581                 do
582                         for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
583                         do
584                                 if [ -e "${IMAGE}" ]
585                                 then
586                                         image_string="${image_string} ${IMAGE}"
587                                 fi
588                         done
589                 done
590
591                 # Now sort the list
592                 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
593         fi
594
595     mkdir -p "${croot}"
596     for image in ${image_string}; do
597         imagename=$(basename "${image}")
598         if [ -d "${image}" ]; then
599             # it is a plain directory: do nothing
600             rofsstring="${image}=${roopt}:${rofsstring}"
601             rofslist="${image} ${rofslist}"
602         elif [ -f "${image}" ]; then
603             backdev=$(get_backing_device "$image")
604             fstype=$(get_fstype "${backdev}")
605             if [ "${fstype}" = "unknown" ]; then
606                 panic "Unknown file system type on ${backdev} (${image})"
607              fi
608             mkdir -p "${croot}/${imagename}"
609             mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
610         fi
611     done
612     rofsstring=${rofsstring%:}
613
614     mkdir -p /cow
615     cowdevice="tmpfs"
616     cow_fstype="tmpfs"
617
618     # Looking for "${root_persistence}" device or file
619     if [ -n "${PERSISTENT}" ]; then
620         cowprobe=$(find_cow_device "${root_persistence}")
621         if [ -b "${cowprobe}" ]; then
622             cowdevice=${cowprobe}
623             cow_fstype=$(get_fstype "${cowprobe}")
624         else
625             [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
626         fi
627     fi
628
629     mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
630
631     mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
632
633     # Adding other custom mounts
634     if [ -n "${PERSISTENT}" ]; then
635         # directly mount /home
636         # FIXME: add a custom mounts configurable system
637         homecow=$(find_cow_device "${home_persistence}" )
638         if [ -b "${homecow}" ]; then
639             mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
640             export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
641         else
642             [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
643         fi
644         # Look for other snapshots to copy in
645         try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
646         try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
647     fi
648
649     if [ -n "${SHOWMOUNTS}" ]; then
650         for d in ${rofslist}; do
651             mkdir -p "${rootmnt}/live/${d##*/}"
652             case d in
653                 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
654                     ;;
655                 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
656                     ;;
657             esac
658         done
659     fi
660
661     # shows cow fs on /cow for use by live-snapshot
662     mkdir -p "${rootmnt}/cow"
663     mount -o bind /cow "${rootmnt}/cow"
664 }
665
666 check_dev ()
667 {
668     sysdev="${1}"
669     devname="${2}"
670     if [ -z "${devname}" ]; then
671         devname=$(sys2dev "${sysdev}")
672     fi
673
674     if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
675         loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
676         devname="${loopdevname}"
677     fi
678
679     fstype=$(get_fstype "${devname}")
680     if is_supported_fs ${fstype}; then
681         mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
682         if is_live_path $mountpoint; then
683             echo $mountpoint
684             return 0
685         else
686             umount $mountpoint
687         fi
688     fi
689
690     if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
691         losetup -d "${loopdevname}"
692     fi
693     return 1
694 }
695
696 find_livefs() {
697     timeout="${1}"
698     # first look at the one specified in the command line
699     if [ ! -z "${LIVE_MEDIA}" ]; then
700         if check_dev "null" "${LIVE_MEDIA}"; then
701             return 0
702         fi
703     fi
704     # don't start autodetection before timeout has expired
705     if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
706         if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
707             return 1
708         fi
709     fi
710     # or do the scan of block devices
711     for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
712         devname=$(sys2dev "${sysblock}")
713         fstype=$(get_fstype "${devname}")
714         if /lib/udev/cdrom_id ${devname} > /dev/null; then
715             if check_dev "null" "${devname}" ; then
716                 return 0
717             fi
718         elif is_nice_device "${sysblock}" ; then
719             for dev in $(subdevices "${sysblock}"); do
720                 if check_dev "${dev}" ; then
721                     return 0
722                 fi
723             done
724         elif [ "${fstype}" = "squashfs" -o \
725                 "${fstype}" = "ext2" -o \
726                 "${fstype}" = "ext3" ]; then
727             # This is an ugly hack situation, the block device has
728             # an image directly on it.  It's hopefully
729             # live-initramfs, so take it and run with it.
730             ln -s "${devname}" "${devname}.${fstype}"
731             echo "${devname}.${fstype}"
732             return 0
733         fi
734     done
735     return 1
736 }
737
738 pulsate() {
739     if [ -x /sbin/usplash_write ]; then
740         /sbin/usplash_write "PULSATE"
741     fi
742 }
743
744 set_usplash_timeout() {
745     if [ -x /sbin/usplash_write ]; then
746         /sbin/usplash_write "TIMEOUT 120"
747     fi
748 }
749
750 mountroot() {
751     exec 6>&1
752     exec 7>&2
753     exec > live.log
754     exec 2>&1
755
756     parse_cmdline
757
758     set_usplash_timeout
759     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
760     pulsate
761     run_scripts /scripts/live-premount
762     [ "$quiet" != "y" ] && log_end_msg
763
764     # Needed here too because some things (*cough* udev *cough*)
765     # changes the timeout
766
767     set_usplash_timeout
768
769     if [ ! -z "${NETBOOT}" ]; then
770         if do_netmount ; then
771             livefs_root="${mountpoint}"
772         else
773             panic "Unable to find a live file system on the network"
774         fi
775     else
776         # Scan local devices for the image
777         for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
778             livefs_root=$(find_livefs $i)
779             if [ -n "${livefs_root}" ]; then
780                 break
781             fi
782             sleep 1
783         done
784     fi
785
786     if [ -z "${livefs_root}" ]; then
787         panic "Unable to find a medium containing a live file system"
788     fi
789
790     if [ "${TORAM}" ]; then
791         live_dest="ram"
792     elif [ "${TODISK}" ]; then
793         live_dest="${TODISK}"
794     fi
795     if [ "${live_dest}" ]; then
796         log_begin_msg "Copying live_media to ${live_dest}"
797         copy_live_to "${livefs_root}" "${live_dest}"
798         log_end_msg
799     fi
800
801     mount_images_in_directory "${livefs_root}" "${rootmnt}"
802
803     log_end_msg
804
805     maybe_break live-bottom
806     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
807
808     pulsate
809     run_scripts /scripts/live-bottom
810     [ "$quiet" != "y" ] && log_end_msg
811
812     exec 1>&6 6>&-
813     exec 2>&7 7>&-
814     cp live.log "${rootmnt}/var/log/"
815 }