summaryrefslogtreecommitdiffstats
path: root/testModule/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'testModule/scripts')
-rwxr-xr-xtestModule/scripts/prepare-disks98
-rwxr-xr-xtestModule/scripts/setup-qcow241
2 files changed, 124 insertions, 15 deletions
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 <path_to_sys_partition>
+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] <dev_path>'"
+ 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!