OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
3.9 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: target/early/initramfs/init.sh
  6. # Copyright (C) 2007 - 2011 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. export PATH=/usr/bin:/usr/sbin:/bin:/sbin
  16. modules=
  17. root=
  18. mode=
  19. init=/sbin/init
  20. NOCOLOR=
  21. initargs="$*"
  22. want_mdadm=
  23. want_lvm=
  24. want_shell=
  25. # read kernel arguments
  26. [ -e /proc/cmdline ] || mount -n -t proc none /proc
  27. set -- $( cat /proc/cmdline )
  28. for x; do
  29. v="${x#*=}"
  30. case "$x" in
  31. root=*) root="$v" ;;
  32. init=*) init="$v" ;;
  33. rw|ro) mode="$x" ;;
  34. modules=*) modules=$( echo "$v" | tr ',' ' ' ) ;;
  35. nocolor) export NOCOLOR=yes ;;
  36. initrdopt=*) for y in $( echo "$v" | tr ',' ' ' ); do
  37. case "$y" in
  38. mdadm) want_mdadm=yes ;;
  39. mdadm=*) want_mdadm="${y#mdadm=}" ;;
  40. lvm) want_lvm=yes ;;
  41. lvm=*) want_lvm="${y#lvm=}" ;;
  42. shell) want_shell=yes ;;
  43. shell=*) want_shell="${y#shell=}" ;;
  44. esac
  45. done
  46. ;;
  47. esac
  48. done
  49. . /etc/rc.d/functions.in
  50. banner "Starting Early User Space environment"
  51. title "Mounting /proc and /sys"
  52. check mount -n -t sysfs none /sys
  53. status
  54. [ -x /bin/dmesg ] && /bin/dmesg -n 3
  55. if grep -q devtmpfs /proc/filesystems; then
  56. title "Preparing /dev (devtmpfs)"
  57. check mount -n -t devtmpfs devtmpfs /dev
  58. status
  59. else
  60. title "Preparing /dev (tmpfs)"
  61. check mount -n -t tmpfs none /dev
  62. status
  63. title "Populating initial device nodes"
  64. check mdev -s
  65. status
  66. fi
  67. title "Setting mdev as kernel hotplug helper"
  68. echo "/sbin/mdev" > /proc/sys/kernel/hotplug
  69. status
  70. if [ -x /sbin/modprobe -a -n "$modules" ]; then
  71. title "Preloading requested kernel modules"
  72. for x in $modules; do
  73. echo -n " $x"
  74. check modprobe -q $x
  75. done
  76. status
  77. fi
  78. title "Triggering coldplug"
  79. find /sys/devices -name "uevent" | while read x; do echo -n "add" > $x; done
  80. status
  81. sleep 2
  82. [ -n "$root" ] || echo "No root device defined."
  83. if [ ! -e "$root" ]; then
  84. if [ "$want_mdadm" = yes ]; then
  85. title "Detecting possible RAID devices"
  86. check mdadm -E --scan > /etc/mdadm.conf
  87. status
  88. fi
  89. if [ "$want_mdadm" != no -a -s /etc/mdadm.conf ]; then
  90. # try activating software raids
  91. title "Activating RAID devices"
  92. modprobe -q md-mod 2> /dev/null
  93. check mdadm -As --auto=yes
  94. status
  95. fi
  96. fi
  97. if [ ! -e "$root" ]; then
  98. if [ "$want_lvm" = yes ]; then
  99. title "Detecting possible LVM devices"
  100. check lvm vgscan
  101. status
  102. fi
  103. if [ "$want_lvm" != no -a -d /etc/lvm/archive ]; then
  104. title "Activating LVM devices"
  105. modprobe -q dm_mod 2> /dev/null
  106. check lvm vgchange -ay
  107. status
  108. fi
  109. fi
  110. if [ -n "$root" ]; then
  111. # give it a second chance to appear (delay 2s)
  112. [ -e "$root" ] || sleep 2;
  113. if [ -e "$root" ]; then
  114. # store detected root filesystem in ROOT_FS_TYPE
  115. eval ROOT_FS_$(blkid $root | cut -d ' ' -f3)
  116. title "Mounting $root (${ROOT_FS_TYPE:-unknown}) "
  117. [ -z "$ROOT_FS_TYPE" ] || modprobe -q "$ROOT_FS_TYPE" 2> /dev/null
  118. check mount ${ROOT_FS_TYPE:+-t $ROOT_FS_TYPE} ${mode:+-o $mode} "$root" /rootfs
  119. status
  120. else
  121. echo "root device ($root) not found on time."
  122. fi
  123. fi
  124. # wait for /sbin/init
  125. while [ ! -x "/rootfs$init" ]; do
  126. # one shell is enough
  127. want_shell=no
  128. echo "Please mount root device on /rootfs and exit to continue"
  129. setsid /bin/sh < /dev/console > /dev/console 2> /dev/console
  130. done
  131. if [ "$want_shell" = yes ]; then
  132. echo "A last-minute shell was requested, please exit to continue"
  133. setsid /bin/sh < /dev/console > /dev/console 2> /dev/console
  134. fi
  135. title "Cleaning up"
  136. check mount -t none -o move /dev /rootfs/dev
  137. check mount -t none -o move /sys /rootfs/sys
  138. check mount -t none -o move /proc /rootfs/proc
  139. status
  140. exec switch_root /rootfs "$init" $initargs
  141. #FIXME: what if it fails?