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