grub2-mkconfig crashes with "free(): invalid next size (normal)" message or fails with "error: environment block too small"

Solution Unverified - Updated

Environment

  • Red Hat Enterprise Linux 8
    • grub2 prior to version 2.02-90.el8

Issue

  • When executing grub2-mkconfig to rebuild the Grub menu, the command dumps core and print the following message

    # grub2-mkconfig -o /etc/grub2.cfg
    Generating grub configuration file ...
    free(): invalid next size (normal)
    /etc/grub.d/10_linux: line 128: PID Aborted                 (core dumped)
    
  • When executing grub2-mkconfig to rebuild the Grub menu, the command fails with the following message

    # grub2-mkconfig -o /etc/grub2.cfg
    Generating grub configuration file ...
    /usr/bin/grub2-editenv: error: environment block too small.
    

Resolution

Workaround

  1. Delete current /boot/grub/grubenv file

    # rm /boot/grub/grubenv
    
  2. Disable BLS in Grub's configuration file

    # sed -i "s/GRUB_ENABLE_BLSCFG=true/GRUB_ENABLE_BLSCFG=false/" /etc/default/grub
    
  3. Rebuild the Grub menu

    # grub2-mkconfig -o /etc/grub2.cfg
    

    Note: on UEFI file systems, specify /etc/grub2-efi.cfg instead of /etc/grub2.cfg

Root Cause

  • Grub corrupts the /boot/grub/grubenv file or file is too big to be handled properly
SBR
Components
Category

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.