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.

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