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