lbwww/site/docs/linux/grub_cbfs.md

8.2 KiB

title x-toc-enable
Modifying grub.cfg in CBFS true

Releases or or after 20231021 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 image). Find it at path (in current lbmk): 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 or older

NOTE: This information will probably be deleted after a certain time has passed. Libreboot changed a lot, as of release 20231021 in reference to 20230625, so it may take a while before people adjust; therefore, this information is provided for reference, but you should consider it to be deprecated:

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 on or after Libreboot 20231021 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 ./flashprog -p internal -w dump.bin

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

If flashprog 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 ./flashprog -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.