grub_cbfs.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <style type="text/css">
  7. @import url('../css/main.css');
  8. </style>
  9. <title>How to replace the default GRUB configuration file on a libreboot system</title>
  10. </head>
  11. <body>
  12. <div class="section">
  13. <h1 id="pagetop">How to replace the default GRUB configuration file on a libreboot system</h1>
  14. <p>
  15. Libreboot on x86 uses the GRUB <a href="http://www.coreboot.org/Payloads#GRUB_2">payload</a>
  16. by default, which means that the GRUB configuration file
  17. (where your GRUB menu comes from) is stored directly alongside libreboot
  18. and its GRUB payload executable, inside
  19. the flash chip. In context, this means that installing distributions and managing them
  20. is handled slightly differently compared to traditional BIOS systems.
  21. </p>
  22. <p>
  23. A libreboot (or coreboot) ROM image is not simply &quot;flat&quot;; there is an actual
  24. filesystem inside called CBFS (coreboot filesystem). A utility called 'cbfstool'
  25. allows you to change the contents of the ROM image. In this case, libreboot is configured
  26. such that the 'grub.cfg' and 'grubtest.cfg' files exist directly inside CBFS instead of
  27. inside the GRUB payload 'memdisk' (which is itself stored in CBFS).
  28. </p>
  29. <p>
  30. You can either modify
  31. the GRUB configuration stored in the flash chip, or you can modify a GRUB configuration
  32. file on the main storage which the libreboot GRUB payload will automatically search for.
  33. </p>
  34. <p>
  35. Here is an excellent writeup about CBFS (coreboot filesystem):
  36. <a href="http://lennartb.home.xs4all.nl/coreboot/col5.html">http://lennartb.home.xs4all.nl/coreboot/col5.html</a>.
  37. </p>
  38. <p>
  39. <b>This guide is *only* for the GRUB payload. If you use the depthcharge payload, ignore this section entirely.</b>
  40. </p>
  41. <p>
  42. <a href="index.html">Back to previous index</a>
  43. </p>
  44. </div>
  45. <div class="section">
  46. <h1>Table of Contents</h1>
  47. <ul>
  48. <li><a href="#introduction">Introduction</a></li>
  49. <li><a href="#option1_dont_reflash">1st option: don't re-flash</a></li>
  50. <li>
  51. <a href="#option2_reflash">2nd option: re-flash</a>
  52. <ul>
  53. <li><a href="#tools">Acquire the necessary utilities</a></li>
  54. <li><a href="#rom">Acquiring the correct ROM image</a></li>
  55. <li><a href="#extract_testconfig">Extract grubtest from the ROM image</a>
  56. <li><a href="#reinsert_modified_testconfig">Re-insert the modified grubtest.cfg into the ROM image</a></li>
  57. <li><a href="#testing">Testing</a>
  58. <li><a href="#final_steps">Final steps</a></li>
  59. </ul>
  60. </li>
  61. </ul>
  62. </div>
  63. <div class="section">
  64. <h2 id="introduction">Introduction</h2>
  65. <p>
  66. Download the latest release from
  67. <a href="http://libreboot.org/">http://libreboot.org/</a>
  68. <br/><b>If you downloaded from git, refer to
  69. <a href="../git/index.html#build_meta">../git/index.html#build_meta</a> before continuing.</b>
  70. </p>
  71. <p>
  72. <a href="#pagetop">Back to top of page.</a>
  73. </p>
  74. <p>
  75. There are several advantages to modifying the GRUB configuration stored in CBFS, but
  76. this also means that you have to flash a new libreboot ROM image on your system (some users
  77. feel intimidated by this, to say the least).
  78. Doing so can be risky if not handled correctly, because it can result in a bricked
  79. system (recovery is easy if you have the <a href="../install/bbb_setup.html">equipment</a>
  80. for it, but most people don't). If you aren't up to that then don't worry; it is possible
  81. to use a custom GRUB menu without flashing a new image, by loading a GRUB configuration
  82. from a partition on the main storage instead.
  83. </p>
  84. </div>
  85. <div class="section">
  86. <h2 id="option1_dont_reflash">1st option: don't re-flash</h2>
  87. <p>
  88. By default, GRUB in libreboot is configured to scan all partitions on the main storage
  89. for /boot/grub/libreboot_grub.cfg or /grub/libreboot_grub.cfg(for systems where /boot
  90. is on a dedicated partition), and then use it automatically.
  91. </p>
  92. <p>
  93. Simply create your custom GRUB configuration and save it to <b>/boot/grub/libreboot_grub.cfg</b>
  94. on the running system. The next time you boot, GRUB (in libreboot) will automatically switch to
  95. this configuration file. <b>This means that you do not have to re-flash, recompile or otherwise
  96. modify libreboot at all!</b>
  97. </p>
  98. <p>
  99. Ideally, your distribution should automatically generate a libreboot_grub.cfg file that is written
  100. specifically under the assumption that it will be read and used on a libreboot system that uses
  101. GRUB as a payload. If your distribution does not do this, then you can try to add that feature
  102. yourself or politely ask someone involved with or otherwise knowledgeable about the distribution
  103. to do it for you. The libreboot_grub.cfg could either contain the full configuration, or it could
  104. chainload another GRUB ELF executable (built to be used as a coreboot payload) that is located in
  105. a partition on the main storage.
  106. </p>
  107. <p>
  108. If you want to adapt a copy of the existing <i>libreboot</i> GRUB configuration and use that for the libreboot_grub.cfg file, then
  109. follow <a href="#tools">#tools</a>, <a href="#rom">#rom</a> and
  110. <a href="#extract_testconfig">#extract_testconfig</a> to get the <b><i>grubtest.cfg</i></b>.
  111. Rename <b><i>grubtest.cfg</i></b> to <b><i>libreboot_grub.cfg</i></b> and save it to <b><i>/boot/grub/</i></b>
  112. on the running system where it is intended to be used. Modify the file at that location however you see fit,
  113. and then stop reading this guide (the rest of this page is irrelevant to you); <b>in libreboot_grub.cfg on disk,
  114. if you are adapting it based on grub.cfg from CBFS then remove the check for libreboot_grub.cfg otherwise it will loop.</b>.
  115. </p>
  116. <p>
  117. <a href="#pagetop">Back to top of page.</a>
  118. </p>
  119. </div>
  120. <div class="section">
  121. <h2 id="option2_reflash">2nd option: re-flash</h2>
  122. <p>
  123. You can modify what is stored inside the flash chip quite easily. Read on to find out how.
  124. </p>
  125. <p>
  126. <a href="#pagetop">Back to top of page.</a>
  127. </p>
  128. </div>
  129. <div class="section">
  130. <h2 id="tools">Acquire the necessary utilities</h2>
  131. <p>
  132. Use <b><i>cbfstool</i></b> and <b><i>flashrom</i></b>. There are available in the <i>libreboot_util</i> release archive,
  133. or they can be compiled (see <a href="../git/index.html#build_flashrom">../git/index.html#build_flashrom</a>).
  134. Flashrom is also available from the repositories:<br/>
  135. # <b>pacman -S flashrom</b>
  136. </p>
  137. <p>
  138. <a href="#pagetop">Back to top of page.</a>
  139. </p>
  140. </div>
  141. <div class="section">
  142. <h2 id="rom">Acquiring the correct ROM image</h2>
  143. <p>
  144. You can either work directly with one of the ROM images already included in the libreboot ROM archives, or re-use the ROM that
  145. you have currently flashed. For the purpose of this tutorial it is assumed that your ROM image file is named <i>libreboot.rom</i>,
  146. so please make sure to adapt.
  147. </p>
  148. <p>
  149. ROM images are included pre-compiled in libreboot. You can also dump your current firmware, using flashrom:<br/>
  150. $ <b>sudo flashrom -p internal -r libreboot.rom</b><br/>
  151. # <b>flashrom -p internal -r libreboot.rom</b><br/>
  152. If you are told to specify the chip, add the option <b>-c {your chip}</b> to the command, for example:<br/>
  153. # <b>flashrom -c MX25L6405 -p internal -r libreboot.rom</b>
  154. </p>
  155. <p>
  156. <a href="#pagetop">Back to top of page.</a>
  157. </p>
  158. </div>
  159. <div class="section">
  160. <h2 id="extract_testconfig">Extract grubtest.cfg from the ROM image</h2>
  161. <p>
  162. You can check the contents of the ROM image, inside CBFS:<br/>
  163. <b>$ cd .../libreboot_util/cbfstool</b>
  164. <b>$ ./cbfstool libreboot.rom print</b>
  165. </p>
  166. <p>
  167. The files <i>grub.cfg</i> and <i>grubtest.cfg</i> should be present. grub.cfg is loaded by default,
  168. with a menuentry for switching to grubtest.cfg. In this tutorial, you will first modify and test <i>grubtest.cfg</i>.
  169. This is to reduce the possibility of bricking your device, so DO NOT SKIP THIS!
  170. </p>
  171. <p>
  172. Extract grubtest.cfg from the ROM image:<br/>
  173. <b>$ ./cbfstool libreboot.rom extract -n grubtest.cfg -f grubtest.cfg</b>
  174. </p>
  175. <p>
  176. Modify the grubtest.cfg accordingly.
  177. </p>
  178. <p>
  179. <a href="#pagetop">Back to top of page.</a>
  180. </p>
  181. </div>
  182. <div class="section">
  183. <h2 id="reinsert_modified_testconfig">Re-insert the modified grubtest.cfg into the ROM image</h2>
  184. <p>
  185. Once your grubtest.cfg is modified and saved, delete the unmodified config from the ROM image:<br/>
  186. <b>$ ./cbfstool libreboot.rom remove -n grubtest.cfg</b>
  187. </p>
  188. <p>
  189. Next, insert the modified version:<br/>
  190. <b>$ ./cbfstool libreboot.rom add -n grubtest.cfg -f grubtest.cfg -t raw</b>
  191. </p>
  192. <p>
  193. <a href="#pagetop">Back to top of page.</a>
  194. </p>
  195. </div>
  196. <div class="section">
  197. <h2 id="testing">Testing</h2>
  198. <p>
  199. <b>
  200. Now you have a modified ROM. Refer back to <a href="../install/index.html#flashrom">../install/index.html#flashrom</a> for information
  201. on how to flash it.<br/>
  202. $ <b>cd /libreboot_util</b>
  203. # <b>./flash update libreboot.rom</b><br/>
  204. Ocassionally, coreboot changes the name of a given board. If flashrom complains about a board mismatch, but you are sure that you chose the correct ROM image, then run this alternative command:<br/>
  205. # <b>./flash forceupdate libreboot.rom</b><br/>
  206. You should see <b>&quot;Verifying flash... VERIFIED.&quot;</b> written at the end of the flashrom output.
  207. Once you have done that, shut down and then boot up with your new test configuration.
  208. </b>
  209. </p>
  210. <p>
  211. Choose (in GRUB) the menu entry that switches to grubtest.cfg. If it works, then your config is safe and you can continue below.
  212. </p>
  213. <p>
  214. <b>
  215. If it does not work like you want it to, if you are unsure or sceptical in any way,
  216. then re-do the steps above until you get it right! Do *not* proceed past this point
  217. unless you are 100% sure that your new configuration is safe (or desirable) to use.
  218. </b>
  219. </p>
  220. <p>
  221. <a href="#pagetop">Back to top of page.</a>
  222. </p>
  223. </div>
  224. <div class="section">
  225. <h2 id="final_steps">Final steps</h2>
  226. <p>
  227. When you are satisfied booting from grubtest.cfg, you can create a copy of grubtest.cfg, called grub.cfg. This is the same except for one difference:
  228. the menuentry 'Switch to grub.cfg' will be changed to 'Switch to grubtest.cfg' and inside it,
  229. all instances of grub.cfg to grubtest.cfg. This is so that the main config still
  230. links (in the menu) to grubtest.cfg, so that you don't have to manually switch to it, in
  231. case you ever want to follow this guide again in the future (modifying the already modified config). From /libreboot_util/cbfstool, do:<br/>
  232. $ <b>sed -e 's:(cbfsdisk)/grub.cfg:(cbfsdisk)/grubtest.cfg:g' -e 's:Switch to grub.cfg:Switch to grubtest.cfg:g' &lt; grubtest.cfg &gt; grub.cfg</b><br/>
  233. </p>
  234. <p>
  235. Delete the grub.cfg that remained inside the ROM:<br/>
  236. <b>$ ./cbfstool libreboot.rom remove -n grub.cfg</b>
  237. </p>
  238. <p>
  239. Add the modified version that you just made:<br/>
  240. <b>$ ./cbfstool libreboot.rom add -n grub.cfg -f grub.cfg -t raw</b>
  241. </p>
  242. <p>
  243. <b>
  244. Now you have a modified ROM. Again, refer back to <a href="../install/index.html#flashrom">../install/index.html#flashrom</a> for information
  245. on how to flash it. It's the same method as you used before. Shut down and then boot up with your new configuration.
  246. </b>
  247. </p>
  248. <p>
  249. <a href="#pagetop">Back to top of page.</a>
  250. </p>
  251. </div>
  252. <div class="section">
  253. <p>
  254. Copyright &copy; 2014, 2015 Leah Rowe &lt;info@minifree.org&gt;<br/>
  255. Copyright &copy; 2015 Jeroen Quint &lt;jezza@diplomail.ch&gt;<br/>
  256. Permission is granted to copy, distribute and/or modify this document
  257. under the terms of the GNU Free Documentation License, Version 1.3
  258. or any later version published by the Free Software Foundation;
  259. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  260. A copy of the license can be found at <a href="../gfdl-1.3.txt">../gfdl-1.3.txt</a>
  261. </p>
  262. <p>
  263. Updated versions of the license (when available) can be found at
  264. <a href="https://www.gnu.org/licenses/licenses.html">https://www.gnu.org/licenses/licenses.html</a>
  265. </p>
  266. <p>
  267. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
  268. EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
  269. AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
  270. ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
  271. IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
  272. WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
  273. PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
  274. ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
  275. KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
  276. ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
  277. </p>
  278. <p>
  279. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
  280. TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
  281. NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
  282. INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
  283. COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
  284. USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
  285. ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
  286. DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
  287. IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
  288. </p>
  289. <p>
  290. The disclaimer of warranties and limitation of liability provided
  291. above shall be interpreted in a manner that, to the extent
  292. possible, most closely approximates an absolute disclaimer and
  293. waiver of all liability.
  294. </p>
  295. </div>
  296. </body>
  297. </html>