Следите за новостями русскоязычного сообщества Ubuntu в Twitter-ленте @ubuntu_ru_loco
- Форум русскоязычного сообщества Ubuntu »
- Поддержка »
- Настройка системы (Модераторы: Дмитрий Бо, www777) »
- [РЕШЕНО]Ошибка : Неправильный блок окружения.
- Печать
Страницы: [1] Вниз
Тема: [РЕШЕНО]Ошибка : Неправильный блок окружения. (Прочитано 5077 раз)
0 Пользователей и 1 Гость просматривают эту тему.

alienonline
Здравствуйте, уважаемые участники форума !
Продолжаю устранять неприятные симптомы после краха SSD.
Сабж возник после одного из эпизодов самопроизвольного монтирования файловой системы в read-only. Теперь все стоит на новом SSD, но возникает при загрузке. Если выбирать пункты загрузки вручную, то его не возникает,а появляется привычное «Загружается начальный образ…»
А вот по умолчанию высвечивается в верхнем левом углу именно это :
Ошибка : Неправильный блок окружения.
Нажмите любую клавишу для продолжения...
В принципе жить не мешает, но раздражает и если по клавише не жмакнуть, то ждет секунд 5, а потом нормально стартует. Может кто сталкивался?
« Последнее редактирование: 20 Октября 2016, 18:27:28 от Punko »

alienonline
- Печать
Страницы: [1] Вверх
- Форум русскоязычного сообщества Ubuntu »
- Поддержка »
- Настройка системы (Модераторы: Дмитрий Бо, www777) »
- [РЕШЕНО]Ошибка : Неправильный блок окружения.
SMF 2.0.19 |
SMF © 2011, Simple Machines | Карта форума
Страница сгенерирована за 0.043 секунд. Запросов: 25.
I recently re-purposed two old computers into one new machine, and installed Linux Mint 19.2.
Now on every boot, something is wrong with GRUB. I know what you’re thinking: Bad disk, replace ASAP. But please read on.
I’ve written down a few of these boot messages and numbered them for reference.
Error 1
error: failure writing sector 0x74800 to `hd0'.
error: failure reading sector 0x6338d from `hd0'.
Press any key to continue...
I don’t think pressing a key ever did anything. I need to hard reset.
Error 2
error: failure writing sector 0x6c808 to `hd0'.
error: failure reading sector 0x74200 from `hd0'.
error: you need to load the kernel first.
Press any key to continue...
Failed to boot both default and fallback entries.
Press any key to continue...
Key-press does not boot the system, but I can press ctrl+alt+del to reboot.
Error 3
error: invalid environment block.
The computer hangs here. Num-lock is responsive but extremely laggy. I need to hard-reset the system.
Error 4
error: invalid environment block.
Press any key to continue...
This is the one that makes me happy, because pressing a key will make it boot normally.
So every boot, 1 out of 2 times I get Error 4 above, and I can just press a key and boot normally.
The other half of the time, I need to boot with a Linux Mint bootable USB stick. I will run fsck.ext4 -f /dev/sda1 (which is my /boot partition), which finds no problem, I reboot and 4 out of 5 times I get Error 4 above and I can boot normally.
I guess there is this 1 out of 10 times left where I need to boot to USB again, and run gdisk, which informs me that the GPT of the bootable SSD has been corrupted and I restore the backup record. Then when I reboot, I get the above Error 4, and I can boot normally.
Hoping for an easy fix, I’ve tried reinstalling Linux Mint completely using different partition layouts. The problem was the same.
Thinking there must be a problem, I’ve run fsck, fsck.ext4 -f, e2fsck -c, e2fsck -cc (these are the ones I recall) and there are never any problems found.
I’ve tried recreating the environment block like so:
cd /boot/grub
rm grubenv
grub-editenv grubenv create
grub-editenv grubenv set default=0
Recreating the environment block will sometimes result in a single boot without error, but the next boot the error is always back.
Hoping to trigger some internal bad blocks reordering system, I tried to zerofil /boot before recreating the environment block like so:
dd if=/dev/zero of=/boot/zerofil.bin bs=32M; rm /boot/zerofil.bin
But this didn’t change anything either. I have backed up my partitions, and compared the backups. I have not encountered any data corruption apart from /boot/grub/grubenv and sometimes the GPT. I have checked all blocks using non-destructive read-write.
According to the SMART screen in the ‘disks’ utility, all assessments are «OK». Not a single attribute assessment exceeds its threshold. The «Reallocated sectors count» is zero, and the «Read Error Rate» is zero.
I believe that there is nothing wrong with the SSD, but somehow my system cannot handle safely writing to the disk prior to starting Linux, causing it to corrupt files it touches. It seems that starting Linux from a live USB stick first and doing a soft reboot fixes this remedy. Sometimes I need to do a hard reset, and I believe this sometimes causes the GPT to be corrupted, needing me to restore the backup using gdisk.
What causes this, and how can I fix this?
So this is a Crucial M4 ATA M4 CT256M4SSD2 revision 0009 on an old ZOTAC H77-ITX WiFi H77ITX-AE (2012) mainboard with an old bios, but unfortunately it’s the latest bios.
A209P 0.10 x64 05/09/2013 09:48:07
I vaguely remember having issues that made me think this SSD was broken when I installed Linux on this ssd/mainboard some 6 (?) years ago, and I tried random things until it just worked. I believe it involved installing Windows first, and then installing Linux alongside of it. But that sounds like a coincidence. The SSD has not been used a lot, because most of the action happened on separate HDD drives. This SSD basically just contained Windows and Linux. I never use(d) Windows on this SSD, and it is not installed today.
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
The error message might refer to GRUB2 environment block, located usually in /boot/grub/grubenv. It should contain readable text, so have a look at it.
Hanging on black screen might be caused by many things. Perhaps your distribution sets up GRUB in such a way that some essential setting is stored in the environment block, and the problem in the environment block also causes the boot to fail. Or perhaps it’s caused by something different, like BIOS detecting the disks in a different order than expected by the grub-install program.
The updates to the Manjaro OS may have included an update to GRUB, causing it to automatically re-install it. If you had to do any special steps in installing GRUB when you originally installed Manjaro, you may have to do them again now.
Or if you added any new disks to the system after installing the OS and updating it, you might not originally have needed any special steps, but might need them now… and that could be what tripped up the automatic update.
If your system uses classic BIOS rather than the new UEFI firmware, the root cause is likely the fact that there is no guaranteed way for the OS to identify the disks that would be meaningful to the BIOS. Without further information from the system administrator, the grub-install command will have to essentially guess in which order the BIOS will detect the disks at boot time.
If the /boot/grub/device.map file exists, it describes the current information/guess GRUB has on the BIOS boot order; if you add/remove/change disks on the system, you should also update this file to match the new state, or else an automatic GRUB update might cause exactly the kind of situation you’re experiencing right now. To fix, correct the current device.map file to match how your BIOS actually sees the disks, then use grub-install to reinstall GRUB.
Table of Contents
1
Introduction
In todays quick guide, let’s focus on how to resolve the grub2-editenv: error: environment block too small error.
This error occurs when we have a corrupted grub environment file. The expected size of /boot/grub2/grubenv or /boot/efi/EFI/redhat/grubenv should not exceed exactly more than 1024 bytes. In most case, this could happen during some grub customization or during OS Update/Upgrade and reboot. Additionally, we may be required to reinstall the current kernel version.
How can be rectified from this error? Using grub2-editenv command we can regenerate the /boot/grub2/grubenv or /boot/efi/EFI/redhat/grubenv files. I have faced this issue on an RHEL 8.2 Linux server, however, the same fix can be applied for RHEL 7/8 versions and CentOS Linux 7/8 versions.
Another grub solution you may be interested are below.
- Recovering from dual boot issue on Ubuntu | Chroot Ubuntu
The Actual Error
I’m trying to set the default kernel using grubby command and getting error as “grub2-editenv: error: environment block too small“.
[root@gruberror ~]# grubby --set-default-index=0 grub2-editenv: error: environment block too small. The default is /boot/loader/entries/9cadf8d3a8ce4efcae3f028610e0e89f-4.18.0-240.el8.x86_64.conf with index 0 and kernel /boot/vmlinuz-4.18.0-240.el8.x86_64 [root@gruberror ~]#
Listing Grub environment (grub2-editenv)
Let’s start now. List the the grub environment files.
[root@gruberror ~]# grub2-editenv list saved_entry=9cadf8d3a8ce4efcae3f028610e0e89f-4.18.0-240.el8.x86_64 kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet boot_success=0 [root@gruberror ~]#
The actual file size should be 1024 bytes as we said before, the actual file is linked under /boot/grub2/grubenv
[root@gruberror ~]# ls -ltr /boot/grub2/grubenv lrwxrwxrwx. 1 root root 25 Aug 31 14:50 /boot/grub2/grubenv -> ../efi/EFI/redhat/grubenv [root@gruberror ~]# [root@gruberror ~]# ls -ltr /boot/efi/EFI/redhat/grubenv -rwx------. 1 root root 1024 Dec 12 00:54 /boot/efi/EFI/redhat/grubenv [root@gruberror ~]#
Regenerate the issue
Let’s start to regenerate the issue and fix it by editing the environment block.
For demonstration purpose just i’m going to increase the file size more than 1024 bytes using fallocate command.
[root@gruberror ~]#
[root@gruberror ~]# fallocate -l 2024 /boot/efi/EFI/redhat/grubenv
[root@gruberror ~]#
Now the size is different than 1024 bytes.
[root@gruberror ~]# ls -ltr /boot/efi/EFI/redhat/grubenv -rwx------. 1 root root 2024 Dec 12 01:03 /boot/efi/EFI/redhat/grubenv [root@gruberror ~]#
In case, if I have installed with multiple kernels and I need to set the latest kernel as default. I may run the grubby command. But, when we try with the grubby command it will throw some error, the cause of the error is due to the wrong file size of grubenv file.
[root@gruberror ~]# grubby --set-default-index=0 grub2-editenv: error: environment block too small. The default is /boot/loader/entries/9cadf8d3a8ce4efcae3f028610e0e89f-4.18.0-240.el8.x86_64.conf with index 0 and kernel /boot/vmlinuz-4.18.0-240.el8.x86_64 [root@gruberror ~]#
So, before setting the default kernel using grubby command i need to fix this error.
The Actual Fix
Run the command # grub2-editenv create to generate a new grubenv file, this will restore the size with appropriate content in it.
[root@gruberror ~]# grub2-editenv create
[root@gruberror ~]#
[root@gruberror ~]# ls -ltr /boot/efi/EFI/redhat/grubenv
-rwx------. 1 root root 1024 Dec 12 01:09 /boot/efi/EFI/redhat/grubenv
[root@gruberror ~]#
That’s it we have done with resolving the issue.
Conclusion
When the grubenv file size changes it will throw the above error, once we regenerate the file the size will be back to normal and which will resolve the issue. Subscribe to our newsletter for more troubleshooting guides in future.