GRUB’s core.img can optionally provide enforcement that all files subsequently read from disk are covered by a valid digital signature. This document does not cover how to ensure that your platform’s firmware (e.g., Coreboot) validates core.img.
If environment variable check_signatures is set to enforce, then every attempt by the GRUB core.img to load another file foo implicitly invokes verify_detached foo foo.sig. foo.sig must contain a valid digital signature over the contents of foo, which can be verified with a public key currently trusted by GRUB. If the validation fails, then the file foo cannot be opened. This failure may even halt or otherwise impact the boot process.
GRUB uses GPG-style detached signatures (meaning that a file foo.sig will be produced when file foo is signed), and currently supports the DSA and RSA signing algorithms. A signing key can be generated as follows:
gpg --gen-keyAn individual file can be signed as follows:
gpg --detach-sign /path/to/fileFor successful validation of all of GRUB’s subcomponents and the loaded OS kernel, they must all be signed. One way to accomplish this is the following (after having already produced the desired grub.cfg file, e.g., by running grub-mkconfig:
# Edit /path/to/passphrase.txt to contain your signing key's passphrasefor i in `find /boot -name "*.cfg" -or -name "*.lst" -or \        -name "*.mod" -or -name "vmlinuz*" -or -name "initrd*" -or \        -name "grubenv"`;do        gpg --batch --detach-sign --passphrase-fd 0 $i < \        /path/to/passphrase.txtdoneshred /path/to/passphrase.txtYou can use:
Note that internally signature enforcement is controlled by setting the environment variable check_signatures equal to enforce. Passing one or more --pubkey options to grub-mkimage implicitly defines check_signatures equal to enforce in core.img prior to processing any configuration files.
Note that signature checking does not prevent an attacker with (serial, physical, ...) console access from dropping manually to the GRUB console and executing:
set check_signatures=noTo prevent this, we use GRUB identity access management.