From 564189d3c0cfb689f08a3d1e85b0e4c741e87016 Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 5 Nov 2015 15:30:47 +0100 Subject: Remove deprecated files. --- builder/dnbd3-qcow2-rootfs/TODO | 4 - builder/dnbd3-qcow2-rootfs/debugging-tools/endless | Bin 0 -> 6752 bytes .../dnbd3-qcow2-rootfs/debugging-tools/endless.c | 10 +++ .../debugging-tools/network.functions | 23 ++++++ .../debugging-tools/setup-network.sh | 84 +++++++++++++++++++++ builder/dnbd3-qcow2-rootfs/debugging_tools/busybox | Bin 931664 -> 0 bytes builder/dnbd3-qcow2-rootfs/debugging_tools/endless | Bin 6752 -> 0 bytes .../dnbd3-qcow2-rootfs/debugging_tools/endless.c | 10 --- .../dnbd3-qcow2-rootfs/debugging_tools/nbd-client | Bin 59639 -> 0 bytes .../debugging_tools/nbd-debugging.ko | Bin 463248 -> 0 bytes .../debugging_tools/network.functions | 23 ------ .../dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd | Bin 7131314 -> 0 bytes .../debugging_tools/qemu-nbd-systemd-mark | Bin 7128103 -> 0 bytes .../debugging_tools/setup-network.sh | 84 --------------------- .../dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules | 1 - 15 files changed, 117 insertions(+), 122 deletions(-) delete mode 100644 builder/dnbd3-qcow2-rootfs/TODO create mode 100755 builder/dnbd3-qcow2-rootfs/debugging-tools/endless create mode 100644 builder/dnbd3-qcow2-rootfs/debugging-tools/endless.c create mode 100644 builder/dnbd3-qcow2-rootfs/debugging-tools/network.functions create mode 100644 builder/dnbd3-qcow2-rootfs/debugging-tools/setup-network.sh delete mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/busybox delete mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/endless delete mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c delete mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client delete mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko delete mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions delete mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd delete mode 100755 builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark delete mode 100644 builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh (limited to 'builder') diff --git a/builder/dnbd3-qcow2-rootfs/TODO b/builder/dnbd3-qcow2-rootfs/TODO deleted file mode 100644 index 93ef7081..00000000 --- a/builder/dnbd3-qcow2-rootfs/TODO +++ /dev/null @@ -1,4 +0,0 @@ -* Dynamic building of systemd-preserver-process-marker if needed anymore. - -* Research whether the dracut busybox module satisfies our requirements -* If not, compiling busybox should be done somehow diff --git a/builder/dnbd3-qcow2-rootfs/debugging-tools/endless b/builder/dnbd3-qcow2-rootfs/debugging-tools/endless new file mode 100755 index 00000000..de7a8c0a Binary files /dev/null and b/builder/dnbd3-qcow2-rootfs/debugging-tools/endless differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging-tools/endless.c b/builder/dnbd3-qcow2-rootfs/debugging-tools/endless.c new file mode 100644 index 00000000..22c9bc50 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/debugging-tools/endless.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + // Provides a dummy worker. + while (1) + sleep(999999999); +} diff --git a/builder/dnbd3-qcow2-rootfs/debugging-tools/network.functions b/builder/dnbd3-qcow2-rootfs/debugging-tools/network.functions new file mode 100644 index 00000000..89ca5a20 --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/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/builder/dnbd3-qcow2-rootfs/debugging-tools/setup-network.sh b/builder/dnbd3-qcow2-rootfs/debugging-tools/setup-network.sh new file mode 100644 index 00000000..3b32a68c --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/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/builder/dnbd3-qcow2-rootfs/debugging_tools/busybox b/builder/dnbd3-qcow2-rootfs/debugging_tools/busybox deleted file mode 100755 index 1212ae20..00000000 Binary files a/builder/dnbd3-qcow2-rootfs/debugging_tools/busybox and /dev/null differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/endless b/builder/dnbd3-qcow2-rootfs/debugging_tools/endless deleted file mode 100755 index de7a8c0a..00000000 Binary files a/builder/dnbd3-qcow2-rootfs/debugging_tools/endless and /dev/null differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c b/builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c deleted file mode 100644 index 22c9bc50..00000000 --- a/builder/dnbd3-qcow2-rootfs/debugging_tools/endless.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include -#include - -int main(int argc, char *argv[]) { - // Provides a dummy worker. - while (1) - sleep(999999999); -} diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client b/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client deleted file mode 100755 index 7bb2207f..00000000 Binary files a/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-client and /dev/null differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko b/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko deleted file mode 100644 index 47cf6cd6..00000000 Binary files a/builder/dnbd3-qcow2-rootfs/debugging_tools/nbd-debugging.ko and /dev/null differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions b/builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions deleted file mode 100644 index 89ca5a20..00000000 --- a/builder/dnbd3-qcow2-rootfs/debugging_tools/network.functions +++ /dev/null @@ -1,23 +0,0 @@ -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/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd b/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd deleted file mode 100755 index b34a3ff7..00000000 Binary files a/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd and /dev/null differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark b/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark deleted file mode 100755 index 03c2a6b1..00000000 Binary files a/builder/dnbd3-qcow2-rootfs/debugging_tools/qemu-nbd-systemd-mark and /dev/null differ diff --git a/builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh b/builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh deleted file mode 100644 index 3b32a68c..00000000 --- a/builder/dnbd3-qcow2-rootfs/debugging_tools/setup-network.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/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/builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules b/builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules index 3f5e382f..5cb3fa52 100644 --- a/builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules +++ b/builder/dnbd3-qcow2-rootfs/udev/70-openslx-disk.rules @@ -5,4 +5,3 @@ KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="gpt" ENV{ID_PART # MBR rules KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="dos" ENV{ID_PART_ENTRY_TYPE}=="0x44" RUN+="/sbin/prepare-disks OPENSLX_TMP %k" KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="dos" ENV{ID_PART_ENTRY_TYPE}=="0x46" RUN+="/sbin/prepare-disks OPENSLX_SYS %k" - -- cgit v1.2.3-55-g7522 From 31615ef0361ec85b0d703e8ee96fbc7474b145ee Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 5 Nov 2015 15:39:07 +0100 Subject: Tidy up. --- .gitignore | 2 +- build-initramfs.sh | 316 ---------------------------- builder/build-initramfs.sh | 261 +++++++++++++++++++++++ builder/dnbd3-qcow2-rootfs/module-setup.sh | 3 +- builder/dnbd3-qcow2-rootfs/scripts/utils.sh | 61 +++++- 5 files changed, 323 insertions(+), 320 deletions(-) delete mode 100755 build-initramfs.sh create mode 100755 builder/build-initramfs.sh (limited to 'builder') diff --git a/.gitignore b/.gitignore index d49884db..5752bb3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -dracut +builder/dracut builder/dnbd3-qcow2-rootfs/kernel_modules/nbd/* !builder/dnbd3-qcow2-rootfs/kernel_modules/nbd/Makefile diff --git a/build-initramfs.sh b/build-initramfs.sh deleted file mode 100755 index ae71bada..00000000 --- a/build-initramfs.sh +++ /dev/null @@ -1,316 +0,0 @@ -#!/usr/bin/env bash -# -*- coding: utf-8 -*- - -# region header - -# Copyright Torben Sickert (t.sickert["~at~"]gmail.com) 29.10.2015 -# Janosch Dobler (TODO) 29.10.2015 - -# License -# ------- - -# This library written by Torben Sickert and Janosch Dobler stand under a -# creative commons naming 3.0 unported license. -# see http://creativecommons.org/licenses/by/3.0/deed.de - -# This tool provides a generic way to install systemd based remote linux -# initramfs. - -# Examples -# -------- - -# Start install progress command (Assuming internet is available): -# >>> ./build_initramfs.sh - -# Note that you only get very necessary output until you provide "--verbose" as -# commandline options. - -# Dependencies -# ------------ - -# - bash (or any bash like shell) -# - cpio - Copies files into or out of a cpio or tar archive. The -# archive can be another file on the disk, a magnetic tape, -# or a pipe. -# - git - The stupid content tracker. -# - test - Check file types and compare values (part of the shell). -# - shift - Shifts the command line arguments (part of the shell). -# - echo - Display a line of text (part of coreutils). -# - mktemp - Create a temporary file or directory (part of coreutils). -# - cat - Concatenate files and print on the standard output (part of -# coreutils). -# - rm - Remove files or directories (part of coreutils). -# - sed - Stream editor for filtering and transforming text. -# - gzip - Compress or expand files. -# - curl - Transfer a URL -# - tar - The GNU version of the tar archiving utility. -# - make - GNU make utility to maintain groups of programs. -# - cmake - The "cmake" executable is the CMake command-line interface. -# - linux-headers - GNU make utility to maintain groups of programs. -# - grep - Searches the named input files (or standard input if no -# files are named, or if a single hyphen-minus (-) is given -# as file name) for lines containing a match to the given -# PATTERN. By default, grep prints the matching lines. - -__NAME__='build_initramfs' - -# endregion - -function build_initramfs() { - # Provides the main module scope. - - # region properties - - local _SCOPE='local' && \ - if [[ $(echo "\"$@\"" | grep --extended-regexp \ - '(^"| )(-l|--load-environment)("$| )') != '' ]] - then - local _SCOPE='export' - fi - # NOTE: Only initialize environment if current scope wasn't set yet. - if [ "$_VERBOSE" == '' ]; then - "$_SCOPE" _VERBOSE='no' - "$_SCOPE" _LOAD_ENVIRONMENT='no' - "$_SCOPE" _CREATE_SYSTEM_IMAGE='no' - local dependencies=(bash cpio git test shift echo mktemp cat rm sed \ - gzip curl tar grep make cmake) - "$_SCOPE" _DEPENDENCIES="${dependencies[*]}" - "$_SCOPE" _KERNEL_MODULE_DIRECTORY="builder/dnbd3-qcow2-rootfs/kernel_modules/" - "$_SCOPE" _STANDARD_OUTPUT=/dev/null - "$_SCOPE" _ERROR_OUTPUT=/dev/null - fi - - # endregion - - # region functions - - ## region command line interface - - function build_initramfs_print_usage_message() { - # Prints a description about how to use this program. - cat << EOF -$__NAME__ provides a generic way to install systemd based remote linux -initramfs. -EOF - } - function build_initramfs_print_usage_examples() { - # Prints a description about how to use this program by providing - # examples. - cat << EOF - # Start install progress: - # >>> ./build_initramfs.sh -EOF - } - function build_initramfs_print_command_line_option_description() { - # Prints descriptions about each available command line option. - cat << EOF - -h --help Shows this help message. - - -v --verbose Tells you what is going on (default: "$_VERBOSE"). - - -d --debug Gives you any output from all tools which are used - (default: "$_DEBUG"). - - -l --load-environment Simple load the install arch linux scope without - doing anything else. - - -c --create-system-image Creates a system image file for given path - (default: "$_CREATE_SYSTEM_IMAGE"). -EOF - } - function build_initramfs_print_help_message() { - # Provides a help message for this module. - echo -e "\nUsage: $0 [options]\n" - build_initramfs_print_usage_message "$@" - echo -e '\nExamples:\n' - build_initramfs_print_usage_examples "$@" - echo -e '\nOption descriptions:\n' - build_initramfs_print_command_line_option_description "$@" - echo - } - function build_initramfs_command_line_interface() { - # Provides the command line interface and interactive questions. - while true; do - case "$1" in - -h|--help) - shift - build_initramfs_print_help_message "$0" - exit 0 - ;; - -v|--verbose) - shift - _VERBOSE='yes' - ;; - -d|--debug) - shift - _STANDARD_OUTPUT=/dev/stdout - _ERROR_OUTPUT=/dev/stderr - ;; - -l|--load-environment) - shift - _LOAD_ENVIRONMENT='yes' - ;; - -c|--create-system-image) - shift - _CREATE_SYSTEM_IMAGE="$1" - shift - ;; - - '') - shift - break - ;; - *) - build_initramfs_log 'critical' \ - "Given argument: \"$1\" is not available." '\n' && \ - if [[ "$_SCOPE" == 'local' ]]; then - build_initramfs_print_help_message "$0" - fi - return 1 - esac - done - if [[ "$UID" != '0' ]]; then - build_initramfs_log 'critical' \ - "You have to run this script as \"root\" not as \"${USER}\"." - exit 2 - fi - return 0 - } - function build_initramfs_log() { - # Handles logging messages. Returns non zero and exit on log level - # error to support chaining the message into toolchain. - # - # Examples: - # - # >>> build_initramfs_log - # info: test - # >>> build_initramfs_log debug message - # debug: message - # >>> build_initramfs_log info message '\n' - # - # info: message - local loggingType='info' && \ - local message="$1" && \ - if [ "$2" ]; then - loggingType="$1" - message="$2" - fi - if [ "$_VERBOSE" == 'yes' ] || [ "$loggingType" == 'error' ] || \ - [ "$loggingType" == 'critical' ]; then - if [ "$3" ]; then - echo -e -n "$3" - fi - echo -e "${loggingType}: $message" - fi - if [ "$loggingType" == 'error' ]; then - exit 1 - fi - return 0 - } - - ## endregion - - ## region tools - - function build_initramfs_perform_dependency_check() { - # This function check if all given dependencies are present. - # - # Examples: - # - # >>> build_initramfs_perform_dependency_check "mkdir pacstrap mktemp" - # ... - local dependenciesToCheck="$1" && \ - local result=0 && \ - local dependency && \ - for dependency in ${dependenciesToCheck[*]}; do - if ! hash "$dependency" 1>"$_STANDARD_OUTPUT" 2>/dev/null; then - build_initramfs_log 'critical' \ - "Needed dependency \"$dependency\" isn't available." && \ - result=1 - fi - done - return $result - } - - ## endregion - - function build_initramfs_initialize_dracut() { - # Downloads and compiles dracut. - # - # Examples: - # - # >>> build_initramfs_initialize_dracut - # ... - mkdir dracut 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ - build_initramfs_log 'Download and extract dracut.' && \ - curl --location \ - https://www.kernel.org/pub/linux/utils/boot/dracut/dracut-043.tar.gz | \ - tar --extract --gzip --directory dracut --strip-components 1 \ - 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ - pushd dracut 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ - # NOTE: On virtualbox shared folder symlinks are not allowed. - # make the dracut-install binary (dracut-install resolves dependencies etc.) - build_initramfs_log 'Compile dracut.' && \ - make install/dracut-install 1>"$_STANDARD_OUTPUT" \ - 2>"$_ERROR_OUTPUT" && \ - # NOTE: We have to copy the binary to current instead of symlinking - # them since this feature isn't supported in shared virtual box - # machine folders. If symlinks would be available we could simply - # use: - # >>> make dracut-install - cp install/dracut-install dracut-install 1>"$_STANDARD_OUTPUT" \ - 2>"$_ERROR_OUTPUT" && \ - popd 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" - return $? - } - function build_initramfs_create_qcow2_system() { - # TODO - qemu-img create -f qcow2 "${CONTAINER_PATH}" "${QCOW_SIZE}" - return $? - } - - # endregion - - # region controller - - if [[ "$0" == *"${__NAME__}.sh" ]]; then - build_initramfs_perform_dependency_check "${_DEPENDENCIES[*]}" || \ - build_initramfs_log 'error' 'Satisfying main dependencies failed.' - build_initramfs_command_line_interface "$@" || return $? - - build_initramfs_log 'Checking dracut.' && \ - if ! [[ -d ./dracut ]]; then - build_initramfs_log "Dracut isn't available yet loading it." && \ - build_initramfs_initialize_dracut - fi - build_initramfs_log 'Build initramfs.' && \ - build_initramfs_log \ - 'Copy dnbd3 qcow2 plugin into dracut modules folder.' && \ - cp --recursive builder/dnbd3-qcow2-rootfs/ \ - dracut/modules.d/90dndb3-qcow2-rootfs \ - 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ - dracut/dracut.sh --local --verbose --force \ - 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" - - fi - return 0 - - # endregion - -} - -# region footer - -if [[ "$0" == *"${__NAME__}.sh" || $(echo "$@" | grep --extended-regexp \ - '(^| )(-l|--load-environment)($| )') ]]; then - "$__NAME__" "$@" -fi - -# endregion - -# region vim modline - -# vim: set tabstop=4 shiftwidth=4 expandtab: -# vim: foldmethod=marker foldmarker=region,endregion: - -# endregion diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh new file mode 100755 index 00000000..f10e9586 --- /dev/null +++ b/builder/build-initramfs.sh @@ -0,0 +1,261 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +# region header + +# Copyright Torben Sickert (t.sickert["~at~"]gmail.com) 29.10.2015 +# Janosch Dobler (TODO) 29.10.2015 + +# License +# ------- + +# This library written by Torben Sickert and Janosch Dobler stand under a +# creative commons naming 3.0 unported license. +# see http://creativecommons.org/licenses/by/3.0/deed.de + +# This tool provides a generic way to install systemd based remote linux +# initramfs. + +# Examples +# -------- + +# Start install progress command (Assuming internet is available): +# >>> ./build_initramfs.sh + +# Note that you only get very necessary output until you provide "--verbose" as +# commandline options. + +# Dependencies +# ------------ + +# - bash (or any bash like shell) +# - cpio - Copies files into or out of a cpio or tar archive. The +# archive can be another file on the disk, a magnetic tape, +# or a pipe. +# - git - The stupid content tracker. +# - test - Check file types and compare values (part of the shell). +# - shift - Shifts the command line arguments (part of the shell). +# - echo - Display a line of text (part of coreutils). +# - mktemp - Create a temporary file or directory (part of coreutils). +# - cat - Concatenate files and print on the standard output (part of +# coreutils). +# - rm - Remove files or directories (part of coreutils). +# - sed - Stream editor for filtering and transforming text. +# - gzip - Compress or expand files. +# - curl - Transfer a URL +# - tar - The GNU version of the tar archiving utility. +# - make - GNU make utility to maintain groups of programs. +# - cmake - The "cmake" executable is the CMake command-line interface. +# - linux-headers - GNU make utility to maintain groups of programs. +# - grep - Searches the named input files (or standard input if no +# files are named, or if a single hyphen-minus (-) is given +# as file name) for lines containing a match to the given +# PATTERN. By default, grep prints the matching lines. + +__NAME__='build_initramfs' + +# endregion + +function build_initramfs() { + # Provides the main module scope. + + # region properties + + local _SCOPE='local' && \ + if [[ $(echo "\"$@\"" | grep --extended-regexp \ + '(^"| )(-l|--load-environment)("$| )') != '' ]] + then + local _SCOPE='export' + fi + # NOTE: Only initialize environment if current scope wasn't set yet. + if [ "$_VERBOSE" == '' ]; then + "$_SCOPE" _VERBOSE='no' + "$_SCOPE" _LOAD_ENVIRONMENT='no' + "$_SCOPE" _CREATE_SYSTEM_IMAGE='no' + local dependencies=(bash cpio git test shift echo mktemp cat rm sed \ + gzip curl tar grep make cmake) + "$_SCOPE" _DEPENDENCIES="${dependencies[*]}" + "$_SCOPE" _KERNEL_MODULE_DIRECTORY="builder/dnbd3-qcow2-rootfs/kernel_modules/" + "$_SCOPE" _STANDARD_OUTPUT=/dev/null + "$_SCOPE" _ERROR_OUTPUT=/dev/null + fi + + # endregion + + # region functions + + ## region command line interface + + function build_initramfs_print_usage_message() { + # Prints a description about how to use this program. + cat << EOF +$__NAME__ provides a generic way to install systemd based remote linux +initramfs. +EOF + } + function build_initramfs_print_usage_examples() { + # Prints a description about how to use this program by providing + # examples. + cat << EOF + # Start install progress: + # >>> ./build_initramfs.sh +EOF + } + function build_initramfs_print_command_line_option_description() { + # Prints descriptions about each available command line option. + cat << EOF + -h --help Shows this help message. + + -v --verbose Tells you what is going on (default: "$_VERBOSE"). + + -d --debug Gives you any output from all tools which are used + (default: "$_DEBUG"). + + -l --load-environment Simple load the install arch linux scope without + doing anything else. + + -c --create-system-image Creates a system image file for given path + (default: "$_CREATE_SYSTEM_IMAGE"). +EOF + } + function build_initramfs_print_help_message() { + # Provides a help message for this module. + echo -e "\nUsage: $0 [options]\n" + build_initramfs_print_usage_message "$@" + echo -e '\nExamples:\n' + build_initramfs_print_usage_examples "$@" + echo -e '\nOption descriptions:\n' + build_initramfs_print_command_line_option_description "$@" + echo + } + function build_initramfs_command_line_interface() { + # Provides the command line interface and interactive questions. + while true; do + case "$1" in + -h|--help) + shift + build_initramfs_print_help_message "$0" + exit 0 + ;; + -v|--verbose) + shift + _VERBOSE='yes' + ;; + -d|--debug) + shift + _STANDARD_OUTPUT=/dev/stdout + _ERROR_OUTPUT=/dev/stderr + ;; + -l|--load-environment) + shift + _LOAD_ENVIRONMENT='yes' + ;; + -c|--create-system-image) + shift + _CREATE_SYSTEM_IMAGE="$1" + shift + ;; + + '') + shift + break + ;; + *) + build_initramfs_log 'critical' \ + "Given argument: \"$1\" is not available." '\n' && \ + if [[ "$_SCOPE" == 'local' ]]; then + build_initramfs_print_help_message "$0" + fi + return 1 + esac + done + if [[ "$UID" != '0' ]]; then + build_initramfs_log 'critical' \ + "You have to run this script as \"root\" not as \"${USER}\"." + exit 2 + fi + return 0 + } + + ## endregion + + function build_initramfs_initialize_dracut() { + # Downloads and compiles dracut. + # + # Examples: + # + # >>> build_initramfs_initialize_dracut + # ... + mkdir dracut 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ + build_initramfs_log 'Download and extract dracut.' && \ + curl --location \ + https://www.kernel.org/pub/linux/utils/boot/dracut/dracut-043.tar.gz | \ + tar --extract --gzip --directory dracut --strip-components 1 \ + 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ + pushd dracut 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ + # NOTE: On virtualbox shared folder symlinks are not allowed. + # make the dracut-install binary (dracut-install resolves dependencies etc.) + build_initramfs_log 'Compile dracut.' && \ + make install/dracut-install 1>"$_STANDARD_OUTPUT" \ + 2>"$_ERROR_OUTPUT" && \ + # NOTE: We have to copy the binary to current instead of symlinking + # them since this feature isn't supported in shared virtual box + # machine folders. If symlinks would be available we could simply + # use: + # >>> make dracut-install + cp install/dracut-install dracut-install 1>"$_STANDARD_OUTPUT" \ + 2>"$_ERROR_OUTPUT" && \ + popd 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" + return $? + } + function build_initramfs_create_qcow2_system() { + # TODO + qemu-img create -f qcow2 "${CONTAINER_PATH}" "${QCOW_SIZE}" + return $? + } + + # endregion + + # region controller + + if [[ "$0" == *"${__NAME__}.sh" ]]; then + build_initramfs_perform_dependency_check "${_DEPENDENCIES[*]}" || \ + build_initramfs_log 'error' 'Satisfying main dependencies failed.' + build_initramfs_command_line_interface "$@" || return $? + + build_initramfs_log 'Checking dracut.' && \ + if ! [[ -d ./dracut ]]; then + build_initramfs_log "Dracut isn't available yet loading it." && \ + build_initramfs_initialize_dracut + fi + build_initramfs_log 'Build initramfs.' && \ + build_initramfs_log \ + 'Copy dnbd3 qcow2 plugin into dracut modules folder.' && \ + cp --recursive builder/dnbd3-qcow2-rootfs/ \ + dracut/modules.d/90dndb3-qcow2-rootfs \ + 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \ + dracut/dracut.sh --local --verbose --force \ + 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" + + fi + return 0 + + # endregion + +} + +# region footer + +if [[ "$0" == *"${__NAME__}.sh" || $(echo "$@" | grep --extended-regexp \ + '(^| )(-l|--load-environment)($| )') ]]; then + "$__NAME__" "$@" +fi + +# endregion + +# region vim modline + +# vim: set tabstop=4 shiftwidth=4 expandtab: +# vim: foldmethod=marker foldmarker=region,endregion: + +# endregion diff --git a/builder/dnbd3-qcow2-rootfs/module-setup.sh b/builder/dnbd3-qcow2-rootfs/module-setup.sh index eb81f347..b9134871 100755 --- a/builder/dnbd3-qcow2-rootfs/module-setup.sh +++ b/builder/dnbd3-qcow2-rootfs/module-setup.sh @@ -5,7 +5,8 @@ source "$moddir/scripts/utils.sh" check() { compile_nbd && \ compile_dnbd3 && \ - compile_systemd_preserve_process_marker && + compile_systemd_preserve_process_marker + return $? } depends() { diff --git a/builder/dnbd3-qcow2-rootfs/scripts/utils.sh b/builder/dnbd3-qcow2-rootfs/scripts/utils.sh index 62f6509f..0e0c9479 100644 --- a/builder/dnbd3-qcow2-rootfs/scripts/utils.sh +++ b/builder/dnbd3-qcow2-rootfs/scripts/utils.sh @@ -1,4 +1,35 @@ -function build_initramfs_compile_nbd() { +function log() { + # Handles logging messages. Returns non zero and exit on log level + # error to support chaining the message into toolchain. + # + # Examples: + # + # >>> build_initramfs_log + # info: test + # >>> build_initramfs_log debug message + # debug: message + # >>> build_initramfs_log info message '\n' + # + # info: message + local loggingType='info' && \ + local message="$1" && \ + if [ "$2" ]; then + loggingType="$1" + message="$2" + fi + if [ "$_VERBOSE" == 'yes' ] || [ "$loggingType" == 'error' ] || \ + [ "$loggingType" == 'critical' ]; then + if [ "$3" ]; then + echo -e -n "$3" + fi + echo -e "${loggingType}: $message" + fi + if [ "$loggingType" == 'error' ]; then + exit 1 + fi + return 0 +} +function compile_nbd() { # Downloads and compiles nbd. # # Examples: @@ -15,7 +46,7 @@ function build_initramfs_compile_nbd() { return $? # TODO make clean } -function build_initramfs_compile_dnbd3() { +function compile_dnbd3() { # Downloads and compiles dnbd3. # # Examples: @@ -36,3 +67,29 @@ function build_initramfs_compile_dnbd3() { return $? # TODO rm -rf build } +function compile_systemd_preserve_process_marker() { + # Compiles simple c program. + pushd && \ + make && \ + popd + return $? +} +function perform_dependency_check() { + # This function check if all given dependencies are present. + # + # Examples: + # + # >>> build_initramfs_perform_dependency_check "mkdir pacstrap mktemp" + # ... + local dependenciesToCheck="$1" && \ + local result=0 && \ + local dependency && \ + for dependency in ${dependenciesToCheck[*]}; do + if ! hash "$dependency" 1>"$_STANDARD_OUTPUT" 2>/dev/null; then + build_initramfs_log 'critical' \ + "Needed dependency \"$dependency\" isn't available." && \ + result=1 + fi + done + return $result +} -- cgit v1.2.3-55-g7522 From 1fd54be3ae8cd71b4a0d733e0b42832f09a730a9 Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 5 Nov 2015 15:40:30 +0100 Subject: Document new simplified approaches. --- builder/INSTALL | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'builder') diff --git a/builder/INSTALL b/builder/INSTALL index e52f0c39..a20a93a5 100644 --- a/builder/INSTALL +++ b/builder/INSTALL @@ -1,10 +1,10 @@ This subfolder is dedicated to dracut related files. The folder 'dnbd3-qcow2-rootfs' is a dracut module used to setup -a client's rootfs based on a (read-only) dnbd3 export made writable -through the qcow2 container format of the qemu ecosystem. +a client's rootfs based on a (read-only) dnbd3 export made writable +through the kernel device mapper features. -To use this module within dracut, you simply need to copy/link/mount +To use this module within dracut, you simply need to copy/link/mount the above mentioned folder to '/usr/lib/dracut/modules.d' prefixed with a numerical priority. We used '90' so far, so the module was linked to '/usr/lib/dracut/modules.d/90dnbd3-qcow2-rootfs'. @@ -12,7 +12,7 @@ to '/usr/lib/dracut/modules.d/90dnbd3-qcow2-rootfs'. Once the module has been integrated in dracut's modules, you can build the initramfs with the following command: - dracut --no-hostonly --modules "dnbd3-qcow2-rootfs" + dracut --no-hostonly --modules "dnbd3-qcow2-rootfs" Note that the '--no-hostonly' is critical if the machine dracut is executed on and the clients supposed to boot the resulting initramfs -- cgit v1.2.3-55-g7522