Help creating a bootable HARD DISK image with GRUB
Posted: Sat Jul 16, 2016 10:19 am
Hello,
Once again, I'm asking for the forum's help (sorry, I wish I was good enough to solve more problems on my own). This time, I'm trying to create a bootable disk image to pass to bochs / qemu as a hard disk image, which has grub installed, a grub config file, my kernel image, and Extra Empty space (or maybe even eventually a few small files). I'm quite aware that grub-mkrescue can be used to make a bootable CDROM image from a directory (and that you can even burn the image to a hard disk image and load it as a hard disk), but I'd like to create something closer to installing my OS onto a hard disk image.
Currently, I'm just using grub-mkrescue on my sysroot folder, and then passing that image as a cdrom to my emulator. While this works, I'm about to begin some file system and disk interaction stuff, and so I'd like to have my build system create a disk image which I can use as a bootable hard drive, instead of a bootable CDROM image. That way, I can work with the file system on the disk, and not have to have both a boot CD and a hard disk to play around with.
I'm pretty bad at explaining things, so I'll try and summarize it as simply as possible: I would like a bootable disk image, like the one made by grub-mkrescue, but I want it to be a Hard disk image, not a CD image, and I want it to have some empty space left over in the filesystem, so I can interact with the filesystem.
So far, I've tried making a blank disk image (something along the lines of "dd if=/dev/zero of=hd.img bs=1M count=64" to make a disk image, formatted it with a single fat32 primary partition using gparted, msdos partition table), then tried to install grub on it in a variety of ways, including just "grub-install hd.img", "grub-install /dev/loop0" (with the disk image looped to /dev/loop0 using "losetup loop0 hd.img"), and even "grub-install --boot-directory=/mnt/loop0p1/boot /dev/loop0" (with the first partition of /dev/loop0 mounted at /mnt/loop0p1). However, grub always errors out on boot, providing some sort of image along the lines of "error: no such device: 5E35-6F94" (the numbers usually vary) and then a grub rescue prompt. So from what I understand about grub, it's loading the MBR fine, which is why grub loads at all, but then, somehow, grub can't load the rest of itself from the disk (either it can't find it or it's not on the disk to begin with).
I've tried searching the forums and google, but the forums seem empty, despite the fact that I would have thought wanting to make a hard drive installation is a common desire, and google turns up nothing but endless pages of ubuntu boot recovery tutorials, none of which seem to have any information at all. Like I mention above, I pretty much just want to make a rescue disk image, but have it be a HDD image and have it not be the minimum size to accommodate GRUB and my image.
I'm concerned this might become a problem later down the track when a user would want to install my OS to their hard drive instead of booting from a CD every time. Even if I were to port grub-install or any of the other grub tools to my OS, how would I use them to install my OS on a hard drive? It's a similar problem to what I'm facing now, the only difference is that right now I want to install the OS (and bootloader) to a hard disk at compile time VS the user trying to install the OS and bootloader to a hard disk at runtime.
I guess, in essence, my question is, how do I install grub on the hard disk and how do I get grub on said hard disk to load my kernel binary. The rescue image seems to have no trouble doing it, so I'm sure it's possible, but how? Maybe if somebody could explain more thoroughly how grub actually installs itself on a medium, and how it runs itself on boot, I could discover the problem as well, because right now, all I know is that grub-mkrescue is a magic black box program which makes a CDROM image, puts the grub bootloader in the MBR, puts the rest of grub on disk, and puts all the other files I ask it to onto the disk, and then spits that image out.
Any information relating is helpful, I know I'm terrible at explaining what I'm trying to do, so ask me some more questions if you think you can help but don't quite get what I'm trying to do...
- Mikumiku747
Once again, I'm asking for the forum's help (sorry, I wish I was good enough to solve more problems on my own). This time, I'm trying to create a bootable disk image to pass to bochs / qemu as a hard disk image, which has grub installed, a grub config file, my kernel image, and Extra Empty space (or maybe even eventually a few small files). I'm quite aware that grub-mkrescue can be used to make a bootable CDROM image from a directory (and that you can even burn the image to a hard disk image and load it as a hard disk), but I'd like to create something closer to installing my OS onto a hard disk image.
Currently, I'm just using grub-mkrescue on my sysroot folder, and then passing that image as a cdrom to my emulator. While this works, I'm about to begin some file system and disk interaction stuff, and so I'd like to have my build system create a disk image which I can use as a bootable hard drive, instead of a bootable CDROM image. That way, I can work with the file system on the disk, and not have to have both a boot CD and a hard disk to play around with.
I'm pretty bad at explaining things, so I'll try and summarize it as simply as possible: I would like a bootable disk image, like the one made by grub-mkrescue, but I want it to be a Hard disk image, not a CD image, and I want it to have some empty space left over in the filesystem, so I can interact with the filesystem.
So far, I've tried making a blank disk image (something along the lines of "dd if=/dev/zero of=hd.img bs=1M count=64" to make a disk image, formatted it with a single fat32 primary partition using gparted, msdos partition table), then tried to install grub on it in a variety of ways, including just "grub-install hd.img", "grub-install /dev/loop0" (with the disk image looped to /dev/loop0 using "losetup loop0 hd.img"), and even "grub-install --boot-directory=/mnt/loop0p1/boot /dev/loop0" (with the first partition of /dev/loop0 mounted at /mnt/loop0p1). However, grub always errors out on boot, providing some sort of image along the lines of "error: no such device: 5E35-6F94" (the numbers usually vary) and then a grub rescue prompt. So from what I understand about grub, it's loading the MBR fine, which is why grub loads at all, but then, somehow, grub can't load the rest of itself from the disk (either it can't find it or it's not on the disk to begin with).
I've tried searching the forums and google, but the forums seem empty, despite the fact that I would have thought wanting to make a hard drive installation is a common desire, and google turns up nothing but endless pages of ubuntu boot recovery tutorials, none of which seem to have any information at all. Like I mention above, I pretty much just want to make a rescue disk image, but have it be a HDD image and have it not be the minimum size to accommodate GRUB and my image.
I'm concerned this might become a problem later down the track when a user would want to install my OS to their hard drive instead of booting from a CD every time. Even if I were to port grub-install or any of the other grub tools to my OS, how would I use them to install my OS on a hard drive? It's a similar problem to what I'm facing now, the only difference is that right now I want to install the OS (and bootloader) to a hard disk at compile time VS the user trying to install the OS and bootloader to a hard disk at runtime.
I guess, in essence, my question is, how do I install grub on the hard disk and how do I get grub on said hard disk to load my kernel binary. The rescue image seems to have no trouble doing it, so I'm sure it's possible, but how? Maybe if somebody could explain more thoroughly how grub actually installs itself on a medium, and how it runs itself on boot, I could discover the problem as well, because right now, all I know is that grub-mkrescue is a magic black box program which makes a CDROM image, puts the grub bootloader in the MBR, puts the rest of grub on disk, and puts all the other files I ask it to onto the disk, and then spits that image out.
Any information relating is helpful, I know I'm terrible at explaining what I'm trying to do, so ask me some more questions if you think you can help but don't quite get what I'm trying to do...
- Mikumiku747