Advertisement
Guest User

Modified casper script

a guest
Jan 23rd, 2014
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. setup_unionfs() {
  2. image_directory="$1"
  3. rootmnt="$2"
  4.  
  5. if [ "${UNIONFS}" = 'DEFAULT' ]; then
  6. for union in 'overlayfs' 'aufs' 'unionfs'
  7. do
  8. modprobe "${MP_QUIET}" -b ${union} || true
  9. if cut -f2 /proc/filesystems | grep -q "^${union}\$"; then
  10. UNIONFS="${union}"
  11. break
  12. fi
  13. done
  14. fi
  15. if [ "${UNIONFS}" = 'DEFAULT' -a -x /bin/unionfs-fuse ]; then
  16. UNIONFS="unionfs-fuse"
  17. fi
  18. # If all else fails fall back to aufs.
  19. if [ "${UNIONFS}" = 'DEFAULT' ]; then
  20. UNIONFS='aufs'
  21. fi
  22.  
  23. # run-init can't deal with images in a subdir, but we're going to
  24. # move all of these away before it runs anyway. No, we're not,
  25. # put them in / since move-mounting them into / breaks mono and
  26. # some other apps.
  27.  
  28. croot="/"
  29.  
  30. # Let's just mount the read-only file systems first
  31. rofsstring=""
  32. rofslist=""
  33. if [ "${UNIONFS}" = "aufs" ]; then
  34. roopt="rr"
  35. elif [ "${UNIONFS}" = "unionfs-fuse" ]; then
  36. roopt="RO"
  37. else
  38. roopt="ro"
  39. fi
  40.  
  41. mkdir -p "${croot}"
  42. for image_type in "ext2" "squashfs" "dir" ; do
  43. for image in "${image_directory}"/*."${image_type}"; do
  44. imagename=$(basename "${image}")
  45.  
  46. # Skip Edubuntu's extra squashfs
  47. if [ "$imagename" = "ltsp.squashfs" ] ||
  48. [ "$imagename" = "server.squashfs" ]; then
  49. continue
  50. fi
  51.  
  52. if [ -d "${image}" ]; then
  53. # it is a plain directory: do nothing
  54. rofsstring="${image}=${roopt}:${rofsstring}"
  55. rofslist="${image} ${rofslist}"
  56. elif [ -f "${image}" ]; then
  57. backdev=$(get_backing_device "$image")
  58. fstype=$(get_fstype "${backdev}")
  59. if [ "${fstype}" = "unknown" ]; then
  60. panic "Unknown file system type on ${backdev} (${image})"
  61. fi
  62. mkdir -p "${croot}/${imagename}"
  63. 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}"
  64. fi
  65. done
  66. done
  67. rofsstring=${rofsstring%:}
  68.  
  69. mkdir -p /cow
  70. cowdevice="tmpfs"
  71. cow_fstype="tmpfs"
  72. cow_mountopt="rw,noatime,mode=755"
  73.  
  74. persistent_ro_mount=""
  75.  
  76. # Looking for "${root_persistence}" device or file
  77. if [ -n "${PERSISTENT}" ]; then
  78. cowprobe=$(find_cow_device "${root_persistence}")
  79. if [ -b "${cowprobe}" ]; then
  80. persistent_ro_device=${cowprobe}
  81. persistent_ro_fstype=$(get_fstype "${cowprobe}")
  82. persistent_ro_mountopt="ro,noatime"
  83. persistent_ro_mount="/persistent"
  84.  
  85. mkdir -p $persistent_ro_mount
  86. mount -t ${persistent_ro_fstype} -o ${persistent_ro_mountopt} ${persistent_ro_device} ${persistent_ro_mount} || panic "Can not mount persistent_ro_device on /persistent"
  87. else
  88. [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
  89. fi
  90. fi
  91.  
  92. mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || panic "Can not mount $cowdevice on /cow"
  93.  
  94. case ${UNIONFS} in
  95. unionfs-fuse)
  96. (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")
  97. mkdir -p /dev/.initramfs/varrun
  98. pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
  99. ;;
  100. aufs|unionfs)
  101. mount -t ${UNIONFS} -o noatime,dirs=/cow=rw:$rofsstring ${UNIONFS} "$rootmnt" || panic "${UNIONFS} mount failed"
  102. ;;
  103. overlayfs)
  104. # Mount the layers pairwise from the bottom onto rootmnt,
  105. # for the second and later layers rootmnt forms the lower layer.
  106. mounts=""
  107. for mount in /cow $persistent_ro_mount $rofslist
  108. do
  109. mounts="$mount $mounts"
  110. done
  111. lower=""
  112. for mount in $mounts
  113. do
  114. if [ "$lower" = "" ]; then
  115. lower="$mount"
  116. continue
  117. fi
  118. mount -t overlayfs -o "upperdir=$mount,lowerdir=$lower" \
  119. "$mount" "$rootmnt"
  120. lower="$rootmnt"
  121. done
  122. ;;
  123. esac
  124.  
  125. # Adding other custom mounts
  126. if [ -n "${PERSISTENT}" ]; then
  127. # directly mount /home
  128. # FIXME: add a custom mounts configurable system
  129. homecow=$(find_cow_device "${home_persistence}" )
  130. if [ -b "${homecow}" ]; then
  131. mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
  132. export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
  133. else
  134. [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
  135. fi
  136. # Look for other snapshots to copy in
  137. try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
  138. try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
  139. fi
  140.  
  141. if [ -n "${SHOWMOUNTS}" ]; then
  142. for d in ${rofslist}; do
  143. mkdir -p "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  144. case d in
  145. *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  146. ;;
  147. *)
  148. if [ "${UNIONFS}" = unionfs-fuse ]; then
  149. mount -o bind "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  150. else
  151. mount -o move "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  152. fi
  153. ;;
  154. esac
  155. done
  156. # shows cow fs on /cow for use by casper-snapshot
  157. mkdir -p "${rootmnt}/cow"
  158. mount -o bind /cow "${rootmnt}/cow"
  159. fi
  160.  
  161. # move the first mount; no head in busybox-initramfs
  162. for d in $(mount -t squashfs | cut -d\ -f 3); do
  163. mkdir -p "${rootmnt}/rofs"
  164. if [ "${UNIONFS}" = unionfs-fuse ]; then
  165. mount -o bind "${d}" "${rootmnt}/rofs"
  166. else
  167. mount -o move "${d}" "${rootmnt}/rofs"
  168. fi
  169. break
  170. done
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement