diff options
Diffstat (limited to 'dev-tools')
| -rw-r--r-- | dev-tools/debugging-tools/endless.c | 10 | ||||
| -rw-r--r-- | dev-tools/debugging-tools/network.functions | 23 | ||||
| -rw-r--r-- | dev-tools/debugging-tools/setup-network.sh | 84 | ||||
| -rw-r--r-- | dev-tools/example-openslx.config | 41 | ||||
| -rwxr-xr-x | dev-tools/exampleDracutModule/apply-package.sh | 8 | ||||
| -rwxr-xr-x | dev-tools/exampleDracutModule/module-setup.sh | 41 |
6 files changed, 199 insertions, 8 deletions
diff --git a/dev-tools/debugging-tools/endless.c b/dev-tools/debugging-tools/endless.c new file mode 100644 index 00000000..22c9bc50 --- /dev/null +++ b/dev-tools/debugging-tools/endless.c @@ -0,0 +1,10 @@ +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +int main(int argc, char *argv[]) { + // Provides a dummy worker. + while (1) + sleep(999999999); +} diff --git a/dev-tools/debugging-tools/network.functions b/dev-tools/debugging-tools/network.functions new file mode 100644 index 00000000..89ca5a20 --- /dev/null +++ b/dev-tools/debugging-tools/network.functions @@ -0,0 +1,23 @@ +wait_for_iface() { + local DEVICE=$1 + local TIMEOUT=10 + echo -n "Waiting for interface $DEVICE: " + # Some systems don't have operstate. Seems to be hardware dependent + [ ! -e "/sys/class/net/${DEVICE}/operstate" ] && usleep 10000 + if [ -e "/sys/class/net/${DEVICE}/operstate" ]; then + while true; do + # check linkstate + [ "x$(cat "/sys/class/net/${DEVICE}/operstate")" == "xup" ] && break + TIMEOUT=$(( $TIMEOUT - 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working + [ "$TIMEOUT" -le 0 ] && break + # else + echo -n "." + usleep 500000 + done + else + # we really don't have a operstate .. then just wait a sec and hope for the best. + sleep 1 + fi + echo ".$(cat "/sys/class/net/${DEVICE}/operstate" 2>/dev/null)" +} +true diff --git a/dev-tools/debugging-tools/setup-network.sh b/dev-tools/debugging-tools/setup-network.sh new file mode 100644 index 00000000..3b32a68c --- /dev/null +++ b/dev-tools/debugging-tools/setup-network.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +echo "Setting up network..." + +echo "Main MAC address is '$MAC'" + +# setup network +source /inc/network.functions + +# set up loopback networking +echo "Setting up loopback" +ip link set dev lo up 2>/dev/null +ip addr add 127.0.0.1/8 dev lo 2>/dev/null + +echo "Setting up bridge" +BRIDGE="br0" + +# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though +## Flip mac address of original interface - this var is not local so init sees the changes too +#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')" +#ip link set addr "$MAC" "$SLAVE" + +mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" + +#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':') +IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') + +if ! echo "$IP_OUT" | grep -q -- "$MAC"; then + drop_shell "Boot interface not found in interface list. NIC driver missing?" +fi + +for LINE in $IP_OUT; do + IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') + IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[A-Z]' '[a-z]') # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm + echo "${IFACE} = ${IFMAC}" + + if [ "x$IFMAC" == "x$MAC" ]; then + brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE" + brctl stp "$BRIDGE" 0 + brctl setfd "$BRIDGE" 0.000000000001 + ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" + ip link set dev "$IFACE" up + wait_for_iface "$IFACE" + brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" + + # save our variables for retry on fail + echo "IFACE=$IFACE" > /run/network.conf + + # analyze ip information from the kernel command line and put parts + # of it into several variables + if [ -n "$CLIENTIP" ] ; then + # set static ip address + ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE" + ip link set dev "$BRIDGE" up + [ -n "$GATEWAY" ] && ip route add default via "$GATEWAY" dev "$BRIDGE" + else + NOIPYET="yes" + fi + # Ignore this device later on when systemd handles network interfaces (see hacked 99-systemd.rules in systemd data dir) + echo "SUBSYSTEM==\"net\", ACTION==\"add\", KERNEL==\"eth*\", ATTR{address}==\"$IFMAC\", TAG+=\"openslxignore\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/01-ignore-boot-interface.rules" + fi + # youdev + echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules" + # continue... + IFACE="" +done + +wait_for_iface "$BRIDGE" + +# udhcpc +PARAM= +if [ -n "$CLIENTIP" ]; then + PARAM="-r $CLIENTIP" +fi +echo -n "$CLIENTIP" > "/run/firstip" +echo -n "$GATEWAY" > "/run/firstgw" + +# save our variables for retry on fail ff. +echo "CLIENTIP=$CLIENTIP" >> /run/network.conf +echo "GATEWAY=$GATEWAY" >> /run/network.conf +echo "BRIDGE=$BRIDGE" >> /run/network.conf + +udhcpc $PARAM -O domain -O nissrv -O nisdomain -O wpad -O search -t 5 -T 2 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE" +# udhcpc return value will be return value of this script diff --git a/dev-tools/example-openslx.config b/dev-tools/example-openslx.config index 47d37c43..57197eec 100644 --- a/dev-tools/example-openslx.config +++ b/dev-tools/example-openslx.config @@ -1,25 +1,50 @@ +# This file contains configuration how the dnbd3 provided read only basic image +# should be injected and made writable by a local writable layer. + +# The openslx config will be placed in "/etc/openslx" in initramfs. + +# Location where this config file should be placed in final booted template +# system. SLX_CONFIGURATION_LOCATION='/opt/openslx/' +# A comma separated list of dnbd3 server host names or ip addresses where +# the read only image should be provided. The first matching ip will be used. SLX_DNBD3_SERVERS='132.230.4.201,132.230.4.202,10.0.2.2' +# dnbd3 image version to use. SLX_DNBD3_RID='0' +# Device name where the read only image should be injected. SLX_DNBD3_DEVICE='/dev/dnbd0' +# Path on remote dnbd3 server for basic readonly image. SLX_DNBD3_IMAGE='archLinux/archLinux.vmdk' -# If empty the whole device is used +# Partition identifier for the system partition, if empty the whole device will +# be used (no partition assumed). SLX_SYSTEM_PARTITION_IDENTIFIER='system' +# Script to run and set the read only device. +# (e.g. "lvm_scan && read_only_partition=/dev/centos/root") +SLX_SYSTEM_PARTITION_PREPARATION_SCRIPT='' +# Device to mount and save the writable binary difference fill in. Empty means +# no writable device should be injected and ram will be used as fallback. SLX_WRITABLE_DEVICE_IDENTIFIER='' -SLX_WRITABLE_DEVICE_IDENTIFIER_TIMEOUT='' -SLX_WRITABLE_DEVICE_STORAGE_FILE='storage.img' +# Time to wait for the writable device in seconds. +SLX_WRITABLE_DEVICE_IDENTIFIER_TIMEOUT_IN_SECONDS=10 +# File path for binary difference file. +SLX_WRITABLE_DEVICE_STORAGE_FILE_PATH='storage.img' # NOTE: if the filesystem is any other than ext4, then the corresponding # filesystem tools have to be added to the initramfs manually. (use the dracut # --install parameter) -SLX_WRITABLE_DEVICE_STORAGE_FILSYSTEM_CREATE_COMMAND='mkfs.ext4' -SLX_WRITABLE_DEVICE_STORAGE_FILSYSTEM_CHECK_COMMAND='fsck.ext4' -SLX_WRITABLE_DEVICE_STORAGE_FILE_MAX_SIZE_MB='1000' +SLX_WRITABLE_DEVICE_STORAGE_FILESYSTEM_CREATE_COMMAND='mkfs.ext4' +SLX_WRITABLE_DEVICE_STORAGE_FILESYSTEM_CHECK_COMMAND='fsck.ext4' +SLX_WRITABLE_DEVICE_STORAGE_MAXIMUM_FILE_SIZE_IN_MB='1000' +# Indicates whether existing persistent file should be taken in account. SLX_WRITABLE_DEVICE_PERSISTENT='no' # If empty we will end up in an empty fstab file. If you want to reuse the # original fstab (from the template system) provide a dummy script like "true". SLX_GENERATE_FSTAB_SCRIPT=' echo "/dev/mapper/root / btrfs subvol=root 0 0" >> "$NEWROOT/etc/fstab" ' -# if empty will use all available ram -SLX_RAMDISK_SIZE='' +# Upper bound for ram using. If empty all available ram will be used. +SLX_RAMDISK_SIZE_IN_KB='' +# Specifies mount options for the final root location where we want to pivot +# root in. SLX_MOUNT_ROOT_OPTIONS='-o subvol=root' +# Path where all the logs should be placed. +SLX_LOG_FILE_PATH='/var/log/openslx' diff --git a/dev-tools/exampleDracutModule/apply-package.sh b/dev-tools/exampleDracutModule/apply-package.sh new file mode 100755 index 00000000..218740ef --- /dev/null +++ b/dev-tools/exampleDracutModule/apply-package.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +source /etc/openslx + +echo -------------------------------------------------------------------------- +echo TEST +echo -------------------------------------------------------------------------- diff --git a/dev-tools/exampleDracutModule/module-setup.sh b/dev-tools/exampleDracutModule/module-setup.sh new file mode 100755 index 00000000..bfe216e7 --- /dev/null +++ b/dev-tools/exampleDracutModule/module-setup.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd '../' && \ + cd *'dnbd3-rootfs/scripts/rebash' && pwd)/core.sh" +core.import exceptions +core.import logging + +check() { + local __doc__=' + Checks whether needed assumptions are satisfied. + + Example: + + `check` + ' + # Tell dracut that this module should only be included if it is required + # explicitly. + return 255 +} +depends() { + local __doc__=' + Outputs all dependent dracut modules to make this module work. + + >>> depends + +doc_test_contains + base + ' + echo dnbd3-rootfs +} +install() { + local __doc__=' + Copies all needed files into the initramfs image and registers all needed + dracut hooks. + + Example: + + `install` + ' + inst_hook pre-pivot 00 "$moddir/apply-package.sh" +} |
