From ebf58d2856976f568dac58dfc241bf6ba59179c8 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Tue, 29 Nov 2022 00:11:24 -0500 Subject: [PATCH] testing --- debianzfs.sh | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/debianzfs.sh b/debianzfs.sh index cfbcb1d..c8f588f 100755 --- a/debianzfs.sh +++ b/debianzfs.sh @@ -97,16 +97,6 @@ function create_root_pool () { rpool $2 } -function mirror_grub () { - DISK1=$(disk_by_id "$1") - DISK2=$(disk_by_id "$2") - umount /boot/efi - dd if="${DISK1}-part2" of="${DISK2}-part2" - efibootmgr -c -g -d "$DISK2" -p 2 \ - -L "debian-${3}" -l '\EFI\debian\grubx64.efi' - mount /boot/efi -} - function disk_by_id () { disk_check "$1" OUTPUT=$(find /dev/disk/by-id -lname "../../$(basename "$1")" | tail -n1) @@ -117,6 +107,29 @@ function disk_by_id () { echo "$OUTPUT" } +function part_by_uuid () { + OUTPUT=$( + blkid -s UUID | grep -e "^${1}.*${2}: UUID=" | \ + awk '{ print substr($2, 7, length($2)-7) }' + ) + + if [ -z "$OUTPUT" ]; then + echo "ERROR: No disk by-uuid label found for: ${1}, partition ${2}" + exit 1 + fi + echo "/dev/disk/by-uuid/$OUTPUT" +} + +function mirror_grub () { + DISK1_PART2="$(part_by_uuid "$1" 2)" + DISK2_PART2="$(part_by_uuid "$2" 2)" + umount /boot/efi + dd if="$DISK1_PART2" of="$DISK2_PART2" + efibootmgr -c -g -d "$DISK2" -p 2 \ + -L "debian-${3}" -l '\EFI\debian\grubx64.efi' + mount /boot/efi +} + ################ ### Settings ### ################ @@ -212,7 +225,7 @@ fi ############################################### # Display commands -set -x +set -xe # 1. Boot the Debian GNU/Linux Live CD... done # 2. Setup and update the repositories @@ -239,20 +252,21 @@ swapoff --all # 3. Partition your disk(s) # UEFI booting + boot pool + ZFS native encryption disk_format "$DISK" -DISK_BYID=$(disk_by_id "$DISK") if [ -n "$MIRROR" ]; then disk_format "$MIRROR" - MIRROR_BYID=$(disk_by_id "$MIRROR") fi +sleep 5 # 4. Create the boot pool # 5. Create the root pool if [ -z "$MIRROR" ]; then - create_boot_pool "$ZFSROOT" "${DISK_BYID}-part3" - create_root_pool "$ZFSROOT" "${DISK_BYID}-part4" "$RPOOLPW" + create_boot_pool "$ZFSROOT" "$(part_by_uuid "$DISK" 3)" + create_root_pool "$ZFSROOT" "$(part_by_uuid "$DISK" 4)" "$RPOOLPW" else - create_boot_pool "$ZFSROOT" "mirror ${DISK_BYID}-part3 ${MIRROR_BYID}-part3" - create_root_pool "$ZFSROOT" "mirror ${DISK_BYID}-part4 ${MIRROR_BYID}-part4" "$RPOOLPW" + create_boot_pool "$ZFSROOT" \ + "mirror $(part_by_uuid "$DISK" 3) $(part_by_uuid "$MIRROR" 3)" + create_root_pool "$ZFSROOT" \ + "mirror $(part_by_uuid "$DISK" 4) $(part_by_uuid "$MIRROR" 4)" "$RPOOLPW" fi ################################### @@ -353,8 +367,8 @@ if [ -n "$MIRROR" ]; then #!/bin/bash # Post-install GRUB mirror helper script /usr/local/bin/debianzfs \ - -gm $(disk_by_id "$MIRROR") \ - $(disk_by_id "$DISK") + -gm "$MIRROR_PART2_BYUUID" \ + "$DISK_PART2_BYUUID" GRUBMIRROR fi