Advertisement
Guest User

casper file for intramfs on linuxmint_9.iso

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