grub_cbfs.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. This is all well and good, but what should you actually put in your GRUB configuration file?
  118. Read <a href="grub_config.html">grub_config.html</a> for more information.
  119. </p>
  120. <p>
  121. <a href="#pagetop">Back to top of page.</a>
  122. </p>
  123. </div>
  124. <div class="section">
  125. <h2 id="option2_reflash">2nd option: re-flash</h2>
  126. <p>
  127. You can modify what is stored inside the flash chip quite easily. Read on to find out how.
  128. </p>
  129. <p>
  130. <a href="#pagetop">Back to top of page.</a>
  131. </p>
  132. </div>
  133. <div class="section">
  134. <h2 id="tools">Acquire the necessary utilities</h2>
  135. <p>
  136. Use <b><i>cbfstool</i></b> and <b><i>flashrom</i></b>. There are available in the <i>libreboot_util</i> release archive,
  137. or they can be compiled (see <a href="../git/index.html#build_flashrom">../git/index.html#build_flashrom</a>).
  138. Flashrom is also available from the repositories:<br/>
  139. # <b>pacman -S flashrom</b>
  140. </p>
  141. <p>
  142. <a href="#pagetop">Back to top of page.</a>
  143. </p>
  144. </div>
  145. <div class="section">
  146. <h2 id="rom">Acquiring the correct ROM image</h2>
  147. <p>
  148. You can either work directly with one of the ROM images already included in the libreboot ROM archives, or re-use the ROM that
  149. you have currently flashed. For the purpose of this tutorial it is assumed that your ROM image file is named <i>libreboot.rom</i>,
  150. so please make sure to adapt.
  151. </p>
  152. <p>
  153. ROM images are included pre-compiled in libreboot. You can also dump your current firmware, using flashrom:<br/>
  154. $ <b>sudo flashrom -p internal -r libreboot.rom</b><br/>
  155. # <b>flashrom -p internal -r libreboot.rom</b><br/>
  156. If you are told to specify the chip, add the option <b>-c {your chip}</b> to the command, for example:<br/>
  157. # <b>flashrom -c MX25L6405 -p internal -r libreboot.rom</b>
  158. </p>
  159. <p>
  160. <a href="#pagetop">Back to top of page.</a>
  161. </p>
  162. </div>
  163. <div class="section">
  164. <h2 id="extract_testconfig">Extract grubtest.cfg from the ROM image</h2>
  165. <p>
  166. You can check the contents of the ROM image, inside CBFS:<br/>
  167. <b>$ cd .../libreboot_util/cbfstool</b>
  168. <b>$ ./cbfstool libreboot.rom print</b>
  169. </p>
  170. <p>
  171. The files <i>grub.cfg</i> and <i>grubtest.cfg</i> should be present. grub.cfg is loaded by default,
  172. with a menuentry for switching to grubtest.cfg. In this tutorial, you will first modify and test <i>grubtest.cfg</i>.
  173. This is to reduce the possibility of bricking your device, so DO NOT SKIP THIS!
  174. </p>
  175. <p>
  176. Extract grubtest.cfg from the ROM image:<br/>
  177. <b>$ ./cbfstool libreboot.rom extract -n grubtest.cfg -f grubtest.cfg</b>
  178. </p>
  179. <p>
  180. Modify the grubtest.cfg accordingly.
  181. </p>
  182. <p>
  183. This is all well and good, but what should you actually put in your GRUB configuration file?
  184. Read <a href="grub_config.html">grub_config.html</a> for more information.
  185. </p>
  186. <p>
  187. <a href="#pagetop">Back to top of page.</a>
  188. </p>
  189. </div>
  190. <div class="section">
  191. <h2 id="reinsert_modified_testconfig">Re-insert the modified grubtest.cfg into the ROM image</h2>
  192. <p>
  193. Once your grubtest.cfg is modified and saved, delete the unmodified config from the ROM image:<br/>
  194. <b>$ ./cbfstool libreboot.rom remove -n grubtest.cfg</b>
  195. </p>
  196. <p>
  197. Next, insert the modified version:<br/>
  198. <b>$ ./cbfstool libreboot.rom add -n grubtest.cfg -f grubtest.cfg -t raw</b>
  199. </p>
  200. <p>
  201. <a href="#pagetop">Back to top of page.</a>
  202. </p>
  203. </div>
  204. <div class="section">
  205. <h2 id="testing">Testing</h2>
  206. <p>
  207. <b>
  208. Now you have a modified ROM. Refer back to <a href="../install/index.html#flashrom">../install/index.html#flashrom</a> for information
  209. on how to flash it.<br/>
  210. $ <b>cd /libreboot_util</b>
  211. # <b>./flash update libreboot.rom</b><br/>
  212. 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/>
  213. # <b>./flash forceupdate libreboot.rom</b><br/>
  214. You should see <b>&quot;Verifying flash... VERIFIED.&quot;</b> written at the end of the flashrom output.
  215. Once you have done that, shut down and then boot up with your new test configuration.
  216. </b>
  217. </p>
  218. <p>
  219. Choose (in GRUB) the menu entry that switches to grubtest.cfg. If it works, then your config is safe and you can continue below.
  220. </p>
  221. <p>
  222. <b>
  223. If it does not work like you want it to, if you are unsure or sceptical in any way,
  224. then re-do the steps above until you get it right! Do *not* proceed past this point
  225. unless you are 100% sure that your new configuration is safe (or desirable) to use.
  226. </b>
  227. </p>
  228. <p>
  229. <a href="#pagetop">Back to top of page.</a>
  230. </p>
  231. </div>
  232. <div class="section">
  233. <h2 id="final_steps">Final steps</h2>
  234. <p>
  235. 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:
  236. the menuentry 'Switch to grub.cfg' will be changed to 'Switch to grubtest.cfg' and inside it,
  237. all instances of grub.cfg to grubtest.cfg. This is so that the main config still
  238. links (in the menu) to grubtest.cfg, so that you don't have to manually switch to it, in
  239. case you ever want to follow this guide again in the future (modifying the already modified config). From /libreboot_util/cbfstool, do:<br/>
  240. $ <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/>
  241. </p>
  242. <p>
  243. Delete the grub.cfg that remained inside the ROM:<br/>
  244. <b>$ ./cbfstool libreboot.rom remove -n grub.cfg</b>
  245. </p>
  246. <p>
  247. Add the modified version that you just made:<br/>
  248. <b>$ ./cbfstool libreboot.rom add -n grub.cfg -f grub.cfg -t raw</b>
  249. </p>
  250. <p>
  251. <b>
  252. Now you have a modified ROM. Again, refer back to <a href="../install/index.html#flashrom">../install/index.html#flashrom</a> for information
  253. on how to flash it. It's the same method as you used before. Shut down and then boot up with your new configuration.
  254. </b>
  255. </p>
  256. <p>
  257. <a href="#pagetop">Back to top of page.</a>
  258. </p>
  259. </div>
  260. <div class="section">
  261. <p>
  262. Copyright &copy; 2014, 2015 Leah Rowe &lt;info@minifree.org&gt;<br/>
  263. Copyright &copy; 2015 Jeroen Quint &lt;jezza@diplomail.ch&gt;<br/>
  264. Permission is granted to copy, distribute and/or modify this document
  265. under the terms of the GNU Free Documentation License, Version 1.3
  266. or any later version published by the Free Software Foundation;
  267. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  268. A copy of the license can be found at <a href="../gfdl-1.3.txt">../gfdl-1.3.txt</a>
  269. </p>
  270. <p>
  271. Updated versions of the license (when available) can be found at
  272. <a href="https://www.gnu.org/licenses/licenses.html">https://www.gnu.org/licenses/licenses.html</a>
  273. </p>
  274. <p>
  275. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
  276. EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
  277. AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
  278. ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
  279. IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
  280. WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
  281. PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
  282. ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
  283. KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
  284. ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
  285. </p>
  286. <p>
  287. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
  288. TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
  289. NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
  290. INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
  291. COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
  292. USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
  293. ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
  294. DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
  295. IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
  296. </p>
  297. <p>
  298. The disclaimer of warranties and limitation of liability provided
  299. above shall be interpreted in a manner that, to the extent
  300. possible, most closely approximates an absolute disclaimer and
  301. waiver of all liability.
  302. </p>
  303. </div>
  304. </body>
  305. </html>