Error: invalid environment block. Press any key to continue

Error: invalid environment block. Press any key to continue...

The error message appears immediately after the boot screen on purple background. Ubuntu 12.04.1 LTS.


From http://ubuntuforums.org/showthread.php?t=1285098:

Press E at the GRUB menu. Find the line saying save_env recordfail and delete all of it with the Del or Backspace key. Press Ctrl+X to boot, and then open the Terminal by searching it in the dash(launcher menu).

Run the following command, and then when it asks for your password, type it, and press Enter. Your password will not be shown, not even asterisks.

sudo -i

Then, run each command, one-by-one.

cd /boot/grub
rm grubenv
grub-editenv grubenv create
grub-editenv grubenv set default=0
grub-editenv grubenv list
update-grub

The second-to-last command should show default=0. If it does, run the last command, and let it finish. When it finishes, you should get the prompt /boot/grub# or something like that again(it's what you see after each command). Run exit twice, and then reboot.


This error message means that the grubenv file is > 1024 bytes. This is mostly caused by manually editing the file. (e.g. vi appends a newline on the last line)

To avoid this, you should never edit grubenv using anything other than grub-editenv.

Using grub-editenv <filename> set exiting_var=existing_value does not fix the file.

Speculation: You should be able to fix the file by deleting a character or two to get the size back to exactly 1024 bytes. If that does not work, you need to recreate the file using the instructions in this answer instead. (Get the correct values of the variables using grub-editenv grubenv list first and recreate a file with those values)