summaryrefslogtreecommitdiff
path: root/src/initrd
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-13 17:00:19 -0400
committerAndrew Cady <d@jerkface.net>2018-06-13 17:13:53 -0400
commit87d9019314d90c13c357628e56ae59196eb16bd8 (patch)
tree2be0423a666103d766aeb47c05bf0593f200723f /src/initrd
parent2389f1c8d49823bbcf55f3a8d249632ed3c03d89 (diff)
making btrfs subvolumes should be idempotent
Diffstat (limited to 'src/initrd')
-rw-r--r--src/initrd/btrfs-create.sh35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/initrd/btrfs-create.sh b/src/initrd/btrfs-create.sh
index ff09bf7..567ad97 100644
--- a/src/initrd/btrfs-create.sh
+++ b/src/initrd/btrfs-create.sh
@@ -109,19 +109,34 @@ copy_execs()
109 done 109 done
110} 110}
111 111
112initialize_root_filesystem() 112is_subvolume()
113{ 113{
114 rm -r /root/root 114 btrfs subvolume show "$1" >/dev/null 2>&1
115 btrfs subvolume create /root/root || return 115}
116 mv /gpg/gnupghome /root/root/.gnupg || return 116
117make_subvolume_idem()
118{
119 is_subvolume "$1" && return
120 if [ -d "$1" ]; then
121 rmdir "$1" || mv "$1" "$1"~
122 btrfs subvolume create "$1"
123 mv "$1"~/* "$1"~/.* "$1"/ 2>&1
124 else
125 if [ -e "$1" ]; then
126 rm -f "$1"
127 fi
128 btrfs subvolume create "$1"
129 fi
130}
117 131
118 rmdir /root/srv 132initialize_root_filesystem()
119 btrfs subvolume create /root/srv 133{
120 rm -r /root/var/cache/apt/archives 134 for d in /root/root /root/srv /root/var/cache/apt/archives /root/home; do
121 btrfs subvolume create /root/var/cache/apt/archives || return 135 make_subvolume_idem "$d"
136 done
122 137
123 rmdir /root/home 138 mv /root/root/.gnupg /root/root/.gnupg~
124 btrfs subvolume create /root/home || return 139 mv /gpg/gnupghome /root/root/.gnupg || return
125 140
126 copy_execs sbin mdadm dmsetup cryptsetup fsck.hfsplus 141 copy_execs sbin mdadm dmsetup cryptsetup fsck.hfsplus
127 copy_execs bin btrfs rsync gpg gpg2 gpg-agent 142 copy_execs bin btrfs rsync gpg gpg2 gpg-agent