@@ -409,21 +409,17 @@ EOT
409409
410410# Change the boot order to disk
411411boot_order_chage_to_disk () {
412- echo -e " ${BLUE} Changing the Boot order to disk!!${NC} "
413-
414- boot_entry=" Emt"
415- efiboot_part=1
416- EFI=" "
412+ echo -e " ${BLUE} Changing the Boot order to disk!!${NC} "
417413
418414 # Delete the pile up Ubuntu/Emt partitions from BIOS bootMenu
419- for bootnumber in $( efibootmgr | grep -iE " emt |Ubuntu" | awk ' {print $1}' | sed ' s/Boot//;s/\*//' ) ; do
415+ for bootnumber in $( efibootmgr | grep -iE " Linux Boot Manager |Ubuntu" | awk ' {print $1}' | sed ' s/Boot//;s/\*//' ) ; do
420416 efibootmgr -b " $bootnumber " -B
421417 done
422418 # Delete the duplicate boot entries from bootmenu
423419 boot_order=$( efibootmgr -D)
424420 echo " $boot_order "
425421
426- # Get the rootfs
422+ # Get the rootfs
427423 rootfs=$( blkid | grep -Ei ' TYPE="ext4"' | grep -Ei ' LABEL="rootfs"' | awk -F: ' {print $1}' )
428424
429425 efiboot=$( blkid | grep -Ei ' TYPE="vfat"' | grep -Ei ' LABEL="esp|uefi"' | awk -F: ' {print $1}' )
@@ -434,45 +430,37 @@ boot_order_chage_to_disk() {
434430 osdisk=$( echo " $rootfs " | grep -oE ' sd[a-z]+' | head -n 1)
435431 fi
436432
433+ # Mount all required partitions to create bootctl install entry
437434 check_mnt_mount_exist
438- mount " ${rootfs} " /mnt
439- mount " $efiboot " /mnt/boot/efi
440-
441- # Get the EFI boot from chroot
442- 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; }
443-
444- # Unmount the file systems
445- umount /mnt/boot/efi
446- umount /mnt
447-
448- # Create the boot entry
449- 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; }
450435
451- echo " Successfully created the boot entry $efiboot_part "
452-
453- new_boot_number=$( efibootmgr | grep -i Emt | grep -oP ' Boot\d{4}' | head -n1 | sed ' s/Boot//' )
454-
455- echo " New boot number is $new_boot_number "
456-
457- # Update the bootorder
458- usb_boot_number=$( efibootmgr | grep -i " Bootcurrent" | awk ' {print $2}' )
436+ mount " ${rootfs} " /mnt
437+ mount $efiboot /mnt/boot/efi
438+ mount --bind /dev /mnt/dev
439+ mount --bind /dev/pts /mnt/dev/pts
440+ mount --bind /proc /mnt/proc
441+ mount --bind /sys /mnt/sys
442+ mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
459443
460- boot_order_cur=$( efibootmgr | grep -i " Bootorder" | awk ' {print $2}' )
444+ chroot /mnt /bin/bash << EOT
445+ set -e
446+ bootctl install
447+ EOT
461448
462- if [ -n " $boot_order_cur " ]; then
463- final_boot_order=" $new_boot_number ,$boot_order_cur " || { echo " Final boot order change failed" ; return 1; }
449+ if [ " $? " -eq 0 ]; then
450+ success " Made Disk as first boot option"
451+ # unmount the partitions
452+ for mount in $( mount | grep ' /mnt' | awk ' {print $3}' | sort -nr) ; do
453+ umount " $mount "
454+ done
455+ return 0
464456 else
465- final_boot_order=" $new_boot_number " || { echo " Final boot order change failed" ; return 1; }
466- fi
467-
468- # Update the boot order using efibootmgr
469- efibootmgr -o " $final_boot_order " || { echo " Updating the Boot order with new boot entry failed" ; return 1; }
470-
471- # Make UEFI boot as inactive
472- efibootmgr -b " $usb_boot_number " -A
473-
474- echo " Made Disk as first boot option"
475- return 0
457+ failure " Boot entry create failed,Please check!!"
458+ # unmount the partitions
459+ for mount in $( mount | grep ' /mnt' | awk ' {print $3}' | sort -nr) ; do
460+ umount " $mount "
461+ done
462+ return 1
463+ fi
476464}
477465
478466# Update the MAC address under 99-dhcp.conf file
0 commit comments