grub_cbfs.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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="#getting_started">Getting started</a></li>
  46. <li><a href="#libreboot_grub_config_ondisk">Option A: don't flash a new ROM</a></li>
  47. <li><a href="#libreboot_grub_config_flash">Option B: flash a new ROM</a></li>
  48. <ul>
  49. <li><a href="#tools">Get the tools ready</a></li>
  50. <ul>
  51. <li><a href="#locate_tools">Locate the tools in the binary release</a></li>
  52. <li><a href="#build_tools">Build the tools from source</a></li>
  53. </ul>
  54. <li><a href="#which_rom">Which ROM image should I use?</a></li>
  55. <ul>
  56. <li><a href="#use_prebuilt_rom">Use one of the provided ROM images</a></li>
  57. <li><a href="#re-use_rom">Re-use the currently flashed ROM image</a></li>
  58. </ul>
  59. <li><a href="#extract_grubtest">Extract grubtest from the ROM image</a>
  60. <li><a href="#reinsert_modified_grubtest">Re-insert the modified grubtest.cfg into the ROM image</a></li>
  61. <li><a href="#test_it">Test it!</a>
  62. <li><a href="#final_steps">Final steps</a></li>
  63. <li><a href="#troubleshooting">Troubleshooting</a></li>
  64. </ul>
  65. </ul>
  66. </div>
  67. <div class="section">
  68. <h2 id="getting_started">Getting started</h2>
  69. <p>
  70. Download the latest release from
  71. <a href="http://libreboot.org/">http://libreboot.org/</a>
  72. <br/><b>If you downloaded from git, refer to
  73. <a href="../git/index.html#build_meta">../git/index.html#build_meta</a> before continuing.</b>
  74. </p>
  75. <p>
  76. <a href="#pagetop">Back to top of page.</a>
  77. </p>
  78. <p>
  79. There are several advantages to modifying the GRUB configuration stored in CBFS, but
  80. this also means that you have to flash a new libreboot ROM image on your machine (some users
  81. feel intimidated by this, to say the least).
  82. Doing so can be risky if not handled correctly, because it can result in a bricked
  83. machine (recovery is easy if you have the <a href="../install/bbb_setup.html">equipment</a>
  84. for it, but most people don't). If you aren't up to that then don't worry; it is possible
  85. to use a custom GRUB menu without flashing a new image, by loading a GRUB configuration
  86. from a partition on the main storage instead.
  87. </p>
  88. </div>
  89. <div class="section">
  90. <h2 id="libreboot_grub_config_ondisk">Option A: don't flash a new ROM</h2>
  91. <p>
  92. By default, GRUB in libreboot is configured to scan all partitions on the main storage
  93. for /boot/grub/libreboot_grub.cfg or /grub/libreboot_grub.cfg(for systems where /boot
  94. is on a dedicated partition), and then use it automatically.
  95. </p>
  96. <p>
  97. Simply create your custom GRUB configuration and save it to <b>/boot/grub/libreboot_grub.cfg</b>
  98. on the running system. The next time you boot, GRUB (in libreboot) will automatically switch to
  99. this configuration file. <b>This means that you do not have to re-flash, recompile or otherwise
  100. modify libreboot at all!</b>
  101. </p>
  102. <p>
  103. Ideally, your distribution should automatically generate a libreboot_grub.cfg file that is written
  104. specifically under the assumption that it will be read and used on a libreboot system that uses
  105. GRUB as a payload. If your distribution does not do this, then you can try to add that feature
  106. yourself or politely ask someone involved with or otherwise knowledgeable about the distribution
  107. to do it for you. The libreboot_grub.cfg could either contain the full configuration, or it could
  108. chainload another GRUB ELF executable (built to be used as a coreboot payload) that is located in
  109. a partition on the main storage.
  110. </p>
  111. <p>
  112. 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
  113. follow <a href="#tools">#tools</a>, <a href="#which_rom">#which_rom</a> and
  114. <a href="#extract_grubtest">#extract_grubtest</a> to get the <b><i>grubtest.cfg</i></b>.
  115. 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>
  116. on the running system where it is intended to be used. Modify the file at that location however you see fit,
  117. and then stop reading this guide (the rest of this page is irrelevant to you); <b>in libreboot_grub.cfg on disk,
  118. if you are adapting it based on grub.cfg from CBFS then remove the check for libreboot_grub.cfg otherwise it will loop.</b>.
  119. </p>
  120. <p>
  121. This is all well and good, but what should you actually put in your GRUB configuration file?
  122. Read <a href="grub_config.html">grub_config.html</a> for more information.
  123. </p>
  124. <p>
  125. <a href="#pagetop">Back to top of page.</a>
  126. </p>
  127. </div>
  128. <div class="section">
  129. <h2 id="libreboot_grub_config_flash">Option B: flash a new ROM</h2>
  130. <p>
  131. Alternatively to editing the GRUB configuration file on your disk, you can also change the configuration that is
  132. stored in the CBFS on the flash chip.
  133. </p>
  134. <p>
  135. <a href="#pagetop">Back to top of page.</a>
  136. </p>
  137. </div>
  138. <div class="section">
  139. <h2 id="tools">Get the tools ready</h2>
  140. <p>
  141. You will need to use the <b><i>cbfstool</i></b>, <b><i>rmodtool</i></b> and <b><i>flashrom</i></b> tools.
  142. You can either use the pre-compiled binaries provided by the binary release of libreboot, or build the tools
  143. yourself from source from the libreboot source code.
  144. </p>
  145. <div class="subsection">
  146. <h3 id="locate_tools">Locate the tools in the binary release</h3>
  147. <p>
  148. If you are working with the binary release libreboot_util, you will find the <b><i>cbfstool</i></b> and
  149. <b><i>rmodtool</i></b> binaries under ./cbfstool/{architecture}/ , where {architecture} refers to your
  150. hardware name for which your current running kernel is compiled for. You can find it by running:
  151. <br/>
  152. <b>$ uname -m</b>
  153. </p>
  154. <p>
  155. The <b><i>flashrom</i></b> binary is located under ./flashrom/{architecture}/
  156. </p>
  157. <p>
  158. Whenever one of the tools is used in a command in this tutorial, it will be called as, e.g., ./cbfstool <br/>
  159. Please adapt the paths accordingly (e.g.: cbfstool/i686/cbfstool).
  160. </p>
  161. </div class="subsection">
  162. <div class="subsection">
  163. <h3 id="build_tools">Build the tools from source</h3>
  164. <p>
  165. If you are working with libreboot_src, then you can run <b><i>make</i></b> command in
  166. libreboot_src/coreboot/util/cbfstool to build the <b><i>cbfstool</i></b> and <b><i>rmodtool</i></b>
  167. executables. See <a href="../git/index.html#build_flashrom">../git/index.html#build_flashrom</a> for
  168. instructions on how to build <b><i>flashrom</i></b>.
  169. </p>
  170. </div class="subsection">
  171. <p>
  172. <a href="#pagetop">Back to top of page.</a>
  173. </p>
  174. </div>
  175. <div class="section">
  176. <h2 id="which_rom">Which ROM image should I use?</h2>
  177. <p>
  178. You can either work directly with one of the ROM images already included in the libreboot ROM archives, or re-use the ROM that
  179. you have currently flashed. For the purpose of this tutorial it is assumed that your ROM image file is named <i>libreboot.rom</i>,
  180. so please make sure to adapt.
  181. </p>
  182. <div class="subsection">
  183. <h3 id="use_prebuilt_rom">Use one of the provided ROM images</h3>
  184. <p>
  185. Libreboot ROM images are distributed in separate tar archives, named {computer_model}.tar.xz.
  186. If you build from source without generated any release archives,
  187. the ROM images will be in ./bin/{computer_model}/. Make a working copy of the ROM you want to use:
  188. <br/>
  189. <b>$ cp ./bin/{computer_model}/{computer_model}_{keyboard_layout}_{mode}.rom libreboot.rom</b>
  190. <br/>
  191. {keyboard_layout} defines the keyboard layout that will be available on the GRUB console. This might be important
  192. if you protect GRUB with a password later on and want to insert non-ASCII characters.
  193. {mode} can be <i>vesafb</i> or <i>txtmode</i> and starts GRUB with a background image or in text mode.
  194. </p>
  195. </div>
  196. <div class="subsection">
  197. <h3 id="re-use_rom">Re-use the currently flashed ROM image</h3>
  198. <p>
  199. If you want to re-use the ROM that you currently have flashed (and running) and then run:<br/>
  200. <b>$ sudo ./flashrom -p internal -r libreboot.rom</b><br/>
  201. Notice that this is using <b>&quot;-r&quot;</b> (read) instead of <b>&quot;-w&quot;</b> (write).
  202. This will create a dump (copy) of your current firmware and name it <b>libreboot.rom</b>.
  203. You need to take ownership of the file. For example:<br/>
  204. <b>$ sudo chown yourusername:yourusername libreboot.rom</b><br/>
  205. <b># chown yourusername:yourusername libreboot.rom</b>
  206. </p>
  207. </div>
  208. <p>
  209. If you currently have flashed a ROM image from an older version, it is recommended to update first:
  210. basically, modify one of the latest ROM images and then flash it.
  211. </p>
  212. <p>
  213. <a href="#pagetop">Back to top of page.</a>
  214. </p>
  215. </div>
  216. <div class="section">
  217. <h2 id="extract_grubtest">Extract grubtest.cfg from the ROM image</h2>
  218. <p>
  219. Display contents of ROM:<br/>
  220. <b>$ ./cbfstool libreboot.rom print</b>
  221. </p>
  222. <p>
  223. The libreboot.rom file contains your <i>grub.cfg</i> and <i>grubtest.cfg</i> files.
  224. grub.cfg will load first, but it has a menu entry for switching to the copy (grubtest.cfg).
  225. Thus, you should extract, modify and re-insert the grubtest.cfg first.
  226. This reduces your chance of making a mistake that could make your machine unbootable (or very hard to boot).
  227. </p>
  228. <p>
  229. Extract grubtest.cfg from the ROM image:<br/>
  230. <b>$ ./cbfstool libreboot.rom extract -n grubtest.cfg -f grubtest.cfg</b>
  231. </p>
  232. <p>
  233. Make a copy of the original file, before you modify it:<br/>
  234. <b>$ cp grubtest.cfg grubtest_vanilla.cfg</b>
  235. </p>
  236. <p>
  237. Now you have a grubtest.cfg in the cbfstool directory.
  238. </p>
  239. <p>
  240. This is all well and good, but what should you actually put in your GRUB configuration file?
  241. Read <a href="grub_config.html">grub_config.html</a> for more information.
  242. </p>
  243. <p>
  244. <a href="#pagetop">Back to top of page.</a>
  245. </p>
  246. </div>
  247. <div class="section">
  248. <h2 id="reinsert_modified_grubtest">Re-insert the modified grubtest.cfg into the ROM image</h2>
  249. <p>
  250. So you've created your configuration. Now, how do you use it?
  251. </p>
  252. <p>
  253. Delete the grubtest.cfg that remained inside the ROM:<br/>
  254. <b>$ ./cbfstool libreboot.rom remove -n grubtest.cfg</b>
  255. </p>
  256. <p>
  257. Display ROM contents and now you see grubtest.cfg no longer exists there:<br/>
  258. <b>$ ./cbfstool libreboot.rom print</b>
  259. </p>
  260. <p>
  261. Add the modified version that you just made:<br/>
  262. <b>$ ./cbfstool libreboot.rom add -n grubtest.cfg -f grubtest.cfg -t raw</b>
  263. </p>
  264. <p>
  265. Now display ROM contents again and see that it exists again:<br/>
  266. <b>$ ./cbfstool libreboot.rom print</b>
  267. </p>
  268. <p>
  269. <a href="#pagetop">Back to top of page.</a>
  270. </p>
  271. </div>
  272. <div class="section">
  273. <h2 id="test_it">Test it!</h2>
  274. <p>
  275. <b>
  276. Now you have a modified ROM. Refer back to <a href="../install/index.html#flashrom">../install/index.html#flashrom</a> for information
  277. on how to flash it. Once you have done that, shut down and then boot up with your new test configuration.
  278. </b>
  279. </p>
  280. <p>
  281. Choose (in GRUB) the menu entry that switches to grubtest.cfg. If it works, then your config is safe and you can continue below.
  282. </p>
  283. <p>
  284. <b>
  285. If it does not work like you want it to, if you are unsure or sceptical in any way,
  286. then re-do the steps above until you get it right! Do *not* proceed past this point
  287. unless you are 100% sure that your new configuration is safe (or desirable) to use.
  288. </b>
  289. </p>
  290. <p>
  291. <a href="#pagetop">Back to top of page.</a>
  292. </p>
  293. </div>
  294. <div class="section">
  295. <h2 id="final_steps">Final steps</h2>
  296. <p>
  297. Create a copy of grubtest.cfg, called grub.cfg, which is the same except for one difference:
  298. change the menuentry 'Switch to grub.cfg' to 'Switch to grubtest.cfg' and inside it,
  299. change all instances of grub.cfg to grubtest.cfg. This is so that the main config still
  300. links (in the menu) to grubtest.cfg, so that you don't have to manually switch to it, in
  301. case you ever want to follow this guide again in the future (modifying the already modified config)<br/>
  302. $ <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/>
  303. </p>
  304. <p>
  305. Delete the grub.cfg that remained inside the ROM:<br/>
  306. <b>$ ./cbfstool libreboot.rom remove -n grub.cfg</b>
  307. </p>
  308. <p>
  309. Display ROM contents and now you see grub.cfg no longer exists there:<br/>
  310. <b>$ ./cbfstool libreboot.rom print</b>
  311. </p>
  312. <p>
  313. Add the modified version that you just made:<br/>
  314. <b>$ ./cbfstool libreboot.rom add -n grub.cfg -f grub.cfg -t raw</b>
  315. </p>
  316. <p>
  317. Now display ROM contents again and see that it exists again:<br/>
  318. <b>$ ./cbfstool libreboot.rom print</b>
  319. </p>
  320. <p>
  321. <b>
  322. Now you have a modified ROM. Refer back to <a href="../install/index.html#flashrom">../install/index.html#flashrom</a> for information
  323. on how to flash it. Once you have done that, shut down and then boot up with your new configuration.
  324. </b>
  325. </p>
  326. <p>
  327. <a href="#pagetop">Back to top of page.</a>
  328. </p>
  329. </div>
  330. <div class="section">
  331. <h2 id="troubleshooting">Troubleshooting</h2>
  332. <p>
  333. A user reported that segmentation faults occur with cbfstool
  334. when using this procedure depending on the size of the grub.cfg being re-insterted.
  335. In his case, a minimum size of 857 bytes was required. This could (at the time of
  336. this release) be a bug in cbfstool that should be investigated with the coreboot
  337. community. If cbfstool segfaults, then keep this in mind. 'strace' (or gdb? clang?)
  338. could be used for debugging. This was in libreboot 5th release (based on coreboot
  339. from late 2013), and I'm not sure if the issue persists in the current releases.
  340. I have not been able to reproduce it. strace (from that user) is here:
  341. <a href="cbfstool_libreboot5_strace">cbfstool_libreboot5_strace</a>.
  342. The issue has been reported by a few users, so it does not happen all the time:
  343. this bug (if it still exists) could (should) be reproduced.
  344. </p>
  345. <p>
  346. <a href="#pagetop">Back to top of page.</a>
  347. </p>
  348. </div>
  349. <div class="section">
  350. <p>
  351. Copyright &copy; 2014, 2015 Francis Rowe &lt;info@gluglug.org.uk&gt;<br/>
  352. Copyright &copy; 2015 Julian Mehne &lt;juli@nmehne.de&gt;<br/>
  353. This document is released under the Creative Commons Attribution-ShareAlike 4.0 International Public License and all future versions.
  354. A copy of the license can be found at <a href="../cc-by-sa-4.txt">../cc-by-sa-4.txt</a>.
  355. </p>
  356. <p>
  357. This document is distributed in the hope that it will be useful,
  358. but WITHOUT ANY WARRANTY; without even the implied warranty of
  359. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See <a href="../cc-by-sa-4.txt">../cc-by-sa-4.txt</a> for more information.
  360. </p>
  361. </div>
  362. </body>
  363. </html>