readme.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. Notes on using Grub2 for BIOS-based platforms
  2. =============================================
  3. 1. Create a disk image
  4. dd if=/dev/zero of=disk.img bs=1M count=32
  5. 2. Partition it (either legacy or GPT style partitions work)
  6. cfdisk disk.img
  7. - Create one partition, type Linux, for the root
  8. filesystem. The only constraint is to make sure there
  9. is enough free space *before* the first partition to
  10. store Grub2. Leaving 1 MB of free space is safe.
  11. 3. Setup loop device and loop partitions
  12. sudo losetup -f disk.img
  13. sudo partx -a /dev/loop0
  14. 4. Prepare the root partition
  15. sudo mkfs.ext3 -L root /dev/loop0p1
  16. sudo mount /dev/loop0p1 /mnt
  17. sudo tar -C /mnt -xf output/images/rootfs.tar
  18. sudo umount /mnt
  19. 5. Install Grub2
  20. sudo ./output/host/sbin/grub-bios-setup \
  21. -b ./output/host/lib/grub/i386-pc/boot.img \
  22. -c ./output/images/grub.img -d . /dev/loop0
  23. 6. Cleanup loop device
  24. sudo partx -d /dev/loop0
  25. sudo losetup -d /dev/loop0
  26. 7. Your disk.img is ready!
  27. Using genimage
  28. --------------
  29. If you use genimage to generate your complete image,
  30. installing Grub can be tricky. Here is how to achieve Grub's
  31. installation with genimage:
  32. partition boot {
  33. in-partition-table = "no"
  34. image = "path_to_boot.img"
  35. offset = 0
  36. size = 512
  37. }
  38. partition grub {
  39. in-partition-table = "no"
  40. image = "path_to_grub.img"
  41. offset = 512
  42. }
  43. The result is not byte to byte identical to what
  44. grub-bios-setup does but it works anyway.
  45. To test your BIOS image in Qemu
  46. -------------------------------
  47. qemu-system-{i386,x86-64} -hda disk.img
  48. Notes on using Grub2 for x86/x86_64 EFI-based platforms
  49. =======================================================
  50. 1. Create a disk image
  51. dd if=/dev/zero of=disk.img bs=1M count=32
  52. 2. Partition it with GPT partitions
  53. cgdisk disk.img
  54. - Create a first partition, type EF00, for the
  55. bootloader and kernel image
  56. - Create a second partition, type 8300, for the root
  57. filesystem.
  58. 3. Setup loop device and loop partitions
  59. sudo losetup -f disk.img
  60. sudo partx -a /dev/loop0
  61. 4. Prepare the boot partition
  62. sudo mkfs.vfat -n boot /dev/loop0p1
  63. sudo mount /dev/loop0p1 /mnt
  64. sudo cp -a output/images/efi-part/* /mnt/
  65. sudo cp output/images/bzImage /mnt/
  66. sudo umount /mnt
  67. 5. Prepare the root partition
  68. sudo mkfs.ext3 -L root /dev/loop0p2
  69. sudo mount /dev/loop0p2 /mnt
  70. sudo tar -C /mnt -xf output/images/rootfs.tar
  71. sudo umount /mnt
  72. 6 Cleanup loop device
  73. sudo partx -d /dev/loop0
  74. sudo losetup -d /dev/loop0
  75. 7. Your disk.img is ready!
  76. To test your i386/x86-64 EFI image in Qemu
  77. ------------------------------------------
  78. 1. Download the EFI BIOS for Qemu
  79. Version IA32 or X64 depending on the chosen Grub2
  80. platform (i386-efi vs. x86-64-efi)
  81. https://www.kraxel.org/repos/jenkins/edk2/
  82. (or use one provided by your distribution as OVMF)
  83. 2. Extract, and rename OVMF.fd to bios.bin and
  84. CirrusLogic5446.rom to vgabios-cirrus.bin.
  85. 3. qemu-system-{i386,x86-64} -L ovmf-dir/ -hda disk.img
  86. 4. Make sure to pass pci=nocrs to the kernel command line,
  87. to workaround a bug in the EFI BIOS regarding the
  88. EFI framebuffer.
  89. Notes on using Grub2 for ARM u-boot-based platforms
  90. ===================================================
  91. The following steps show how to use the Grub2 arm-uboot platform
  92. support in the simplest way possible and with a single
  93. buildroot-generated filesystem.
  94. 1. Load qemu_arm_vexpress_defconfig
  95. 2. Enable u-boot with the vexpress_ca9x4 board name and with
  96. u-boot.elf image format.
  97. 3. Enable grub2 for the arm-uboot platform.
  98. 4. Enable "Install kernel image to /boot in target" in the kernel
  99. menu to populate a /boot directory with zImage in it.
  100. 5. The upstream u-boot vexpress_ca9x4 doesn't have CONFIG_API enabled
  101. by default, which is required.
  102. Before building, patch u-boot (for example, make u-boot-extract to
  103. edit the source before building) file
  104. include/configs/vexpress_common.h to define:
  105. #define CONFIG_API
  106. #define CONFIG_SYS_MMC_MAX_DEVICE 1
  107. 6. Create a custom grub2 config file with the following contents and
  108. set its path in BR2_TARGET_GRUB2_CFG:
  109. set default="0"
  110. set timeout="5"
  111. menuentry "Buildroot" {
  112. set root='(hd0)'
  113. linux /boot/zImage root=/dev/mmcblk0 console=ttyAMA0
  114. devicetree /boot/vexpress-v2p-ca9.dtb
  115. }
  116. 7. Create a custom builtin config file with the following contents
  117. and set its path in BR2_TARGET_GRUB2_BUILTIN_CONFIG:
  118. set root=(hd0)
  119. set prefix=/boot/grub
  120. 8. Create a custom post-build script which copies files from
  121. ${BINARIES_DIR}/boot-part to $(TARGET_DIR)/boot (set its path in
  122. BR2_ROOTFS_POST_BUILD_SCRIPT):
  123. #!/bin/sh
  124. cp -r ${BINARIES_DIR}/boot-part/* ${TARGET_DIR}/boot/
  125. 9. make
  126. 10. Run qemu with:
  127. qemu-system-arm -M vexpress-a9 -kernel output/images/u-boot -m 1024 \
  128. -nographic -sd output/images/rootfs.ext2
  129. 11. In u-boot, stop at the prompt and run grub2 with:
  130. => ext2load mmc 0:0 ${loadaddr} /boot/grub/grub.img
  131. => bootm
  132. 12. This should bring the grub2 menu, upon which selecting the "Buildroot"
  133. entry should boot Linux.
  134. Notes on using Grub2 for Aarch64 EFI-based platforms
  135. ====================================================
  136. The following steps show how to use the Grub2 arm64-efi platform,
  137. using qemu and EFI firmware built for qemu.
  138. 1. Load aarch64_efi_defconfig
  139. 2. make
  140. 3. Download the EFI firmware for qemu aarch64
  141. https://www.kraxel.org/repos/jenkins/edk2/
  142. (or use one provided by your distribution as OVMF-aarch64 or AAVMF)
  143. 4. Run qemu with:
  144. qemu-system-aarch64 -M virt -cpu cortex-a57 -m 512 -nographic \
  145. -bios <path/to/EDK2>/QEMU_EFI.fd -hda output/images/disk.img \
  146. -netdev user,id=eth0 -device virtio-net-device,netdev=eth0
  147. 5. This should bring the grub2 menu, upon which selecting the
  148. "Buildroot" entry should boot Linux.