readme.txt
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/install the EFI BIOS for Qemu
90 You can get it using the edk2 package in Buildroot (installed
91 in BINARIES_DIR), grab prebuilt images from the unofficial nightly
92 builds [0], or use one provided by your distribution as OVMF.
93
94 [0] https://github.com/retrage/edk2-nightly
95
962. qemu-system-{i386,x86-64} -bios <path-to-OVMF.fd> -hda disk.img
97
98Notes on using Grub2 for ARM u-boot-based platforms
99===================================================
100
101The following steps show how to use the Grub2 arm-uboot platform
102support in the simplest way possible and with a single
103buildroot-generated filesystem.
104
105 1. Load qemu_arm_vexpress_defconfig
106
107 2. Enable u-boot with the vexpress_ca9x4 board name and with
108 u-boot.elf image format.
109
110 3. Enable grub2 for the arm-uboot platform.
111
112 4. Enable "Install kernel image to /boot in target" in the kernel
113 menu to populate a /boot directory with zImage in it.
114
115 5. The upstream u-boot vexpress_ca9x4 doesn't have CONFIG_API enabled
116 by default, which is required.
117
118 Before building, patch u-boot (for example, make u-boot-extract to
119 edit the source before building) file
120 include/configs/vexpress_common.h to define:
121
122 #define CONFIG_API
123 #define CONFIG_SYS_MMC_MAX_DEVICE 1
124
125 6. Create a custom grub2 config file with the following contents and
126 set its path in BR2_TARGET_GRUB2_CFG:
127
128 set default="0"
129 set timeout="5"
130
131 menuentry "Buildroot" {
132 set root='(hd0)'
133 linux /boot/zImage root=/dev/mmcblk0 console=ttyAMA0
134 devicetree /boot/vexpress-v2p-ca9.dtb
135 }
136
137 7. Create a custom builtin config file with the following contents
138 and set its path in BR2_TARGET_GRUB2_BUILTIN_CONFIG:
139
140 set root=(hd0)
141 set prefix=/boot/grub
142
143 8. Create a custom post-build script which copies files from
144 ${BINARIES_DIR}/boot-part to $(TARGET_DIR)/boot (set its path in
145 BR2_ROOTFS_POST_BUILD_SCRIPT):
146
147 #!/bin/sh
148 cp -r ${BINARIES_DIR}/boot-part/* ${TARGET_DIR}/boot/
149
150 9. make
151
15210. Run qemu with:
153
154 qemu-system-arm -M vexpress-a9 -kernel output/images/u-boot -m 1024 \
155 -nographic -sd output/images/rootfs.ext2
156
15711. In u-boot, stop at the prompt and run grub2 with:
158
159 => ext2load mmc 0:0 ${loadaddr} /boot/grub/grub.img
160 => bootm
161
16212. This should bring the grub2 menu, upon which selecting the "Buildroot"
163 entry should boot Linux.
164
165
166Notes on using Grub2 for Aarch64 EFI-based platforms
167====================================================
168
169The following steps show how to use the Grub2 arm64-efi platform,
170using qemu and EFI firmware built for qemu.
171
172 1. Load aarch64_efi_defconfig
173
174 2. make
175
176 3. Download the EFI firmware for qemu aarch64
177
178 You can get it using the edk2 package in Buildroot (installed
179 in BINARIES_DIR), grab prebuilt images from the unofficial nightly
180 builds [1], or use one provided by your distribution as OVMF-aarch64
181 or AAVMF.
182
183 [1] https://github.com/retrage/edk2-nightly
184
185 4. Run qemu with:
186
187 qemu-system-aarch64 -M virt -cpu cortex-a57 -m 512 -nographic \
188 -bios <path/to/EDK2>/QEMU_EFI.fd -hda output/images/disk.img \
189 -netdev user,id=eth0 -device virtio-net-device,netdev=eth0
190
191 5. This should bring the grub2 menu, upon which selecting the
192 "Buildroot" entry should boot Linux.
193