summaryrefslogtreecommitdiffstats
path: root/testModule/scripts/setup-qcow2
diff options
context:
space:
mode:
Diffstat (limited to 'testModule/scripts/setup-qcow2')
-rwxr-xr-xtestModule/scripts/setup-qcow254
1 files changed, 36 insertions, 18 deletions
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!