blob: 0f4e117c135a59df0a32f2df680f9f928eab4d83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/bin/sh
die()
{
printf '%s\n' "$*" >&2
exit 1
}
target=$1
if [ ! "$target" ] && mountpoint -q /srv && [ ! -e /srv/samizdat.iso ]; then
target=/srv/samizdat.iso
fi
[ "$target" ] || die "Usage: $0 <target filename>"
[ ! -e "$target" ] || die "Error: file exists: $target"
if mountpoint -q /outerfs; then
temp_target=$(mktemp --tmpdir=/outerfs)
else
die "Error: /outerfs is not a mountpoint. Please mount a safe filesystem to temporarily store the ISO on /outerfs"
fi
. 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" ] || set -- # avoid messing up someone's btrfs!
copy()
{
mdadm_copy_eject_crypt /dev/md55 "$temp_target" &&
dd if=/dev/md55 of="$target".part &&
mv "$target".part "$target"
# I suppose at this point $target should be made the backing device of
# /dev/md55
# Alternatively: mdadm --stop /dev/md55
}
remove()
{
for dev; do
(set -x; btrfs device remove "$dev" /)
dmsetup remove "$dev" 2>/dev/null
losetup -D
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
|