#!/bin/sh . mdadm-dup.sh || exit 1 btrfs_subdevices() { local mountpoint="$1" btrfs filesystem show "$mountpoint" | sed -ne 's/^[ \t]*devid.* path //p' } devices=$(btrfs_subdevices /) || exit 1 set -- seen= for dev in $devices; do [ -b "$dev" ] || exit 1 case "$dev" in /dev/mapper/loop*) set -- "$@" "$dev" ;; /dev/mapper/samizdatcrypt) seen=y ;; esac done [ "$seen" ] || exit 1 copy() { mdadm_copy_eject /dev/md55 /root/samizdat.iso } remove() { for dev; do (set -x; btrfs device remove "$dev" /) done } # Doing the mdadm copy before removing the devices means our filesystem includes # devices that are ultimately backed by files ON THE SAME FILESYSTEM. As such, it # might conceivably put btrfs into a deadlock of some kind. # If it turns out this doesn't work, the order can be reversed. This will # perform the read IO twice, though, almost doubling the total installation # time. copy & remove "$@" set -x wait