From b3312f86061a0d887233f5068cbc335aa2612bed Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 6 May 2015 18:13:52 +0200 Subject: current state: udev disk detection still not done! also improved module structure and code commentary --- testModule/scripts/prepare-disks | 98 ++++++++++++++++++++++++++++++++++++++++ testModule/scripts/setup-qcow2 | 41 +++++++++++------ 2 files changed, 124 insertions(+), 15 deletions(-) create mode 100755 testModule/scripts/prepare-disks (limited to 'testModule/scripts') diff --git a/testModule/scripts/prepare-disks b/testModule/scripts/prepare-disks new file mode 100755 index 00000000..28113cc7 --- /dev/null +++ b/testModule/scripts/prepare-disks @@ -0,0 +1,98 @@ +#!/bin/bash +############################################################################### +# GLOBALS +# + +declare -rg FLAG="/tmp/openslx.disks" +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 +mount_sys_part() { + if [ ! -b "$1" ]; then + warn "'$1' is not a block device?" + echo "!block: $1" >> /tmp/openslx.disks.log + 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." + echo "mount phail" >> /tmp/openslx.disks.log + return 1 + fi + echo "ZOMG" >> /tmp/openslx.disks.log + return 0 + +} +# +# 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] '" + echo "Not enough args!" >> /tmp/openslx.disks.log + 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'." + warn "Given: $1" + echo "OPENSLX? $1" >> /tmp/openslx.disks.log + exit 1 +fi +# $2 sane? +if [ ! -b "/dev/$2" ]; then + warn "Second arg appears not to be a block device!" + echo "block? $2" >> /tmp/openslx.disks.log + exit 1 +fi + +# ok all seems well +PART_TYPE="$1" +PART_DEV="/dev/$2" + +# lets check if we are already running +INSTANCES="$(grep "$PART_TYPE" "$FLAG" | busybox wc -l)" +if [ "$INSTANCES" -ge 1 ]; then + # uhoh we are not alone! + warn "'$0' already running for $PART_TYPE ... ignoring." + echo "already running for $PART_TYPE" >> /tmp/openslx.disks.log + exit 1 +fi + +# now comes the funny part. We write our pid to $FLAG in order to make sure +# we are the only instance of this script running. +echo "$PART_TYPE.$$" >> "$FLAG" + +# if we are still here, then we can go on and process the partition +echo "Processing: $PART_TYPE -> $PART_DEV" >> /tmp/openslx.disks.log + +if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then + # mark it for later mounting! + echo "$PART_DEV" > /tmp/openslx.disk.tmp + exit 0 +fi +if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then + # mount it now, since qemu-nbd needs it asap! + exit $(mount_sys_part "$PART_DEV") +fi + +# +# END MAIN CODE +############################################################################### diff --git a/testModule/scripts/setup-qcow2 b/testModule/scripts/setup-qcow2 index ba1ef6b1..b14ccd87 100755 --- a/testModule/scripts/setup-qcow2 +++ b/testModule/scripts/setup-qcow2 @@ -2,6 +2,7 @@ # 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 @@ -12,6 +13,7 @@ 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 +51,18 @@ 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 # 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 +77,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 +104,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! -- cgit v1.2.3-55-g7522 From fe968c954def3b26b8ce503adfd16d20029bab75 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 6 May 2015 18:19:03 +0200 Subject: deprecated --- testModule/scripts/r | 3 --- testModule/scripts/retry-nbdroot | 5 ----- testModule/scripts/setup-nbdroot | 12 ------------ 3 files changed, 20 deletions(-) delete mode 100755 testModule/scripts/r delete mode 100755 testModule/scripts/retry-nbdroot delete mode 100755 testModule/scripts/setup-nbdroot (limited to 'testModule/scripts') 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 -- cgit v1.2.3-55-g7522 From c50dd3c817814d7d8e3be66efe1ade9a11fac636 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 6 May 2015 18:24:51 +0200 Subject: minor - flag names ... --- testModule/hooks/pre-pivot/mount-tmp.sh | 2 +- testModule/scripts/prepare-disks | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'testModule/scripts') diff --git a/testModule/hooks/pre-pivot/mount-tmp.sh b/testModule/hooks/pre-pivot/mount-tmp.sh index 152c844e..3fa24cce 100755 --- a/testModule/hooks/pre-pivot/mount-tmp.sh +++ b/testModule/hooks/pre-pivot/mount-tmp.sh @@ -3,7 +3,7 @@ # 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.tmpdisk" +OPENSLX_TMP_DISK_FLAG="/tmp/openslx.disk.tmp" if [ ! -e "$OPENSLX_TMP_DISK_FLAG" ]; then warn "'$OPENSLX_TMP_DISK_FLAG' not found!" diff --git a/testModule/scripts/prepare-disks b/testModule/scripts/prepare-disks index 28113cc7..2e7dd673 100755 --- a/testModule/scripts/prepare-disks +++ b/testModule/scripts/prepare-disks @@ -3,7 +3,7 @@ # GLOBALS # -declare -rg FLAG="/tmp/openslx.disks" +declare -rg FLAG="/tmp/openslx.disk" declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" # @@ -18,7 +18,7 @@ declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" mount_sys_part() { if [ ! -b "$1" ]; then warn "'$1' is not a block device?" - echo "!block: $1" >> /tmp/openslx.disks.log + echo "!block: $1" >> /tmp/openslx.disk.log return 1 fi @@ -26,10 +26,9 @@ mount_sys_part() { 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." - echo "mount phail" >> /tmp/openslx.disks.log + echo "mount phail" >> /tmp/openslx.disk.log return 1 fi - echo "ZOMG" >> /tmp/openslx.disks.log return 0 } @@ -46,20 +45,20 @@ 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] '" - echo "Not enough args!" >> /tmp/openslx.disks.log + echo "Not enough args!" >> /tmp/openslx.disk.log 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'." warn "Given: $1" - echo "OPENSLX? $1" >> /tmp/openslx.disks.log + echo "OPENSLX? $1" >> /tmp/openslx.disk.log exit 1 fi # $2 sane? if [ ! -b "/dev/$2" ]; then warn "Second arg appears not to be a block device!" - echo "block? $2" >> /tmp/openslx.disks.log + echo "block? $2" >> /tmp/openslx.disk.log exit 1 fi @@ -72,7 +71,7 @@ INSTANCES="$(grep "$PART_TYPE" "$FLAG" | busybox wc -l)" if [ "$INSTANCES" -ge 1 ]; then # uhoh we are not alone! warn "'$0' already running for $PART_TYPE ... ignoring." - echo "already running for $PART_TYPE" >> /tmp/openslx.disks.log + echo "already running for $PART_TYPE" >> /tmp/openslx.disk.log exit 1 fi @@ -81,7 +80,7 @@ fi echo "$PART_TYPE.$$" >> "$FLAG" # if we are still here, then we can go on and process the partition -echo "Processing: $PART_TYPE -> $PART_DEV" >> /tmp/openslx.disks.log +echo "Processing: $PART_TYPE -> $PART_DEV" >> /tmp/openslx.disk.log if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then # mark it for later mounting! -- cgit v1.2.3-55-g7522 From 9f715701236bdc418a174828cccf27a8ab63874c Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 7 May 2015 17:29:03 +0200 Subject: prepare-disk: check state of disk detection when an instance sees another --- testModule/module-setup.sh | 2 +- testModule/scripts/prepare-disks | 145 +++++++++++++++++++++++++++++++++------ testModule/scripts/setup-qcow2 | 4 ++ 3 files changed, 128 insertions(+), 23 deletions(-) (limited to 'testModule/scripts') diff --git a/testModule/module-setup.sh b/testModule/module-setup.sh index efd79cf1..c06435c9 100644 --- a/testModule/module-setup.sh +++ b/testModule/module-setup.sh @@ -108,7 +108,7 @@ install() { # 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 index 2e7dd673..1992a262 100755 --- a/testModule/scripts/prepare-disks +++ b/testModule/scripts/prepare-disks @@ -3,7 +3,15 @@ # GLOBALS # -declare -rg FLAG="/tmp/openslx.disk" +# 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" # @@ -17,8 +25,7 @@ declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" # Usage: mount_sys_part mount_sys_part() { if [ ! -b "$1" ]; then - warn "'$1' is not a block device?" - echo "!block: $1" >> /tmp/openslx.disk.log + warn "Refusing to mount '$1' as its not a block device!" return 1 fi @@ -26,12 +33,41 @@ mount_sys_part() { 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." - echo "mount phail" >> /tmp/openslx.disk.log 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 +# 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 ############################################################################### @@ -45,51 +81,116 @@ 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] '" - echo "Not enough args!" >> /tmp/openslx.disk.log 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'." - warn "Given: $1" - echo "OPENSLX? $1" >> /tmp/openslx.disk.log + 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!" - echo "block? $2" >> /tmp/openslx.disk.log exit 1 fi -# ok all seems well +# 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" "$FLAG" | busybox wc -l)" +INSTANCES="$(grep "$PART_TYPE" "$OPENSLX_DISK_FLAG" | busybox wc -l)" if [ "$INSTANCES" -ge 1 ]; then - # uhoh we are not alone! - warn "'$0' already running for $PART_TYPE ... ignoring." - echo "already running for $PART_TYPE" >> /tmp/openslx.disk.log - exit 1 + # uhoh we are not alone! Need to check + # if the other instance actually did its job + warn "'$0' already running for $PART_TYPE ... 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? + [ -f "${OPENSLX_TMP_MARKER}" ] || continue + # it was, is it a valid block device? + OPENSLX_TMP_DEVICE="$(cat ${OPENSLX_TMP_MARKER})" + [ -b $OPENSLX_TMP_DEVICE ] || continue + # 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" + exit 0 + ;; + OPENSLX_SYS) + # was the system partition marker created with a device? + [ -f "${OPENSLX_SYS_MARKER}" ] || continue + # it was, is it a valid block device? + OPENSLX_SYS_DEVICE="$(cat ${OPENSLX_SYS_MARKER})" + [ -b $OPENSLX_SYS_DEVICE ] || continue + # 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" + 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 "'$PART_TYPE' was found but not device was associated to it!" fi -# now comes the funny part. We write our pid to $FLAG in order to make sure +# We write our pid to $OPENSLX_DISK_FLAG in order to make sure # we are the only instance of this script running. -echo "$PART_TYPE.$$" >> "$FLAG" +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 -echo "Processing: $PART_TYPE -> $PART_DEV" >> /tmp/openslx.disk.log - if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then - # mark it for later mounting! - echo "$PART_DEV" > /tmp/openslx.disk.tmp + # 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! - exit $(mount_sys_part "$PART_DEV") + 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 # diff --git a/testModule/scripts/setup-qcow2 b/testModule/scripts/setup-qcow2 index b14ccd87..86b69db2 100755 --- a/testModule/scripts/setup-qcow2 +++ b/testModule/scripts/setup-qcow2 @@ -57,6 +57,10 @@ create_qcow() { # check if we already created the qcow2-container [ -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 "$QCOW_CONTAINER"; then -- cgit v1.2.3-55-g7522 From deacdfe13b2eac8e84d72a62bb5c161436aa3c19 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 7 May 2015 18:10:51 +0200 Subject: added pids to log messages for better debugging --- testModule/scripts/prepare-disks | 57 ++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'testModule/scripts') diff --git a/testModule/scripts/prepare-disks b/testModule/scripts/prepare-disks index 1992a262..2e68dd9e 100755 --- a/testModule/scripts/prepare-disks +++ b/testModule/scripts/prepare-disks @@ -25,14 +25,14 @@ declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" # Usage: mount_sys_part mount_sys_part() { if [ ! -b "$1" ]; then - warn "Refusing to mount '$1' as its not a block device!" + 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." + warn "($$) Mounting '${OPENSLX_SYS_DEVICE}' to '${OPENSLX_SYS_MOUNT}' failed." return 1 fi return 0 @@ -58,13 +58,13 @@ format_disk () { mkfs.xfs) fopt="-fq" ;; mkfs.ext4) fopt="-Fq" ;; esac - info "Formatting $TARGET_DEVICE as $fs" + 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." + warn "($$) Could not format $PART_DEV as $fs." return 1 } @@ -80,17 +80,17 @@ 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] '" + warn "($$) '$0' need 2 arguments: '$0 [OPENSLX_SYS|OPENSLX_TMP] '" 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" + 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!" + warn "($$) Second arg appears not to be a block device!" exit 1 fi @@ -106,7 +106,7 @@ 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 ... checking state." + 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 @@ -116,41 +116,54 @@ if [ "$INSTANCES" -ge 1 ]; then case "$PART_TYPE" in OPENSLX_TMP) # was the tmp partition marker created with a device? - [ -f "${OPENSLX_TMP_MARKER}" ] || continue + 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})" - [ -b $OPENSLX_TMP_DEVICE ] || continue + 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" + info "($$) Valid state for $OPENSLX_TMP_DEVICE as $PART_TYPE" exit 0 ;; OPENSLX_SYS) # was the system partition marker created with a device? - [ -f "${OPENSLX_SYS_MARKER}" ] || continue + 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})" - [ -b $OPENSLX_SYS_DEVICE ] || continue + 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" + 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: $@" + warn "($$) If you see this, then $0 was called with a bad PART_TYPE: $@" continue ;; esac done - warn "'$PART_TYPE' was found but not device was associated to it!" + 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 ($$)" +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 @@ -158,11 +171,11 @@ 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 $$" + warn "($$) Error formatting $PART_DEV ... removing $$" sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" exit 1 fi - info "Using '$PART_DEV' as '$PART_TYPE'" + 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" @@ -174,7 +187,7 @@ 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 $$" + warn "($$) Error formatting $PART_DEV ... removing $$" sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" exit 1 fi @@ -182,12 +195,12 @@ if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then # 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'" + 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" + warn "($$) 'mount_sys_part' failed in $0" sed -i "/^${PART_TYPE}\.$$/d" "${OPENSLX_DISK_FLAG}" exit 1 fi -- cgit v1.2.3-55-g7522 From 46ba927a27fc6d6b2fc76096e57ae127c41b65b9 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 7 May 2015 18:12:30 +0200 Subject: started configuration stuff --- testModule/hooks/pre-mount/fetch-config.sh | 12 ++++++++++++ testModule/module-setup.sh | 3 +++ testModule/scripts/setup-qcow2 | 9 ++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100755 testModule/hooks/pre-mount/fetch-config.sh (limited to 'testModule/scripts') 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/module-setup.sh b/testModule/module-setup.sh index c06435c9..e40069ce 100644 --- a/testModule/module-setup.sh +++ b/testModule/module-setup.sh @@ -79,6 +79,9 @@ install() { 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" diff --git a/testModule/scripts/setup-qcow2 b/testModule/scripts/setup-qcow2 index 86b69db2..cc74457b 100755 --- a/testModule/scripts/setup-qcow2 +++ b/testModule/scripts/setup-qcow2 @@ -9,10 +9,13 @@ command -v emergency_shell >/dev/null || . /lib/dracut-lib.sh # # 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 -- cgit v1.2.3-55-g7522