Installing GRUB to an hd image

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Installing GRUB to an hd image

Post by alethiophile »

I can't figure out how to install GRUB to an HD image so I can test it on an emulator. I create a bootable image as it says to in the GRUB wiki page and in the Grub docs, create the new os image, make a filesystem on it (I have tried both FAT16 and ext2), and boot with Qemu. When I try to install it, it gives me an error similar to 'cannot mount selected partition'. Also, when I try the find command on files I know are in the image, it returns 'cannot find file'. Does anyone know how to do this?
If I had an OS, there would be a link here.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Installing GRUB to an hd image

Post by JamesM »

Hi,

The workflow pretty much goes like this:

1) Create the (blank) HDD image using 'dd' or similar.
2) Mount it as loopback and run fdisk to set up the partition table. Create your partitions here.
3) Unmount. Remount as loopback with a byte offset to the start of the first partition.
4) Run mke2fs/mkdosfs on the loopback device to create the FS.
5) Copy the grub stage1/stage2 to /boot.
6) Create a menu.lst.
7) Copy your OS across and unmount.

See Loopback Device.

James
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Re: Installing GRUB to an hd image

Post by alethiophile »

Thanks. I hadn't been making a partition table, just using the whole disk.
If I had an OS, there would be a link here.
Post Reply