Reordered persistence lookups and boundaries (Closes: #500672).
[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 LIVE_MEDIA_PATH="live"
12
13 root_persistence="live-rw"
14 home_persistence="home-rw"
15 root_snapshot_label="live-sn"
16 home_snapshot_label="home-sn"
17
18 USERNAME="user"
19 USERFULLNAME="Live user"
20 HOSTNAME="host"
21
22 mkdir -p "${mountpoint}"
23
24 # Create /etc/mtab for debug purpose and future syncs
25 if [ ! -d /etc ]
26 then
27         mkdir /etc/
28 fi
29
30 if [ ! -f /etc/mtab ]
31 then
32         touch /etc/mtab
33 fi
34
35 [ -f /etc/live.conf ] && . /etc/live.conf
36 export USERNAME USERFULLNAME HOSTNAME
37
38 . /scripts/live-helpers
39
40 if [ ! -f /live.vars ]
41 then
42         touch /live.vars
43 fi
44
45 Arguments ()
46 {
47         PRESEEDS=""
48
49         for ARGUMENT in $(cat /proc/cmdline)
50         do
51                 case "${ARGUMENT}" in
52                         access=*)
53                                 ACCESS="${ARGUMENT#access=}"
54                                 export ACCESS
55                                 ;;
56
57                         console=*)
58                                 DEFCONSOLE="${ARGUMENT#*=}"
59                                 export DEFCONSOLE
60                                 ;;
61
62                         debug)
63                                 DEBUG="Yes"
64                                 export DEBUG
65
66                                 set -x
67                                 ;;
68
69                         fetch=*)
70                                 FETCH="${ARGUMENT#fetch=}"
71                                 export FETCH
72                                 ;;
73
74                         hook=*)
75                                 HOOK="${ARGUMENT#hook=}"
76                                 export HOOK
77                                 ;;
78
79                         ftpfs=*)
80                                 FTPFS="${ARGUMENT#ftpfs=}"
81                                 export FTPFS
82                                 ;;
83
84                         httpfs=*)
85                                 HTTPFS="${ARGUMENT#httpfs=}"
86                                 export HTTPFS
87                                 ;;
88
89                         hostname=*)
90                                 HOSTNAME="${ARGUMENT#hostname=}"
91                                 LIVECONF="changed"
92                                 export HOSTNAME LIVECONF
93                                 ;;
94
95                         username=*)
96                                 USERNAME="${ARGUMENT#username=}"
97                                 LIVECONF="changed"
98                                 export USERNAME LIVECONF
99                                 ;;
100
101                         userfullname=*)
102                                 USERFULLNAME="${ARGUMENT#userfullname=}"
103                                 LIVECONF="changed"
104                                 export USERFULLNAME LIVECONF
105                                 ;;
106
107                         ignore_uuid)
108                                 IGNORE_UUID="Yes"
109                                 export IGNORE_UUID
110                                 ;;
111
112                         ip=*)
113                                 STATICIP="${ARGUMENT#ip=}"
114
115                                 if [ -z "${STATICIP}" ]
116                                 then
117                                         STATICIP="frommedia"
118                                 fi
119
120                                 export STATICIP
121                                 ;;
122
123                         keyb=*|kbd-chooser/method=*)
124                                 KBD="${ARGUMENT#*=}"
125                                 export KBD
126                                 ;;
127
128                         klayout=*|console-setup/layoutcode=*)
129                                 KLAYOUT="${ARGUMENT#*=}"
130                                 export KLAYOUT
131                                 ;;
132
133                         kvariant=*|console-setup/variantcode=*)
134                                 KVARIANT="${ARGUMENT#*=}"
135                                 export KVARIANT
136                                 ;;
137
138                         kmodel=*|console-setup/modelcode=*)
139                                 KMODEL="${ARGUMENT#*=}"
140                                 export KMODEL
141                                 ;;
142
143                         koptions=*)
144                                 KOPTIONS="${ARGUMENT#koptions=}"
145                                 export KOPTIONS
146                                 ;;
147
148                         live-getty)
149                                 LIVE_GETTY="1"
150                                 export LIVE_GETTY
151                                 ;;
152
153                         live-media=*|bootfrom=*)
154                                 LIVE_MEDIA="${ARGUMENT#*=}"
155                                 export LIVE_MEDIA
156                                 ;;
157
158                         live-media-encryption=*|encryption=*)
159                                 LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}"
160                                 export LIVE_MEDIA_ENCRYPTION
161                                 ;;
162
163                         live-media-offset=*)
164                                 LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}"
165                                 export LIVE_MEDIA_OFFSET
166                                 ;;
167
168                         live-media-path=*)
169                                 LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}"
170                                 export LIVE_MEDIA_PATH
171                                 ;;
172
173                         live-media-timeout=*)
174                                 LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}"
175                                 export LIVE_MEDIA_TIMEOUT
176                                 ;;
177
178                         language=*|debian-installer/language=*)
179                                 language=${x#debian-installer/language=}
180                                 locale="$(lang2locale "$language")"
181                                 set_locale="true"
182                                 ;;
183
184                         locale=*|debian-installer/locale=*)
185                                 LOCALE="${ARGUMENT#*=}"
186                                 export LOCALE
187                                 ;;
188
189                         module=*)
190                                 MODULE="${ARGUMENT#module=}"
191                                 export MODULE
192                                 ;;
193
194                         netboot=*)
195                                 NETBOOT="${ARGUMENT#netboot=}"
196                                 export NETBOOT
197                                 ;;
198
199                         nfsopts=*)
200                                 NFSOPTS="${ARGUMENT#nfsopts=}"
201                                 export NFSOPTS
202                                 ;;
203
204                         nfscow=*)
205                                 NFS_COW="${ARGUMENT#nfscow=}"
206                                 export NFS_COW
207                                 ;;
208
209                         noaccessibility)
210                                 NOACCESSIBILITY="Yes"
211                                 export NOACCESSIBILITY
212                                 ;;
213
214                         noapparmor)
215                                 NOAPPARMOR="Yes"
216                                 export NOAPPARMOR
217                                 ;;
218
219                         noaptcdrom)
220                                 NOAPTCDROM="Yes"
221                                 export NOAPTCDROM
222                                 ;;
223
224                         noautologin)
225                                 NOAUTOLOGIN="Yes"
226                                 export NOAUTOLOGIN
227                                 ;;
228
229                         noxautologin)
230                                 NOXAUTOLOGIN="Yes"
231                                 export NOXAUTOLOGIN
232                                 ;;
233
234                         noconsolekeyboard)
235                                 NOCONSOLEKEYBOARD="Yes"
236                                 export NOCONSOLEKEYBOARD
237                                 ;;
238
239                         nofastboot)
240                                 NOFASTBOOT="Yes"
241                                 export NOFASTBOOT
242                                 ;;
243
244                         nofstab)
245                                 NOFSTAB="Yes"
246                                 export NOFSTAB
247                                 ;;
248
249                         nognomepanel)
250                                 NOGNOMEPANEL="Yes"
251                                 export NOGNOMEPANEL
252                                 ;;
253
254                         nohosts)
255                                 NOHOSTS="Yes"
256                                 export NOHOSTS
257                                 ;;
258
259                         nokpersonalizer)
260                                 NOKPERSONALIZER="Yes"
261                                 export NOKPERSONALIZER
262                                 ;;
263
264                         nolanguageselector)
265                                 NOLANGUAGESELECTOR="Yes"
266                                 export NOLANGUAGESELECTOR
267                                 ;;
268
269                         nolocales)
270                                 NOLOCALES="Yes"
271                                 export NOLOCALES
272                                 ;;
273
274                         nonetworking)
275                                 NONETWORKING="Yes"
276                                 export NONETWORKING
277                                 ;;
278
279                         nopowermanagement)
280                                 NOPOWERMANAGEMENT="Yes"
281                                 export NOPOWERMANAGEMENT
282                                 ;;
283
284                         noprogramcrashes)
285                                 NOPROGRAMCRASHES="Yes"
286                                 export NOPROGRAMCRASHES
287                                 ;;
288
289                         norestrictedmanager)
290                                 NORESTRICTEDMANAGER="Yes"
291                                 export NORESTRICTEDMANAGER
292                                 ;;
293
294                         nosudo)
295                                 NOSUDO="Yes"
296                                 export NOSUDO
297                                 ;;
298
299                         swapon)
300                                 SWAPON="Yes"
301                                 export SWAPON
302                                 ;;
303
304                         noupdatenotifier)
305                                 NOUPDATENOTIFIER="Yes"
306                                 export NOUPDATENOTIFIER
307                                 ;;
308
309                         nouser)
310                                 NOUSER="Yes"
311                                 export NOUSER
312                                 ;;
313
314                         noxautoconfig)
315                                 NOXAUTOCONFIG="Yes"
316                                 export NOXAUTOCONFIG
317                                 ;;
318
319                         noxscreensaver)
320                                 NOXSCREENSAVER="Yes"
321                                 export NOXSCREENSAVER
322                                 ;;
323
324                         persistent)
325                                 PERSISTENT="Yes"
326                                 export PERSISTENT
327                                 ;;
328
329                         nopersistent)
330                                 NOPERSISTENT="Yes"
331                                 export NOPERSISTENT
332                                 ;;
333
334                         preseed/file=*|file=*)
335                                 LOCATION="${ARGUMENT#*=}"
336                                 export LOCATION
337                                 ;;
338
339                         nopreseed)
340                                 NOPRESEED="Yes"
341                                 export NOPRESEED
342                                 ;;
343
344                         url=*)
345                                 location="${ARGUMENT#url=}"
346
347                                 mount -o bind /sys /root/sys
348                                 mount -o bind /proc /root/proc
349                                 mount -o bind /dev /root/dev
350
351                                 mkdir -p /root/var/run/network
352                                 chroot /root dhclient eth0
353                                 chroot /root wget -P /tmp "${location}"
354                                 chroot /root ifconfig eth0 down
355
356                                 umount /root/sys
357                                 umount /root/proc
358                                 umount /root/dev
359
360                                 LOCATION="/tmp/$(basename "${location}")"
361                                 ;;
362
363                         */*=*)
364                                 question="${ARGUMENT%%=*}"
365                                 value="${ARGUMENT#*=}"
366                                 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
367                                 export PRESEEDS
368                                 ;;
369
370                         showmounts)
371                                 SHOWMOUNTS="Yes"
372                                 export SHOWMOUNTS
373                                 ;;
374
375                         textonly)
376                                 TEXTONLY="Yes"
377                                 export TEXTONLY
378                                 ;;
379
380                         timezone=*)
381                                 TIMEZONE="${ARGUMENT#timezone=}"
382                                 export TIMEZONE
383                                 ;;
384
385                         notimezone)
386                                 NOTIMEZONE="Yes"
387                                 export NOTIMEZONE
388                                 ;;
389
390                         todisk=*)
391                                 TODISK="${ARGUMENT#todisk=}"
392                                 export TODISK
393                                 ;;
394
395                         toram)
396                                 TORAM="Yes"
397                                 export TORAM
398                                 ;;
399
400                         toram=*)
401                                 TORAM="Yes"
402                                 MODULETORAM="${ARGUMENT#toram=}"
403                                 export TORAM MODULETORAM
404                                 ;;
405
406                         exposedroot)
407                                 EXPOSED_ROOT="Yes"
408                                 export EXPOSED_ROOT
409                                 ;;
410
411                         plainroot)
412                                 PLAIN_ROOT="Yes"
413                                 export PLAIN_ROOT
414                                 ;;
415
416                         root=*)
417                                 ROOT="${ARGUMENT#root=}"
418                                 export ROOT
419                                 ;;
420
421                         union=*)
422                                 UNIONTYPE="${ARGUMENT#union=}"
423                                 export UNIONTYPE
424                                 ;;
425
426                         utc=*)
427                                 UTC="${ARGUMENT#utc=}"
428                                 export UTC
429                                 ;;
430
431                         xdebconf)
432                                 XDEBCONF="Yes"
433                                 export XDEBCONF
434                                 ;;
435
436                         xdriver=*)
437                                 XDRIVER="${ARGUMENT#xdriver=}"
438                                 export XDRIVER
439                                 ;;
440
441                         xvideomode=*)
442                                 XVIDEOMODE="${ARGUMENT#xvideomode=}"
443                                 export XVIDEOMODE
444                                 ;;
445                 esac
446         done
447
448         # sort of compatibility with netboot.h from linux docs
449         if [ -z "${NETBOOT}" ]
450         then
451                 if [ "${ROOT}" = "/dev/nfs" ]
452                 then
453                         NETBOOT="nfs"
454                         export NETBOOT
455                 elif [ "${ROOT}" = "/dev/cifs" ]
456                 then
457                         NETBOOT="cifs"
458                         export NETBOOT
459                 fi
460         fi
461
462         if [ -z "${MODULE}" ]
463         then
464                 MODULE="filesystem"
465                 export MODULE
466         fi
467
468         if [ -z "${UNIONTYPE}" ]
469         then
470                 UNIONTYPE="aufs"
471                 export UNIONTYPE
472         fi
473 }
474
475 is_live_path ()
476 {
477         DIRECTORY="${1}"
478
479         if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ]
480         then
481                 for FILESYSTEM in squashfs ext2 ext3 xfs dir jffs2
482                 do
483                         if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ]
484                         then
485                                 return 0
486                         fi
487                 done
488         fi
489
490         return 1
491 }
492
493 matches_uuid ()
494 {
495         if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ]
496         then
497                 return 0
498         fi
499
500         path="${1}"
501         uuid="$(cat /conf/uuid.conf)"
502
503         for try_uuid_file in "${mountpoint}/.disk/live-uuid"*
504         do
505                 [ -e "${try_uuid_file}" ] || continue
506
507                 try_uuid="$(cat "${try_uuid_file}")"
508
509                 if [ "${uuid}" = "${try_uuid}" ]
510                 then
511                         return 0
512                 fi
513         done
514
515         return 1
516 }
517
518 get_backing_device ()
519 {
520         case "${1}" in
521                 *.squashfs|*.ext2|*.ext3|*.jffs2)
522                         echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}")
523                         ;;
524
525                 *.dir)
526                         echo "directory"
527                         ;;
528
529                 *)
530                         panic "Unrecognized live filesystem: ${1}"
531                         ;;
532         esac
533 }
534
535 match_files_in_dir ()
536 {
537         # Does any files match pattern ${1} ?
538         local pattern="${1}"
539
540         if [ "$(echo ${pattern})" != "${pattern}" ]
541         then
542                 return 0
543         fi
544
545         return 1
546 }
547
548 mount_images_in_directory ()
549 {
550         directory="${1}"
551         rootmnt="${2}"
552         mac="${3}"
553
554
555         if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" ||
556                 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" ||
557                 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" ||
558                 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" ||
559                 match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir"
560         then
561                 [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}"
562                 setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}"
563         else
564                 :
565         fi
566 }
567
568 is_nice_device ()
569 {
570         sysfs_path="${1#/sys}"
571
572         if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"
573         then
574                 return 0
575         elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
576         then
577                 return 0
578         fi
579
580         return 1
581 }
582
583 copy_live_to ()
584 {
585         copyfrom="${1}"
586         copytodev="${2}"
587         copyto="${copyfrom}_swap"
588
589         if [ -z "${MODULETORAM}" ]
590         then
591                 size=$(fs_size "" ${copyfrom} "used")
592         else
593                 MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}"
594
595                 if [ -f "${MODULETORAMFILE}" ]
596                 then
597                         size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 )
598                 else
599                         log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read."
600                         return 1
601                 fi
602         fi
603
604         if [ "${copytodev}" = "ram" ]
605         then
606                 # copying to ram:
607                 freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
608                 mount_options="-o size=${size}k"
609                 free_string="memory"
610                 fstype="tmpfs"
611                 dev="/dev/shm"
612         else
613                 # it should be a writable block device
614                 if [ -b "${copytodev}" ]
615                 then
616                         dev="${copytodev}"
617                         free_string="space"
618                         fstype=$(get_fstype "${dev}")
619                         freespace=$(fs_size "${dev}")
620                 else
621                         log_warning_msg "${copytodev} is not a block device."
622                         return 1
623                 fi
624         fi
625
626         if [ "${freespace}" -lt "${size}" ]
627         then
628                 log_warning_msg "Not enough free ${free_string} (${freespace}k free, ${size}k needed) to copy live media in ${copytodev}."
629                 return 1
630         fi
631
632         # begin copying (or uncompressing)
633         mkdir "${copyto}"
634         echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
635         mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
636
637         if [ "${extension}" = "tgz" ]
638         then
639                 cd "${copyto}"
640                 tar zxf "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
641                 rm -f "${copyfrom}/${LIVE_MEDIA_PATH}/$(basename ${FETCH})"
642                 mount -r -o move "${copyto}" "${rootmnt}"
643                 cd "${OLDPWD}"
644         else
645                 if [ -n "${MODULETORAMFILE}" ]
646                 then
647                         cp ${MODULETORAMFILE} ${copyto} # copy only the filesystem module
648                 else
649                         cp -a ${copyfrom}/* ${copyto}   # "cp -a" from busybox also copies hidden files
650                 fi
651
652                 livefs_root
653                 umount ${copyfrom}
654                 mount -r -o move ${copyto} ${copyfrom}
655         fi
656
657         rmdir ${copyto}
658         return 0
659 }
660
661 do_netmount ()
662 {
663         rc=1
664
665         modprobe -q af_packet # For DHCP
666
667         if [ -x /sbin/udevadm ]
668         then
669                 # lenny
670                 udevadm trigger
671                 udevadm settle
672         else
673                 # etch
674                 udevtrigger
675                 udevsettle
676         fi
677
678         ipconfig ${DEVICE} | tee /netboot.config
679
680         # source relevant ipconfig output
681         OLDHOSTNAME=${HOSTNAME}
682         . /tmp/net-${DEVICE}.conf
683         [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
684         export HOSTNAME
685
686         if [ "${NFSROOT}" = "auto" ]
687         then
688                 NFSROOT=${ROOTSERVER}:${ROOTPATH}
689         fi
690
691         if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
692         then
693                 rc=0
694                 return ${rc}
695         fi
696
697         if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
698         then
699                 NFSROOT=${ROOTSERVER}:${NFSROOT}
700         fi
701
702         log_begin_msg "Trying netboot from ${NFSROOT}"
703
704         if [ "${NETBOOT}" != "nfs" ] && do_cifsmount
705         then
706                 rc=0
707         elif do_nfsmount
708         then
709                 NETBOOT="nfs"
710                 export NETBOOT
711                 rc=0
712         fi
713
714         log_end_msg
715         return ${rc}
716 }
717
718 do_httpmount ()
719 {
720         rc=1
721         dest="${mountpoint}/${LIVE_MEDIA_PATH}"
722         mount -t ramfs ram "${mountpoint}"
723         mkdir -p "${dest}"
724
725         for webfile in HTTPFS FTPFS FETCH
726         do
727                 url="$(eval echo \"\$\{${webfile}\}\")"
728                 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
729
730                 if [ -n "$url" ]
731                 then
732                         case "${extension}" in
733                                 squashfs|tgz|tar)
734                                         if [ "${webfile}" = "FETCH" ]
735                                         then
736                                                 case "$url" in
737                                                         tftp*)
738                                                                 ip="$(dirname $url | sed -e 's|tftp://||g')"
739                                                                 log_begin_msg "Trying tftp -g -b 10240 -r $(basename ${url})  -l ${dest}/$(basename ${url}) $ip"
740                                                                 tftp -g -b 10240 -r $(basename ${url})  -l ${dest}/$(basename ${url}) $ip
741                                                         ;;
742
743                                                         *)
744                                                                 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
745                                                                 wget "${url}" -O "${dest}/$(basename ${url})"
746                                                                 ;;
747                                                 esac
748                                         else
749                                                 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
750                                                 if [ "${webfile}" = "FTPFS" ]
751                                                 then
752                                                         FUSE_MOUNT="curlftpfs"
753                                                         url="$(dirname ${url})"
754                                                 else
755                                                         FUSE_MOUNT="httpfs"
756                                                 fi
757                                                 modprobe fuse
758                                                 $FUSE_MOUNT "${url}" "${dest}"
759                                         fi
760                                         [ ${?} -eq 0 ] && rc=0
761                                         [ "${extension}" = "tgz" ] && live_dest="ram"
762                                         break
763                                         ;;
764
765                                 *)
766                                         log_begin_msg "Unrecognized archive extension for ${url}"
767                                         ;;
768                         esac
769                 fi
770         done
771
772         if [ ${rc} != 0 ]
773         then
774             umount "${mountpoint}"
775         fi
776
777         return ${rc}
778 }
779
780 do_nfsmount ()
781 {
782         rc=1
783
784         modprobe -q nfs
785
786         if [ -z "${NFSOPTS}" ]
787         then
788                 NFSOPTS=""
789         fi
790
791         log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
792
793         # FIXME: This for loop is an ugly HACK round an nfs bug
794         for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13
795         do
796                 nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
797                 sleep 1
798         done
799
800         return ${rc}
801 }
802
803 do_cifsmount ()
804 {
805         rc=1
806
807         if [ -x "/sbin/mount.cifs" ]
808         then
809                 if [ -z "${NFSOPTS}" ]
810                 then
811                         CIFSOPTS="-ouser=root,password="
812                 else
813                         CIFSOPTS="${NFSOPTS}"
814                 fi
815
816                 log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
817                 modprobe -q cifs
818
819                 if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}"
820                 then
821                         rc=0
822                 fi
823         fi
824
825         return ${rc}
826 }
827
828 do_snap_copy ()
829 {
830         fromdev="${1}"
831         todir="${2}"
832         snap_type="${3}"
833         size=$(fs_size "${fromdev}" "" "used")
834
835         if [ -b "${fromdev}" ]
836         then
837                 # look for free mem
838                 if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
839                 then
840                         todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
841                         freespace=$(df -k  | grep -s ${todev} | awk '{print $4}')
842                 else
843                         freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
844                 fi
845
846                 tomount="/mnt/tmpsnap"
847
848                 if [ ! -d "${tomount}" ]
849                 then
850                         mkdir -p "${tomount}"
851                 fi
852
853                 fstype=$(get_fstype "${fromdev}")
854
855                 if [ -n "${fstype}" ]
856                 then
857                         # Copying stuff...
858                         mount -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${fromdev} ${tomount}"
859                         cp -a "${tomount}"/* ${todir}
860                         umount "${tomount}"
861                 else
862                         log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
863                 fi
864
865                 rmdir "${tomount}"
866
867                 if echo ${fromdev} | grep -qs loop
868                 then
869                         losetup -d "${fromdev}"
870                 fi
871
872                 return 0
873         else
874                 return 1
875
876                 log_warning_msg "Unable to find the snapshot ${snap_type} medium"
877         fi
878 }
879
880 find_snap ()
881 {
882         # Look for ${snap_label}.* in block devices
883         snap_label="${1}"
884         snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3 ${snap_label}.jffs2")
885         if [ -z "${snapdata}" ]
886         then
887                 snapdata=$(find_cow_device "${snap_label}")
888         fi
889         echo "${snapdata}"
890 }
891
892 try_snap ()
893 {
894         # copy the contents of previously found snapshot to ${snap_mount}
895         # and remember the device and filename for resync on exit in live-initramfs.init
896
897         snapdata="${1}"
898         snap_mount="${2}"
899         snap_type="${3}"
900
901         if [ ! -z "${snapdata}" ]
902         then
903                 log_success_msg "found snapshot: ${snapdata}"
904                 snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
905                 snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
906                 snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
907
908                 RES=""
909                 if ! try_mount "${snapdev}" "${snapback}" "ro"
910                 then
911                         break
912                 fi
913
914                 if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|jffs2\)'
915                 then
916                         # squashfs, jffs2 or ext2/ext3 snapshot
917                         dev=$(get_backing_device "${snapback}/${snapfile}")
918
919                         do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
920                         RES=$?
921                 else
922                         # cpio.gz snapshot
923                         cd "${snap_mount}"
924                         zcat "${snapback}/${snapfile}" | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1
925                         RES=$?
926                         if [ "${RES}" != "0" ]
927                         then
928                                 log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\""
929                         fi
930                         cd "${OLDPWD}"
931                 fi
932
933                 umount "${snapback}" ||  log_warning_msg "failure to \"umount ${snapback}\""
934
935                 if [ "${RES}" != "0" ]
936                 then
937                         log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
938                 fi
939
940
941         elif [ -b "${snapdata}" ]
942         then
943                 # Try to find if it could be a snapshot partition
944                 dev="${snapdata}"
945                 log_success_msg "found snapshot device on ${dev}"
946                 if echo "${dev}" | grep -qs loop
947                 then
948                         # strange things happens, user confused?
949                         snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
950                         snapfile=$(basename ${snaploop})
951                         snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
952                 else
953                         snapdev="${dev}"
954                 fi
955
956                 if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
957                 then
958                         log_warning_msg "Impossible to include the ${snap_type} Snapshot"
959                         return 1
960                 else
961                         if [ -n "${snapfile}" ]
962                         then
963                                 # it was a loop device, user confused
964                                 umount ${snapdev}
965                         fi
966                 fi
967         else
968                 log_warning_msg "Impossible to include the ${snap_type} Snapshot"
969                 return 1
970         fi
971
972         echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
973         return 0
974 }
975
976 setup_unionfs ()
977 {
978         image_directory="${1}"
979         rootmnt="${2}"
980         addimage_directory="${3}"
981         modprobe -q -b ${UNIONTYPE}
982
983         # run-init can't deal with images in a subdir, but we're going to
984         # move all of these away before it runs anyway.  No, we're not,
985         # put them in / since move-mounting them into / breaks mono and
986         # some other apps.
987
988         croot="/"
989
990         # Let's just mount the read-only file systems first
991         rofsstring=""
992         rofslist=""
993         minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//')
994
995         if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ]
996         then
997                 # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4
998                 roopt="nfsro"
999         elif [ "${UNIONTYPE}" = "aufs" ]
1000         then
1001                 roopt="rr"
1002         else
1003                 roopt="ro"
1004         fi
1005
1006         # Read image names from ${MODULE}.module if it exists
1007         if [ -e "${image_directory}/filesystem.${MODULE}.module" ]
1008         then
1009                 for IMAGE in $(cat ${image_directory}/filesystem.${MODULE}.module)
1010                 do
1011                         image_string="${image_string} ${image_directory}/${IMAGE}"
1012                 done
1013         elif [ -e "${image_directory}/${MODULE}.module" ]
1014         then
1015                 for IMAGE in $(cat ${image_directory}/${MODULE}.module)
1016                 do
1017                         image_string="${image_string} ${image_directory}/${IMAGE}"
1018                 done
1019         else
1020                 # ${MODULE}.module does not exist, create a list of images
1021                 for FILESYSTEM in squashfs ext2 ext3 xfs jffs2 dir
1022                 do
1023                         for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
1024                         do
1025                                 if [ -e "${IMAGE}" ]
1026                                 then
1027                                         image_string="${image_string} ${IMAGE}"
1028                                 fi
1029                         done
1030                 done
1031
1032                 if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
1033                 then
1034                         for FILESYSTEM in squashfs ext2 ext3 xfs jffs2 dir
1035                         do
1036                                 for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
1037                                 do
1038                                         if [ -e "${IMAGE}" ]
1039                                         then
1040                                                 image_string="${image_string} ${IMAGE}"
1041                                         fi
1042                                 done
1043                         done
1044                 fi
1045
1046                 # Now sort the list
1047                 image_string="$(echo ${image_string} | sed -e 's/ /\n/g' | sort )"
1048         fi
1049
1050         [ -n "${MODULETORAMFILE}" ] && image_string="${image_directory}/$(basename ${MODULETORAMFILE})"
1051
1052         mkdir -p "${croot}"
1053
1054         for image in ${image_string}
1055         do
1056                 imagename=$(basename "${image}")
1057
1058                 if [ -d "${image}" ]
1059                 then
1060                         # it is a plain directory: do nothing
1061                         rofsstring="${image}=${roopt}:${rofsstring}"
1062                         rofslist="${image} ${rofslist}"
1063                 elif [ -f "${image}" ]
1064                 then
1065                         if losetup --help 2>&1 | grep -q -- "-r\b"
1066                         then
1067                                 backdev=$(get_backing_device "${image}" "-r")
1068                         else
1069                                 backdev=$(get_backing_device "${image}")
1070                         fi
1071                         fstype=$(get_fstype "${backdev}")
1072
1073                         if [ "${fstype}" = "unknown" ]
1074                         then
1075                                 panic "Unknown file system type on ${backdev} (${image})"
1076                         fi
1077
1078                         if [ -z "${fstype}" ]
1079                         then
1080                                 fstype="${imagename##*.}"
1081                                 log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
1082                         fi
1083
1084                         mkdir -p "${croot}/${imagename}"
1085                         log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
1086                         mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
1087                         log_end_msg
1088                 fi
1089         done
1090
1091         rofsstring=${rofsstring%:}
1092
1093         mkdir -p /cow
1094
1095         # Looking for "${root_persistence}" device or file
1096         if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1097         then
1098                 # Load USB modules
1099                 num_block=$(ls -l /sys/block | wc -l)
1100                 for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage
1101                 do
1102                         modprobe -q -b ${module}
1103                 done
1104
1105                 if [ -x /sbin/udevadm ]
1106                 then
1107                         # lenny
1108                         udevadm trigger
1109                         udevadm settle
1110                 else
1111                         # etch
1112                         udevtrigger
1113                         udevsettle
1114                 fi
1115
1116                 # For some reason, udevsettle does not block in this scenario,
1117                 # so we sleep for a little while.
1118                 #
1119                 # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591
1120                 for timeout in 5 4 3 2 1
1121                 do
1122                         sleep 1
1123
1124                         if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ]
1125                         then
1126                                 break
1127                         fi
1128                 done
1129
1130                 # search for label and files (this could be hugely optimized)
1131                 cowprobe=$(find_cow_device "${root_persistence}")
1132                 if [ -b "${cowprobe}" ]
1133                 then
1134                         # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
1135                         # makes sense to have both persistence for /cow and /home mounted, maybe also with
1136                         # snapshots to be sure to really store some e.g key config files,
1137                         # but not on the same media
1138                         blacklistdev="${cowprobe}"
1139                 fi
1140                 # homecow just mount something on /home, this should be generalized some way
1141                 homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
1142                 root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
1143                 # This second type should be removed when snapshot grow smarter
1144                 home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
1145
1146                 if [ -b "${cowprobe}" ]
1147                 then
1148                         cowdevice=${cowprobe}
1149                         cow_fstype=$(get_fstype "${cowprobe}")
1150                         cow_mountopt="rw,noatime"
1151                 else
1152                         log_warning_msg "Unable to find the persistent medium"
1153                         cowdevice="tmpfs"
1154                         cow_fstype="tmpfs"
1155                         cow_mountopt="rw,noatime,mode=755"
1156                 fi
1157         elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
1158         then
1159                 # check if there are any nfs options
1160                 if echo ${NFS_COW}|grep -q ','
1161                 then
1162                         nfs_cow_opts="-o nolock,$(echo ${NFS_COW}|cut -d, -f2-)"
1163                         nfs_cow=$(echo ${NFS_COW}|cut -d, -f1)
1164                 else
1165                         nfs_cow_opts="-o nolock"
1166                         nfs_cow=${NFS_COW}
1167                 fi
1168                 mac="$(get_mac)"
1169                 if [ -n "${mac}" ]
1170                 then
1171                         cowdevice=$(echo ${nfs_cow}|sed "s/client_mac_address/${mac}/")
1172                         cow_fstype="nfs"
1173                 else
1174                         panic "unable to determine mac address"
1175                 fi
1176         else
1177                 cowdevice="tmpfs"
1178                 cow_fstype="tmpfs"
1179                 cow_mountopt="rw,noatime,mode=755"
1180         fi
1181
1182         if [ "${cow_fstype}" = "nfs" ]
1183         then
1184                 log_begin_msg \
1185                         "Trying nfsmount ${nfs_cow_opts} ${cowdevice} /cow"
1186                 nfsmount ${nfs_cow_opts} ${cowdevice} /cow || \
1187                         panic "Can not mount ${cowdevice} (n: ${cow_fstype}) on /cow"
1188         else
1189                 mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
1190                         panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
1191         fi
1192
1193         rofscount=$(echo ${rofslist} |wc -w)
1194
1195         if [ -n "${EXPOSED_ROOT}" ]
1196         then
1197                 if [ ${rofscount} -ne 1 ]
1198                 then
1199                         panic "only one RO file system supported with exposedroot: ${rofslist}"
1200                 fi
1201                 exposedrootfs=${rofslist%% }
1202
1203                 mount --bind ${exposedrootfs} ${rootmnt} || \
1204                         panic "bind mount of ${exposedrootfs} failed"
1205
1206                 cow_dirs='/var/tmp /var/lock /var/run /var/log /var/spool
1207                         /home /var/lib/live'
1208
1209                 for dir in ${cow_dirs}; do
1210                         mkdir -p /cow${dir}
1211                         mount -t ${UNIONTYPE} \
1212                                 -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro \
1213                                 ${UNIONTYPE} "${rootmnt}${dir}" || \
1214                                 panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option \
1215                                         rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro"
1216                 done
1217         else
1218                 mount -t ${UNIONTYPE} -o noatime,dirs=/cow=rw:${rofsstring} \
1219                         ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on \
1220                         ${rootmnt} failed with option noatime,dirs=/cow=rw:${rofsstring}"
1221         fi
1222
1223         # tmpfs file systems
1224         touch /etc/fstab
1225         mkdir -p "${rootmnt}/live"
1226         mount -t tmpfs tmpfs ${rootmnt}/live
1227
1228         # Adding other custom mounts
1229         if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
1230         then
1231                 # directly mount /home
1232                 # FIXME: add a custom mounts configurable system
1233
1234                 if [ -b "${homecow}" ]
1235                 then
1236                         mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
1237                         export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
1238                 else
1239                         log_warning_msg "Unable to find the persistent home medium"
1240                 fi
1241
1242                 # Look for other snapshots to copy in
1243                 try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
1244                 # This second type should be removed when snapshot grow smarter
1245                 try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
1246         fi
1247
1248         if [ -n "${SHOWMOUNTS}" ]
1249         then
1250                 for d in ${rofslist}
1251                 do
1252                         mkdir -p "${rootmnt}/live/${d##*/}"
1253
1254                         case d in
1255                                 *.dir)
1256                                         # do nothing # mount -o bind "${d}" "${rootmnt}/live/${d##*/}"
1257                                         ;;
1258
1259                                 *)
1260                                         mount -o move "${d}" "${rootmnt}/live/${d##*/}"
1261                                         ;;
1262                         esac
1263                 done
1264         fi
1265
1266         # shows cow fs on /cow for use by live-snapshot
1267         mkdir -p "${rootmnt}/live/cow"
1268         mount -o move /cow "${rootmnt}/live/cow" >/dev/null 2>&1 || mount -o bind /cow "${rootmnt}/live/cow" || log_warning_msg "Unable to move or bind /cow to ${rootmnt}/live/cow"
1269 }
1270
1271 check_dev ()
1272 {
1273         sysdev="${1}"
1274         devname="${2}"
1275         skip_uuid_check="${3}"
1276
1277         if [ -z "${devname}" ]
1278         then
1279                 devname=$(sys2dev "${sysdev}")
1280         fi
1281
1282         if [ -d "${devname}" ]
1283         then
1284                 mount -o bind "${devname}" $mountpoint || continue
1285
1286                 if is_live_path $mountpoint
1287                 then
1288                         echo $mountpoint
1289                         return 0
1290                 else
1291                         umount $mountpoint
1292                 fi
1293         fi
1294
1295         if [ -n "${LIVE_MEDIA_OFFSET}" ]
1296         then
1297                 loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVE_MEDIA_OFFSET}" '')
1298                 devname="${loopdevname}"
1299         fi
1300
1301         fstype=$(get_fstype "${devname}")
1302
1303         if is_supported_fs ${fstype}
1304         then
1305                 mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
1306
1307                 if is_live_path ${mountpoint} && \
1308                         ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
1309                 then
1310                         echo ${mountpoint}
1311                         return 0
1312                 else
1313                         umount ${mountpoint}
1314                 fi
1315         fi
1316
1317         if [ -n "${LIVE_MEDIA_OFFSET}" ]
1318         then
1319                 losetup -d "${loopdevname}"
1320         fi
1321
1322         return 1
1323 }
1324
1325 find_livefs ()
1326 {
1327         timeout="${1}"
1328
1329         # first look at the one specified in the command line
1330         if [ ! -z "${LIVE_MEDIA}" ]
1331         then
1332                 if check_dev "null" "${LIVE_MEDIA}" "skip_uuid_check"
1333                 then
1334                         return 0
1335                 fi
1336         fi
1337
1338         # don't start autodetection before timeout has expired
1339         if [ -n "${LIVE_MEDIA_TIMEOUT}" ]
1340         then
1341                 if [ "${timeout}" -lt "${LIVE_MEDIA_TIMEOUT}" ]
1342                 then
1343                         return 1
1344                 fi
1345         fi
1346
1347         # or do the scan of block devices
1348         for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v 'dm-' | grep -v fd )
1349         do
1350                 devname=$(sys2dev "${sysblock}")
1351                 fstype=$(get_fstype "${devname}")
1352
1353                 if /lib/udev/cdrom_id ${devname} > /dev/null
1354                 then
1355                         if check_dev "null" "${devname}"
1356                         then
1357                                 return 0
1358                         fi
1359                 elif is_nice_device "${sysblock}"
1360                 then
1361                         for dev in $(subdevices "${sysblock}")
1362                         do
1363                                 if check_dev "${dev}"
1364                                 then
1365                                         return 0
1366                                 fi
1367                         done
1368                 elif [ "${fstype}" = "squashfs" -o \
1369                         "${fstype}" = "ext2" -o \
1370                         "${fstype}" = "ext3" -o \
1371                         "${fstype}" = "jffs2" ]
1372                 then
1373                         # This is an ugly hack situation, the block device has
1374                         # an image directly on it.  It's hopefully
1375                         # live-initramfs, so take it and run with it.
1376                         ln -s "${devname}" "${devname}.${fstype}"
1377                         echo "${devname}.${fstype}"
1378                         return 0
1379                 fi
1380         done
1381
1382         return 1
1383 }
1384
1385 set_usplash_timeout ()
1386 {
1387         if [ -x /sbin/usplash_write ]
1388         then
1389                 /sbin/usplash_write "TIMEOUT 120"
1390         else if [ -x /sbin/splashy_update ] ; then
1391                 /sbin/splashy_update "TIMEOUT 120"
1392         fi ; fi
1393 }
1394
1395 mountroot ()
1396 {
1397         if [ -x /scripts/local-top/cryptroot ]; then
1398             /scripts/local-top/cryptroot
1399         fi
1400
1401         exec 6>&1
1402         exec 7>&2
1403         exec > live.log
1404         exec 2>&1
1405         tail -f live.log >&7 &
1406         tailpid="${!}"
1407
1408         # Ensure 'panic' function is overridden
1409         . /scripts/live-functions
1410
1411         Arguments
1412
1413         set_usplash_timeout
1414
1415         maybe_break live-premount
1416         log_begin_msg "Running /scripts/live-premount"
1417         run_scripts /scripts/live-premount
1418         log_end_msg
1419
1420         # Needed here too because some things (*cough* udev *cough*)
1421         # changes the timeout
1422
1423         set_usplash_timeout
1424
1425         if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
1426         then
1427                 if do_netmount
1428                 then
1429                         livefs_root="${mountpoint}"
1430                 else
1431                         panic "Unable to find a live file system on the network"
1432                 fi
1433         else
1434                 if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
1435                 then
1436                         # Do a local boot from hd
1437                         livefs_root=${ROOT}
1438                 else
1439                         # Scan local devices for the image
1440                         for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1441                         do
1442                                 livefs_root=$(find_livefs ${i})
1443
1444                                 if [ -n "${livefs_root}" ]
1445                                 then
1446                                         break
1447                                 fi
1448
1449                                 sleep 1
1450                         done
1451                 fi
1452         fi
1453
1454         if [ -z "${livefs_root}" ]
1455         then
1456                 panic "Unable to find a medium containing a live file system"
1457         fi
1458
1459         if [ "${TORAM}" ]
1460         then
1461                 live_dest="ram"
1462         elif [ "${TODISK}" ]
1463         then
1464                 live_dest="${TODISK}"
1465         fi
1466
1467         if [ "${live_dest}" ]
1468         then
1469                 log_begin_msg "Copying live media to ${live_dest}"
1470                 copy_live_to "${livefs_root}" "${live_dest}"
1471                 log_end_msg
1472         fi
1473
1474         if [ -n "${MODULETORAMFILE}" ]
1475         then
1476                 setup_unionfs "${livefs_root}" "${rootmnt}"
1477         else
1478                 mac="$(get_mac)"
1479                 mac="$(echo ${mac} | sed 's/-//g')"
1480                 mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
1481         fi
1482
1483         log_end_msg
1484
1485         maybe_break live-bottom
1486         log_begin_msg "Running /scripts/live-bottom"
1487
1488         run_scripts /scripts/live-bottom
1489         log_end_msg
1490
1491         exec 1>&6 6>&-
1492         exec 2>&7 7>&-
1493         kill ${tailpid}
1494         cp live.log "${rootmnt}/var/log/"
1495 }