lbwww/site/docs/linux/grub_cbfs.md

7.8 KiB

Releases after Libreboot 20230625 contain grub.cfg inside the GRUB memdisk, inaccessible directly from CBFS, but the memdisk is inside grub.elf which gets put inside CBFS.

An override is possible, on these Libreboot revisions. If grub.cfg is present in CBFS, Libreboot's GRUB will use that and not the memdisk one; it will not auto-switch to grubtest.cfg, but the test config will be available in the menu to switch to, if present.

You can find grub.cfg under lbmk (for this purpose, it's best to use the lbmk one, not the release one - unless you're using a release after 20230625). Find it at path: config/grub/config/grub.cfg.

So, you can add grubtest.cfg as normal, test that, and then add grub.cfg once you're happy, and it will override the default.

Libreboot 20230625 and below:

libreboot images that use the GRUB bootloader will have two configuration files in CBFS:

  • grub.cfg
  • grubtest.cfg

We recommend that you modify grubtest.cfg first, and boot. Select the boot menu option for loading grubtest.cfg and verify that your new config works correctly. If it doesn't, keep modifying grubtest.cfg until it does work. When that it done, copy the changes over to `grub.cfg

You can use the following commands to modify the contents of CBFS, where GRUB's configuration file is concerned (dump.bin is the ROM that you dumped, or it could refer to the libreboot ROM image that you compiled or otherwise acquired).

Show the contents of CBFS, in your ROM:

cbfstool dump.bin print

Extract grub.cfg (substitude with grubtest.cfg as desired):

cbfstool dump.bin extract -n grub.cfg -f grub.cfg

You will now have a file named grub.cfg.

Make your desired modifications. You should then delete the old grub.cfg from your ROM image.

Insert new grub.cfg

NOTE: As stated above, releases after Libreboot 20230625 only default to the config in memdisk, and lack a CBFS config, so you can skip the remove step below and just directly add the new grub.cfg - unless you already added one before, in which case removal is required first.

Remove the old grub.cfg (substitute with grubtest.cfg as desired):

cbfstool dump.bin remove -n grub.cfg

Add your modified grub.cfg (substitute with grubtest.cfg as desired):

cbfstool dump.bin add -f grub.cfg -n grub.cfg -t raw

Flash the modified ROM image

Your modified dump.bin or other modified libreboot ROM can then be re-flashed using:

sudo ./flashrom -p internal -w dump.bin

If a -c option is required, use it and specify a flash chip name. This is only useful when flashrom complains about multiple flash chips being detected.

If flashrom complains about wrong chip/board, make sure that your ROM is for the correct system. If you're sure, you can disable the safety checks by running this instead:

sudo ./flashrom -p internal:laptop=force_I_want_a_brick,boardmismatch=force -w dump.bin

If you need to use external flashing equipment, see the link above to the Raspberry Pi page.