init.orig 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #!/bin/sh
  2. # Default PATH differs between shells, and is not automatically exported
  3. # by klibc dash. Make it consistent.
  4. export PATH=/sbin:/usr/sbin:/bin:/usr/bin
  5. [ -d /dev ] || mkdir -m 0755 /dev
  6. [ -d /root ] || mkdir -m 0700 /root
  7. [ -d /sys ] || mkdir /sys
  8. [ -d /proc ] || mkdir /proc
  9. [ -d /tmp ] || mkdir /tmp
  10. mkdir -p /var/lock
  11. mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
  12. mount -t proc -o nodev,noexec,nosuid proc /proc
  13. # Some things don't work properly without /etc/mtab.
  14. ln -sf /proc/mounts /etc/mtab
  15. grep -q '\<quiet\>' /proc/cmdline || echo "Loading, please wait..."
  16. # Note that this only becomes /dev on the real filesystem if udev's scripts
  17. # are used; which they will be, but it's worth pointing out
  18. if ! mount -t devtmpfs -o nosuid,mode=0755 udev /dev; then
  19. echo "W: devtmpfs not available, falling back to tmpfs for /dev"
  20. mount -t tmpfs -o nosuid,mode=0755 udev /dev
  21. [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
  22. [ -e /dev/null ] || mknod /dev/null c 1 3
  23. fi
  24. mkdir /dev/pts
  25. mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
  26. mount -t tmpfs -o "noexec,nosuid,size=10%,mode=0755" tmpfs /run
  27. mkdir -m 0755 /run/initramfs
  28. # Export the dpkg architecture
  29. export DPKG_ARCH=
  30. . /conf/arch.conf
  31. # Set modprobe env
  32. export MODPROBE_OPTIONS="-qb"
  33. # Export relevant variables
  34. export ROOT=
  35. export ROOTDELAY=
  36. export ROOTFLAGS=
  37. export ROOTFSTYPE=
  38. export IP=
  39. export BOOT=
  40. export BOOTIF=
  41. export UBIMTD=
  42. export break=
  43. export init=/sbin/init
  44. export quiet=n
  45. export readonly=y
  46. export rootmnt=/root
  47. export debug=
  48. export panic=
  49. export blacklist=
  50. export resume=
  51. export resume_offset=
  52. export drop_caps=
  53. export fastboot=n
  54. export forcefsck=n
  55. export fsckfix=
  56. export recovery=
  57. # mdadm needs hostname to be set. This has to be done before the udev rules are called!
  58. if [ -f "/etc/hostname" ]; then
  59. /bin/hostname -F /etc/hostname >/dev/null 2>&1
  60. fi
  61. # Bring in the main config
  62. . /conf/initramfs.conf
  63. for conf in conf/conf.d/*; do
  64. [ -f ${conf} ] && . ${conf}
  65. done
  66. . /scripts/functions
  67. # Parse command line options
  68. for x in $(cat /proc/cmdline); do
  69. case $x in
  70. init=*)
  71. init=${x#init=}
  72. ;;
  73. root=*)
  74. ROOT=${x#root=}
  75. if [ -z "${BOOT}" ] && [ "$ROOT" = "/dev/nfs" ]; then
  76. BOOT=nfs
  77. fi
  78. ;;
  79. rootflags=*)
  80. ROOTFLAGS="-o ${x#rootflags=}"
  81. ;;
  82. rootfstype=*)
  83. ROOTFSTYPE="${x#rootfstype=}"
  84. ;;
  85. rootdelay=*)
  86. ROOTDELAY="${x#rootdelay=}"
  87. case ${ROOTDELAY} in
  88. *[![:digit:].]*)
  89. ROOTDELAY=
  90. ;;
  91. esac
  92. ;;
  93. resumedelay=*)
  94. RESUMEDELAY="${x#resumedelay=}"
  95. ;;
  96. loop=*)
  97. LOOP="${x#loop=}"
  98. ;;
  99. loopflags=*)
  100. LOOPFLAGS="-o ${x#loopflags=}"
  101. ;;
  102. loopfstype=*)
  103. LOOPFSTYPE="${x#loopfstype=}"
  104. ;;
  105. cryptopts=*)
  106. cryptopts="${x#cryptopts=}"
  107. ;;
  108. nfsroot=*)
  109. NFSROOT="${x#nfsroot=}"
  110. ;;
  111. netboot=*)
  112. NETBOOT="${x#netboot=}"
  113. ;;
  114. ip=*)
  115. IP="${x#ip=}"
  116. ;;
  117. boot=*)
  118. BOOT=${x#boot=}
  119. ;;
  120. ubi.mtd=*)
  121. UBIMTD=${x#ubi.mtd=}
  122. ;;
  123. resume=*)
  124. RESUME="${x#resume=}"
  125. case $RESUME in
  126. UUID=*)
  127. RESUME="/dev/disk/by-uuid/${RESUME#UUID=}"
  128. esac
  129. ;;
  130. resume_offset=*)
  131. resume_offset="${x#resume_offset=}"
  132. ;;
  133. noresume)
  134. noresume=y
  135. ;;
  136. drop_capabilities=*)
  137. drop_caps="-d ${x#drop_capabilities=}"
  138. ;;
  139. panic=*)
  140. panic="${x#panic=}"
  141. case ${panic} in
  142. *[![:digit:].]*)
  143. panic=
  144. ;;
  145. esac
  146. ;;
  147. quiet)
  148. quiet=y
  149. ;;
  150. ro)
  151. readonly=y
  152. ;;
  153. rw)
  154. readonly=n
  155. ;;
  156. debug)
  157. debug=y
  158. quiet=n
  159. if [ -n "${netconsole}" ]; then
  160. exec >/dev/kmsg 2>&1
  161. else
  162. exec >/run/initramfs/initramfs.debug 2>&1
  163. fi
  164. set -x
  165. ;;
  166. debug=*)
  167. debug=y
  168. quiet=n
  169. set -x
  170. ;;
  171. break=*)
  172. break=${x#break=}
  173. ;;
  174. break)
  175. break=premount
  176. ;;
  177. blacklist=*)
  178. blacklist=${x#blacklist=}
  179. ;;
  180. netconsole=*)
  181. netconsole=${x#netconsole=}
  182. [ "x$debug" = "xy" ] && exec >/dev/kmsg 2>&1
  183. ;;
  184. BOOTIF=*)
  185. BOOTIF=${x#BOOTIF=}
  186. ;;
  187. hwaddr=*)
  188. BOOTIF=${x#hwaddr=}
  189. ;;
  190. fastboot|fsck.mode=skip)
  191. fastboot=y
  192. ;;
  193. forcefsck|fsck.mode=force)
  194. forcefsck=y
  195. ;;
  196. fsckfix|fsck.repair=yes)
  197. fsckfix=y
  198. ;;
  199. fsck.repair=no)
  200. fsckfix=n
  201. ;;
  202. recovery)
  203. recovery=y
  204. ;;
  205. esac
  206. done
  207. # Default to BOOT=local if no boot script defined.
  208. if [ -z "${BOOT}" ]; then
  209. BOOT=local
  210. fi
  211. if [ -n "${noresume}" ]; then
  212. export noresume
  213. unset resume
  214. else
  215. resume=${RESUME:-}
  216. fi
  217. maybe_break top
  218. # export BOOT variable value for compcache,
  219. # so we know if we run from casper
  220. export BOOT
  221. # Don't do log messages here to avoid confusing graphical boots
  222. run_scripts /scripts/init-top
  223. maybe_break modules
  224. [ "$quiet" != "y" ] && log_begin_msg "Loading essential drivers"
  225. [ -n "${netconsole}" ] && modprobe netconsole netconsole="${netconsole}"
  226. load_modules
  227. [ "$quiet" != "y" ] && log_end_msg
  228. maybe_break premount
  229. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
  230. run_scripts /scripts/init-premount
  231. [ "$quiet" != "y" ] && log_end_msg
  232. maybe_break mount
  233. log_begin_msg "Mounting root file system"
  234. # Always load local and nfs (since these might be needed for /etc or
  235. # /usr, irrespective of the boot script used to mount the rootfs).
  236. . /scripts/local
  237. . /scripts/nfs
  238. . /scripts/${BOOT}
  239. parse_numeric ${ROOT}
  240. maybe_break mountroot
  241. mount_top
  242. mount_premount
  243. mountroot
  244. log_end_msg
  245. if read_fstab_entry /usr; then
  246. log_begin_msg "Mounting /usr file system"
  247. mountfs /usr
  248. log_end_msg
  249. fi
  250. # Mount cleanup
  251. mount_bottom
  252. nfs_bottom
  253. local_bottom
  254. maybe_break bottom
  255. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
  256. # We expect udev's init-bottom script to move /dev to ${rootmnt}/dev
  257. run_scripts /scripts/init-bottom
  258. [ "$quiet" != "y" ] && log_end_msg
  259. # Move /run to the root
  260. mount -n -o move /run ${rootmnt}/run
  261. validate_init() {
  262. run-init -n "${rootmnt}" "${1}"
  263. }
  264. # Check init is really there
  265. if ! validate_init "$init"; then
  266. echo "Target filesystem doesn't have requested ${init}."
  267. init=
  268. for inittest in /sbin/init /etc/init /bin/init /bin/sh; do
  269. if validate_init "${inittest}"; then
  270. init="$inittest"
  271. break
  272. fi
  273. done
  274. fi
  275. # No init on rootmount
  276. if ! validate_init "${init}" ; then
  277. panic "No init found. Try passing init= bootarg."
  278. fi
  279. maybe_break init
  280. # don't leak too much of env - some init(8) don't clear it
  281. # (keep init, rootmnt, drop_caps)
  282. unset debug
  283. unset MODPROBE_OPTIONS
  284. unset DPKG_ARCH
  285. unset ROOTFLAGS
  286. unset ROOTFSTYPE
  287. unset ROOTDELAY
  288. unset ROOT
  289. unset IP
  290. unset BOOT
  291. unset BOOTIF
  292. unset UBIMTD
  293. unset blacklist
  294. unset break
  295. unset noresume
  296. unset panic
  297. unset quiet
  298. unset readonly
  299. unset resume
  300. unset resume_offset
  301. unset fastboot
  302. unset forcefsck
  303. unset fsckfix
  304. # Move virtual filesystems over to the real filesystem
  305. mount -n -o move /sys ${rootmnt}/sys
  306. mount -n -o move /proc ${rootmnt}/proc
  307. # Chain to real filesystem
  308. exec run-init ${drop_caps} ${rootmnt} ${init} "$@" ${recovery:+--startup-event=recovery} <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1
  309. echo "Something went badly wrong in the initramfs."
  310. panic "Please file a bug on initramfs-tools."