diff options
author | torben | 2015-11-05 15:25:43 +0100 |
---|---|---|
committer | torben | 2015-11-05 15:25:43 +0100 |
commit | 5d853b5a1f037ef0888fd039fdf4bd86739fcb11 (patch) | |
tree | 1d92b1a99fb8a3faf79cb3aec130bf4929fa87cc /builder/dnbd3-qcow2-rootfs/hooks/pre-mount/prepare-root-partition.sh | |
parent | Merge branch 'master' of git.openslx.org:openslx-ng/systemd-init (diff) | |
download | systemd-init-5d853b5a1f037ef0888fd039fdf4bd86739fcb11.tar.gz systemd-init-5d853b5a1f037ef0888fd039fdf4bd86739fcb11.tar.xz systemd-init-5d853b5a1f037ef0888fd039fdf4bd86739fcb11.zip |
Refactor structure.
Diffstat (limited to 'builder/dnbd3-qcow2-rootfs/hooks/pre-mount/prepare-root-partition.sh')
-rwxr-xr-x | builder/dnbd3-qcow2-rootfs/hooks/pre-mount/prepare-root-partition.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/prepare-root-partition.sh b/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/prepare-root-partition.sh new file mode 100755 index 00000000..8b5ea48e --- /dev/null +++ b/builder/dnbd3-qcow2-rootfs/hooks/pre-mount/prepare-root-partition.sh @@ -0,0 +1,42 @@ +function create_partition_via_offset() { + local device="$1" + local nameOrUUID="$2" + local loopDevice=$(losetup -f) + + local sectorSize=$(blockdev --getbsz $device) + local partitionInfo=$(partx --raw --noheadings --output START,NAME,UUID /dev/nbd0 2>/dev/null| grep $nameOrUUID) + local offsetSectors=$(echo $partitionInfo | cut -d' ' -f1) + if [ -z "$offsetSectors" ]; then + warn "could not find partition with label/uuid '$nameOrUUID' on device $device" + return 1 + fi + #warn $(($offsetSectors*512)) # could overflow on 32bit systems + local offsetBytes=$(echo $| awk -v x=$offsetSectors -v y=$sectorSize '{print x * y}') + + # test if mount works directly (problem with btrfs device id) + #mount -v -o loop,offset=$offsetBytes $device $mountPoint + losetup -v -o $offsetBytes $loopDevice $device + echo $loopDevice +} + +# Close previous connections to be able to run this script many times. +dnbd3-client --device /dev/dnbd0 --close && \ +dnbd3-client --host gateway --image archLinux.qcow2 --device /dev/dnbd0 && \ +qemu-nbd --connect=/dev/nbd0 /dev/dnbd0 --read-only && \ +local read_only_partition="$(create_partition_via_offset /dev/nbd0 system)" && \ +# Make read-only partition writable. +# TODO implement persistent available indicator. +if true; then + local writable_device="/dev/ram0" && \ + mknod --mode 660 "$writable_device" b 1 1 && \ + chown root.disk "$writable_device" +else + # Use next free loop device. + local writable_device="$(losetup -f)" && \ + dd if=/dev/zero of=persistent_storage.img bs=1k count=1000 && \ + losetup "$writable_device" persistent_storage.img +fi +local size="$(blockdev --getsz "$read_only_partition")" && \ +local writable_partition_name="root" && \ +dmsetup create "$writable_partition_name" --table \ + "0 $partion_size snapshot $read_only_partition $writable_device N 1" |