readme.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. loop_dev=$(sudo losetup -f --show disk.img)
  13. sudo partx -a "$loop_dev"
  14. 4. Prepare the root partition
  15. sudo mkfs.ext3 -L root "${loop_dev}p1"
  16. sudo mount "${loop_dev}p1" /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 . "$loop_dev"
  23. 6. Cleanup loop device
  24. sudo partx -d "$loop_dev"
  25. sudo losetup -d "$loop_dev"
  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. loop_dev=$(sudo losetup -f --show disk.img)
  60. sudo partx -a "$loop_dev"
  61. 4. Prepare the boot partition
  62. sudo mkfs.vfat -n boot "${loop_dev}p1"
  63. sudo mount "${loop_dev}p1" /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 "${loop_dev}p2"
  69. sudo mount "${loop_dev}p2" /mnt
  70. sudo tar -C /mnt -xf output/images/rootfs.tar
  71. sudo umount /mnt
  72. 6 Cleanup loop device
  73. sudo partx -d "$loop_dev"
  74. sudo losetup -d "$loop_dev"
  75. 7. Your disk.img is ready!
  76. To test your i386/x86-64 EFI image in Qemu
  77. ------------------------------------------
  78. 1. Download/install the EFI BIOS for Qemu
  79. You can get it using the edk2 package in Buildroot (installed
  80. in BINARIES_DIR), grab prebuilt images from the unofficial nightly
  81. builds [0], or use one provided by your distribution as OVMF.
  82. [0] https://github.com/retrage/edk2-nightly
  83. 2. qemu-system-{i386,x86_64} -bios <path-to-OVMF.fd> -hda disk.img
  84. Notes on using Grub2 for ARM u-boot-based platforms
  85. ===================================================
  86. The following steps show how to use the Grub2 arm-uboot platform
  87. support in the simplest way possible and with a single
  88. buildroot-generated filesystem.
  89. 1. Load qemu_arm_vexpress_defconfig
  90. 2. Enable u-boot with the vexpress_ca9x4 board name and with
  91. u-boot.elf image format.
  92. 3. Enable grub2 for the arm-uboot platform.
  93. 4. Enable "Install kernel image to /boot in target" in the kernel
  94. menu to populate a /boot directory with zImage in it.
  95. 5. The upstream u-boot vexpress_ca9x4 doesn't have CONFIG_API enabled
  96. by default, which is required.
  97. Before building, patch u-boot (for example, make u-boot-extract to
  98. edit the source before building) file
  99. include/configs/vexpress_common.h to define:
  100. #define CONFIG_API
  101. #define CONFIG_SYS_MMC_MAX_DEVICE 1
  102. 6. Create a custom grub2 config file with the following contents and
  103. set its path in BR2_TARGET_GRUB2_CFG:
  104. set default="0"
  105. set timeout="5"
  106. menuentry "Buildroot" {
  107. set root='(hd0)'
  108. linux /boot/zImage root=/dev/mmcblk0 console=ttyAMA0
  109. devicetree /boot/vexpress-v2p-ca9.dtb
  110. }
  111. 7. Create a custom builtin config file with the following contents
  112. and set its path in BR2_TARGET_GRUB2_BUILTIN_CONFIG:
  113. set root=(hd0)
  114. set prefix=/boot/grub
  115. 8. Create a custom post-build script which copies files from
  116. ${BINARIES_DIR}/boot-part to $(TARGET_DIR)/boot (set its path in
  117. BR2_ROOTFS_POST_BUILD_SCRIPT):
  118. #!/bin/sh
  119. cp -r ${BINARIES_DIR}/boot-part/* ${TARGET_DIR}/boot/
  120. 9. make
  121. 10. Run qemu with:
  122. qemu-system-arm -M vexpress-a9 -kernel output/images/u-boot -m 1024 \
  123. -nographic -sd output/images/rootfs.ext2
  124. 11. In u-boot, stop at the prompt and run grub2 with:
  125. => ext2load mmc 0:0 ${loadaddr} /boot/grub/grub.img
  126. => bootm
  127. 12. This should bring the grub2 menu, upon which selecting the "Buildroot"
  128. entry should boot Linux.
  129. Notes on using Grub2 for Aarch64 EFI-based platforms
  130. ====================================================
  131. The following steps show how to use the Grub2 arm64-efi platform,
  132. using qemu and EFI firmware built for qemu.
  133. 1. Load aarch64_efi_defconfig
  134. 2. make
  135. 3. Download the EFI firmware for qemu aarch64
  136. You can get it using the edk2 package in Buildroot (installed
  137. in BINARIES_DIR), grab prebuilt images from the unofficial nightly
  138. builds [1], or use one provided by your distribution as OVMF-aarch64
  139. or AAVMF.
  140. [1] https://github.com/retrage/edk2-nightly
  141. 4. Run qemu with:
  142. qemu-system-aarch64 -M virt -cpu cortex-a57 -m 512 -nographic \
  143. -bios <path/to/EDK2>/QEMU_EFI.fd -hda output/images/disk.img \
  144. -netdev user,id=eth0 -device virtio-net-device,netdev=eth0
  145. 5. This should bring the grub2 menu, upon which selecting the
  146. "Buildroot" entry should boot Linux.