summaryrefslogtreecommitdiff
path: root/btrfs-receive-root.sh
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2016-04-22 16:03:26 -0400
committerAndrew Cady <d@jerkface.net>2016-04-22 18:50:58 -0400
commit59df1261e0dc123c22dde588ced5c3abbf8300ca (patch)
tree0d43897973fd866f32cb11c202fb26a521d94f7e /btrfs-receive-root.sh
parent727026bb76dc2e9cbc4d935db5eb03049d65385e (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.sh45
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
3layer_dir=/home/d/sami 3. sami/btrfs-functions.sh
4seed_file=debian-live-8.4.0-amd64-standard.btrfs 4. sami/var.sh
5layer_file=debian-live-8.4.0-amd64-standard.layer.$$.btrfs
6layer_size=1000
7mountpoint=layer_dest.$$
8 5
9disable_stdout() { exec 3>&1; exec >&2; } 6disable_stdout() { exec 3>&1; exec >&2; }
10enable_stdout() { exec >&3; } 7enable_stdout() { exec >&3; }
@@ -14,24 +11,38 @@ with_stdout() { enable_stdout; "$@"; disable_stdout; }
14create_layer_filesystem() 11create_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
25finish() 23finish()
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
31set -ex 31set -e
32disable_stdout
33
34receive_dest=$1
35receive_subv=$2
36
37[ "$receive_subv" ]
38[ "$receive_dest" ]
39
40mountpoint=$(realpath -m --relative-base=. "$receive_dest")
41
42seed_file=sami/debian-live-8.4.0-amd64-standard.btrfs
43layer_file=sami/debian-live-8.4.0-amd64-standard.layer.$receive_subv.btrfs
44layer_size=1000
32 45
33cd "$layer_dir" && 46create_layer_filesystem
34disable_stdout && 47with_stdout sex btrfs receive "$mountpoint"
35create_layer_filesystem &&
36with_stdout btrfs receive "$mountpoint" &&
37finish 48finish