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