From cec704825e7efa19a18d6b628fdab7ca2025da17 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 11 Mar 2013 12:44:31 +0100 Subject: new setup_core script, builds the stage3.1 rootfs on the remote system, instead of the server --- remote/core/data/init | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100755 remote/core/data/init (limited to 'remote/core/data/init') diff --git a/remote/core/data/init b/remote/core/data/init new file mode 100755 index 00000000..510a17e3 --- /dev/null +++ b/remote/core/data/init @@ -0,0 +1,153 @@ +#!/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 +############################################################################# + +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/openslx/bin:/openslx/sbin +export LD_LIBRARY_PATH=/usr/lib64 + +mount -n -t tmpfs -o 'mode=755' run "/run" + +# mount the important standard directories +[ ! -f /proc/cpuinfo ] && mount -n -t proc proc /proc +[ ! -d /sys/class ] && mount -n -t sysfs sysfs /sys + +echo "/sbin/mdev" > /proc/sys/kernel/hotplug +# read graphic and network adaptor configuration (without proprietary drivers yet) + +( hwinfo --gfxcard > /etc/hwinfo ) & +( hwinfo --netcard > /etc/netcard ) & + +# read kernel command line for debugging switch +read KCL < /proc/cmdline +export KCL +for opts in ${KCL}; do + case ${opts} in + debug=*) + DEBUG=1;; + ip=*) + # process IP info + ipinfo=${opts#ip=};; + nfs=*) + nfs=${opts#nfs=} + nfspath=${nfs#*:} + nfsserver=${nfs%:/*} + ;; + esac +done + +while ps | grep -v grep | grep -q " hwinfo --gfxcard" ; do usleep 10 ; done + +case $(cat /etc/hwinfo) in + *i915*) + modprobe -a i915 2>/dev/null + ;; + *intel*|*Intel*) + modprobe -a i810 i830 i915 2>/dev/null + ;; + *nvidia*|*NVidia*|*nouveau*) + modprobe -q nouveau 2>/dev/null + ;; + *radeon*|*Radeon*) + modprobe -q radeon 2>/dev/null + ;; + *mga*|*matrox*|*Matrox*) + modprobe -q mga 2>/dev/null + ;; + *VMWARE*) + ;; + *) + modprobe -qa r128 savage sis tdfx ttm via viafb + ;; +esac +( modprobe -a drm fbcon; mdev -s ) & + +# load required network and usb controller drivers, filter out wireless adaptors +while ps | grep -v grep | grep -q " hwinfo --netcard" ; do usleep 10 ; done +nwcardlist="forcedeth|e1000e|e1000|e100|tg3|via-rhine|r8169|pcnet32" +echo "modprobe -qa usbhid hid-bright" >/etc/modprobe.base +grep modprobe /etc/netcard | grep -E "$nwcardlist" \ + | sed 's/.* Cmd: "//;s/"//;s/modprobe/modprobe -qb/' \ + | sort -u >>/etc/modprobe.base +# virtio hack +if [ $(grep -ic "virtio_pci" /etc/modprobe.base) -ge 1 ]; then + echo "modprobe -q virtio_net" >>/etc/modprobe.base +fi +/bin/sh /etc/modprobe.base; mdev -s + +# setup network +nwif="eth0" +# set up loopback networking +[ $DEBUGLEVEL -eq 20 ] && echo "** starting ip config at $(sysup)" +ip link set dev lo up 2>/dev/null +ip addr add 127.0.0.1/8 dev lo 2>/dev/null +ip link set dev $nwif up 2>/dev/null || { echo "No link for $nwif, dropping to shell.."; setsid sh -c 'exec sh /dev/tty1 2>&1'; } + +# analyze ip information from the kernel command line and put parts +# of it into several variables +if [ -n "$ipinfo" ] ; then + getip () { + local val="$ipinfo:"; i=$(($1 - 1)); + while [ $i -gt 0 ] ; do + val=${val#*:} ; i=$(($i - 1)); + done; + echo $val|sed "s/:.*//"; } + clientip=$(getip 1) + serverip=$(getip 2) + gateway=$(getip 3) + subnet_mask=$(getip 4) + broadcast_address=$(ipcalc -s -b $clientip $subnet_mask|sed s/.*=//) + [ -z "$broadcast_address" ] && broadcast_address=255.255.255.255 + # we might have an idea of the dns server via preboot + dns_srv=$(getip 5) + [ -n "$dns_srv" ] && echo nameserver $dns_srv >/etc/resolv.conf; + echo -e "# ip configuration written by $0 script:\nclientip=$clientip\n\ +subnet_mask=$subnet_mask\ngateway=$gateway\nserverip=$serverip\n\ +broadcast_address=$broadcast_address" >>/etc/initramfs-setup + # set static ip address + ip addr add $clientip/$(ipcalc -s -p $clientip $subnet_mask|sed s/.*=//) \ + broadcast $broadcast_address dev $nwif 2>/dev/null + ip route add default via $gateway 2>/dev/null +else + noipyet="yes" +fi + + +# load local file systems +modprobe aufs +modprobe squashfs + +mkdir -p /dev/shm/union /dev/shm/uniontmp /rorootfs +mount -n -t tmpfs none /dev/shm/uniontmp + +if [ -n "$nfs" ] ; then + mount -t nfs -o ro,async,nolock ${nfsserver}:${nfspath} /rorootfs || { echo "Problem mounting NFS-Directory from ${nfsserver}:${nfspath}. Dropping to DEBUG shell."; DEBUG=1; } +else + mount -n /mnt/openslx.sqfs /rorootfs || { echo "Problem mounting Squashfs. Dropping to DEBUG shell."; DEBUG=1; } +fi + +mount -n -t aufs -o br:/dev/shm/uniontmp:/rorootfs=ro none /mnt +mkdir -p /mnt/uniontmp /mnt/tmp +mount -n --move /dev/shm/uniontmp /mnt/uniontmp + +if [ $DEBUG -ge 1 ]; then + echo "Starting debug shell, CTRL + D will start Stage 3.2." + setsid sh -c 'exec sh /dev/tty1 2>&1' +fi + +for mnt in proc sys run ; do + umount -n $mnt +done + +unset BOOT_IMAGE initrd +# new style of pivoting (switch_root or run-init) +exec /sbin/switch_root -c /dev/console /mnt /usr/lib/systemd/systemd -- cgit v1.2.3-55-g7522