summaryrefslogtreecommitdiffstats
path: root/remote/rootfs/rootfs-stage31/data/init
blob: 586b21df0c3ee5101460b2458fc575cdb44ed323 (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
134
135
136
137
#!/bin/sh
# 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
#############################################################################

# debug shell
drop_shell() {
	[ $# -gt 0 ] && echo $@
	echo "CTRL + D will continue booting."
	setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'
}

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

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

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

# read graphic and network adaptor configuration (without proprietary drivers yet)
# TODO: must ugly hack ever... needs to be improved when we add prop drivers
for DRM in /lib/modules/*/kernel/drivers/gpu/drm/*.ko /lib/modules/*/kernel/drivers/gpu/drm/*/*.ko; do
	DRM="$(basename "$DRM")"
	DRM="${DRM%.ko}"
	echo "Trying to load module $DRM"
	modprobe "$DRM"
done

# discover devices
mdev -s &

# read kernel command line for debugging switch
DEBUG=0
read KCL < /proc/cmdline
export KCL
for opts in ${KCL}; do
	case ${opts} in
		debug=*)
			DEBUG=${opts#debug=} ;;
		splash*)
			SPLASH=1 ;;
		ip=*)
			# process IP info
			export IPINFO=${opts#ip=} ;;
		nfs=*)
			export NFS=${opts#nfs=}
			export NFSPATH=${nfs#*:}
			export NFSSERVER=${nfs%:/*}
			;;
		BOOTIF=*)
			export MAC="$( echo "$opts" | cut -b 11- | tr '-' ':' )" ;;
	esac
done

# suppress kernel output if DEBUG is not set
[ "$DEBUG" -ge 1 ] && echo "0" >/proc/sys/kernel/printk || echo "4 4 1 7" >/proc/sys/kernel/printk

# start plymouth if activated
if [ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ]; then
	echo "Starting plymouth..."
	plymouthd && plymouth show-splash
fi

# preparations for mounting stage3.2
mkdir -p /dev/shm/union /dev/shm/uniontmp /rorootfs
mount -n -t tmpfs none /dev/shm/uniontmp

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

echo "Setup networking..." # Source script so the variables are still available to us
. "/bin/setup_network" || echo "Error setting up network"

# mount rootfs
if [ -n "$NFS" ]; then
	# mount stage32 per NFS if activated
	echo "Mounting stage 3.2 as NFS..."
	mount -t nfs -o ro,async,nolock ${NFSSERVER}:${NFSPATH} /rorootfs || drop_shell "Problem mounting NFS-Directory from ${NFSSERVER}:${NFSPATH}."
else
	# or per squashfs else
	echo "Mounting stage 3.2 as SquashFS..."
	mount -t squashfs /mnt/*.sqfs /rorootfs || drop_shell "Problem mounting Squashfs."
fi
			
[ $DEBUG -ge 3 ] && drop_shell "Requested Debug Shell: squashfs/nfs mounted, before aufs."

echo "Building aufs..."
mv /mnt/modprobing /dev/shm/uniontmp
#mount -t overlayfs -o lowerdir=/rorootfs,upperdir=/dev/shm/uniontmp overlayfs /mnt
mount -n -t aufs -o br:/dev/shm/uniontmp:/rorootfs=ro none /mnt || drop_shell "Problem building aufs."
mkdir -p /mnt/uniontmp /mnt/tmp
mount -n --move /dev/shm/uniontmp /mnt/uniontmp || drop_shell "Problem moving uniontmp."

[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after aufs'ing."

# Download config if available
/mnt/opt/openslx/bin/activate-sysconfig /mnt

# create udev rule for nic we booted from
cat > "/mnt/etc/udev/rules.d/70-net-boot-nic-name.rules" <<HEREEND
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="$MAC", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="br0"
HEREEND

# create ip config
cat >> /mnt/opt/openslx/config <<HEREEND
# IP Config written in stage31
SLX_PXE_CLIENT_IP='$CLIENTIP'
SLX_PXE_SERVER_IP='$SERVERIP'
SLX_PXE_GATEWAY='$GATEWAY'
SLX_PXE_DNS='$DNS_SERVER'
SLX_PXE_MAC='$BRIDGEMAC'
HEREEND

[ $DEBUG -ge 1 ] && drop_shell "Requested Debug Shell: before switch_root."

for mnt in proc sys run ; do
  umount -n "$mnt"
done

echo "Switching root...."
unset BOOT_IMAGE initrd
[ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ] && plymouth update-root-fs --new-root-dir=/mnt
# new style of pivoting (switch_root or run-init)
exec /sbin/switch_root -c /dev/console /mnt /usr/lib/systemd/systemd