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