grub_cbfs.html 14 KB

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