Ubuntu/GRUB: Error: invalid environment block

After a recent system update I got the following error message:

Error: invalid environment block

Press any key to continue...

Luckily the system would boot up but ignoring errors isn’t best practice. This error is caused by a faulty GRUB2 environment block. This is a file located in /boot/grub/grubenv.

You can easily regenerate it with the following commands. It is advisable to make a backup copy the file just in case you need to revert.

# grub-editenv grubenv create
# grub-editenv grubenv set default=
# grub-editenv grubenv list
# update-grub

After rebooting the message should have disappeared.

If you can’t boot from your system drive you can use a Live CD and then mount your system’s boot partition and apply the same commands.

I haven’t tested this part personally but maybe the commands will help as a reference. Details are scarce on purpose, check what the commands do before doing anything.

# mount /dev/sda1 /mnt/boot/efi
or
# mount /dev/sda1 /mnt/boot/

# grub-editenv /mnt/boot/grub/grubenv grubenv create 
# grub-editenv /mnt/boot/grub/grubenv grubenv set default=
# grub-editenv /mnt/boot/grub/grubenv grubenv list
# grub-mkconfig  -o /mnt/boot/grub/grub.cfg

The other approach, also untested by me, could involve chroot.

# mount /dev/sda2 /target
# mount --bind /dev /target/dev
# mount --bind /dev/pts /target/dev/pts
# mount --bind /sys /target/sys
# mount --bind /proc /target/proc
# mount /dev/sda1 /target/boot

chroot /target

# grub-editenv grubenv create
# grub-editenv grubenv set default=
# grub-editenv grubenv list
# update-grub