diff options
author | jandob | 2015-12-08 13:21:55 +0100 |
---|---|---|
committer | jandob | 2015-12-08 13:21:55 +0100 |
commit | 69b4052ff1e507259b1eb21490c2ac4663e97958 (patch) | |
tree | bfbed8c344f322022da52b3e91d54272f00a938f /builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh | |
parent | improved block device discovery (diff) | |
download | systemd-init-69b4052ff1e507259b1eb21490c2ac4663e97958.tar.gz systemd-init-69b4052ff1e507259b1eb21490c2ac4663e97958.tar.xz systemd-init-69b4052ff1e507259b1eb21490c2ac4663e97958.zip |
add image container probing via qemu-img
Diffstat (limited to 'builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh')
-rwxr-xr-x | builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh b/builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh index 2b266012..fc99226d 100755 --- a/builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh +++ b/builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh @@ -1,9 +1,12 @@ +# region imports source "/usr/lib/rebash/core.sh" core.import utils core.import logging logging.set_commands_log_level debug logging.set_log_level debug +# endregion +# region connect dnbd3 # Close previous connections to be able to run this script many times. dnbd3-client --device "$SLX_DNBD3_DEVICE" --close local IFS_backup="$IFS" @@ -19,32 +22,39 @@ for host in ${SLX_DNBD3_SERVERS}; do continue done IFS="$IFS_backup" + if [[ $return_code != 0 ]]; then warn "Failed to connect '${SLX_SERVER_BASE#/}${SLX_DNBD3_IMAGE}' from" \ "one of '$SLX_DNBD3_SERVERS' to '$SLX_DNBD3_DEVICE'." emergency_shell -n "Error in $0" return 1 fi -local nbd_device='/dev/nbd0' -systemd-preserve-process-marker qemu-nbd --connect="$nbd_device" \ - "$SLX_DNBD3_DEVICE" --read-only +# endregion + +# region detect read-only partition +local read_only_device="$SLX_DNBD3_DEVICE" +if ! qemu-img info --output json "$read_only_device" | grep '"format": "raw"' +then + read_only_device='/dev/nbd0' + systemd-preserve-process-marker qemu-nbd --connect="$read_only_device" \ + "$SLX_DNBD3_DEVICE" --read-only -# TODO make nicer :) -touch $nbd_device -udevadm settle + # wait for partitions TODO make nicer :) + touch $read_only_device + udevadm settle +fi local read_only_partition if ! read_only_partition=$(utils.find_block_device \ - "$SLX_SYSTEM_PARTITION_IDENTIFIER" "$nbd_device"); then + "$SLX_SYSTEM_PARTITION_IDENTIFIER" "$read_only_device"); then logging.warn "Failed to find unique device with identifier" \ "'${SLX_SYSTEM_PARTITION_IDENTIFIER}'; matched devices:" \ "'${read_only_partition}'" emergency_shell fi +# endregion -# Make read-only partition writable. - -## detect partition for persistent storage +# region detect writable partition local persistent_device if ! persistent_device=$(utils.find_block_device \ "$SLX_WRITABLE_DEVICE_IDENTIFIER"); then @@ -84,6 +94,9 @@ fi #losetup "$writable_device" persistent_storage.img #persistent='P' +# endregion + +# region combine devices with device mapper local partition_size="$(blockdev --getsz "$read_only_partition")" local writable_partition_name='root' logging.info "Using read-only device: $read_only_partition" @@ -93,3 +106,11 @@ modprobe dm_snapshot dmsetup create "$writable_partition_name" --noudevsync --table \ "0 $partition_size snapshot $read_only_partition $writable_device $persistent $chunksize" dmsetup mknodes --noudevsync "$writable_partition_name" +# enregion + +# region vim modline + +# vim: set tabstop=4 shiftwidth=4 expandtab: +# vim: foldmethod=marker foldmarker=region,endregion: + +# endregion |