1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!/bin/ash
# Copyright (c) 2008..2009 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org
#
# Main script for preboot initial ramfs - preloading environment for running
# OpenSLX linux stateless clients version 5.
fetchip () {
# we expect to get an ip address within 10++ seconds
( sleep 10 ; killall udhcpc >/dev/null 2>&1 ) &
for i in 1 2 ; do
udhcpc -f -n -q $vci -s /usr/share/udhcpc/default.script -i $nwif 2>/dev/null
if grep "ip=" /tmp/ipstuff >/dev/null 2>&1 ; then
. /tmp/ipstuff
for ns in $dns ; do
echo "nameserver $ns" >>/etc/resolv.conf
done
# simply add a single dns server for passing via kernel cmdline to stage3
# (quickhack, just the last, list of dns might be better ...)
echo "dnssrv=$ns" >>/tmp/ipstuff
return
else
if [ $i -eq 1 ] ; then
sleep 1
else
dialog --msgbox "Did not get any proper IP configuration: Please check \
that your Ethernet card is supported, the machine is connected to the network \
and a DHCP server is answering your requests." 7 65
ash
echo "o" >/proc/sysrq-trigger
fi
fi
done
}
#############################################################################
# PreBoot init main part
# device files get their own filesystem
devdir="/dev"
mount -n -t tmpfs -o 'size=25%,mode=0755' initramfsdevs ${devdir}
export DEBUGLEVEL=0
# create basic device files an directories in dev
for i in "/dev/mem c 1 1" "/dev/null c 1 3" "/dev/zero c 1 5" \
"/dev/urandom c 1 9" "/dev/kmsg c 1 11" "/dev/tty0 c 4 0" \
"/dev/tty1 c 4 1" "/dev/tty2 c 4 2" "/dev/tty3 c 4 3" \
"/dev/tty4 c 4 4" "/dev/tty5 c 4 5" "/dev/tty6 c 4 6" \
"/dev/tty7 c 4 7" "/dev/tty8 c 4 8" "/dev/tty9 c 4 9" \
"/dev/tty10 c 4 10" "/dev/tty c 5 0" "/dev/console c 5 1" \
"/dev/ptmx c 5 2" "/dev/psaux c 10 1" "/dev/agpgart c 10 175" \
"/dev/fb0 c 29 0" "/dev/bootsplash p" "/dev/xconsole p"; do
mknod $i
done
mkdir -p ${devdir}/pts ${devdir}/shm
export PATH=/bin:/sbin:/usr/bin/:/usr/sbin
# redirect kernel messages to tty10 instead of tty1
getty -i -n -l /bin/cat 38400 tty10 &
setlogcons 10
# initramfs-setup configuration (common settings for all clients using a
# certain InitRamFS generated by slxmkramfs/mkdxsinitrd)
[ -f /etc/initramfs-setup ] && . /etc/initramfs-setup 2>/dev/null
# set a default LAN interface, has to be modified for WLAN or on machines
# with more than one ethernet card built in
nwif="eth0"
# mount the important standard directories
[ ! -f /proc/cpuinfo ] && mount -n -t proc proc /proc
[ ! -d /sys/class ] && mount -n -t sysfs sysfs /sys
# load framebuffer modules if needed
for mod in vesafb fbcon; do
if [ x != x$(find /lib/modules -name ${mod}.ko) ]; then
modprobe $mod || \
dialog --infobox "Module $mod did not load for some reason." 3 65
usleep 1000
fi
done
# give startup information
dialog --infobox "Starting OpenSLX preboot environment ..." 3 65
# load usb keyboard and network adaptor modules
for mod in ${ramfs_nicmods} af_packet unix hid hid-bright usbhid \
uhci-hcd ohci-hcd ; do
if [ x != x$(find /lib/modules -name ${mod}.ko) ]; then
modprobe $mod || \
dialog --infobox "Module $mod did not load for some reason." 3 65
usleep 10000
fi
done
# set the default for boot type and read kernel commandline (for this and
# other options)
export TYPE=fastboot
read KCMDLINE </proc/cmdline
# read the system wide machine-setup and then the kernel commandline
for opts in ${KCMDLINE} ; do
case ${opts} in
debug)
DEBUGLEVEL=1;;
# ... or a specified debug level (will be passed to next stage)
debug=*)
DEBUGLEVEL=${opts#debug=};;
# WLAN ssid (most probably passed that way, unused yet ...)
ssid=*)
SSID=${opts#SSID=};;
# Boot type (fastboot)/directkiosk/cfgkiosk/slxconfig
type=*)
TYPE=${opts#type=};;
esac
done
# start a watchdog to ensure an automated reboot or halt of the machine if the
# preboot init does not succeed (e.g. missing kernel module/firmware for the
# network adaptor)
if [ "${DEBUGLEVEL}" -eq 0 ] ; then
cat<<EOF >/bin/watchdog
#!/bin/ash
echo \$$ > /tmp/watchdogpid
[ ! -f /proc/version ] && mount -n -t proc proc /proc
sleep 120 2>/dev/null
echo "o" >/proc/sysrq-trigger
EOF
chmod u+x /bin/watchdog
watchdog &
else
getty -i -n -l /bin/ash 38400 tty2 &
fi
if [ -n "${SSID}" ] ; then
# WLAN setup will most probably change the network interface name stored in
# nwif (to wlan0 or something like that)
[ $DEBUGLEVEL -gt 0 ] && echo "set essid to ${essid}";
#value of essid unchecked yet
# load network adaptor modules
cd /lib/modules/$(ls /lib/modules/)/kernel/drivers/net/wireless
for mod in $(find . | grep .ko | sed 's,.*/\([^/]*\).ko,\1',); do
echo "Mod:";
echo $mod;
modprobe $mod || echo "module $mod did not load for some reason"
usleep 10000
done
cd /
wlanif=$(iwconfig 2>/dev/null|sed -n "/ESSID:/p"|sed "s/ .*//")
[ $DEBUGLEVEL -gt 0 ] && echo "wlancard recognized as ${wlanif}";
ip link set dev ${wlanif} up
if iwconfig ${wlanif} mode managed essid "${essid}"; then
nwif=${wlanif}
else
error " Unable to configure the WLAN interface."
fi
:
else
# check here for the active Ethernet link
ip link show dev eth1 >/dev/null 2>&1 && \
dialog --msgbox "More than one network interface found. This could cause \
some trouble as their activation and ordering depends on the module load \
order ..." 7 65
fi
# set up loopback networking and power up ethernet
ip link set dev lo up
ip addr add 127.0.0.1/8 dev lo
ip link set dev $nwif up || echo "I did not find any usable network adaptor."
# run udhcpc and start a debug shell if no lease could be obtained
mkdir -p /usr/share/udhcpc
echo -e "#!/bin/ash\nunset infomsg HOME IFS mask lease interface DEBUGLEVEL \
BOOT_IMAGE\nset >/tmp/ipstuff" >/usr/share/udhcpc/default.script
chmod u+x /usr/share/udhcpc/default.script
modprobe -q af_packet
[ -n $vci ] && vci="-V $vci"
fetchip
ip addr add $ip/$(ipcalc -s -p $ip $subnet|sed s/.*=//) dev $nwif
ip route add default via $router
# get the mac address of the boot network adaptor
macaddr=$(ip link show dev $nwif 2>/dev/null | \
sed -n "/ether [0-9e-f]\{2\}:.*/p" | sed -e "s/.*ether //;s/ .*//")
echo "macaddr=$macaddr" >>/etc/initramfs-setup
# at this point a little selection script could be downloaded, which lets the
# user choose what kind of SLX client he wants to get
dialog --infobox "Fetching preboot interactive part and configuration from \
the net ($boot_uri) ..." 4 65
wget -q -O /tmp/preboot.env $boot_uri/bootloader/${preboot_id}.env
mkdir /preboot
tar -xzf /tmp/preboot.env -C /preboot
# start a debug shell if needed, else set quiet kernel parameter
if [ "${DEBUGLEVEL}" -gt 0 ] ; then
echo "Starting shell, leaving it would continue init."
/bin/ash
else
# no debugging output for stage3 run
echo "quiet=quiet" >>/etc/initramfs-setup
fi
# run the preboot interactive part which finally will execute kexec
cd /preboot
exec ./preboot.sh
# we should never return from that one ...
dialog --msgbox "The execution of the main preboot component failed. Please \
check network access of your box. Is $boot_uri reachable!?" 6 65
# ping -c 1 $boot_uri
sleep 20 && echo "o" >/proc/sysrq-trigger
|