b52a3ea634965bf807efab780c4af8233233a152
[people/pravin/BKO.git] / bko / live / ubuntu / U9.10 / casper
1 #!/bin/sh
2
3 # set -e
4
5 export PATH=/usr/bin:/usr/sbin:/bin:/sbin
6
7 mountpoint=/cdrom
8 LIVE_MEDIA_PATH=casper
9
10 root_persistence="casper-rw"
11 home_persistence="home-rw"
12 root_snapshot_label="casper-sn"
13 home_snapshot_label="home-sn"
14
15 USERNAME=casper
16 USERFULLNAME="Live session user"
17 HOST=live
18 BUILD_SYSTEM=Custom
19
20 mkdir -p $mountpoint
21 tried=/tmp/tried
22
23 [ -f /etc/casper.conf ] && . /etc/casper.conf
24 export USERNAME USERFULLNAME HOST BUILD_SYSTEM
25
26 . /scripts/casper-helpers
27
28 if [ ! -f /casper.vars ]; then
29     touch /casper.vars
30 fi
31
32 parse_cmdline() {
33     for x in $(cat /proc/cmdline); do
34         case $x in
35             showmounts|show-cow)
36                 export SHOWMOUNTS='Yes' ;;
37             persistent)
38                 export PERSISTENT="Yes" ;;
39             nopersistent)
40                 export PERSISTENT="" ;;
41             union=*)
42                 export UNIONFS="${x#union=}";;
43             ip*)
44                 STATICIP=${x#ip=}
45                 if [ "${STATICIP}" = "" ]; then
46                     STATICIP="frommedia"
47                 fi
48                 export STATICIP ;;
49             ignore_uuid)
50                 IGNORE_UUID="Yes" ;;
51             live-media-path=*)
52                 LIVE_MEDIA_PATH="${x#live-media-path=}"
53                 export LIVE_MEDIA_PATH
54                 echo "export LIVE_MEDIA_PATH=\"$LIVE_MEDIA_PATH\"" >> /etc/casper.conf ;;
55         esac
56     done
57     if [ "${UNIONFS}" = "" ]; then
58         export UNIONFS="aufs"
59     fi
60 }
61
62 is_casper_path() {
63     path=$1
64     if [ -d "$path/$LIVE_MEDIA_PATH" ]; then
65         if [ "$(echo $path/$LIVE_MEDIA_PATH/*.squashfs)" != "$path/$LIVE_MEDIA_PATH/*.squashfs" ] ||
66             [ "$(echo $path/$LIVE_MEDIA_PATH/*.ext2)" != "$path/$LIVE_MEDIA_PATH/*.ext2" ] ||
67             [ "$(echo $path/$LIVE_MEDIA_PATH/*.dir)" != "$path/$LIVE_MEDIA_PATH/*.dir" ]; then
68             return 0
69         fi
70     fi
71     return 1
72 }
73
74 matches_uuid() {
75     if [ "$IGNORE_UUID" ] || [ ! -e /conf/uuid.conf ]; then
76         return 0
77     fi
78     path="$1"
79     uuid="$(cat /conf/uuid.conf)"
80     for try_uuid_file in "$path/.disk/casper-uuid"*; do
81         [ -e "$try_uuid_file" ] || continue
82         try_uuid="$(cat "$try_uuid_file")"
83         if [ "$uuid" = "$try_uuid" ]; then
84             return 0
85         fi
86     done
87     return 1
88 }
89
90 get_backing_device() {
91     case "$1" in
92         *.squashfs|*.ext2)
93             echo $(setup_loop "$1" "loop" "/sys/block/loop*")
94             ;;
95         *.dir)
96             echo "directory"
97             ;;
98         *)
99             panic "Unrecognized casper filesystem: $1"
100             ;;
101     esac
102 }
103
104 match_files_in_dir() {
105     # Does any files match pattern $1 ?
106
107     local pattern="$1"
108     if [ "$(echo $pattern)" != "$pattern" ]; then
109         return 0
110     fi
111     return 1
112 }
113
114 mount_images_in_directory() {
115     directory="$1"
116     rootmnt="$2"
117     if match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.squashfs" ||
118         match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.ext2" ||
119         match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.dir"; then
120         setup_unionfs "$directory/$LIVE_MEDIA_PATH" "$rootmnt"
121     else
122         :
123     fi
124 }
125
126 is_nice_device() {
127     sysfs_path="${1#/sys}"
128     if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-(ide|scsi|usb)|platform-orion-ehci|platform-mmc|platform-mxsdhci)"; then
129         return 0
130     fi
131     return 1
132 }
133
134 copy_live_to() {
135     copyfrom="${1}"
136     copytodev="${2}"
137     copyto="${copyfrom}_swap"
138
139     size=$(fs_size "" ${copyfrom} "used")
140
141     if [ "${copytodev}" = "ram" ]; then
142         # copying to ram:
143         freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ) )
144         mount_options="-o size=${size}k"
145         free_string="memory"
146         fstype="tmpfs"
147         dev="/dev/shm"
148     else
149         # it should be a writable block device
150         if [ -b "${copytodev}" ]; then
151             dev="${copytodev}"
152             free_string="space"
153             fstype=$(get_fstype "${dev}")
154             freespace=$(fs_size "${dev}")
155         else
156             [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
157             return 1
158         fi
159     fi
160     if [ "${freespace}" -lt "${size}" ] ; then
161         [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
162         return 1
163     fi
164
165     # begin copying..
166     mkdir "${copyto}"
167     echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
168     mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
169     cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
170     umount ${copyfrom}
171     mount -r -o move ${copyto} ${copyfrom}
172     rmdir ${copyto}
173     return 0
174 }
175
176 do_netmount() {
177     rc=1
178
179     modprobe "${MP_QUIET}" af_packet # For DHCP
180
181     /sbin/udevadm trigger
182     /sbin/udevadm settle
183
184     ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
185
186     if [ "${NFSROOT}" = "auto" ]; then
187         NFSROOT=${ROOTSERVER}:${ROOTPATH}
188     fi
189
190     [ "$quiet" != "y" ] && log_begin_msg "Trying netboot from ${NFSROOT}"
191
192     if [ "${NETBOOT}" != "nfs" ] && do_cifsmount ; then
193         rc=0
194     elif do_nfsmount ; then
195         NETBOOT="nfs"
196         export NETBOOT
197         rc=0
198     fi
199
200     [ "$quiet" != "y" ] && log_end_msg
201     return ${rc}
202 }
203
204 do_nfsmount() {
205     rc=1
206     modprobe "${MP_QUIET}" nfs
207     if [ -z "${NFSOPTS}" ]; then
208         NFSOPTS=""
209     fi
210
211     [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
212     # FIXME: This while loop is an ugly HACK round an nfs bug
213     i=0
214     while [ "$i" -lt 60 ]; do
215         nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
216         sleep 1
217         i="$(($i + 1))"
218     done
219     return ${rc}
220 }
221
222 do_cifsmount() {
223     rc=1
224     if [ -x "/sbin/mount.cifs" ]; then
225         if [ -z "${NFSOPTS}" ]; then
226             CIFSOPTS="-ouser=root,password="
227         else
228             CIFSOPTS="${NFSOPTS}"
229         fi
230
231         [ "$quiet" != "y" ] && log_begin_msg "Trying mount.cifs ${NFSROOT} ${mountpoint} ${CIFSOPTS}"
232         modprobe "${MP_QUIET}" cifs
233
234         if mount.cifs "${NFSROOT}" "${mountpoint}" "${CIFSOPTS}" ; then
235             rc=0
236         fi
237     fi
238     return ${rc}
239 }
240
241 do_snap_copy ()
242 {
243     fromdev="${1}"
244     todir="${2}"
245     snap_type="${3}"
246
247     size=$(fs_size "${fromdev}" "" "used")
248
249     if [ -b "${fromdev}" ]; then
250         # look for free mem
251         if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
252             todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
253             freespace=$(df -k  | grep -s ${todev} | awk '{print $4}')
254         else
255             freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( cat /proc/meminfo | grep Cached | head -n 1 | awk '/Cached/{print $2}' - ))
256         fi
257
258         tomount="/mnt/tmpsnap"
259         if [ ! -d "${tomount}" ] ; then
260             mkdir -p "${tomount}"
261         fi
262
263         fstype=$(get_fstype "${fromdev}")
264         if [ -n "${fstype}" ]; then
265             # Copying stuff...
266             mount -t "${fstype}" -o ro,noatime "${fromdev}" "${tomount}"
267             cp -a "${tomount}"/* ${todir}
268             umount "${tomount}"
269         else
270             log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
271         fi
272
273         rmdir "${tomount}"
274         if echo ${fromdev} | grep -qs loop; then
275            losetup -d "${fromdev}"
276         fi
277         return 0
278     else
279         return 1
280         [ "$quiet" != "y" ] && log_warning_msg "Unable to find the snapshot ${snap_type} medium"
281     fi
282 }
283
284 try_snap ()
285 {
286     # Look for $snap_label.* in block devices and copy the contents to $snap_mount
287     #   and remember the device and filename for resync on exit in casper.init
288
289     snap_label="${1}"
290     snap_mount="${2}"
291     snap_type="${3}"
292
293     snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
294     if [ ! -z "${snapdata}" ]; then
295         snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
296         snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
297         snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
298         if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
299             # squashfs or ext2 snapshot
300             dev=$(get_backing_device "${snapback}/${snapfile}")
301             if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
302                  log_warning_msg "Impossible to include the ${snapfile} Snapshot"
303                  return 1
304             fi
305         else
306             # cpio.gz snapshot
307             # Unfortunately klibc's cpio is incompatible with the rest of
308             # the world; everything else requires -u -d, while klibc doesn't
309             # implement them. Try to detect whether it's in use.
310             cpiopath="$(which cpio)" || true
311             if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"; then
312                 cpioargs=
313             else
314                 cpioargs='-u -d'
315             fi
316             if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i $cpioargs 2>/dev/null) ; then
317                 log_warning_msg "Impossible to include the ${snapfile} Snapshot"
318                 return 1
319             fi
320         fi
321         umount "${snapback}"
322     else
323         dev=$(find_cow_device "${snap_label}")
324         if [ -b "${dev}" ]; then
325             if echo "${dev}" | grep -qs loop; then
326                 # strange things happens, user confused?
327                 snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
328                 snapfile=$(basename ${snaploop})
329                 snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
330             else
331                 snapdev="${dev}"
332             fi
333             if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
334                 log_warning_msg "Impossible to include the ${snap_label} Snapshot"
335                 return 1
336             else
337                 if [ -n "${snapfile}" ]; then
338                      # it was a loop device, user confused
339                      umount ${snapdev}
340                 fi
341             fi
342         else
343             log_warning_msg "Impossible to include the ${snap_label} Snapshot"
344             return 1
345         fi
346     fi
347     echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
348     return 0
349 }
350
351 setup_unionfs() {
352     image_directory="$1"
353     rootmnt="$2"
354
355     case ${UNIONFS} in
356         aufs|unionfs)
357             modprobe "${MP_QUIET}" -b ${UNIONFS} || true
358             if ! cut -f2 /proc/filesystems | grep -q "^${UNIONFS}\$" && \
359                [ -x /bin/unionfs-fuse ]; then
360                 UNIONFS="unionfs-fuse"
361             fi
362             ;;
363     esac
364
365     # run-init can't deal with images in a subdir, but we're going to
366     # move all of these away before it runs anyway.  No, we're not,
367     # put them in / since move-mounting them into / breaks mono and
368     # some other apps.
369
370     croot="/"
371
372     # Let's just mount the read-only file systems first
373     rofsstring=""
374     rofslist=""
375     if [ "${NETBOOT}" = "nfs" ] ; then
376         roopt="nfsro" # work around a bug in nfs-unionfs locking
377     elif [ "${UNIONFS}" = "aufs" ]; then
378         roopt="rr"
379     elif [ "${UNIONFS}" = "unionfs-fuse" ]; then
380         roopt="RO"
381     else
382         roopt="ro"
383     fi
384
385     mkdir -p "${croot}"
386     for image_type in "ext2" "squashfs" "dir" ; do
387         for image in "${image_directory}"/*."${image_type}"; do
388             imagename=$(basename "${image}")
389             if [ -d "${image}" ]; then
390                 # it is a plain directory: do nothing
391                 rofsstring="${image}=${roopt}:${rofsstring}"
392                 rofslist="${image} ${rofslist}"
393             elif [ -f "${image}" ]; then
394                 backdev=$(get_backing_device "$image")
395                 fstype=$(get_fstype "${backdev}")
396                 if [ "${fstype}" = "unknown" ]; then
397                     panic "Unknown file system type on ${backdev} (${image})"
398                 fi
399                 mkdir -p "${croot}/${imagename}"
400                 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}"
401             fi
402         done
403     done
404     rofsstring=${rofsstring%:}
405
406     mkdir -p /cow
407     cowdevice="tmpfs"
408     cow_fstype="tmpfs"
409     cow_mountopt="rw,noatime,mode=755"
410
411     # Looking for "${root_persistence}" device or file
412     if [ -n "${PERSISTENT}" ]; then
413         cowprobe=$(find_cow_device "${root_persistence}")
414         if [ -b "${cowprobe}" ]; then
415             cowdevice=${cowprobe}
416             cow_fstype=$(get_fstype "${cowprobe}")
417             cow_mountopt="rw,noatime"
418         else
419             [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
420         fi
421     fi
422
423     mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || panic "Can not mount $cowdevice on /cow"
424
425     case ${UNIONFS} in
426         unionfs-fuse)
427             (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:$rofsstring "$rootmnt" || panic "${UNIONFS} mount failed")
428             mkdir -p /dev/.initramfs/varrun
429             pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
430             ;;
431         *)
432             mount -t ${UNIONFS} -o noatime,dirs=/cow=rw:$rofsstring ${UNIONFS} "$rootmnt" || panic "${UNIONFS} mount failed"
433             ;;
434     esac
435
436     # Adding other custom mounts
437     if [ -n "${PERSISTENT}" ]; then
438         # directly mount /home
439         # FIXME: add a custom mounts configurable system
440         homecow=$(find_cow_device "${home_persistence}" )
441         if [ -b "${homecow}" ]; then
442             mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
443             export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
444         else
445             [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
446         fi
447         # Look for other snapshots to copy in
448         try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
449         try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
450     fi
451
452     if [ -n "${SHOWMOUNTS}" ]; then
453         for d in ${rofslist}; do
454             mkdir -p "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
455             case d in
456                 *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
457                     ;;
458                 *)
459                     if [ "${UNIONFS}" = unionfs-fuse ]; then
460                         mount -o bind "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
461                     else
462                         mount -o move "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
463                     fi
464                     ;;
465             esac
466         done
467         # shows cow fs on /cow for use by casper-snapshot
468         mkdir -p "${rootmnt}/cow"
469         mount -o bind /cow "${rootmnt}/cow"
470     fi
471
472     # move the first mount; no head in busybox-initramfs
473     for d in $(mount -t squashfs | cut -d\  -f 3); do
474         mkdir -p "${rootmnt}/rofs"
475         if [ "${UNIONFS}" = unionfs-fuse ]; then
476             mount -o bind "${d}" "${rootmnt}/rofs"
477         else
478             mount -o move "${d}" "${rootmnt}/rofs"
479         fi
480         break
481     done
482 }
483
484 check_dev ()
485 {
486     sysdev="${1}"
487     devname="${2}"
488     skip_uuid_check="${3}"
489     if [ -z "${devname}" ]; then
490         devname=$(sys2dev "${sysdev}")
491     fi
492
493     if [ -d "${devname}" ]; then
494         mount -o bind "${devname}" $mountpoint || continue
495         if is_casper_path $mountpoint; then
496             echo $mountpoint
497             return 0
498         else
499             umount $mountpoint
500         fi
501     fi
502     [ -e "$devname" ] || continue
503
504     if [ -n "${LIVEMEDIA_OFFSET}" ]; then
505         loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVEMEDIA_OFFSET}")
506         devname="${loopdevname}" 
507     fi
508
509     fstype=$(get_fstype "${devname}")
510     if is_supported_fs ${fstype}; then
511         devuid=$(blkid -o value -s UUID "$devname")
512         [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue
513         mount -t ${fstype} -o ro,noatime "${devname}" $mountpoint || continue
514         [ -n "$devuid" ] && echo "$devuid" >> $tried
515         if is_casper_path $mountpoint && \
516            ([ "$skip_uuid_check" ] || matches_uuid $mountpoint); then
517             echo $mountpoint
518             return 0
519         else
520             umount $mountpoint
521         fi
522     fi
523
524     if [ -n "${LIVEMEDIA_OFFSET}" ]; then
525         losetup -d "${loopdevname}"
526     fi
527     return 1
528 }
529
530 find_livefs() {
531     timeout="${1}"
532     # first look at the one specified in the command line
533     if [ ! -z "${LIVEMEDIA}" ]; then
534         if check_dev "null" "${LIVEMEDIA}" "skip_uuid_check"; then
535             return 0
536         fi
537     fi
538     # don't start autodetection before timeout has expired
539     if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
540         if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
541             return 1
542         fi
543     fi
544     # or do the scan of block devices
545     for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|fd)"); do
546         devname=$(sys2dev "${sysblock}")
547         [ -e "$devname" ] || continue
548         fstype=$(get_fstype "${devname}")
549         if /lib/udev/cdrom_id ${devname} > /dev/null; then
550             if check_dev "null" "${devname}" ; then
551                 return 0
552             fi
553         elif is_nice_device "${sysblock}" ; then
554             for dev in $(subdevices "${sysblock}"); do
555                 if check_dev "${dev}" ; then
556                     return 0
557                 fi
558             done
559         elif [ "${fstype}" = "squashfs" -o \
560                 "${fstype}" = "ext4" -o \
561                 "${fstype}" = "ext3" -o \
562                 "${fstype}" = "ext2" ]; then
563             # This is an ugly hack situation, the block device has
564             # an image directly on it.  It's hopefully
565             # casper, so take it and run with it.
566             ln -s "${devname}" "${devname}.${fstype}"
567             echo "${devname}.${fstype}"
568             return 0
569         fi
570     done
571     return 1
572 }
573
574 set_usplash_timeout() {
575     if [ -x /sbin/usplash_write ]; then
576         /sbin/usplash_write "TIMEOUT 120"
577     fi
578 }
579
580 mountroot() {
581     exec 6>&1
582     exec 7>&2
583     exec > casper.log
584     exec 2>&1
585     tail -f casper.log >&7 &
586     tailpid="$!"
587
588     parse_cmdline
589
590     set_usplash_timeout
591     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-premount"
592     run_scripts /scripts/casper-premount
593     [ "$quiet" != "y" ] && log_end_msg
594
595     # Needed here too because some things (*cough* udev *cough*)
596     # changes the timeout
597
598     set_usplash_timeout
599
600     if [ ! -z "${NETBOOT}" ]; then
601         if do_netmount ; then
602             livefs_root="${mountpoint}"
603         else
604             panic "Unable to find a live file system on the network"
605         fi
606     else
607         # Scan local devices for the image
608         i=0
609         while [ "$i" -lt 60 ]; do
610             livefs_root=$(find_livefs $i)
611             if [ "${livefs_root}" ]; then
612                 break
613             fi
614             sleep 1
615             i="$(($i + 1))"
616         done
617     fi
618
619     if [ -z "${livefs_root}" ]; then
620         panic "Unable to find a medium containing a live file system"
621     fi
622
623     if [ "${TORAM}" ]; then
624         live_dest="ram"
625     elif [ "${TODISK}" ]; then
626         live_dest="${TODISK}"
627     fi
628     if [ "${live_dest}" ]; then
629         log_begin_msg "Copying live_media to ${live_dest}"
630         copy_live_to "${livefs_root}" "${live_dest}"
631         log_end_msg
632     fi
633
634     mount_images_in_directory "${livefs_root}" "${rootmnt}"
635
636     log_end_msg
637
638     # unionfs-fuse needs /dev to be bind-mounted for the duration of
639     # casper-bottom; udev's init script will take care of things after that
640     if [ "${UNIONFS}" = unionfs-fuse ]; then
641         mount -n -o bind /dev "${rootmnt}/dev"
642     fi
643
644     maybe_break casper-bottom
645     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/casper-bottom"
646
647     run_scripts /scripts/casper-bottom
648     [ "$quiet" != "y" ] && log_end_msg
649
650     if [ "${UNIONFS}" = unionfs-fuse ]; then
651         umount "${rootmnt}/dev"
652     fi
653
654     exec 1>&6 6>&-
655     exec 2>&7 7>&-
656     kill "$tailpid"
657     cp casper.log "${rootmnt}/var/log/"
658     if [ -f /etc/casper.conf ]; then
659         cp /etc/casper.conf "${rootmnt}/etc/"
660     fi
661 }