I have an ext4 image file which wants to be used as a disk image for qemu. I want to install GRUB to it. After some research I found the following commands:
Create the image with a size of 5 GB:
qemu-img create hd.img 5G
Mount it as a loop device:
sudo mount -o loop hd.img /mnt
Install GRUB to it:
sudo grub-install --root-directory=/mnt --no-floppy --recheck /dev/loop0
The qemu system should be an x86 system. And that's the problem: I'm not on i386 and I don't have GRUB installed on my host system. So I'm searching for a precompiled version of GRUB 2 which I could just copy to the image's file system. Is there a way to do that?
Sure, if you are using (for example) Debian, then you already have per-architecture/platform packages for the target components of grub - in the x86 case:
If building from source, just specify --target=<TARGET>
on your configure line, where TARGET in your case would be i386-pc
, i386-efi
or x86_64-efi
.
Install by passing --target=<TARGET>
to grub-install
.