refactor(zbm): Update UEFI boot entries when images are done (#3)
This commit is contained in:
parent
598b176ec6
commit
915ded9c1b
60
setup.sh
60
setup.sh
@ -651,30 +651,50 @@ function configure_zfs_mount_gen () {
|
|||||||
systemctl enable 'zfs-zed.service' --root='/mnt'
|
systemctl enable 'zfs-zed.service' --root='/mnt'
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure_zfsbootmenu () {
|
function set_new_uefi_boot_entries () {
|
||||||
#3.8
|
|
||||||
zfs set org.zfsbootmenu:commandline='rw nowatchdog rd.vconsole.keymap=de-latin1' "${zpool_name}"'/root/'"${zfs_arch_dataset_name}"
|
|
||||||
}
|
|
||||||
|
|
||||||
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_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
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_zbm_to_efi () {
|
|
||||||
#3.9
|
#3.9
|
||||||
|
declare -a uefi_images
|
||||||
|
mapfile -t uefi_images < \
|
||||||
|
<(find '/mnt/efi/EFI/ZBM' -type f -iname '*.efi' -print0 | \
|
||||||
|
xargs -0 --no-run-if-empty --max-args '1' stat -c '%Y %n' | \
|
||||||
|
sort -V | \
|
||||||
|
awk '{print $2}')
|
||||||
|
|
||||||
|
if efibootmgr | grep -Piq -- 'ZFSBootMenu'; then
|
||||||
|
local -a old_uefi_entries
|
||||||
|
mapfile -t old_uefi_entries < \
|
||||||
|
<(efibootmgr | \
|
||||||
|
grep -Pio -- '(?<=^Boot)[^\*[:space:]]+(?=\*? ZFSBootMenu)')
|
||||||
|
for old_uefi_entry in "${old_uefi_entries[@]}"; do
|
||||||
|
efibootmgr --bootnum "${old_uefi_entry}" --delete-bootnum &>/dev/null && {
|
||||||
|
>&3 printf -- '%s\n' \
|
||||||
|
'EFI boot entry '"${old_uefi_entry}"' deleted.'
|
||||||
|
}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if ! efibootmgr | grep -Piq -- 'ZFSBootMenu'; then
|
if ! efibootmgr | grep -Piq -- 'ZFSBootMenu'; then
|
||||||
local efi_disks_list
|
local efi_disks_list
|
||||||
efi_disks_list="$(get_disks_with_one_efipart)"
|
efi_disks_list="$(get_disks_with_one_efipart)"
|
||||||
if grep -Piq -- '^'"${efi_drive}"'$' <<<"${efi_disks_list}"; then
|
if grep -Piq -- '^'"${efi_drive}"'$' <<<"${efi_disks_list}"; then
|
||||||
|
for uefi_image in "${uefi_images[@]}"; do
|
||||||
|
uefi_image_version="$(basename "${uefi_image##*-}")"
|
||||||
|
uefi_image_version="${uefi_image_version%%.EFI}"
|
||||||
|
uefi_image_inverted="${uefi_image#/mnt/efi}"
|
||||||
|
uefi_image_inverted="${uefi_image_inverted//\//\\}"
|
||||||
|
efibootmgr --disk "${efi_drive}" \
|
||||||
|
--part 1 \
|
||||||
|
--create \
|
||||||
|
--label 'ZFSBootMenu '"${uefi_image_version}" \
|
||||||
|
--loader "${uefi_image_inverted}" &>/dev/null && {
|
||||||
|
>&3 printf -- '%s\n' \
|
||||||
|
'EFI boot entry ZFSBootMenu '"${uefi_image_version}"' added.'
|
||||||
|
}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function insert_zbm_postconf_hook () {
|
function insert_zbm_postconf_hook () {
|
||||||
declare postconf_target_abs='/mnt/etc/zfsbootmenu/posthooks.d/'"$(basename "${postconf_hook}")"
|
declare postconf_target_abs='/mnt/etc/zfsbootmenu/posthooks.d/'"$(basename "${postconf_hook}")"
|
||||||
curl --silent --location "${postconf_hook}" --output "${postconf_target_abs}"
|
curl --silent --location "${postconf_hook}" --output "${postconf_target_abs}"
|
||||||
@ -696,7 +716,7 @@ function finalize_os_setup () {
|
|||||||
configure_reflector #3.5
|
configure_reflector #3.5
|
||||||
configure_zfs #3.6
|
configure_zfs #3.6
|
||||||
configure_zfs_mount_gen #3.7
|
configure_zfs_mount_gen #3.7
|
||||||
configure_zfsbootmenu #3.8
|
set_new_uefi_boot_entries #3.9
|
||||||
insert_zbm_postconf_hook
|
insert_zbm_postconf_hook
|
||||||
umount_all #3.11
|
umount_all #3.11
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user