summaryrefslogtreecommitdiffstats
path: root/core/rootfs/rootfs-stage31/data/inc/setup_stage4
blob: a00117f2c914c5c49f87f920f57df3c27e6597c6 (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
#!/bin/ash

[ -z "${SLX_STAGE4}" ] && { echo "SLX_STAGE4 is not set in /opt/openslx/config." && exit 1; }

MOUNTPOINT="/rorootfs/"
mkdir -p "$MOUNTPOINT"


# first load module
insmod /lib/modules/dnbd3/dnbd3.ko

# dnbd3 it is
if [ -z "${SLX_DNBD3_SERVERS}${SLX_DNBD3_PRIO_SERVERS}" ]; then
	slxlog --echo "mount-stage4" "dnbd3 stage4 configured, but SLX_DNBD3(_PRIO)_SERVERS empty or not set in /opt/openslx/config."
	exit 1
fi
# Determine revision
if [ -z "$SLX_STAGE4_RID" ] || echo "$SLX_STAGE4_RID" | grep -v -q -E "^[0-9]+$"; then
	SLX_STAGE4_RID="0"
fi
# Randomize list
SERVERS=$(for SERVER in $SLX_DNBD3_SERVERS; do echo "$RANDOM $SERVER"; done | sort -u | sed -r 's/^[0-9]+ //')
IMAGE=$(echo $SLX_STAGE4 | awk '{printf $2}')
[ -e /var/run/dnbd3.socket ] || sleep 2 # Ugly, service should only start when dnbd3 daemon is up and running
RET=1337
for SRV in $SLX_DNBD3_PRIO_SERVERS $SERVERS; do
	echo "Requesting $IMAGE from $SRV"
	dnbd3=$(/opt/openslx/bin/dnbd3-client -h "$SRV" -i "$IMAGE" -r "$SLX_STAGE4_RID" -d /dev/dnbd0)
	RET=$?
	[ "$RET" -eq "0" ] && break
	echo "... didn't work ($RET)"
	sleep 1
done
if [ "$RET" -ne "0" ]; then
	drop_shell "Omg"
	slxlog --echo "mount-stage4" "Could not get stage4 via dnbd3 ($IMAGE : $SLX_STAGE4_RID) ($SLX_DNBD3_PRIO_SERVERS / $SERVERS)"
	exit $RET
fi
echo "Mounting /dev/dnbd0 to $MOUNTPOINT"
if ! busybox mount -t squashfs -o ro /dev/dnbd0 "$MOUNTPOINT"; then
	slxlog --echo "mount-stage4" "Could not mount stage4 from '$dnbd3' to '$MOUNTPOINT' ($SRV, $IMAGE)"
	exit 1
fi

busybox mount -n -t aufs -o "br:${FUTURE_ROOT}:${MOUNTPOINT}=ro" none /mnt || drop_shell "Problem building aufs."
mkdir -p /mnt/opt/openslx/uniontmp /mnt/tmp
FUTURE_ROOT="/mnt"

cp /etc/hostname /etc/hosts   "${FUTURE_ROOT}/etc/"
cp /etc/resolv.conf   "${FUTURE_ROOT}/opt/openslx/"

# if booting with splash, suppress kernel output in stage32
if [ $SPLASH -eq 1 ]; then
        if grep -q -E "^ *kernel.printk" "${FUTURE_ROOT}/usr/lib/sysctl.d/50-default.conf"; then
                sed -i 's/^ *kernel\.printk.*/kernel\.printk = 1 1 0 1/g' "${FUTURE_ROOT}/usr/lib/sysctl.d/50-default.conf"
        else
                echo "kernel.printk = 1 1 0 1" >> "${FUTURE_ROOT}/usr/lib/sysctl.d/50-default.conf"
        fi
fi

# Kinda specific for virtualization environment: Autologin and run VM for benchmarks
if [ -n "$SLX_BENCHMARK_VM" ]; then
        # Enable KDM autologin for demo user
        sed -i 's/^AutoLoginUser=.*//;s/^AutoLoginEnable=.*/AutoLoginEnable=true\nAutoLoginUser=demo/' "${FUTURE_ROOT}/etc/kde4/kdm/kdmrc"
        # Running the VM automatically has to be taken care of by run-virt and vmchooser. SLX_BENCHMARK_VM should contain
        # a numeric value for the index in vmchooser
fi