local 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. # Local filesystem mounting -*- shell-script -*-
  2. local_top()
  3. {
  4. if [ "${local_top_used}" != "yes" ]; then
  5. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
  6. run_scripts /scripts/local-top
  7. [ "$quiet" != "y" ] && log_end_msg
  8. fi
  9. local_top_used=yes
  10. }
  11. local_block()
  12. {
  13. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-block"
  14. run_scripts /scripts/local-block "$@"
  15. [ "$quiet" != "y" ] && log_end_msg
  16. }
  17. local_premount()
  18. {
  19. if [ "${local_premount_used}" != "yes" ]; then
  20. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
  21. run_scripts /scripts/local-premount
  22. [ "$quiet" != "y" ] && log_end_msg
  23. fi
  24. local_premount_used=yes
  25. }
  26. local_bottom()
  27. {
  28. if [ "${local_premount_used}" = "yes" ] || [ "${local_top_used}" = "yes" ]; then
  29. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
  30. run_scripts /scripts/local-bottom
  31. [ "$quiet" != "y" ] && log_end_msg
  32. fi
  33. local_premount_used=no
  34. local_top_used=no
  35. }
  36. # $1=device ID to mount
  37. # $2=optionname (for root and etc)
  38. # Sets $DEV to the resolved device node
  39. local_device_setup()
  40. {
  41. local dev_id="$1"
  42. local name="$2"
  43. local real_dev
  44. # If wait-for-root understands this prefix, then use it to wait for
  45. # the device rather than settling the whole of udev.
  46. case "$dev_id" in
  47. UUID=*|LABEL=*|/dev/*)
  48. FSTYPE=$( wait-for-root "$dev_id" 10 )
  49. ;;
  50. *)
  51. wait_for_udev 10
  52. ;;
  53. esac
  54. # Load ubi with the correct MTD partition and return since fstype
  55. # doesn't work with a char device like ubi.
  56. if [ -n "$UBIMTD" ]; then
  57. modprobe ubi mtd=$UBIMTD
  58. DEV="${dev_id}"
  59. return
  60. fi
  61. # Don't wait for a device that doesn't have a corresponding
  62. # device in /dev and isn't resolvable by blkid (e.g. mtd0)
  63. if [ "${dev_id#/dev}" = "${dev_id}" ] &&
  64. [ "${dev_id#*=}" = "${dev_id}" ]; then
  65. DEV="${dev_id}"
  66. return
  67. fi
  68. # If the root device hasn't shown up yet, give it a little while
  69. # to allow for asynchronous device discovery (e.g. USB). We
  70. # also need to keep invoking the local-block scripts in case
  71. # there are devices stacked on top of those.
  72. if ! real_dev=$(resolve_device "${dev_id}") ||
  73. ! get_fstype "${real_dev}" >/dev/null; then
  74. log_begin_msg "Waiting for ${name} file system"
  75. # Timeout is max(30, rootdelay) seconds (approximately)
  76. case $DPKG_ARCH in
  77. powerpc|ppc64|ppc64el)
  78. slumber=180
  79. ;;
  80. *)
  81. slumber=30
  82. ;;
  83. esac
  84. if [ ${ROOTDELAY:-0} -gt $slumber ]; then
  85. slumber=$ROOTDELAY
  86. fi
  87. while true; do
  88. sleep 1
  89. local_block "${dev_id}"
  90. if real_dev=$(resolve_device "${dev_id}") &&
  91. get_fstype "${real_dev}" >/dev/null; then
  92. wait_for_udev 10
  93. log_end_msg 0
  94. break
  95. fi
  96. slumber=$(( ${slumber} - 1 ))
  97. if [ ${slumber} -eq 0 ]; then
  98. log_end_msg 1 || true
  99. break
  100. fi
  101. done
  102. fi
  103. # We've given up, but we'll let the user fix matters if they can
  104. while ! real_dev=$(resolve_device "${dev_id}") ||
  105. ! get_fstype "${real_dev}" >/dev/null; do
  106. echo "Gave up waiting for ${name} device. Common problems:"
  107. echo " - Boot args (cat /proc/cmdline)"
  108. echo " - Check rootdelay= (did the system wait long enough?)"
  109. if [ "${name}" = root ]; then
  110. echo " - Check root= (did the system wait for the right device?)"
  111. fi
  112. echo " - Missing modules (cat /proc/modules; ls /dev)"
  113. panic "ALERT! ${dev_id} does not exist. Dropping to a shell!"
  114. done
  115. DEV="${real_dev}"
  116. }
  117. local_mount_root()
  118. {
  119. local_top
  120. local_device_setup "${ROOT}" root
  121. ROOT="${DEV}"
  122. # Get the root filesystem type if not set
  123. if [ -z "${ROOTFSTYPE}" ]; then
  124. FSTYPE=$(get_fstype "${ROOT}")
  125. else
  126. FSTYPE=${ROOTFSTYPE}
  127. fi
  128. local_premount
  129. if [ "${readonly}" = "y" ] && \
  130. [ -z "$LOOP" ]; then
  131. roflag=-r
  132. else
  133. roflag=-w
  134. fi
  135. # FIXME This has no error checking
  136. [ -n "${FSTYPE}" ] && modprobe ${FSTYPE}
  137. checkfs ${ROOT} root
  138. # FIXME This has no error checking
  139. # Mount root
  140. mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt}
  141. mountroot_status="$?"
  142. if [ "$LOOP" ]; then
  143. if [ "$mountroot_status" != 0 ]; then
  144. if [ ${FSTYPE} = ntfs ] || [ ${FSTYPE} = vfat ]; then
  145. panic "
  146. Could not mount the partition ${ROOT}.
  147. This could also happen if the file system is not clean because of an operating
  148. system crash, an interrupted boot process, an improper shutdown, or unplugging
  149. of a removable device without first unmounting or ejecting it. To fix this,
  150. simply reboot into Windows, let it fully start, log in, run 'chkdsk /r', then
  151. gracefully shut down and reboot back into Windows. After this you should be
  152. able to reboot again and resume the installation.
  153. (filesystem = ${FSTYPE}, error code = $mountroot_status)
  154. "
  155. fi
  156. fi
  157. mkdir -p /host
  158. mount -o move ${rootmnt} /host
  159. while [ ! -e "/host/${LOOP#/}" ]; do
  160. panic "ALERT! /host/${LOOP#/} does not exist. Dropping to a shell!"
  161. done
  162. # Get the loop filesystem type if not set
  163. if [ -z "${LOOPFSTYPE}" ]; then
  164. eval $(fstype < "/host/${LOOP#/}")
  165. else
  166. FSTYPE="${LOOPFSTYPE}"
  167. fi
  168. if [ "$FSTYPE" = "unknown" ] && [ -x /sbin/blkid ]; then
  169. FSTYPE=$(/sbin/blkid -s TYPE -o value "/host/${LOOP#/}")
  170. [ -z "$FSTYPE" ] && FSTYPE="unknown"
  171. fi
  172. if [ ${readonly} = y ]; then
  173. roflag=-r
  174. else
  175. roflag=-w
  176. fi
  177. # FIXME This has no error checking
  178. modprobe loop
  179. modprobe ${FSTYPE}
  180. # FIXME This has no error checking
  181. mount ${roflag} -o loop -t ${FSTYPE} ${LOOPFLAGS} "/host/${LOOP#/}" ${rootmnt}
  182. if [ -d ${rootmnt}/host ]; then
  183. mount -o move /host ${rootmnt}/host
  184. fi
  185. fi
  186. }
  187. local_mount_fs()
  188. {
  189. read_fstab_entry "$1"
  190. local_device_setup "$MNT_FSNAME" "$1"
  191. MNT_FSNAME="${DEV}"
  192. local_premount
  193. if [ "${readonly}" = "y" ]; then
  194. roflag=-r
  195. else
  196. roflag=-w
  197. fi
  198. # FIXME This has no error checking
  199. modprobe "${MNT_TYPE}"
  200. if [ "$MNT_PASS" != 0 ]; then
  201. checkfs "$MNT_FSNAME" "$MNT_DIR"
  202. fi
  203. # FIXME This has no error checking
  204. # Mount filesystem
  205. mount ${roflag} -t "${MNT_TYPE}" -o "${MNT_OPTS}" "$MNT_FSNAME" "${rootmnt}${MNT_DIR}"
  206. }
  207. mountroot()
  208. {
  209. local_mount_root
  210. }
  211. mount_top()
  212. {
  213. # Note, also called directly in case it's overridden.
  214. local_top
  215. }
  216. mount_premount()
  217. {
  218. # Note, also called directly in case it's overridden.
  219. local_premount
  220. }
  221. mount_bottom()
  222. {
  223. # Note, also called directly in case it's overridden.
  224. local_bottom
  225. }