Adding live-initramfs 1.91.4-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     [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
401
402     if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
403         rc=0
404     elif do_nfsmount ; then
405         NETBOOT="nfs"
406         export NETBOOT
407         rc=0
408     fi
409
410     [ "$quiet" != "y" ] && log_end_msg
411     return ${rc}
412 }
413
414 do_nfsmount() {
415     rc=1
416     modprobe "${MP_QUIET}" nfs
417     if [ -z "${NFSOPTS}" ]; then
418         NFSOPTS=""
419     fi
420
421     [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
422     # FIXME: This for loop is an ugly HACK round an nfs bug
423     for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
424         nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
425         sleep 1
426     done
427     return ${rc}
428 }
429
430 do_cifsmount() {
431     rc=1
432     if [ -x "/sbin/mount.cifs" ]; then
433         if [ -z "${NFSOPTS}" ]; then
434             CIFSOPTS="-ouser=root,password="
435         else
436             CIFSOPTS="${NFSOPTS}"
437         fi
438
439         [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
440         modprobe "${MP_QUIET}" cifs
441
442         if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
443             rc=0
444         fi
445     fi
446     return ${rc}
447 }
448
449 do_snap_copy ()
450 {
451     fromdev="${1}"
452     todir="${2}"
453     snap_type="${3}"
454
455     size=$(fs_size "${fromdev}" "" "used")
456
457     if [ -b "${fromdev}" ]; then
458         # look for free mem
459         if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
460             todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
461             freespace=$(df -k  | grep -s ${todev} | awk '{print $4}')
462         else
463             freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
464         fi
465
466         tomount="/mnt/tmpsnap"
467         if [ ! -d "${tomount}" ] ; then
468             mkdir -p "${tomount}"
469         fi
470
471         fstype=$(get_fstype "${fromdev}")
472         if [ -n "${fstype}" ]; then
473             # Copying stuff...
474             mount -t "${fstype}" -o ro "${fromdev}" "${tomount}"
475             cp -a "${tomount}"/* ${todir}
476             umount "${tomount}"
477         else
478             log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
479         fi
480
481         rmdir "${tomount}"
482         if echo ${fromdev} | grep -qs loop; then
483            losetup -d "${fromdev}"
484         fi
485         return 0
486     else
487         return 1
488         [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
489     fi
490 }
491
492 try_snap ()
493 {
494     # Look for $snap_label.* in block devices and copy the contents to $snap_mount
495     #   and remember the device and filename for resync on exit in live-initramfs.init
496
497     snap_label="${1}"
498     snap_mount="${2}"
499     snap_type="${3}"
500
501     snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3")
502     if [ ! -z "${snapdata}" ]; then
503         snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
504         snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
505         snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
506         if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\)'; then
507             # squashfs or ext2/ext3 snapshot
508             dev=$(get_backing_device "${snapback}/${snapfile}")
509             if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
510                  log_warning_msg "Impossible to include the ${snapfile} Snapshot"
511                  return 1
512             fi
513         else
514             # cpio.gz snapshot
515             if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i -u -d 2>/dev/null) ; then
516                 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
517                 return 1
518             fi
519         fi
520         umount "${snapback}"
521     else
522         dev=$(find_cow_device "${snap_label}")
523         if [ -b ${dev} ]; then
524             if echo "${dev}" | grep -qs loop; then
525                 # strange things happens, user confused?
526                 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
527                 snapfile=$(basename ${snaploop})
528                 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
529             else
530                 snapdev="${dev}"
531             fi
532             if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
533                 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
534                 return 1
535             else
536                 if [ -n "${snapfile}" ]; then
537                      # it was a loop device, user confused
538                      umount ${snapdev}
539                 fi
540             fi
541         else
542             log_warning_msg "Impossible to include the ${snap_label} Snapshot"
543             return 1
544         fi
545     fi
546     echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
547     return 0
548 }
549
550 setup_unionfs() {
551     image_directory="$1"
552     rootmnt="$2"
553
554     modprobe "${MP_QUIET}" -b ${UNIONTYPE}
555
556     # run-init can't deal with images in a subdir, but we're going to
557     # move all of these away before it runs anyway.  No, we're not,
558     # put them in / since move-mounting them into / breaks mono and
559     # some other apps.
560
561     croot="/"
562
563     # Let's just mount the read-only file systems first
564     rofsstring=""
565     rofslist=""
566     if [ "${NETBOOT}" = "nfs" ] ; then
567         roopt="nfsro" # go aroung a bug in nfs-unionfs locking
568     else
569         roopt="ro"
570     fi
571
572         # Read image names from ${MODULE}.module if it exists
573         if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
574         then
575                 for IMAGE in `cat ${image_directory}/filesystem.${MODULE}.module`
576                 do
577                         image_string="${image_string} ${image_directory}/${image}"
578                 done
579         elif [ -e "${image_directory}/${MODULE}.module" ]
580         then
581                 for IMAGE in `cat ${image_directory}/${MODULE}.module`
582                 do
583                         image_string="${image_string} ${image_directory}/${image}"
584                 done
585         else
586                 # ${MODULE}.module does not exist, create a list of images
587                 for FILESYSTEM in squashfs ext2 ext3 xfs dir
588                 do
589                         for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
590                         do
591                                 if [ -e "${IMAGE}" ]
592                                 then
593                                         image_string="${image_string} ${IMAGE}"
594                                 fi
595                         done
596                 done
597
598                 # Now sort the list
599                 image_string="`echo ${image_string} | sed -e 's/ /\n/g' | sort `"
600         fi
601
602     mkdir -p "${croot}"
603     for image in ${image_string}; do
604         imagename=$(basename "${image}")
605         if [ -d "${image}" ]; then
606             # it is a plain directory: do nothing
607             rofsstring="${image}=${roopt}:${rofsstring}"
608             rofslist="${image} ${rofslist}"
609         elif [ -f "${image}" ]; then
610             backdev=$(get_backing_device "$image")
611             fstype=$(get_fstype "${backdev}")
612             if [ "${fstype}" = "unknown" ]; then
613                 panic "Unknown file system type on ${backdev} (${image})"
614              fi
615             mkdir -p "${croot}/${imagename}"
616             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}"
617         fi
618     done
619     rofsstring=${rofsstring%:}
620
621     mkdir -p /cow
622     cowdevice="tmpfs"
623     cow_fstype="tmpfs"
624
625     # Looking for "${root_persistence}" device or file
626     if [ -n "${PERSISTENT}" ]; then
627         cowprobe=$(find_cow_device "${root_persistence}")
628         if [ -b "${cowprobe}" ]; then
629             cowdevice=${cowprobe}
630             cow_fstype=$(get_fstype "${cowprobe}")
631         else
632             [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
633         fi
634     fi
635
636     mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
637
638     mount -t ${UNIONTYPE} -o dirs=/cow=rw:$rofsstring ${UNIONTYPE} "$rootmnt" || panic "${UNIONTYPE} mount failed"
639
640     # Adding other custom mounts
641     if [ -n "${PERSISTENT}" ]; then
642         # directly mount /home
643         # FIXME: add a custom mounts configurable system
644         homecow=$(find_cow_device "${home_persistence}" )
645         if [ -b "${homecow}" ]; then
646             mount -t $(get_fstype "${homecow}") -o rw "${homecow}" "${rootmnt}/home"
647             export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
648         else
649             [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
650         fi
651         # Look for other snapshots to copy in
652         try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
653         try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
654     fi
655
656     if [ -n "${SHOWMOUNTS}" ]; then
657         for d in ${rofslist}; do
658             mkdir -p "${rootmnt}/live/${d##*/}"
659             case d in
660                 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
661                     ;;
662                 *) mount --move "${d}" "${rootmnt}/live/${d##*/}"
663                     ;;
664             esac
665         done
666     fi
667
668     # shows cow fs on /cow for use by live-snapshot
669     mkdir -p "${rootmnt}/live/cow"
670     mount -o bind /cow "${rootmnt}/live/cow"
671 }
672
673 check_dev ()
674 {
675     sysdev="${1}"
676     devname="${2}"
677     if [ -z "${devname}" ]; then
678         devname=$(sys2dev "${sysdev}")
679     fi
680
681     if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
682         loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
683         devname="${loopdevname}"
684     fi
685
686     fstype=$(get_fstype "${devname}")
687     if is_supported_fs ${fstype}; then
688         mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
689         if is_live_path $mountpoint; then
690             echo $mountpoint
691             return 0
692         else
693             umount $mountpoint
694         fi
695     fi
696
697     if [ -n "${LIVE_MEDIA_OFFSET}" ]; then
698         losetup -d "${loopdevname}"
699     fi
700     return 1
701 }
702
703 find_livefs() {
704     timeout="${1}"
705     # first look at the one specified in the command line
706     if [ ! -z "${LIVE_MEDIA}" ]; then
707         if check_dev "null" "${LIVE_MEDIA}"; then
708             return 0
709         fi
710     fi
711     # don't start autodetection before timeout has expired
712     if [ -n "${LIVE_MEDIA_TIMEOUT}" ]; then
713         if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]; then
714             return 1
715         fi
716     fi
717     # or do the scan of block devices
718     for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
719         devname=$(sys2dev "${sysblock}")
720         fstype=$(get_fstype "${devname}")
721         if /lib/udev/cdrom_id ${devname} > /dev/null; then
722             if check_dev "null" "${devname}" ; then
723                 return 0
724             fi
725         elif is_nice_device "${sysblock}" ; then
726             for dev in $(subdevices "${sysblock}"); do
727                 if check_dev "${dev}" ; then
728                     return 0
729                 fi
730             done
731         elif [ "${fstype}" = "squashfs" -o \
732                 "${fstype}" = "ext2" -o \
733                 "${fstype}" = "ext3" ]; then
734             # This is an ugly hack situation, the block device has
735             # an image directly on it.  It's hopefully
736             # live-initramfs, so take it and run with it.
737             ln -s "${devname}" "${devname}.${fstype}"
738             echo "${devname}.${fstype}"
739             return 0
740         fi
741     done
742     return 1
743 }
744
745 pulsate() {
746     if [ -x /sbin/usplash_write ]; then
747         /sbin/usplash_write "PULSATE"
748     fi
749 }
750
751 set_usplash_timeout() {
752     if [ -x /sbin/usplash_write ]; then
753         /sbin/usplash_write "TIMEOUT 120"
754     fi
755 }
756
757 mountroot() {
758     exec 6>&1
759     exec 7>&2
760     exec > live.log
761     exec 2>&1
762
763     parse_cmdline
764
765     set_usplash_timeout
766     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-premount"
767     pulsate
768     run_scripts /scripts/live-premount
769     [ "$quiet" != "y" ] && log_end_msg
770
771     # Needed here too because some things (*cough* udev *cough*)
772     # changes the timeout
773
774     set_usplash_timeout
775
776     if [ ! -z "${NETBOOT}" ]; then
777         if do_netmount ; then
778             livefs_root="${mountpoint}"
779         else
780             panic "Unable to find a live file system on the network"
781         fi
782     else
783         # Scan local devices for the image
784         for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
785             livefs_root=$(find_livefs $i)
786             if [ -n "${livefs_root}" ]; then
787                 break
788             fi
789             sleep 1
790         done
791     fi
792
793     if [ -z "${livefs_root}" ]; then
794         panic "Unable to find a medium containing a live file system"
795     fi
796
797     if [ "${TORAM}" ]; then
798         live_dest="ram"
799     elif [ "${TODISK}" ]; then
800         live_dest="${TODISK}"
801     fi
802     if [ "${live_dest}" ]; then
803         log_begin_msg "Copying live media to ${live_dest}"
804         copy_live_to "${livefs_root}" "${live_dest}"
805         log_end_msg
806     fi
807
808     mount_images_in_directory "${livefs_root}" "${rootmnt}"
809
810     log_end_msg
811
812     maybe_break live-bottom
813     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/live-bottom"
814
815     pulsate
816     run_scripts /scripts/live-bottom
817     [ "$quiet" != "y" ] && log_end_msg
818
819     exec 1>&6 6>&-
820     exec 2>&7 7>&-
821     cp live.log "${rootmnt}/var/log/"
822 }