Created
February 18, 2025 18:02
-
-
Save jhoblitt/a149f070676e587804151b1002651cbc to your computer and use it in GitHub Desktop.
chatgpt 4o generated script to set net boot. The prompt: `What a bash script to use efibootmgr to set the next boot and the boot order to the first boot option which contains the string UEFI PXE: IPv4 Intel(R) Ethernet Controller X550`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Find the boot entry number that matches the given string | |
BOOT_ENTRY=$(efibootmgr | grep "UEFI PXE: IPv4 Intel(R) Ethernet Controller X550" | head -n 1 | awk '{print $1}' | sed 's/Boot//;s/\*//') | |
# Check if a matching boot entry was found | |
if [[ -z "$BOOT_ENTRY" ]]; then | |
echo "No matching UEFI PXE boot entry found!" | |
exit 1 | |
fi | |
echo "Found boot entry: Boot$BOOT_ENTRY" | |
# Set this entry as the next boot option | |
efibootmgr --bootnext $BOOT_ENTRY | |
if [[ $? -ne 0 ]]; then | |
echo "Failed to set bootnext." | |
exit 1 | |
fi | |
echo "Set BootNext to Boot$BOOT_ENTRY." | |
# Set this entry as the first boot option in the boot order | |
CURRENT_ORDER=$(efibootmgr | grep "BootOrder" | awk -F ' ' '{print $2}') | |
NEW_ORDER="$BOOT_ENTRY,$(echo $CURRENT_ORDER | sed "s/$BOOT_ENTRY,//")" | |
efibootmgr --bootorder $NEW_ORDER | |
if [[ $? -ne 0 ]]; then | |
echo "Failed to update boot order." | |
exit 1 | |
fi | |
echo "Updated BootOrder to prioritize Boot$BOOT_ENTRY." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment