diff options
| author | torben | 2015-05-07 23:33:05 +0200 |
|---|---|---|
| committer | torben | 2015-05-07 23:33:05 +0200 |
| commit | ab7c2b5e09247b6b4935c11051f25a1114afad8d (patch) | |
| tree | 1399ea9eb29806e2bd1929abed6855b82cd726f6 | |
| parent | Improve docu. (diff) | |
| parent | started configuration stuff (diff) | |
| download | systemd-init-ab7c2b5e09247b6b4935c11051f25a1114afad8d.tar.gz systemd-init-ab7c2b5e09247b6b4935c11051f25a1114afad8d.tar.xz systemd-init-ab7c2b5e09247b6b4935c11051f25a1114afad8d.zip | |
Merge branch 'master' of git.openslx.org:openslx-ng/systemd-init
| -rwxr-xr-x | testModule/hooks/cmdline/enable-sysrq.sh | 2 | ||||
| -rwxr-xr-x | testModule/hooks/cmdline/expand-kcl-ip.sh (renamed from testModule/hooks/cmdline.sh) | 8 | ||||
| -rwxr-xr-x | testModule/hooks/cmdline/mark-root-device.sh | 9 | ||||
| -rwxr-xr-x | testModule/hooks/mount.sh | 3 | ||||
| -rwxr-xr-x | testModule/hooks/mount/mount-root-device.sh | 4 | ||||
| -rwxr-xr-x | testModule/hooks/nbd-cmdline.sh | 5 | ||||
| -rwxr-xr-x | testModule/hooks/pre-mount.sh | 9 | ||||
| -rwxr-xr-x | testModule/hooks/pre-mount/fetch-config.sh | 12 | ||||
| -rwxr-xr-x | testModule/hooks/pre-mount/mount-qcow.sh | 49 | ||||
| -rwxr-xr-x | testModule/hooks/pre-pivot/mount-tmp.sh | 38 | ||||
| -rwxr-xr-x | testModule/hooks/pre-udev/load-dnbd3-nbd-modules.sh (renamed from testModule/hooks/pre-udev.sh) | 20 | ||||
| -rw-r--r-- | testModule/module-setup.sh | 68 | ||||
| -rwxr-xr-x | testModule/scripts/prepare-disks | 211 | ||||
| -rwxr-xr-x | testModule/scripts/r | 3 | ||||
| -rwxr-xr-x | testModule/scripts/retry-nbdroot | 5 | ||||
| -rwxr-xr-x | testModule/scripts/setup-nbdroot | 12 | ||||
| -rwxr-xr-x | testModule/scripts/setup-qcow2 | 54 | ||||
| -rw-r--r-- | testModule/udev/70-openslx-disk.rules | 8 |
18 files changed, 429 insertions, 91 deletions
diff --git a/testModule/hooks/cmdline/enable-sysrq.sh b/testModule/hooks/cmdline/enable-sysrq.sh new file mode 100755 index 00000000..f779aa7a --- /dev/null +++ b/testModule/hooks/cmdline/enable-sysrq.sh @@ -0,0 +1,2 @@ +# enables magic sysrq keys +echo 1 > /proc/sys/kernel/sysrq diff --git a/testModule/hooks/cmdline.sh b/testModule/hooks/cmdline/expand-kcl-ip.sh index b1f06ea6..8be1c718 100755 --- a/testModule/hooks/cmdline.sh +++ b/testModule/hooks/cmdline/expand-kcl-ip.sh @@ -1,5 +1,3 @@ -echo 1 > /proc/sys/kernel/sysrq - # fakes the cmdline to fix the ip parsing when using # syslinux's IPAPPEND 1 mask [ -d /fake ] || mkdir /fake @@ -12,11 +10,11 @@ mount -t tmpfs tmpfs /fake sed 's/\(ip=\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}:\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}:\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}:\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)/\1:hiwi:eno1:none/' /proc/cmdline > /fake/cmdline # bind mount it. Can we trust mount return codes here? -# if so, we should check what we get in $? +# # if so, we should check what we get in $? mount -o bind /fake/cmdline /proc/cmdline # check if it worked if ! grep 'hiwi:eth0:none' /proc/cmdline; then - command -v warn >/dev/null || . /lib/dracut-lib.sh - warn 'Haxing cmdline did not work :( sad pandaz...' + command -v warn >/dev/null || . /lib/dracut-lib.sh + warn 'Haxing cmdline did not work :( sad pandaz...' fi diff --git a/testModule/hooks/cmdline/mark-root-device.sh b/testModule/hooks/cmdline/mark-root-device.sh new file mode 100755 index 00000000..b7282521 --- /dev/null +++ b/testModule/hooks/cmdline/mark-root-device.sh @@ -0,0 +1,9 @@ +# set rootok and root as dracut expects them to be set by +# the module preparing the root filesystem. +# +# Once the root filesystem is mounted per dnbd3 and +# exported as qcow2 per nbd, /dev/root will be a symlink +# to /dev/nbd0 as this is then our rootfs-device +rootok=1 +root=block:/dev/root + diff --git a/testModule/hooks/mount.sh b/testModule/hooks/mount.sh deleted file mode 100755 index e893642d..00000000 --- a/testModule/hooks/mount.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -mount /dev/root $NEWROOT diff --git a/testModule/hooks/mount/mount-root-device.sh b/testModule/hooks/mount/mount-root-device.sh new file mode 100755 index 00000000..d02f9002 --- /dev/null +++ b/testModule/hooks/mount/mount-root-device.sh @@ -0,0 +1,4 @@ +# this rudimentary script just mounts the rootfs device that was symlinked to +# /dev/root to dracut's $NEWROOT (usually /sysroot). + +mount /dev/root $NEWROOT diff --git a/testModule/hooks/nbd-cmdline.sh b/testModule/hooks/nbd-cmdline.sh deleted file mode 100755 index 6464646f..00000000 --- a/testModule/hooks/nbd-cmdline.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -rootok=1 -root=block:/dev/root - diff --git a/testModule/hooks/pre-mount.sh b/testModule/hooks/pre-mount.sh deleted file mode 100755 index b22cdc35..00000000 --- a/testModule/hooks/pre-mount.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/bash - -while ! /sbin/setup-qcow2; do - sleep 0.5 -done - -while ! /sbin/setup-nbdroot; do - sleep 0.5 -done diff --git a/testModule/hooks/pre-mount/fetch-config.sh b/testModule/hooks/pre-mount/fetch-config.sh new file mode 100755 index 00000000..013b0058 --- /dev/null +++ b/testModule/hooks/pre-mount/fetch-config.sh @@ -0,0 +1,12 @@ +command -v info >/dev/null || . /lib/dracut-lib.sh + +info "Getting configuration from OPENSLX-Server..." + +WGET="$(busybox which wget)" +if [ -z $WGET ]; then + # do nothing + warn "'wget' not found. Skipping openslx configuration..." + exit 1 +fi +mkdir -p /opt/openslx +$WGET http://10.4.9.51/openslx/config -O /opt/openslx/config diff --git a/testModule/hooks/pre-mount/mount-qcow.sh b/testModule/hooks/pre-mount/mount-qcow.sh new file mode 100755 index 00000000..d70492bf --- /dev/null +++ b/testModule/hooks/pre-mount/mount-qcow.sh @@ -0,0 +1,49 @@ +############################################################################### +# CHECKS +# + +SETUP_ROOTFS_SCRIPT="/sbin/setup-qcow2" + +if [ ! -e "${SETUP_ROOTFS_SCRIPT}" ]; then + warn "No such file of directory: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +if [ ! -x "${SETUP_ROOTFS_SCRIPT}" ]; then + warn "Cannot execute: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +# +# END CHECKS +############################################################################### + +############################################################################### +# MAIN CODE +# + +# ok, let's source the setup script +if ! . ${SETUP_ROOTFS_SCRIPT} ; then + warn "Could not source: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +# just go over the functions in the right order ;-) +for fun in connect_dnbd3 create_qcow export_qcow connect_qcow; do + if ! $fun; then + # something failed, drop a shell for debugging + warn "'$fun' failed with: $?" + emergency_shell -n "Error in $fun" + return 1 + fi +done + +# all good, we are done +return 0 + +# +# END MAIN CODE +############################################################################### diff --git a/testModule/hooks/pre-pivot/mount-tmp.sh b/testModule/hooks/pre-pivot/mount-tmp.sh new file mode 100755 index 00000000..3fa24cce --- /dev/null +++ b/testModule/hooks/pre-pivot/mount-tmp.sh @@ -0,0 +1,38 @@ +# This script only checks if we found a usable partition for the +# future /tmp. The discovery of that partition is done by udev during +# the initqueue. If a valid partition is found (either GPT with the label +# OPENSLX_TMP or MBR with the type 0x44) its path will be written to +# /tmp/openslx.tmpdisk +OPENSLX_TMP_DISK_FLAG="/tmp/openslx.disk.tmp" + +if [ ! -e "$OPENSLX_TMP_DISK_FLAG" ]; then + warn "'$OPENSLX_TMP_DISK_FLAG' not found!" + warn "Systemd will manage $NEWROOT/tmp on its own." + # no partition for the future /tmp found, just + # let systemd manage it then (probably a tmpfs) + return 1 +fi + +# in /tmp/openslx.disk.tmp is the name of the device +# to mount as /tmp in the real system +# meaning we need to mount it to /sysroot/tmp here. + +OPENSLX_TMP_DISK_DEV="$(cat $OPENSLX_TMP_DISK_FLAG)" + +# sanity check: is the content a block device? +if [ ! -b "$OPENSLX_TMP_DISK_DEV" ]; then + warn "'$OPENSLX_TMP_DISK_DEV' appears not to be a block device!" + warn "Systemd will manage $NEWROOT/tmp on its own." + return 1 +fi + +# all good, keep on +if ! mount -t auto "$OPENSLX_TMP_DISK_DEV" /sysroot/tmp; then + # something else went wrong :( + warn "Mounting '$OPENSLX_TMP_DISK_DEV' to '/sysroot/tmp' failed with: $!" + warn "Systemd will manage $NEWROOT/tmp on its own." + return 1 +fi + +# still here? mount worked wohoo +return 0 diff --git a/testModule/hooks/pre-udev.sh b/testModule/hooks/pre-udev/load-dnbd3-nbd-modules.sh index 578169e9..29f9f210 100755 --- a/testModule/hooks/pre-udev.sh +++ b/testModule/hooks/pre-udev/load-dnbd3-nbd-modules.sh @@ -1,19 +1,10 @@ -#!/usr/bin/bash - # include dracut-lib.sh to use 'warn' command -v warn >/dev/null || . /lib/dracut-lib.sh -SETUP_SCRIPT="/sbin/setup-qcow2" -NBDROOT_SCRIPT="/sbin/setup-nbdroot" NBD_MOD_PATH="/usr/lib/modules/current/extra/nbd.ko" DNBD3_MOD_PATH="/usr/lib/modules/current/extra/dnbd3.ko" -# sanity checks -if [ ! -e "${SETUP_SCRIPT}" ]; then - warn "No such file of directory: ${SETUP_SCRIPT}" - emergency_shell -n "Error in $0" - return 1 -fi +# do we actually have our modules? if [ ! -e "${NBD_MOD_PATH}" ]; then warn "No such file of directory: ${NBD_MOD_PATH}" emergency_shell -n "Error in $0" @@ -26,19 +17,16 @@ if [ ! -e "${DNBD3_MOD_PATH}" ]; then fi # load the kernel modules for dnbd3 and nbd -if ! insmod /usr/lib/modules/current/extra/dnbd3.ko; then +if ! insmod "${DNBD3_MOD_PATH}"; then warn "Failed to load DNBD3 kernel module..." emergency_shell -n "Error in $0" return 1 fi -if ! insmod /usr/lib/modules/current/extra/nbd.ko; then +if ! insmod "${NBD_MOD_PATH}"; then warn "Failed to load NBD kernel module..." emergency_shell -n "Error in $0" return 1 fi -# now let's "install" the setup script in the initqueue -#/sbin/initqueue --settled --unique "${SETUP_SCRIPT}" -#/sbin/initqueue --settled --unique "${NBDROOT_SCRIPT}" -#/sbin/initqueue --settled --unique "/sbin/retry-nbdroot" +return 0 diff --git a/testModule/module-setup.sh b/testModule/module-setup.sh index 839e5deb..e40069ce 100644 --- a/testModule/module-setup.sh +++ b/testModule/module-setup.sh @@ -42,38 +42,76 @@ installkernel() { } install() { - # cause we need reboots - inst "$moddir/scripts/r" /usr/bin/r - # Needed to mount remote dnbd3 filesystem. - inst "$moddir/binaries/dnbd3-client" /usr/bin/dnbd3-client + ### BINARIES + # + # busybox: cause we want lightweight tools inst "$moddir/binaries/busybox" /usr/bin/busybox - # A generic wrapper program to prepend a "@" to each process spawned by - # given nested programs. + # dnbd3-client: needed to mount remote dnbd3 filesystem. + inst "$moddir/binaries/dnbd3-client" /usr/bin/dnbd3-client + # A generic wrapper program to prepend a "@" to each process + # spawned by given nested programs. inst "$moddir/binaries/systemd-preserve-process-marker" \ /usr/bin/systemd-preserve-process-marker # NOTE: These modules are build again Kernel: 3.10.0-229.1.2.el7.x86_64 + # TODO: build these in check() ! inst "$moddir/kernel_modules/dnbd3.ko" \ /usr/lib/modules/current/extra/dnbd3.ko inst "$moddir/kernel_modules/nbd.ko" \ /usr/lib/modules/current/extra/nbd.ko - # NOTE: Priority has to be lower than the network cmdline parsing hooks - # since we have to modify the some kernel parameter before. - inst_hook cmdline 00 "$moddir/hooks/cmdline.sh" - inst_hook cmdline 90 "$moddir/hooks/nbd-cmdline.sh" - inst_hook pre-udev 00 "$moddir/hooks/pre-udev.sh" - inst_hook pre-mount 10 "$moddir/hooks/pre-mount.sh" - inst_hook mount 10 "$moddir/hooks/mount.sh" + ### HOOKS + ## HOOK cmdline + # enables sysrq-shortcuts + inst_hook cmdline 00 "$moddir/hooks/cmdline/enable-sysrq.sh" + + # expands the ip parameter in the kernel command line to + # make it dracut-compatible + # TODO: dracut still parses this incorrectly... + inst_hook cmdline 10 "$moddir/hooks/cmdline/expand-kcl-ip.sh" + + # sets environment variables to tell dracut which device + # holds the future root filesystem + inst_hook cmdline 90 "$moddir/hooks/cmdline/mark-root-device.sh" + + ## HOOK pre-udev + # loads the dnbd3/nbd kernel modules + inst_hook pre-udev 00 "$moddir/hooks/pre-udev/load-dnbd3-nbd-modules.sh" + + ## HOOK pre-mount + # this is the configuration hook where the config stuff is wget'ed + inst_hook pre-mount 00 "$moddir/hooks/pre-mount/fetch-config.sh" + + # this is the main hook where all the magic is triggered + inst_hook pre-mount 10 "$moddir/hooks/pre-mount/mount-qcow.sh" + + ## HOOK mount + # this simply mounts the prepared /dev/root to $NEWROOT + # aka "the dracut way" + inst_hook mount 10 "$moddir/hooks/mount/mount-root-device.sh" + + ## HOOK pre-pivot + # this checks whether we found a partition suitable for + # the future /tmp and if so, mounts it + inst_hook pre-pivot 00 "$moddir/hooks/pre-pivot/mount-tmp.sh" + + ### SCRIPTS + # the main magic script containing all the functions needed + # to prepare the qcow2-based root filesystem inst "$moddir/scripts/setup-qcow2" /sbin/setup-qcow2 - inst "$moddir/scripts/setup-nbdroot" /sbin/setup-nbdroot + # the script triggered by udev upon finding the right partitions + inst "$moddir/scripts/prepare-disks" /sbin/prepare-disks + + # udev rules detecting 44, 45, 46 partitions and running + # 'prepare-disks' to do then format/mount/use them + inst "$moddir/udev/70-openslx-disk.rules" /etc/udev/rules.d/70-openslx-disk.rules # Debugging Uncomment this version if you need some useful debugging tools # in your iniramfs. inst_multiple lsblk ping ip ifconfig sshd htop tail head cat vim \ touch sed lsmod insmod qemu-img sleep route wget find lsof strace \ - chroot switch_root pivot_root qemu-nbd mount nbd-client fdisk + chroot switch_root pivot_root qemu-nbd mount nbd-client fdisk mkfs.xfs # Production: # inst_multiple insmod qemu-img qemu-nbd return 0 diff --git a/testModule/scripts/prepare-disks b/testModule/scripts/prepare-disks new file mode 100755 index 00000000..2e68dd9e --- /dev/null +++ b/testModule/scripts/prepare-disks @@ -0,0 +1,211 @@ +#!/bin/bash +############################################################################### +# GLOBALS +# + +# flag file containing pids of running instances for concurrency checks +declare -rg OPENSLX_DISK_FLAG="/tmp/openslx.disk" +# file that will contain the name of the device used for the /tmp partition +# - label 'OPENSLX_TMP' in GPT / type '0x44' in MBR +declare -rg OPENSLX_TMP_MARKER="/tmp/openslx.disk.tmp" +# file that will contain the name of the device used for storing qcow2 +# - label 'OPENSLX_SYS' in GPT / type '0x46' in MBR +declare -rg OPENSLX_SYS_MARKER="/tmp/openslx.disk.sys" +# mount point for system partition +declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" + +# +# END GLOBALS +############################################################################### + +############################################################################### +# FUNCTION DEFINITIONS +# +# helper to mount the OPENSLX_SYS partition to /opt/openslx/system +# Usage: mount_sys_part <path_to_sys_partition> +mount_sys_part() { + if [ ! -b "$1" ]; then + warn "($$) Refusing to mount '$1' as its not a block device!" + return 1 + fi + + local OPENSLX_SYS_DEVICE="$1" + mkdir -p ${OPENSLX_SYS_MOUNT} + if ! mount -t auto "${OPENSLX_SYS_DEVICE}" "${OPENSLX_SYS_MOUNT}"; then + warn "($$) Mounting '${OPENSLX_SYS_DEVICE}' to '${OPENSLX_SYS_MOUNT}' failed." + return 1 + fi + return 0 + +} +# +# generic helper to format the given partition with the given filesystem or +# from the prefdefined list of xfs, ext4, ... +# Usage: format_disk <dev> <fs> +# e.g. format_disk /dev/sda1 xfs +format_disk () { + local TARGET_DEVICE="$1" + local fslist="xfs ext4" + # if we have a second arguments, its the filesystem of choice + local fs + [ $# -ge 2 ] && fslist="$2" + for fs in $fslist ; do + unset found + local MKFS="$(busybox which mkfs.$fs)" + if [ -n $MKFS ]; then + found=yes + case "mkfs.$fs" in + mkfs.xfs) fopt="-fq" ;; + mkfs.ext4) fopt="-Fq" ;; + esac + info "($$) Formatting $TARGET_DEVICE as $fs" + return $(${MKFS} ${fopt} "${TARGET_DEVICE}") + fi + [ -n "$found" ] && break + done + # still here? then we didn't find a proper formatter... + warn "($$) Could not format $PART_DEV as $fs." + return 1 +} + +# +# END FUNCTION DEFINITIONS +############################################################################### + +############################################################################### +# MAIN CODE +# + +command -v warn >/dev/null || . /lib/dracut-lib.sh + +# let check the arguments +if [ "$#" -ne 2 ]; then + warn "($$) '$0' need 2 arguments: '$0 [OPENSLX_SYS|OPENSLX_TMP] <dev_path>'" + exit 1 +fi +# $1 sane? +if [ "x$1" != "xOPENSLX_SYS" ] && [ "x$1" != "xOPENSLX_TMP" ]; then + warn "($$) First arg needs to be either 'OPENSLX_SYS' or 'OPENSLX_TMP', given: $1" + exit 1 +fi +# $2 sane? +if [ ! -b "/dev/$2" ]; then + warn "($$) Second arg appears not to be a block device!" + exit 1 +fi + +# ok all seems well, set the arguments +PART_TYPE="$1" +PART_DEV="/dev/$2" + +unset OPENSLX_TMP_DEVICE +unset OPENSLX_SYS_DEVICE + +# lets check if we are already running +INSTANCES="$(grep "$PART_TYPE" "$OPENSLX_DISK_FLAG" | busybox wc -l)" +if [ "$INSTANCES" -ge 1 ]; then + # uhoh we are not alone! Need to check + # if the other instance actually did its job + warn "($$) '$0' already running for $PART_TYPE on $PART_DEV... checking state." + # here two/three cases depending on which PART_TYPE we are + # currently processing. + for timeout in 1 1 2; do + # always give the other instance time to finish + # but only check 3 times overall + sleep $timeout + case "$PART_TYPE" in + OPENSLX_TMP) + # was the tmp partition marker created with a device? + if [ ! -f "${OPENSLX_TMP_MARKER}" ]; then + info "($$) Invalid state: no marker for $PART_TYPE" + continue + fi + # it was, is it a valid block device? + OPENSLX_TMP_DEVICE="$(cat ${OPENSLX_TMP_MARKER})" + if [ -z $OPENSLX_TMP_DEVICE -o ! -b $OPENSLX_TMP_DEVICE ]; then + info "($$) Invalid state: no for device $OPENSLX_TMP_DEVICE" + continue + fi + # its detected, its a block device and as mounting is + # done later, we can not check for more at this point + info "($$) Valid state for $OPENSLX_TMP_DEVICE as $PART_TYPE" + exit 0 + ;; + OPENSLX_SYS) + # was the system partition marker created with a device? + if [ ! -f "${OPENSLX_SYS_MARKER}" ]; then + info "($$) Invalid state: no marker for $PART_TYPE" + continue + fi + # it was, is it a valid block device? + OPENSLX_SYS_DEVICE="$(cat ${OPENSLX_SYS_MARKER})" + if [ -z $OPENSLX_SYS_DEVICE -o ! -b $OPENSLX_SYS_DEVICE ]; then + info "($$) Invalid state: no for device $OPENSLX_SYS_DEVICE" + continue + fi + # its detected, its a block device, is it mounted? + if mount | grep -qE "^$OPENSLX_SYS_DEVICE\ on $OPENSLX_SYS_MOUNT"; then + info "($$) Valid state for $OPENSLX_SYS_DEVICE as $PART_TYPE" + exit 0 + fi + # if its not mounted, we want to keep on, so no exit! + ;; + *) + # weird case which should never happen + warn "($$) If you see this, then $0 was called with a bad PART_TYPE: $@" + continue + ;; + esac + done + warn "($$) Timeout reached!" + warn "($$) '$PART_TYPE' was found but not device was associated to it!" +fi + +# We write our pid to $OPENSLX_DISK_FLAG in order to make sure +# we are the only instance of this script running. +info "($$) Processing: $PART_TYPE -> $PART_DEV ($$)" +echo "$PART_TYPE.$$" >> "$OPENSLX_DISK_FLAG" + +# if we are still here, then we can go on and process the partition +if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then + # always format /tmp partition + if ! format_disk "${PART_DEV}" xfs; then + # error while formatting, cleanup + warn "($$) Error formatting $PART_DEV ... removing $$" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 1 + fi + info "($$) Using '$PART_DEV' as '$PART_TYPE'" + # mark it for later: in pre-pivot we will check this file + # and mount it as $NEWROOT/tmp + echo "$PART_DEV" > "$OPENSLX_TMP_MARKER" + # remove our pid from OPENSLX_DISK_FLAG + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 0 +fi +if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then + # TODO make the formatting of the system partition configurable + if ! format_disk "${PART_DEV}" xfs; then + # error while formatting, cleanup + warn "($$) Error formatting $PART_DEV ... removing $$" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 1 + fi + # mark it + # mount it now, since qemu-nbd needs it asap! + if mount_sys_part "$PART_DEV"; then + # mount worked, mark it as done + info "($$) Using '$PART_DEV' as '$PART_TYPE'" + echo "$PART_DEV" > "$OPENSLX_SYS_MARKER" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 0 + else + warn "($$) 'mount_sys_part' failed in $0" + sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" + exit 1 + fi +fi + +# +# END MAIN CODE +############################################################################### diff --git a/testModule/scripts/r b/testModule/scripts/r deleted file mode 100755 index 9b4fd4fc..00000000 --- a/testModule/scripts/r +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/bash - -echo b > /proc/sysrq-trigger diff --git a/testModule/scripts/retry-nbdroot b/testModule/scripts/retry-nbdroot deleted file mode 100755 index 8eb4bd27..00000000 --- a/testModule/scripts/retry-nbdroot +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -[ -f /tmp/qemu-nbd.pid ] || exit 1 - -/sbin/nbdroot eno1 nbd:127.0.0.1:2000 /sysroot diff --git a/testModule/scripts/setup-nbdroot b/testModule/scripts/setup-nbdroot deleted file mode 100755 index 38f48dd4..00000000 --- a/testModule/scripts/setup-nbdroot +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# exit 1 until qemu-nbd is running -[ -f /tmp/qemu-nbd.pid ] || exit 1 - -# -if nbd-client --systemd-mark --persist 127.0.0.1 2000 /dev/nbd0; then - ln -sf /dev/nbd0 /dev/root - exit 0 -else - exit 1 -fi diff --git a/testModule/scripts/setup-qcow2 b/testModule/scripts/setup-qcow2 index ba1ef6b1..cc74457b 100755 --- a/testModule/scripts/setup-qcow2 +++ b/testModule/scripts/setup-qcow2 @@ -2,16 +2,21 @@ # dracut-lib to use debugging functions command -v warn >/dev/null || . /lib/dracut-lib.sh +command -v emergency_shell >/dev/null || . /lib/dracut-lib.sh ############################################################################### # GLOBALS # # TODO make this configurable [ -f /opt/openslx/config ] && . /opt/openslx/config +[ -z $SLX_DNBD3_SERVER ] && SLX_DNBD3_SERVER="132.230.4.1" +[ -z $SLX_STAGE4 ] && SLX_STAGE4="stage4/joe/centos7" +[ -z $SLX_STAGE4_RID ] && SLX_STAGE4_RID="4" +declare -rg DNBD3_SERVER="$SLX_DNBD3_SERVER" +declare -rg DNBD3_IMAGE="$SLX_STAGE4" +declare -rg DNBD3_RID="$SLX_STAGE4_RID" declare -rg DNBD3_DEVICE="/dev/dnbd0" -declare -rg DNBD3_SERVER="132.230.4.1" -declare -rg DNBD3_IMAGE="stage4/joe/centos7" -declare -rg DNBD3_RID="4" +declare -rg QCOW_CONTAINER="/opt/openslx/system/system.qcow2" # # END GLOBALS ############################################################################### @@ -49,18 +54,22 @@ connect_dnbd3() { # helper to create the qcow2 container file using # DNBD3_DEVICE as the base of the filesystem -# /run/test.qcow2 as the writable file +# QCOW_CONTAINER as the writable file # (our future rootfs) create_qcow() { # check if we already created the qcow2-container - [ -e /run/test.qcow2 ] && return 0 + [ -e "$QCOW_CONTAINER" ] && return 0 + + # check if we have our target directory, if not create it + [ ! -d "$(busybox dirname $QCOW_CONTAINER)" ] && \ + mkdir -p "$(busybox dirname $QCOW_CONTAINER)" # we did not, let's create it if ! qemu-img create -f qcow2 -o \ - backing_file="$DNBD3_DEVICE",backing_fmt=qcow2 /run/test.qcow2; then + backing_file="$DNBD3_DEVICE",backing_fmt=qcow2 "$QCOW_CONTAINER"; then warn "Failed to create qcow2-Container from $DNBD3_DEVICE" emergency_shell -n "Error in $0" - rm -f -- /run/test.qcow2 + rm -f -- "$QCOW_CONTAINER" return 1 fi return 0 @@ -75,7 +84,7 @@ export_qcow() { fi # since we use the wrapper, we need a little more logic to see if it runs /usr/bin/systemd-preserve-process-marker \ - /usr/bin/qemu-nbd -t -p 2000 /run/test.qcow2 & + /usr/bin/qemu-nbd -t -p 2000 "$QCOW_CONTAINER" & # the wrapper returns 255 if the qemu-nbd binary is missing local qemu_nbd_pid="$!" for i in 0.5 1 2; do @@ -102,17 +111,26 @@ export_qcow() { # fallback return 1 } +# helper to mount the qcow2-container per nbd +connect_qcow() { + # try to mount the locally exported qcow2-container using nbd-client + if nbd-client --systemd-mark --persist 127.0.0.1 2000 /dev/nbd0; then + # it worked, lets set the symlink to /dev/root as dracut needs it + # later on to mount that device to the future root (/sysroot) + ln -sf /dev/nbd0 /dev/root + return 0 + else + # this is pretty bad, dracut would spawn an emergency later on + # since there is no /dev/root to mount. + # For debugging purposes, we drop an emergency shell ourselves + # if the mount fails. + warn "Could not mount /dev/nbd0 from 127.0.0.1:2000." + emergency_shell -n "Error in $0" + return 1 + fi +} # # END FUNCTION DEFINITIONS ############################################################################### -############################################################################### -# MAIN CODE -# -#check_dnbd3 || return 1 -connect_dnbd3 || exit 1 -create_qcow || exit 1 -export_qcow || exit 1 - -# all good, we are done :) -exit 0 +# No main, use functions! diff --git a/testModule/udev/70-openslx-disk.rules b/testModule/udev/70-openslx-disk.rules new file mode 100644 index 00000000..3f5e382f --- /dev/null +++ b/testModule/udev/70-openslx-disk.rules @@ -0,0 +1,8 @@ +# GPT rules +KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="gpt" ENV{ID_PART_ENTRY_NAME}=="OPENSLX_TMP" RUN+="/sbin/prepare-disks %E{ID_PART_ENTRY_NAME} %k" +KERNEL=="sd?[0-9]" SUBSYSTEM=="block" ENV{ID_PART_TABLE_TYPE}=="gpt" ENV{ID_PART_ENTRY_NAME}=="OPENSLX_SYS" RUN+="/sbin/prepare-disks %E{ID_PART_ENTRY_NAME} %k" + +# 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" + |
