How to re-generate the grubenv file if missing or corrupted ?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8

Issue

  • The grubenv file is corrupted or missing in BIOS and UEFI systems.

  • Detected a corrupted grubenv file in the /var/log/leapp/leapp-report.txt.

  • Following messages were repeatedly observed in the /var/log/messages:

    grub2-set-bootflag[736726]: Error reading from /boot/grub2/grubenv: Invalid argument
    systemd[732552]: grub-boot-success.service: Main process exited, code=exited, status=1/FAILURE
    systemd[732552]: grub-boot-success.service: Failed with result 'exit-code'.
    systemd[732552]: Failed to start Mark boot as successful.
    

Resolution

  • check the size of grubenv file , this should be 1024 in size , else the file is corrupted.

       For BIOS 
       # ls -l /boot/grub2/grubenv
    
       For UEFI
       # ls -l /boot/efi/EFI/redhat/grubenv
    
  • Remove the corrupted remove grubenv file.

       For BIOS 
       # rm  /boot/grub2/grubenv
    
       For UEFI
       # rm /boot/efi/EFI/redhat/grubenv
    
  • Re-generate the grubenv file.

    # grub2-mkconfig
    

Root Cause

  • The leapp-report.txt had a inhibitor of missing files.

    Risk Factor: high (inhibitor)
    Title: Detected a corrupted grubenv file
    Summary: The grubenv file must be valid to pass the upgrade correctly: 
     - an exact size of 1024 bytes is expected 
     - it cannot end with a newline. 
    The corruption could be caused by a manual modification of the file which is not
     recommended.
    

Diagnostic Steps

  • For a UEFI system the grubenv file was 953 in size which should be 1024.

    -rwx------. 1 root root 953 Apr 21  2023 /boot/efi/EFI/redhat/grubenv
    
SBR
Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.