diff options
author | Jonathan Bauer | 2021-05-04 15:42:26 +0200 |
---|---|---|
committer | Jonathan Bauer | 2021-05-04 15:42:26 +0200 |
commit | f8a9ca6faf7c10a680c4ce7e504f66db15285962 (patch) | |
tree | 22b1e176b9628de25dd072b079b202458e9253a7 | |
parent | modules.d/dnbd3-rootfs/helper/build.inc: improve logging (diff) | |
download | systemd-init-centos7-fix.tar.gz systemd-init-centos7-fix.tar.xz systemd-init-centos7-fix.zip |
[dnbd3-rootfs] support RAW imagescentos7-fix
-rwxr-xr-x | builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh b/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh index b0c338d3..dd66d9a9 100755 --- a/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh +++ b/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh @@ -28,21 +28,20 @@ container_unpack_xmount() { else in_device="${out_path}/${_dnbd3_dev##*/}.dd" fi - local out_device="$(losetup -f)" - if ! losetup "$out_device" "$in_device" --partscan; then - logging.warn "Failed to attach '$in_device' to '$out_device'." - return - fi - udevadm settle - echo "$out_device" + # unpack the raw device now + container_unpack_raw "$in_device" } -container_unpack_losetup() { +container_unpack_raw() { + if [ -z "$1" ]; then + warn "No target device given to setup as loop device." + return 1 + fi local in_device="$1" local out_device="$(losetup -f)" - if ! losetup -r -t QCOW "$out_device" "$in_device" --partscan; then - logging.warn "Failed to attach '$in_device' to '$out_device'." - return + if ! losetup "$out_device" "$in_device" --partscan; then + emergency_shell "Failed to attach '$in_device' to '$out_device'." + return 1 fi udevadm settle echo "$out_device" @@ -77,13 +76,12 @@ done ) # endregion # region unpack dnbd3 image -[ -z "$SLX_QCOW_HANDLER" ] && SLX_QCOW_HANDLER="kernel" -if [ "$SLX_QCOW_HANDLER" = "xmount" ]; then +if [ "$(xxd -ps -l4 "$_dnbd3_dev")" = "514649fb" ]; then + logging.info "'$_dnbd3_dev' is a qcow2 image, trying to unpack with xmount." read_only_device="$(container_unpack_xmount "$_dnbd3_dev")" -elif [ "$SLX_QCOW_HANDLER" = "kernel" ]; then - read_only_device="$(container_unpack_losetup "$_dnbd3_dev")" else - logging.warn "Unsupported QCOW handler: $SLX_QCOW_HANDLER" + logging.info "'$_dnbd3_dev' is not a qcow2 image, assuming a raw image." + read_only_device="$(container_unpack_raw "$_dnbd3_dev")" fi # Fail fast if unpacking dnbd3 image failed. |