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.6 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 - 2008 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 usbfs none /proc/bus/usb
  53. check mount -n -t sysfs none /sys
  54. status
  55. [ -x /bin/dmesg ] && /bin/dmesg -n 3
  56. title "Preparing /dev"
  57. check mount -n -t tmpfs none /dev
  58. check cp -a /lib/udev/devices/* /dev
  59. status
  60. title "Starting udev daemon"
  61. echo "" > /sys/kernel/uevent_helper
  62. check udevd --daemon
  63. status
  64. if [ -x /sbin/modprobe -a -n "$modules" ]; then
  65. title "Preloading requested kernel modules"
  66. for x in $modules; do
  67. echo -n " $x"
  68. check modprobe -q $x
  69. done
  70. status
  71. fi
  72. title "Triggering coldplug"
  73. check udevtrigger
  74. check udevsettle
  75. status
  76. sleep 2
  77. [ -n "$root" ] || echo "No root device defined."
  78. if [ ! -e "$root" ]; then
  79. if [ "$want_mdadm" = yes ]; then
  80. title "Detecting possible RAID devices"
  81. check mdadm -E --scan > /etc/mdadm.conf
  82. status
  83. fi
  84. if [ "$want_mdadm" != no -a -s /etc/mdadm.conf ]; then
  85. # try activating software raids
  86. title "Activating RAID devices"
  87. modprobe -q md-mod
  88. udevsettle
  89. check mdadm -As --auto=yes
  90. status
  91. fi
  92. fi
  93. if [ ! -e "$root" ]; then
  94. if [ "$want_lvm" = yes ]; then
  95. title "Detecting possible LVM devices"
  96. check lvm vgscan
  97. status
  98. fi
  99. if [ "$want_lvm" != no -a -d /etc/lvm/archive ]; then
  100. title "Activating LVM devices"
  101. modprobe -q dm_mod
  102. udevsettle
  103. check lvm vgchange -ay
  104. status
  105. fi
  106. fi
  107. if [ -n "$root" ]; then
  108. udevsettle
  109. # give it a second chance to appear (delay 2s)
  110. [ -e "$root" ] || sleep 2;
  111. if [ -e "$root" ]; then
  112. /lib/udev/vol_id "$root" > /tmp/$$.vol_id
  113. . /tmp/$$.vol_id
  114. rm /tmp/$$.vol_id
  115. title "Mounting $root (${ID_FS_TYPE:-unknown}) "
  116. check mount ${ID_FS_TYPE:+-t $ID_FS_TYPE} ${mode:+-o $mode} "$root" /rootfs
  117. status
  118. else
  119. echo "root device ($root) not found on time."
  120. fi
  121. fi
  122. # wait for /sbin/init
  123. while [ ! -x "/rootfs$init" ]; do
  124. # one shell is enough
  125. want_shell=no
  126. echo -e "\nPlease mount root device on /rootfs and exit to continue."
  127. /sbin/getsh
  128. done
  129. if [ "$want_shell" = yes ]; then
  130. echo -e "\nA last-minute shell was requested, please exit to continue."
  131. /sbin/getsh
  132. fi
  133. title "Cleaning up"
  134. check killall udevd
  135. check mount -t none -o move /dev /rootfs/dev
  136. check mount -t none -o move /sys /rootfs/sys
  137. check mount -t none -o move /proc /rootfs/proc
  138. status
  139. exec switch_root /rootfs "$init" $initargs
  140. #FIXME: what if it fails?