fix(iso): Propagate EFI drive to efibootmgr (#1)
This commit is contained in:
parent
05f2aa8035
commit
a5f32cfe76
37
setup.sh
37
setup.sh
@ -11,7 +11,7 @@ zfs_arch_dataset_name='archlinux'
|
||||
set -E
|
||||
trap '[ "$?" -ne 77 ] || exit 77' ERR
|
||||
|
||||
declare zpool_drive
|
||||
declare zpool_drive efi_drive
|
||||
|
||||
function set_ntp () {
|
||||
timedatectl set-ntp true
|
||||
@ -51,6 +51,14 @@ function get_partitions () {
|
||||
return 0
|
||||
}
|
||||
|
||||
function get_part_parent () {
|
||||
local child_partition parent_partition
|
||||
child_partition="${1:?}"
|
||||
parent_partition="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | select(.children[].path=="'"${child_partition:?}"'") | .path')"
|
||||
printf -- '%s' "${parent_partition}"
|
||||
return 0
|
||||
}
|
||||
|
||||
function get_parts () {
|
||||
local zfs_install_drive
|
||||
declare parttype parts
|
||||
@ -61,7 +69,7 @@ function get_parts () {
|
||||
parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | .children[] | select(.parttype=="6a85cf4d-1dd2-11b2-99a6-080020736631") | .path')" || exit 1
|
||||
;;
|
||||
efi)
|
||||
parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | select(.children[].path=="'"${zfs_install_drive:?}"'") | .children[] | select(.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b") | .path')" || exit 1
|
||||
parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | select(.path=="'"${zfs_install_drive:?}"'") | .children[] | select(.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b") | .path')" || exit 1
|
||||
;;
|
||||
*)
|
||||
>2 printf -- '%s\n' 'Unknown partition type '"'"'"${parttype}"'"'"', exiting ...'
|
||||
@ -212,7 +220,10 @@ function mount_system () {
|
||||
zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}"
|
||||
zfs mount -a
|
||||
|
||||
local efi_part="$(select_part 'efi' "${zpool_drive:?}")"
|
||||
local zfs_parent efi_part
|
||||
zfs_parent="$(get_part_parent "${zpool_drive:?}")"
|
||||
efi_drive="${zfs_parent}"
|
||||
efi_part="$(select_part 'efi' "${zfs_parent:?}")"
|
||||
mkdir -p '/mnt/efi'
|
||||
mount "${efi_part}" '/mnt/efi'
|
||||
}
|
||||
@ -523,7 +534,6 @@ function configure_zfs_mount_gen () {
|
||||
}
|
||||
|
||||
function configure_zfsbootmenu () {
|
||||
mkdir -p '/mnt/efi/EFI/ZBM'
|
||||
curl -s 'https://raw.githubusercontent.com/zbm-dev/zfsbootmenu/master/etc/zfsbootmenu/mkinitcpio.conf' | sed -r -e '/^#/d' -e '/^$/d' > '/mnt/etc/zfsbootmenu/mkinitcpio.conf'
|
||||
cat > '/mnt/etc/zfsbootmenu/config.yaml' <<EOF
|
||||
Global:
|
||||
@ -548,19 +558,20 @@ EOF
|
||||
function gen_zfsbootmenu () {
|
||||
arch-chroot /mnt /bin/bash -xe <<"EOF"
|
||||
source /etc/locale.conf
|
||||
mkdir -p '/efi/EFI/ZBM'
|
||||
find /efi/EFI/ZBM -type f -delete
|
||||
generate-zbm
|
||||
EOF
|
||||
}
|
||||
|
||||
function get_disk_with_efipart () {
|
||||
declare disks_with_efipart
|
||||
function get_disks_with_one_efipart () {
|
||||
local disks_with_one_efipart
|
||||
# Find disks that have exactly one EFI partition and where that EFI
|
||||
# partition is partition number 1. We expect exactly one disk to meet
|
||||
# these criteria. Anything else and we bail.
|
||||
disks_with_efipart="$(lsblk --output PATH,PARTTYPE --json --tree | jq --raw-output '.[][] | select(.children | length > 0) | select( any (.children[]; (.path | test("^[^[:digit:]]+1")) and (.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b")) and ([select(.children[].parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b")] | length == 1) ) | .path')"
|
||||
if [[ "$(wc -l <<<"${disks_with_efipart}")" -eq '1' ]] && [[ "$(wc -c <<<"${disks_with_efipart}")" -gt '1' ]]; then
|
||||
printf -- '%s' "${disks_with_efipart}"
|
||||
disks_with_one_efipart="$(lsblk --output PATH,PARTTYPE --json --tree | jq --raw-output '.[][] | select(.children | length > 0) | select( any (.children[]; (.path | test("^[^[:digit:]]+1")) and (.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b")) and ([select(.children[].parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b")] | length == 1) ) | .path')"
|
||||
if [[ "$(wc -l <<<"${disks_with_one_efipart}")" -eq '1' ]] && [[ "$(wc -c <<<"${disks_with_one_efipart}")" -gt '1' ]]; then
|
||||
printf -- '%s' "${disks_with_one_efipart}"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
@ -568,15 +579,17 @@ function get_disk_with_efipart () {
|
||||
|
||||
function add_zbm_to_efi () {
|
||||
if ! efibootmgr | grep -Pi -- 'ZFSBootMenu'; then
|
||||
declare efi_disk
|
||||
efi_disk="$(get_disk_with_efipart)"
|
||||
efibootmgr --disk "${efi_disk}" \
|
||||
local efi_disks_list
|
||||
efi_disks_list="$(get_disks_with_one_efipart)"
|
||||
if grep -Piq -- '^'"${efi_drive}"'$' <<<"${efi_disks_list}"; then
|
||||
efibootmgr --disk "${efi_drive}" \
|
||||
--part 1 \
|
||||
--create \
|
||||
--label "ZFSBootMenu" \
|
||||
--loader "\EFI\ZBM\vmlinuz.efi" \
|
||||
--verbose
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function umount_all () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user