diff options
author | Andrew Cady <d@jerkface.net> | 2016-04-22 16:03:26 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-04-22 18:50:58 -0400 |
commit | 59df1261e0dc123c22dde588ced5c3abbf8300ca (patch) | |
tree | 0d43897973fd866f32cb11c202fb26a521d94f7e /btrfs-receive-root.sh | |
parent | 727026bb76dc2e9cbc4d935db5eb03049d65385e (diff) |
updated btrfs send/recv code; script to put layered seed on iso
Diffstat (limited to 'btrfs-receive-root.sh')
-rw-r--r-- | btrfs-receive-root.sh | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/btrfs-receive-root.sh b/btrfs-receive-root.sh index 178fd64..175dd49 100644 --- a/btrfs-receive-root.sh +++ b/btrfs-receive-root.sh | |||
@@ -1,10 +1,7 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | layer_dir=/home/d/sami | 3 | . sami/btrfs-functions.sh |
4 | seed_file=debian-live-8.4.0-amd64-standard.btrfs | 4 | . sami/var.sh |
5 | layer_file=debian-live-8.4.0-amd64-standard.layer.$$.btrfs | ||
6 | layer_size=1000 | ||
7 | mountpoint=layer_dest.$$ | ||
8 | 5 | ||
9 | disable_stdout() { exec 3>&1; exec >&2; } | 6 | disable_stdout() { exec 3>&1; exec >&2; } |
10 | enable_stdout() { exec >&3; } | 7 | enable_stdout() { exec >&3; } |
@@ -14,24 +11,38 @@ with_stdout() { enable_stdout; "$@"; disable_stdout; } | |||
14 | create_layer_filesystem() | 11 | create_layer_filesystem() |
15 | { | 12 | { |
16 | [ ! -e "$layer_file" ] || return | 13 | [ ! -e "$layer_file" ] || return |
17 | mkdir -p "$mountpoint" && | 14 | ! mountpoint "$mountpoint" || return |
18 | dd if=/dev/zero of="$layer_file" bs=1M count="$layer_size" && | 15 | mkdir -p "$mountpoint" && |
19 | mount -o subvol=/,compress "$seed_file" "$mountpoint" && | 16 | sex dd if=/dev/zero of="$layer_file" bs=1M count="$layer_size" && |
20 | layer_dev=$(losetup -f --show "$layer_file") && | 17 | sex mount -o subvol=/,compress "$seed_file" "$mountpoint" && |
21 | btrfs device add "$layer_dev" "$mountpoint" && | 18 | layer_dev=$(losetup -f --show "$layer_file") && |
19 | sex btrfs device add "$layer_dev" "$mountpoint" && | ||
22 | mount -o rw,remount "$mountpoint" | 20 | mount -o rw,remount "$mountpoint" |
23 | } | 21 | } |
24 | 22 | ||
25 | finish() | 23 | finish() |
26 | { | 24 | { |
27 | umount "$mountpoint" && | 25 | btrfs_replace_default_subvolume_with "$mountpoint"/"$receive_subv" && |
28 | btrfstune -S1 "$layer_file" | 26 | umount "$mountpoint" && |
27 | sex btrfstune -S1 "$layer_file" && | ||
28 | losetup -d "$layer_dev" | ||
29 | } | 29 | } |
30 | 30 | ||
31 | set -ex | 31 | set -e |
32 | disable_stdout | ||
33 | |||
34 | receive_dest=$1 | ||
35 | receive_subv=$2 | ||
36 | |||
37 | [ "$receive_subv" ] | ||
38 | [ "$receive_dest" ] | ||
39 | |||
40 | mountpoint=$(realpath -m --relative-base=. "$receive_dest") | ||
41 | |||
42 | seed_file=sami/debian-live-8.4.0-amd64-standard.btrfs | ||
43 | layer_file=sami/debian-live-8.4.0-amd64-standard.layer.$receive_subv.btrfs | ||
44 | layer_size=1000 | ||
32 | 45 | ||
33 | cd "$layer_dir" && | 46 | create_layer_filesystem |
34 | disable_stdout && | 47 | with_stdout sex btrfs receive "$mountpoint" |
35 | create_layer_filesystem && | ||
36 | with_stdout btrfs receive "$mountpoint" && | ||
37 | finish | 48 | finish |