3 # T2 SDE: target/share/install/init
4 # Partially based on linuxrc.c, Copyright (C) 2003, 2004 Clifford Wolf and Rene Rebe
5 # Converted from C to shell, heavily cleaned and improved for the T2 SDE by:
6 # (C)2005-2021 Rene Rebe, ExactCODE GmbH; Germany.
8 # Only print important stuff to console
12 if [ ! -e /sbin
/init
]; then
13 echo "Can't find /sbin/init."
17 if [ $exit_linuxrc = 1 ]; then
18 echo "finished. Continuing execution of second stage ..."
19 # we re-use all stage1 stuff, mounts, udev, you name it!
25 # try best match / detected rootfs first, all the others thereafter
26 local filesystems
=`disktype $1 2>/dev/null |
27 sed -e '/file system/!d' -e 's/file system.*//' -e 's/ //g' \
28 -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \
30 sed '1!G ; $p ; h ; d' /proc/filesystems | sed /^nodev/d`
31 for fs
in $filesystems; do
32 mount
-t $fs -o ro
$1 $2 && return
38 *.bz2
) echo bunzip2
;;
49 # the last sed is a uniq
50 images
=`fget $1/ | sed 's/[<>"]/\n/g' | sed -n '/stage2/p' |
53 N; /^\(.*\)\n\1$/ {g; bb
61 images
=`cd /media; ls stage2*.tar*`
66 [ "$images" ] ||
return 1
68 mem
=`sed -n '/MemTotal/{s/.* \([[:digit:]]*\) .*/\1/p}' /proc/meminfo`
69 if [ $mem -le 512000 ]; then
70 echo "Deleting /lib/firmware to save memory"
74 echo "Select a second stage image file:"
77 if [[ "$x" = *ext
* ]]; then
78 [ $mem -gt 384000 ] && default
=$i
80 [ $mem -le 384000 ] && default
=$i
84 [ $mem -le 64000 ] && autoload
=0
85 echo -n "Enter number or image file names (default=$default): "
87 in=; [ $autoload = 0 ] && read in ||
echo
88 [ "$in" ] ||
in=$default
92 if [ "$((i++))" = "$in" ]; then
93 i
=${x%.tar.*} # add base "stage2.tar.*"?
94 if [ "$i" != "stage2" ]; then
95 x
="stage2.${x#stage2*.} $x"
108 url
="http://${url:-server/path}/"
109 echo -en "\nEnter base URL (e.g. $url): "
112 baseurl
="${baseurl:-$url}"
114 select_stage2
"$baseurl" filename
115 if [ -z "$filename" ]; then
116 echo "Failure retrieving the second stage image."
121 export ROCK_INSTALL_SOURCE_URL
=$baseurl
124 echo "Extracting second stage filesystem ..."
125 filter
=`filter_for "$filename"`
127 for f
in $filename; do
129 if ! fget
$url |
$filter |
(cd /; .
tar x
); then
130 echo "ERROR EXTRacting $f."
141 echo "TODO: implement module loading shell"
148 # if no dev, wait for devices to appear, default Linux USB settle delay is 5s
149 local i
=0; local default
=
150 while [ -z "$devicelist" -a $i -le 6 ]; do
151 # with udev the above links are not created yet, so try to find
152 # device based on sysfs
154 for x
in /sys
/block
/*/device
; do
155 [ -e "$x" ] ||
continue
156 x
=${x#/sys/block/}; x
=${x%/device}
157 [[ "$x" = fd
* ]] && continue
158 local dev
=/dev
/$x; [ -L "$dev" ] && dev
=$
(readlink
"$dev")
161 local vendor
="$(cat /sys/block/$x/device/vendor 2>/dev/null)"
162 local model
="$(cat /sys/block/$x/device/model 2>/dev/null)"
165 local devs
=`echo ${dev}*`
167 if [ "$devs" != "$dev" ]; then
169 echo " $dev $vendor $model" # header
174 if [ -z "$parts" -o "$d" != "$dev" ]; then
175 echo " $j. $d${vendor:+ $vendor $model}"
176 devicelist
="$devicelist $d"
177 [ -z "$default" -a "$(< /sys/block/$x/removable)" == 1 ] && default
=$j
183 if [ -z "$devicelist" ]; then
184 echo "Waiting for devices to appear."
191 if [ -z "$devicelist" ]; then
192 echo "No device found."
196 [ "$default" ] || default
=1
197 echo -en "\nEnter number or device file name (default=$default): "
199 in=; [ $autoload = 0 ] && read in ||
echo
200 [ "$in" ] ||
in=$default
201 while [ -z "$device" ]; do
202 [ -z "$in" ] && return
207 for x
in $devicelist; do
208 [ $in = $i ] && device
=$x && break
213 if [ -z "$device" ]; then
214 echo -n "No such device found. Try again (enter=back): "
222 load_ramdisk_file
() {
226 echo -e "\nSelect a device for loading the second stage system from:\n"
229 if [ -z "$devicefile" ]; then
230 echo "No device detected."
234 select_stage2
$devicefile filename
235 if [ -z "$filename" ]; then
236 echo "No image found."
241 echo "Using $devicefile:$filename"
243 mkdir
-p /media || exit_linuxrc
=0
244 trymount
$devicefile /media || exit_linuxrc
=0
246 echo "Extracting second stage filesystem ..."
247 filter
=`filter_for "$filename"`
249 for f
in $filename; do
250 if ! $filter < /media
/$f |
(cd /; .
tar x
); then
251 echo "Error extracting $f."
257 umount
/media || exit_linuxrc
=0
259 export ROCK_INSTALL_SOURCE_DEV
=$devicefile
260 export ROCK_INSTALL_SOURCE_FILE
=$filename
265 echo -ne "\nEnter file name of swap device: "
268 [ "$in" ] && swapon
$in
272 echo -n "Interfaces: "; ls -A /sys
/class
/net
/
274 echo -n "Enter interface name (eth0): "
275 read dev
; [ "$dev" ] || dev
="eth0"
277 echo -n "Enter IP address (auto): "
280 echo -n "Enter default gateway (none): "
282 ipconfig
$ip::$gw:::$dev:none
284 # let the link autoneg.
285 ipconfig
:::::$dev:none
> /dev
/null
2>&1 ; sleep 4
286 echo "Auto configuration via DHCP, BOOTP, RARP ..."
287 ipconfig
-d $dev -t 10
293 for i
in $
(echo "$1" |
sed 's/\(..\)\(..\)\(..\)\(..\)/\4 \3 \2 \1/'); do
294 # pre- or append based on endianness
295 [ "$2" ] && ip
="$((16#$i)).$ip" || ip
="$ip$((16#$i))."
303 while read if dst gw _ _ _ _ mask _
; do
304 [ "$dst" = "00000000" ] && gateway
=$gw
305 [[ $mask = FF
*00 ]] && endian
=big
# guess little vs. big from mask
306 done < /proc
/net
/route
308 [ "$gateway" ] && hex_to_ip
"$gateway" "$endian"
312 echo "Exit the shell to return to the 1st stage loader."
316 load_modules_disk
() {
319 trymount
/dev
/floppy
/0 /mnt_floppy
320 load_modules
/mnt_floppy
326 # try to auto-load from a disc, first
330 T2 SDE installer (1st stage - loader) ...
332 The T2 install system boots up in two stages. You are now in the first stage
333 and if everything goes right, you will not spend much time here. Just
334 configure the installation source so the second stage boot system can be
335 loaded and you can start the installation."
337 while [ $exit_init = 0 ]; do
339 0. Load second stage system from local device
340 1. Load second stage system from network
341 2. Configure network interfaces
342 3. Load kernel modules from this disk
343 4. Load kernel modules from another disk
344 5. Activate already formatted swap device
345 6. Run shell (for experts!)
347 What do you want to do [0-8] (default=0)? "
349 in=; [ $autoload = 0 ] && read in ||
echo
352 0) load_ramdisk_file
;;
356 4) load_modules_disk
;;
359 *) echo "No such option." ;;
361 # only try autoload once
365 exec /sbin
/init
/sbin
/init
367 echo -e "\nPanic: Can't start /sbin/init!\n\n"