Guest User

Untitled

a guest
Jan 23rd, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  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. # Looking for "${root_persistence}" device or file
  75. if [ -n "${PERSISTENT}" ]; then
  76. cowprobe=$(find_cow_device "${root_persistence}")
  77. if [ -b "${cowprobe}" ]; then
  78. cowdevice=${cowprobe}
  79. cow_fstype=$(get_fstype "${cowprobe}")
  80. cow_mountopt="rw,noatime"
  81. else
  82. [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
  83. fi
  84. fi
  85.  
  86. mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || panic "Can not mount $cowdevice on /cow"
  87.  
  88. case ${UNIONFS} in
  89. unionfs-fuse)
  90. (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")
  91. mkdir -p /dev/.initramfs/varrun
  92. pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
  93. ;;
  94. aufs|unionfs)
  95. mount -t ${UNIONFS} -o noatime,dirs=/cow=rw:$rofsstring ${UNIONFS} "$rootmnt" || panic "${UNIONFS} mount failed"
  96. ;;
  97. overlayfs)
  98. # Mount the layers pairwise from the bottom onto rootmnt,
  99. # for the second and later layers rootmnt forms the lower layer.
  100. mounts=""
  101. for mount in /cow $rofslist
  102. do
  103. mounts="$mount $mounts"
  104. done
  105. lower=""
  106. for mount in $mounts
  107. do
  108. if [ "$lower" = "" ]; then
  109. lower="$mount"
  110. continue
  111. fi
  112. mount -t overlayfs -o "upperdir=$mount,lowerdir=$lower" \
  113. "$mount" "$rootmnt"
  114. lower="$rootmnt"
  115. done
  116. ;;
  117. esac
  118.  
  119. # Adding other custom mounts
  120. if [ -n "${PERSISTENT}" ]; then
  121. # directly mount /home
  122. # FIXME: add a custom mounts configurable system
  123. homecow=$(find_cow_device "${home_persistence}" )
  124. if [ -b "${homecow}" ]; then
  125. mount -t $(get_fstype "${homecow}") -o rw,noatime "${homecow}" "${rootmnt}/home"
  126. export HOMEMOUNTED=1 # used to proper calculate free space in do_snap_copy()
  127. else
  128. [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent home medium"
  129. fi
  130. # Look for other snapshots to copy in
  131. try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
  132. try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
  133. fi
  134.  
  135. if [ -n "${SHOWMOUNTS}" ]; then
  136. for d in ${rofslist}; do
  137. mkdir -p "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  138. case d in
  139. *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  140. ;;
  141. *)
  142. if [ "${UNIONFS}" = unionfs-fuse ]; then
  143. mount -o bind "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  144. else
  145. mount -o move "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
  146. fi
  147. ;;
  148. esac
  149. done
  150. # shows cow fs on /cow for use by casper-snapshot
  151. mkdir -p "${rootmnt}/cow"
  152. mount -o bind /cow "${rootmnt}/cow"
  153. fi
  154.  
  155. # move the first mount; no head in busybox-initramfs
  156. for d in $(mount -t squashfs | cut -d\ -f 3); do
  157. mkdir -p "${rootmnt}/rofs"
  158. if [ "${UNIONFS}" = unionfs-fuse ]; then
  159. mount -o bind "${d}" "${rootmnt}/rofs"
  160. else
  161. mount -o move "${d}" "${rootmnt}/rofs"
  162. fi
  163. break
  164. done
  165. }
Advertisement
Add Comment
Please, Sign In to add comment