summaryrefslogtreecommitdiffstats
path: root/remote/rootfs/rootfs-stage31/data/init
blob: a4de81317d39f9c21e9384db9b1b30fcc3b780b3 (plain) (blame)
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
#!/bin/ash
# Copyright (c) 2012 - 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
#
# First script for initial ramfs for OpenSLX linux stateless clients
#############################################################################

# set PATH correctly
export PATH=/bin:/sbin:/usr/bin:/usr/sbin

# import common functions
. "/inc/functions"

# mount the important standard directories
[ ! -f /proc/cpuinfo ] && busybox mount -n -t proc proc /proc
bench_event "KERNEL" "Kernel initialized"
[ ! -d /sys/class ] && busybox mount -n -t sysfs sysfs /sys
busybox mount -n -t tmpfs -o 'mode=755' run "/run"

# preparations for mounting stage3.2
FUTURE_ROOT="/dev/shm/uniontmp"
mkdir -p "$FUTURE_ROOT" /rorootfs
busybox mount -n -t tmpfs -o 'mode=755' none "$FUTURE_ROOT"
mkdir -p "$FUTURE_ROOT/opt/openslx"

# let kernel know that mdev is to be used for hotplug
echo "/sbin/mdev" > /proc/sys/kernel/hotplug

# read kernel command line for debugging switch
DEBUG=0
SPLASH=0
read KCL < "/proc/cmdline"
for opts in ${KCL}; do
	case "${opts}" in
		debug=*)
			DEBUG=${opts#debug=} ;;
		ip=*)
			# process IP info
			IPINFO=${opts#ip=} ;;
		nfs=*)
			NFS=${opts#nfs=}
			NFSPATH=${NFS#*:}
			NFSSERVER=${NFS%:/*}
			;;
		BOOTIF=*)
			MAC="$( echo "$opts" | cut -b 11- | tr '-' ':' | tr '[A-Z]' '[a-z]' )" ;; # make mac lowercase for udev (see setup_network)
		splash*)
			[ -e "/etc/splash.ppm" ] && SPLASH=1
	esac
done

. "/inc/drm.functions"

if [ "$SPLASH" -eq 1 ]; then
	if setup_gfx; then
		echo "1 1 0 1" > /proc/sys/kernel/printk
		exec 4>&1 5>&2 > /dev/null 2>&1
		MUTED_OUTPUT=1
		setsid fbsplash -x -c -s /etc/splash.ppm &
	fi
else
	setup_gfx
fi


# discover devices
mdev -s
bench_event "MDEV" "mdev done"

# suppress kernel output if neither DEBUG nor SPLASH is set
if [ $SPLASH -eq 0 ]; then
	[ $DEBUG -ge 1 ] && echo "4 4 1 7" > /proc/sys/kernel/printk || echo "1 1 0 1" >/proc/sys/kernel/printk
fi

[ $DEBUG -ge 4 ] && drop_shell "Requested Debug Shell: before network."

. "/inc/setup_network" || . "/inc/setup_network_retry" || drop_shell "Error setting up network"
bench_event "NETWORK" "Network up and running"

[ $DEBUG -ge 3 ] && drop_shell "Requested Debug Shell: after network/before configuring."

. "/inc/activate_sysconfig" || drop_shell "Could not source /inc/activate_sysconfig"
bench_event "CONFIG" "Downloaded config"
# From here on, we have all the vars from /opt/openslx/config

[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after configuration/before stage32."

. "/inc/setup_stage32" || drop_shell "Problem setting up stage3.2"
bench_event "STAGE32" "Downloaded stage 3.2"

# copy files needed for stage3.2 to FUTURE_ROOT
echo "Copying busybox etc. to stage32..."
tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" "/inc/functions" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/"

# set the SLX_ROOT_PASS if given in config
if [ ! -z "$SLX_ROOT_PASS" ]; then
	sed -i "s#^root:[^:]*:#root:$SLX_ROOT_PASS:#" "${FUTURE_ROOT}/etc/shadow"
fi

# one last debug shell if activated
[ $DEBUG -ge 1 ] && drop_shell "Requested Debug Shell: before switch_root."

# need /proc for this ;)
bench_event "PRESWITCH" "Switching to stage 3.2"

# unmount filesystems
for mnt in proc sys run ; do
	busybox umount -f -l "/$mnt" 2>/dev/null
done

# make sure the splash screen is restarted in stage32
if [ "$SPLASH" -eq 1 ]; then
	ln -s "../fbsplash.service" "${FUTURE_ROOT}/etc/systemd/system/sysinit.target.wants/fbsplash.service"
	killall fbsplash
fi

echo "Switching root...."
echo "$bench_result" > "${FUTURE_ROOT}/opt/openslx/.benchmark"
# Prepare environment (HOME is needed as a hack for nss_ldap with ssl and no caching)
unset BOOT_IMAGE initrd KCL ip slxbase slxsrv IPINFO vga ip MAC BOOTIF DEBUG OLDPWD MUTED_OUTPUT
export HOME=/
export init="/usr/lib/systemd/systemd"
export recovery=
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/openslx/usr/sbin:/opt/openslx/usr/bin:/opt/openslx/sbin:/opt/openslx/bin"
exec /sbin/switch_root -c /dev/console /mnt /usr/lib/systemd/systemd