From 004812b461ff45c8771c5513afa379a32d322046 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 22 Apr 2016 18:48:58 -0400 Subject: Add multi-layered seed support The available filesystem with the largest number of seeds will be chosen for the root of the initial install. --- old-school/lvm-create.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'old-school/lvm-create.sh') diff --git a/old-school/lvm-create.sh b/old-school/lvm-create.sh index e6f4eea..743b83a 100644 --- a/old-school/lvm-create.sh +++ b/old-school/lvm-create.sh @@ -31,9 +31,19 @@ init_samizdat() local imgfile="$1" megs="$2" keyfile="$3" dev init_samizdat_blockdev "$imgfile" "$megs" "$keyfile" || return - local blockdev=/dev/mapper/samizdatcrypt + local blockdev=/dev/mapper/samizdatcrypt uuid + + for fs in /cdrom/live/*.btrfs; do + losetup -f "$fs" || return + done + modprobe btrfs || return + btrfs device scan || return + + uuid=$(choose_uuid) || return + [ "$uuid" ] + + mount -t btrfs -o subvol=ROOT UUID="$uuid" /root || return - mount -t btrfs -o subvol=ROOT /cdrom/live/filesystem.btrfs /root || return btrfs device add "$blockdev" /root || return mount -o rw,remount /root || return btrfs subvolume create /root/gpg || return @@ -53,14 +63,44 @@ init_samizdat() bootdone root-mounted } +# Get the uuid of the filesystem with the most devices, +# excluding filesystems that don't incorporate loop devices. +# This is used to choose the latest seed -- which should have +# the most layers. +choose_uuid() +{ + local seen_loop= seen_uuid= seen_devs= + btrfs filesystem show | + while read line; do + case "$line" in + Label*) + seen_uuid=${line##*uuid: } + seen_devs= + seen_loop= + ;; + *Total\ devices*) + seen_devs=${line#*Total devices } + seen_devs=${seen_devs%% *} + ;; + *path\ /dev/loop*) + seen_loop=t;; + esac + [ "$seen_loop" ] && echo "$seen_devs $seen_uuid" + done | + uniq | sort -nr | head -n1 | (read _ x; echo $x) +} + open_samizdat() { open_samizdat_blockdev "$@" || return - local blockdev=/dev/mapper/samizdatcrypt - losetup -f /cdrom/live/filesystem.btrfs || return + local blockdev=/dev/mapper/samizdatcrypt fs + for fs in /cdrom/live/*.btrfs; do + losetup -f "$fs" || return + done modprobe btrfs || return btrfs device scan || return mount -t btrfs -o subvol=ROOT "$blockdev" /root || return + LoSetup -D bootdone root-mounted } -- cgit v1.2.3