@@ -437,50 +437,67 @@ EOT
437437boot_order_chage_to_disk () {
438438 echo -e " ${BLUE} Changing the Boot order to disk!!${NC} "
439439
440+ boot_entry=" Emt"
441+ efiboot_part=1
442+ EFI=" "
443+
444+ # Delete the pile up Ubuntu/Emt partitions from BIOS bootMenu
445+ for bootnumber in $( efibootmgr | grep -iE " emt|Ubuntu" | awk ' {print $1}' | sed ' s/Boot//;s/\*//' ) ; do
446+ efibootmgr -b " $bootnumber " -B
447+ done
448+ # Delete the duplicate boot entries from bootmenu
440449 boot_order=$( efibootmgr -D)
441450 echo " $boot_order "
442- usb_boot_number=$( efibootmgr | grep -i " Bootcurrent" | awk ' {print $2}' )
443451
444- boot_order=$( efibootmgr | grep -i " Bootorder" | awk ' {print $2}' )
452+ # Get the rootfs
453+ rootfs=$( blkid | grep -Ei ' TYPE="ext4"' | grep -Ei ' LABEL="rootfs"' | awk -F: ' {print $1}' )
445454
446- # Convert boot_order to an array and remove , between the entries
447- IFS=' ,' read -ra boot_order_array <<< " $boot_order"
455+ efiboot=$( blkid | grep -Ei ' TYPE="vfat"' | grep -Ei ' LABEL="esp|uefi"' | awk -F: ' {print $1}' )
448456
449- # Remove PXE boot entry from Array
450- final_boot_array=()
451- for element in " ${boot_order_array[@]} " ; do
452- if [[ " $element " != " $usb_boot_number " ]]; then
453- final_boot_array+=(" $element " )
454- fi
455- done
457+ if echo " $efiboot " | grep -q " nvme" ; then
458+ osdisk=$( echo " $rootfs " | grep -oE ' nvme[0-9]+n[0-9]+' | head -n 1)
459+ elif echo " $efiboot " | grep -q " sd" ; then
460+ osdisk=$( echo " $rootfs " | grep -oE ' sd[a-z]+' | head -n 1)
461+ fi
456462
457- # Add the PXE boot entry to the end of the boot order array
458- final_boot_array+=(" $usb_boot_number " )
463+ check_mnt_mount_exist
464+ mount " ${rootfs} " /mnt
465+ mount $efiboot /mnt/boot/efi
459466
460- # Join the elements of boot_order_array into a comma-separated string
461- final_boot_order=$(
462- IFS=,
463- echo " ${final_boot_array[*]} "
464- )
467+ # Get the EFI boot from chroot
468+ EFI=$( chroot /mnt sh -c ' basename $(find /boot/efi/EFI/Linux -type f -iname "*.efi" | head -n1)' ) || { echo " EFI binary not present,please check" ; return 1; }
465469
466- # remove trail and leading , if preset
467- final_boot_order=$( echo " $final_boot_order " | sed -e ' s/^,//;s/,$//' )
470+ # Unmount the file systems
471+ umount /mnt/boot/efi
472+ umount /mnt
468473
469- echo " final_boot order--->" " $final_boot_order "
474+ # Create the boot entry
475+ new_boot_number=$( efibootmgr -c -d " /dev/${osdisk} " -p $efiboot_part -L " $boot_entry " -l " \\ EFI\\ Linux\\ $EFI " ) || { echo " Failed to create new boot entry" ; return 1; }
470476
471- # Update the boot order using efibootmgr
477+ echo " Successfully created the boot entry $efiboot_part "
472478
473- if efibootmgr -o " $final_boot_order " ; then
474- success " Made Disk as first boot and USB boot at end"
475- # Make UEFI boot as inactive
476- efibootmgr -b " $usb_boot_number " -A
477- boot_order=$( efibootmgr)
478- echo " $boot_order "
479+ new_boot_number=$( efibootmgr | grep -i Emt | grep -oP ' Boot\d{4}' | head -n1 | sed ' s/Boot//' )
480+
481+ echo " New boot number is $new_boot_number "
482+
483+ # Update the bootorder
484+ usb_boot_number=$( efibootmgr | grep -i " Bootcurrent" | awk ' {print $2}' )
485+
486+ boot_order_cur=$( efibootmgr | grep -i " Bootorder" | awk ' {print $2}' )
487+
488+ if [ -n " $boot_order_cur " ]; then
489+ final_boot_order=" $new_boot_number ,$boot_order_cur " || { echo " Final boot order change failed" ; return 1; }
479490 else
480- failure " Boot order change not successful,Please Manually Select the Disk boot option"
481- return 1
491+ final_boot_order=" $new_boot_number " || { echo " Final boot order change failed" ; return 1; }
482492 fi
483- efibootmgr
493+
494+ # Update the boot order using efibootmgr
495+ efibootmgr -o " $final_boot_order " || { echo " Updating the Boot order with new boot entry failed" ; return 1; }
496+
497+ # Make UEFI boot as inactive
498+ efibootmgr -b " $usb_boot_number " -A
499+
500+ echo " Made Disk as first boot option"
484501 return 0
485502}
486503
@@ -769,13 +786,13 @@ platform_config_manager() {
769786 update_ssh_settings || return 1
770787
771788 update_mac_under_dhcp_systemd || return 1
789+
790+ boot_order_chage_to_disk || return 1
772791}
773792
774793# Post installation tasks
775794system_finalizer () {
776795
777- boot_order_chage_to_disk || return 1
778-
779796 dump_logs_to_usb || return 1
780797}
781798
0 commit comments