Skip to content

Commit

Permalink
Merge pull request #340 from jouvin/aii-ks_pxe_first
Browse files Browse the repository at this point in the history
UEFI boot order definition: set the device currently booted as the first entry
  • Loading branch information
jrha committed Jul 28, 2023
2 parents 22a61e4 + d6675ac commit 0fbae97
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions aii-ks/src/main/perl/ks.pm
Expand Up @@ -1787,27 +1787,25 @@ EOF
# restore pxeboot as first boot order in case efibootmgr is around
#
efibootmgr=/usr/sbin/efibootmgr
function join { local IFS=","; echo "\$*"; }
if [ -x \$efibootmgr ]; then
ordertxt=\$(\$efibootmgr |grep BootOrder | sed "s/.*: \\?//")
order=(\$(echo \$ordertxt | tr ',' ' '))
pxe=(\$(\$efibootmgr -v | grep -Pi '\\s(NIC|PXE|Network)\\s' | sed "s/*\\? .*//;s/^Boot//" | sort ))
neworder=("\${pxe[@]}")
for idx in "\${order[@]}"; do
add=1
for pxeidx in "\${pxe[@]}"; do
if [ \$pxeidx == \$idx ]; then
add=0
boot_current=\$(\$efibootmgr -v | grep BootCurrent | cut -d' ' -f2-)
boot_order=\$(\$efibootmgr -v | grep BootOrder | cut -d' ' -f2-)
first_boot_nr_hex=\$(echo \${boot_order} | awk -F, '{print \$1}')
if [ "\${first_boot_nr_hex}" != "\${boot_current}" ]
then
new_boot_order=\${boot_current}
for entry in \$(echo \$boot_order | sed -e 's/,/ /g')
do
if [ \${entry} != \${boot_current} ]
then
new_boot_order="\$new_boot_order,\${entry}"
fi
done
if [ \$add -eq 1 ]; then
neworder+=(\$idx)
fi
done
newordertxt=\$(join "\${neworder[@]}")
if [ \$newordertxt != \$ordertxt ]; then
echo "Found PXE indices \${pxe[@]}; old bootorder \$ordertxt, new bootorder \$newordertxt"
\$efibootmgr -o \$newordertxt
echo "Setting entry \${boot_current} first in boot order list"
\$efibootmgr -o "\$new_boot_order" -q
echo "New boot order: \$(\$efibootmgr -v | grep BootOrder | cut -d' ' -f2-)"
fi
fi
Expand Down

0 comments on commit 0fbae97

Please sign in to comment.