Next: Special environment block variables, Previous: Special environment variables, Up: GRUB environment variables [Contents][Index]
It is often useful to be able to remember a small amount of information from one boot to the next. For example, you might want to set the default menu entry based on what was selected the last time. GRUB deliberately does not implement support for writing files in order to minimise the possibility of the boot loader being responsible for file system corruption, so a GRUB configuration file cannot just create a file in the ordinary way. However, GRUB provides an “environment block” which can be used to save a small amount of state.
The environment block is a preallocated 1024-byte file, which normally lives
in /boot/grub/grubenv (although you should not assume this). At boot
time, the load_env command (see load_env) loads environment
variables from it, and the save_env (see save_env) command
saves environment variables to it. From a running system, the
grub-editenv utility can be used to edit the environment block.
For safety reasons, this storage is only available when installed on a plain disk (no LVM or RAID), using a non-checksumming filesystem (no ZFS), and using BIOS or EFI functions (no ATA, USB or IEEE1275).
On Btrfs filesystems, a reserved area in the filesystem header may be used to
store the environment block. This static block avoids the problems of updating
a normal file on a copy-on-write filesystem, where writing raw block is not
stable and requires metadata update. The reserved area provides a fixed
location that GRUB can update directly, allowing commands such as
grub-reboot and ‘GRUB_SAVEDEFAULT’ to function correctly on
Btrfs volumes.
grub-mkconfig uses this facility to implement
‘GRUB_SAVEDEFAULT’ (see Simple configuration handling).
Next: Special environment block variables, Previous: Special environment variables, Up: GRUB environment variables [Contents][Index]