diff options
| author | Jonathan Bauer | 2015-05-06 18:13:52 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-05-06 18:13:52 +0200 |
| commit | b3312f86061a0d887233f5068cbc335aa2612bed (patch) | |
| tree | 32a0bace5eb6a7afeb29dae80d7f01fefecb36cc /testModule/scripts/setup-qcow2 | |
| parent | Merge branch 'master' of git.openslx.org:openslx-ng/systemd-init (diff) | |
| download | systemd-init-b3312f86061a0d887233f5068cbc335aa2612bed.tar.gz systemd-init-b3312f86061a0d887233f5068cbc335aa2612bed.tar.xz systemd-init-b3312f86061a0d887233f5068cbc335aa2612bed.zip | |
current state: udev disk detection still not done!
also improved module structure and code commentary
Diffstat (limited to 'testModule/scripts/setup-qcow2')
| -rwxr-xr-x | testModule/scripts/setup-qcow2 | 41 |
1 files changed, 26 insertions, 15 deletions
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! |
