diff options
Diffstat (limited to 'remote/rootfs')
| -rwxr-xr-x | remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig | 66 | ||||
| -rwxr-xr-x | remote/rootfs/rootfs-stage31/data/bin/setup_network | 2 | ||||
| -rwxr-xr-x | remote/rootfs/rootfs-stage31/data/bin/setup_stage32 | 47 | ||||
| -rw-r--r-- | remote/rootfs/rootfs-stage31/data/etc/functions | 71 | ||||
| -rwxr-xr-x | remote/rootfs/rootfs-stage31/data/init | 55 |
5 files changed, 140 insertions, 101 deletions
diff --git a/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig b/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig index 0d8d33c4..9c21565a 100755 --- a/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig +++ b/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig @@ -1,40 +1,15 @@ #!/bin/bash -# first a few variables -CONFIG="/mnt/opt/openslx/config" +echo "Configuring stage 3.2 ..." -# parse kernel command line to determine the URL -URL="$(grep -o -E "slxconfig=\S+" /proc/cmdline | cut -c 11-)" -if [ -z "$URL" ]; then - echo "Error - 'slxconfig=' not found in command line, or empty" - exit 1 -fi +# include /etc/functions +. /etc/functions || drop_shell "Could not source /etc/functions." -######################################################################### -# -# Helper function to download given FILE_URL under TARGET_PATH -# -# Usage: -# download $FILE_URL $TARGET_PATH -# -download() { - [ $# -ne 2 ] && echo "Error - 'download' requires 2 arguements, $# given." \ - && exit 1 - - local FILE_URL="$1" - local TARGET_PATH="$2" - - wget -T 5 -q -O "$TARGET_PATH" "$FILE_URL" - RET=$? - if [ "x$RET" != "x0" ]; then - echo "Error - downloading '$FILE_URL' via wget failed. Exit Code: $RET" - exit 1 - else - echo "Successfully downloaded '$FILE_URL'." - fi - - return 0 -} +# first a few variables +CONFIG="${FUTURE_ROOT}/opt/openslx/config" + +# parse kernel command line to determine the base for the URLs +SLX_BASE=$(read_from_cmdline "slxbase") ######################################################################### # @@ -42,9 +17,9 @@ download() { # fetch_sysconfig() { [ -e "$CONFIG" ] && grep '^#_RCONFIG_TAG$' "$CONFIG" > /dev/null \ - && echo "Config already fetched." && exit 0 + && echo "Config already fetched." && return 0 - download "$URL" "$CONFIG-remote" || exit 1 + download "${SLX_BASE}/config" "${CONFIG}-remote" || return 1 echo "# Config fetched from $URL" >> "$CONFIG" echo "#_RCONFIG_TAG" >> "$CONFIG" @@ -55,11 +30,9 @@ fetch_sysconfig() { # This function downloads the config.tgz and unpacks it to $TARGET_PATH # fetch_config_files() { - [ -e "$CONFIG.tgz" ] && echo "config.tgz already downloaded." && exit 0 - download "$URL.tgz" "$CONFIG.tgz" || exit 1 + [ -e "${CONFIG}.tgz" ] && echo "config.tgz already downloaded." && exit 0 - tar xf "$CONFIG.tgz" -C /mnt || { echo "Could not untar $CONFIG.tgz to /mnt"; exit 1; } - exit 0 + download "${SLX_BASE}/config.tgz" "${CONFIG}.tgz" || return 1 } @@ -69,9 +42,8 @@ fetch_config_files() { # received from /bin/setup_network update_sysconfig() { # sanity checks - [ ! -e "$CONFIG" ] && { echo "Cannot update $CONFIG: file does not exist!"; exit 1; } - [ -z "$CLIENTIP" -o -z "$SERVERIP" -o -z "$BRIDGEMAC" -o -z "$GATEWAY" -o -z "$DNS_SERVER" ] \ - && echo "Something seems wrong with the IP information read from /bin/setup_network ... going on." + [ ! -e "${CONFIG}" ] && { echo "Cannot update. '$CONFIG' does not exist."; return 1; } + [ ! -e "${CONFIG}.tgz" ] && { echo "Cannot update. '$CONFIG' does not exist."; return 1; } # write IP configuration to $CONFIG cat >> "$CONFIG" <<HEREEND @@ -84,12 +56,14 @@ SLX_PXE_MAC='$BRIDGEMAC' HEREEND # setup hardware clock - . /mnt/opt/openslx/config + . "${CONFIG}" if [ "x$SLX_BIOS_CLOCK" == "xlocal" ]; then hwclock -s -l elif [ "x$SLX_BIOS_CLOCK" == "xutc" ]; then hwclock -s -u fi + + tar xf "${CONFIG}.tgz" -C "${FUTURE_ROOT}" || { echo "Could not untar ${CONFIG}.tgz to ${FUTURE_ROOT}"; return 1; } } @@ -98,6 +72,6 @@ HEREEND # MAIN PART # -fetch_sysconfig || exit 1 -fetch_config_files || exit 1 -update_sysconfig || exit 1 +fetch_sysconfig +fetch_config_files +update_sysconfig diff --git a/remote/rootfs/rootfs-stage31/data/bin/setup_network b/remote/rootfs/rootfs-stage31/data/bin/setup_network index 93ecd75f..8e070bdf 100755 --- a/remote/rootfs/rootfs-stage31/data/bin/setup_network +++ b/remote/rootfs/rootfs-stage31/data/bin/setup_network @@ -1,5 +1,7 @@ #!/bin/sh +echo "Setting up network..." + echo "Main MAC address is '$MAC'" # setup network diff --git a/remote/rootfs/rootfs-stage31/data/bin/setup_stage32 b/remote/rootfs/rootfs-stage31/data/bin/setup_stage32 new file mode 100755 index 00000000..b6ef2bab --- /dev/null +++ b/remote/rootfs/rootfs-stage31/data/bin/setup_stage32 @@ -0,0 +1,47 @@ +#!/bin/bash +# +# This script sets up the stage 3.2. +# - downloads/mounts stage32.sqfs +# - merge it with current rootfs through aufs +# - will not download, if the "nfs=" is used in the +# kernel command line +# +######################################################################### +# +# first check if an NFS-share was given per command line +# +if [ -n "$NFS" ]; then + 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}." \ + || return 1 + return 0 +fi + +######################################################################### +# +# MAIN PART +# + +echo "Setting up stage 3.2 ..." + +# include /etc/functions +. /etc/functions + +# parse kernel command line to determine the URL of the stage3.2 +SLX_BASE="$(read_from_cmdline "slxbase")" +STAGE32_TARGET_PATH="/stage32.sqfs" +STAGE32_MOUNT_POINT="/rorootfs" + +# try to download it +download "${SLX_BASE}/stage32.sqfs" "$STAGE32_TARGET_PATH" || return 1 + +# try to mount it at STAGE32_MOUNT_POINT +echo "Mounting stage 3.2 as SquashFS..." +mount -t squashfs "$STAGE32_TARGET_PATH" "$STAGE32_MOUNT_POINT" || drop_shell "Problem mounting Squashfs." + +echo "Building aufs ..." +mount -n -t aufs -o "br:${FUTURE_ROOT}:${STAGE32_MOUNT_POINT}=ro" none /mnt || drop_shell "Problem building aufs." +mkdir -p /mnt/opt/openslx/uniontmp /mnt/tmp +mount -n --move "$FUTURE_ROOT" /mnt/opt/openslx/uniontmp || drop_shell "Problem moving uniontmp." +FUTURE_ROOT="/mnt" diff --git a/remote/rootfs/rootfs-stage31/data/etc/functions b/remote/rootfs/rootfs-stage31/data/etc/functions index ff1276a5..5c5ba56c 100644 --- a/remote/rootfs/rootfs-stage31/data/etc/functions +++ b/remote/rootfs/rootfs-stage31/data/etc/functions @@ -18,27 +18,70 @@ drop_shell() { ######################################################################### # -# Helper function to download given FILE_URL under TARGET_PATH +# Helper function to parse parameter named OPTION from the kernel command line (/proc/cmdline) # # Usage: -# download $FILE_URL $TARGET_PATH +# read_from_cmdline OPTION +# +read_from_cmdline(){ + [ $# -ne 1 ] && echo "Error - 'read_from_cmdline' requires 1 argument, $# given." && exit 1 + + local OPTION="$1" + local VALUE="" + + VALUE="$(grep -o -E "${OPTION}=\S+" /proc/cmdline | cut -c $((${#OPTION}+2))-)" + if [ -z "$VALUE" ]; then + echo "Error - '${OPTION}=' not found in command line, or empty" + return 1 + else + echo "$VALUE" + fi +} + +######################################################################### +# +# Helper function to download given FILE_URL from servers in 'slxsrv' +# as given through the kernel command line. File will be saved under TARGET_PATH +# +# Usage: +# download FILE_URL TARGET_PATH +# +# Example: +# download "config" "/opt/openslx/config" +# +# Note: +# FILE_URL can have subpath, e.g. "ubuntu-13.04-x64/config" # download() { - [ $# -ne 2 ] && echo "Error - 'download' requires 2 arguements, $# given." \ - && exit 1 + [ $# -ne 2 ] && echo "Error - 'download' requires 2 arguments, $# given." && return 1 + + if [ -e ${FUTURE_ROOT}/opt/openslx/config ]; then + . ${FUTURE_ROOT}/opt/openslx/config || echo "Error - could not source '${FUTURE_ROOT}/opt/openslx/config'" + fi + local SLX_BASE_SERVERS="$(read_from_cmdline "slxsrv" | tr ',' ' ')" local FILE_URL="$1" local TARGET_PATH="$2" - wget -T 5 -q -O "$TARGET_PATH" "$FILE_URL" - RET=$? - if [ "x$RET" != "x0" ]; then - echo "Error - downloading '$FILE_URL' via wget failed. Exit Code: $RET" - exit 1 - else - echo "Successfully downloaded '$FILE_URL'." - fi + for TIMEOUT in 1 2 3 4 5; do + for SERVER in $SLX_BASE_SERVERS $SLX_SERVERS; do + wget -T 5 -q -O "$TARGET_PATH" "http://${SERVER}/${FILE_URL}" + RET=$? + if [ "x$RET" != "x0" ]; then + echo "Error - downloading 'http://$SERVER/$FILE_URL' via wget failed. Exit Code: $RET" + echo "Trying again in $(($TIMEOUT * 500)) ms..." + [ $TIMEOUT -eq 5 ] && drop_shell "Max timeouts reached. Dropping shell..." + usleep $(($TIMEOUT * 500000)) + else + [ $DEBUG -ge 1 ] && echo "Successfully downloaded '$FILE_URL'." + return 0 + fi + done + done - return 0 + # check if it actually worked + if [ ! -e $TARGET_PATH ]; then + echo "Error - $TARGET_PATH does not exists. Downloading '$FILE_URL' from '$SERVER_LIST' failed." + return 1 + fi } - diff --git a/remote/rootfs/rootfs-stage31/data/init b/remote/rootfs/rootfs-stage31/data/init index 8b971081..f0db8730 100755 --- a/remote/rootfs/rootfs-stage31/data/init +++ b/remote/rootfs/rootfs-stage31/data/init @@ -12,17 +12,13 @@ # 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 +# import common functions +. /etc/functions + # mount the important standard directories mount -n -t tmpfs -o 'mode=755' run "/run" [ ! -f /proc/cpuinfo ] && mount -n -t proc proc /proc @@ -81,44 +77,21 @@ if [ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ]; then plymouthd && plymouth show-splash fi +[ $DEBUG -ge 4 ] && drop_shell "Requested Debug Shell: before network." -echo "Copying busybox etc. to stage32..." -tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/" +. "/bin/setup_network" || drop_shell "Error setting up network" -[ $DEBUG -ge 4 ] && drop_shell "Requested Debug Shell (before network)." +[ $DEBUG -ge 3 ] && drop_shell "Requested Debug Shell: after network/before configuring." -echo "Setup networking..." # Source script so the variables are still available to us -. "/bin/setup_network" || drop_shell "Error setting up network" +. "/bin/activate_sysconfig" || drop_shell "Could not source /bin/activate_sysconfig" -# 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..." -#mount -t overlayfs -o lowerdir=/rorootfs,upperdir=/dev/shm/uniontmp overlayfs /mnt -mount -n -t aufs -o "br:${FUTURE_ROOT}:/rorootfs=ro" none /mnt || drop_shell "Problem building aufs." -mkdir -p /mnt/opt/openslx/uniontmp /mnt/tmp -mount -n --move "$FUTURE_ROOT" /mnt/opt/openslx/uniontmp || drop_shell "Problem moving uniontmp." -FUTURE_ROOT="/mnt" - -[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after aufs'ing/before configuring." - -# Download config. Try 5 times with increasing sleeps. -for TIMEOUT in 1 2 3 4 5; do - if [ ! -e /mnt/opt/openslx/config ]; then - /bin/activate_sysconfig - sleep $TIMEOUT - fi -done +[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after configuration/before stage32." + +. "/bin/setup_stage32" || drop_shell "Problem setting up stage3.2" + +# copy files needed for stage3.2 to FUTURE_ROOT +[ $DEBUG -ge 1 ] && echo "Copying busybox etc. to stage32..." +tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" "/etc/functions" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/" # one last debug shell if activated [ $DEBUG -ge 1 ] && drop_shell "Requested Debug Shell: before switch_root." |
