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.

398 lines
8.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/share/install/init
  6. # Copyright (C) 2006 The OpenSDE Project
  7. # Copyright (C) 2006 The T2 SDE Project
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. # partly based on linuxrc.c, Copyright (C) 2003, 2004 Cliford Wolf and Rene Rebe
  17. # converted from C to shell code and heavily cleaned and improved for the T2 SDE
  18. echo "OpenSDE early userspace ..."
  19. PATH=/sbin:/bin:/usr/bin:/usr/sbin
  20. echo "Mounting /dev, /proc and /sys ..."
  21. mount -t tmpfs none /dev
  22. mount -t proc none /proc
  23. mount -t usbfs none /proc/bus/usb
  24. mount -t sysfs none /sys
  25. ln -s /proc/self/fd /dev/fd
  26. echo "Populating /dev (u/dev) ..."
  27. udevd --daemon
  28. udevtrigger
  29. if [ ! -f /dev/console ]; then
  30. mknod /dev/console c 5 1
  31. mknod /dev/null c 1 3
  32. mknod /dev/zero c 1 5
  33. fi
  34. echo "Running hotplug++ hardware detection ..."
  35. /sbin/hotplug++ -synth
  36. echo "/sbin/hotplug++" > /proc/sys/kernel/hotplug
  37. echo "Loading additional subsystem and filesystem driver ..."
  38. # hack to be removed
  39. modprobe sbp2
  40. # well some hardcoded help for now ...
  41. modprobe ide-generic
  42. modprobe ide-disk
  43. modprobe ide-cd
  44. modprobe sd_mod
  45. modprobe sr_mod
  46. modprobe sg
  47. # the modular filesystems ...
  48. for x in /lib/modules/*/kernel/fs/{*/,}*.*o ; do
  49. x=${x##*/} ; x=${x%.*o}
  50. modprobe $x
  51. done
  52. # Only print important stuff to console
  53. # klogctl(8, NULL, 3);
  54. doboot()
  55. {
  56. if [ ! -e /mnt_root/sbin/init ]; then
  57. echo "Can't find /mnt_root/sbin/init."
  58. exit_linuxrc=0
  59. fi
  60. if [ $exit_linuxrc = 1 ]; then
  61. mount /dev /mnt_root/dev -t none -o move
  62. mount /proc /mnt_root/proc -t none -o move
  63. mount /sys /mnt_root/sys -t none -o move
  64. if [ ! -f /mnt_root/dev/console ]; then
  65. mknod /mnt_root/dev/console c 5 1
  66. mknod /mnt_root/dev/null c 1 3
  67. mknod /mnt_root/dev/zero c 1 5
  68. fi
  69. # copy stuff only in the 1st_stage image
  70. mkdir -p /mnt_root/lib/modules
  71. cp -ar /lib/modules/* /mnt_root/lib/modules/
  72. # TODO: inject more first stage stuff if it was a small image
  73. # Before we switch to the real root we have to kill
  74. # the udevd we started in early userspace
  75. ls -1l /mnt_root/proc/*/exe 2> /dev/null | \
  76. sed -n -e "s,.*/proc/\([0-9]*\)/.*udevd.*,kill \1,p" | \
  77. /bin/sh
  78. exec switch_root /mnt_root /sbin/init
  79. else
  80. umount /mnt_root
  81. rmdir /mnt_root
  82. fi
  83. }
  84. trymount()
  85. {
  86. for fs in iso9660 ext3 ext2 minix vfat; do
  87. mount $1 $2 -t $fs -o ro && return
  88. done
  89. }
  90. select_2nd_stage()
  91. {
  92. # choices
  93. case $1 in
  94. http://*|ftp://*)
  95. # the last sed is a uniq
  96. images=`fget $1/ | sed 's/[<>"]/\n/g' | sed -n '/2nd_stage/p' |
  97. sed 'h;:b
  98. $b
  99. N; /^\(.*\)\n\1$/ {g; bb
  100. }
  101. $b
  102. P; D'`
  103. ;;
  104. *)
  105. mkdir /mnt_source
  106. trymount $1 /mnt_source
  107. images=`cd /mnt_source ; ls 2nd_stage*.tar*`
  108. umount /mnt_source; rmdir /mnt_source
  109. ;;
  110. esac
  111. [ "$images" ] || return 1
  112. echo "Select a second stage image file:"
  113. mem=`sed -n '/MemTotal/{s/.* \([[:digit:]]*\) .*/\1/p}' /proc/meminfo`
  114. i=1; default=$i
  115. for x in $images; do
  116. if [[ "$x" = *small* ]]; then
  117. [ $mem -le 96000 ] && default=$i
  118. else
  119. [ $mem -gt 96000 ] && default=$i
  120. fi
  121. echo " $(( i++ )). $x"
  122. done
  123. echo -n "Enter number or image file name (default=$default): "
  124. in=; [ $autoload = 0 ] && read in || echo
  125. [ "$in" ] || in=$default
  126. i=1
  127. for x in $images; do
  128. if [ "$(( i++ ))" = $in ]; then
  129. eval $2=$x
  130. return
  131. fi
  132. done
  133. }
  134. httpload()
  135. {
  136. baseurl=
  137. filename=
  138. url=
  139. echo -en "\nEnter base URL (e.g. http://1.2.3.4/t2): "
  140. read baseurl
  141. [ "$baseurl" ] || return
  142. select_2nd_stage "$baseurl" filename
  143. if [ -z "$filename" ]; then
  144. echo "Failure retrieving the second stage image."
  145. return
  146. fi
  147. exit_init=1
  148. url=$baseurl/$filename
  149. echo -e "[ $url ]\n"
  150. export ROCK_INSTALL_SOURCE_URL=$baseurl
  151. exit_linuxrc=1
  152. mkdir /mnt_root || exit_linuxrc=0
  153. mount none /mnt_root -t tmpfs || exit_linuxrc=0
  154. fget $url | ( cd /mnt_root; tar x ) # -z
  155. echo "finished ... continuing execution of second stage"
  156. doboot
  157. }
  158. load_modules()
  159. {
  160. echo "TODO: implement module loading shell"
  161. }
  162. getdevice()
  163. {
  164. device=
  165. devicelist=`ls /dev/cdrom* /dev/floppy* 2>/dev/null`
  166. # FIXME review and cleanup needed:
  167. if [ -z "$devicelist" ]; then
  168. # with udev, these links are not created yet, so try to find
  169. # device based on sysfs
  170. for sysname in /sys/*/*/removable; do
  171. [ `cat $sysname` = 1 ] || continue
  172. devname="`echo $sysname | sed -e 's,/removable,,' -e 's,.*/,,'`"
  173. # FIXME as udev is not running yet we are probably save
  174. # to assume that /dev/$devname exists, a check should be
  175. # performed however
  176. devicelist="$devicelist /dev/$devname"
  177. done
  178. if [ -z "$devicelist" ]; then
  179. echo "No device found."
  180. return
  181. fi
  182. fi
  183. i=1
  184. default=
  185. for dev in $devicelist ; do
  186. x=`readlink $dev`; [ "$x" ] && [[ "$x" != /dev/* ]] && x=/dev/$x
  187. [ "$x" ] && dev=$x
  188. case $dev in
  189. /dev/floppy*|/dev/fd*)
  190. echo " $i. $dev Floppy Disk Drive" ;;
  191. *)
  192. model=`cat /proc/ide/${dev#/dev/}/model 2>/dev/null`
  193. [ "$model" ] || model="SCSI or ATAPI CD-ROM"
  194. echo " $i. $dev $model"
  195. [ "$default" ] || default=$i
  196. ;;
  197. esac
  198. : $(( i++ ))
  199. done
  200. [ "$default" ] || default=1
  201. echo -en "\nEnter number or device file name (default=$default): "
  202. in=; [ $autoload = 0 ] && read in || echo
  203. [ "$in" ] || in=$default
  204. while [ -z "$device" ]; do
  205. [ -z "$in" ] && return
  206. if [ -e $in ]; then
  207. device=$in
  208. else
  209. i=1
  210. for x in $devicelist; do
  211. [ $in = $i ] && device=$x
  212. : $(( i++ ))
  213. done
  214. fi
  215. if [ -z "$device" ]; then
  216. echo -n "No such device found. Try again (enter=back): "
  217. read in
  218. fi
  219. done
  220. eval $1=$device
  221. }
  222. load_ramdisk_file()
  223. {
  224. devicefile=
  225. filename=
  226. echo -e "\nSelect a device for loading the second stage system from:\n"
  227. getdevice devicefile
  228. if [ -z "$devicefile" ]; then
  229. echo "No device detected."
  230. return
  231. fi
  232. select_2nd_stage $devicefile filename
  233. if [ -z "$filename" ]; then
  234. echo "No image found."
  235. return
  236. fi
  237. exit_linuxrc=1
  238. echo "Using $devicefile:$filename"
  239. mkdir /mnt_source || exit_linuxrc=0
  240. trymount $devicefile /mnt_source || exit_linuxrc=0
  241. mkdir /mnt_root || exit_linuxrc=0
  242. mount none /mnt_root -t tmpfs || exit_linuxrc=0
  243. echo "Extracting second stage filesystem ..."
  244. cat /mnt_source/$filename | ( cd /mnt_root; tar x ) || # -z
  245. echo "Can't run tar on $fielname."
  246. umount /mnt_source || exit_linuxrc=0
  247. rmdir /mnt_source || exit_linuxrc=0
  248. export ROCK_INSTALL_SOURCE_DEV=$devicefile
  249. export ROCK_INSTALL_SOURCE_FILE=$filename
  250. doboot
  251. }
  252. activate_swap()
  253. {
  254. echo -ne "\nEnter file name of swap device: "
  255. read in
  256. [ "$in" ] && swapon $in
  257. }
  258. net_config()
  259. {
  260. echo -n "Interfaces: "; ls -A /sys/class/net/
  261. echo -n "Enter interface name (eth0): "
  262. read dev ; [ "$dev" ] || dev="eth0"
  263. echo -n "Enter IP address (auto): "
  264. read ip
  265. if [ "$ip" ]; then
  266. echo -n "Enter default gateway (none): "
  267. read gw
  268. ipconfig $ip::$gw:::$dev:none
  269. else
  270. # let the link autoneg.
  271. ipconfig :::::$dev:none > /dev/null 2>&1 ; sleep 4
  272. echo "Auto configuration via DHCP, BOOTP, RARP ..."
  273. ipconfig -d $dev -t 10
  274. fi
  275. }
  276. exec_sh()
  277. {
  278. echo "Exit the shell to return to the 1st stage loader."
  279. sh
  280. }
  281. load_modules_disk ()
  282. {
  283. mkdir /mnt_floppy
  284. trymount /dev/floppy/0 /mnt_floppy
  285. load_modules /mnt_floppy
  286. umount /mnt_floppy
  287. rmdir /mnt_floppy
  288. }
  289. # try to auto-load from a disc, first
  290. autoload=1
  291. echo "
  292. OpenSDE installer (1st stage - loader) ...
  293. The OpenSDE install system boots up in two stages. You are now in the first
  294. stage and if everything goes right, you will not spend much time here.
  295. Just configure the installation source so the second stage boot system can
  296. be loaded and you can start the installation."
  297. exit_init=0
  298. while [ $exit_init = 0 ]; do
  299. echo -n "
  300. 0. Load second stage system from local device
  301. 1. Load second stage system from network
  302. 2. Configure network interfaces
  303. 3. Load kernel modules from this disk
  304. 4. Load kernel modules from another disk
  305. 5. Activate already formatted swap device
  306. 6. Run shell (for experts!)
  307. What do you want to do [0-8] (default=0)? "
  308. in=; [ $autoload = 0 ] && read in || echo
  309. [ "$in" ] || in=0
  310. case $in in
  311. 0) load_ramdisk_file ;;
  312. 1) httpload ;;
  313. 2) net_config ;;
  314. 3) load_modules ;;
  315. 4) load_modules_disk ;;
  316. 5) activate_swap ;;
  317. 6) exec_sh ;;
  318. *) echo "No such option." ;;
  319. esac
  320. # only try autoload once
  321. autoload=0
  322. done
  323. exec /sbin/init /sbin/init
  324. echo -e "\nPanic: Can't start /sbin/init!\n\n"