How to create a bootable HARDDISK Image with GRUB2?

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
ashishkumar4
Member
Member
Posts: 73
Joined: Wed Dec 23, 2015 10:42 pm

How to create a bootable HARDDISK Image with GRUB2?

Post by ashishkumar4 »

Here I am, the most idiotic person ever to be on osdev forums :p
So this time my Question is JUST THIS-> I WANT TO CREATE AN HDD IMAGE via GRUB2 Which also contains my KERNEL and CONFIG FILE. HOW TO DO IT??? In another way, i wanna ask that I just want to create something SIMILAR to the CDROM ISO File we create using grub-mkrescue except that it should be for HDD not CD-ROM. Help please :/
I Tried made an hdd using 'dd' and then formated via 'fdisk'. then creating the loopback devices to it and formatting it with ext2 and fat32 (once with ext2, didnt worked, then with fat32 so i can check it directly on my windows and dont have to boot linux again. still didnt work :/ ). So here is what I did after that-> I mounted the new partition (starting from 1MB) and then used grub-install .... (I experimented with several configs, none worked). Then I put my Kernel and grub.cfg in /boot and /boot/grub dirs respectively of my hdd image. Currently I get <b>'error: no such device:<some no>'</b>.

I just wanna ask the EXACT steps for doing this (And with using my kernel and config file being included in the core image itself while on build). PLEASE HELP >_<
The best method for accelerating a computer is the one that boosts it by 9.8 m/s2.
My OS : https://github.com/AshishKumar4/Aqeous
User avatar
Mikumiku747
Member
Member
Posts: 64
Joined: Thu Apr 16, 2015 7:37 am

Re: How to create a bootable HARDDISK Image with GRUB2?

Post by Mikumiku747 »

Hello, somehow I managed to ask this question after you and get a bunch of replies, so I'll try and share some of the help I got on my post.

For starters, I found that the wiki article on GRUB was helpful, as it provides step by step instructions for creating a disk with the required setup and stuff to boot into GRUB. From there, as mentioned by linuxyne, you just need to mount the file system using losetup and mount (see steps 3 and 5), copy your files in, and then unmount and remove from losetup (sudo umount and losetup -d /dev/loop0 or something like that).

If you have some folder which you're making grub mkrescue images from, let's call it, "sysroot", and the mount point for your disk image, let's call it "/mnt/disk", you can use something like "cp -r sysroot/* /mnt/disk/" to copy all the files to your boot disk. This is what you'd use to copy in your kernel, the other files in your system, and your grub config file.

Just thought I'd mention, if you've got some automated build system like a makefile or something, rather than trying to create and entire disk image, partition it, and configure it every time I did a build, I made a "template" disk image, which was pretty much blank apart from GRUB and its files. When I wanted to build, I'd make a copy of the template ("cp template.img myos_hdd.img" or whatever you prefer) and then mounted the new copy and did a recursive copy (like the one mentioned above) to load all my files into the image, that way whenever I did a build I'd get a clean, predictable image, and wouldn't have to do everything by hand.

As also mentioned by linuxyne, if you want a nice GRUB menu, you need to make a grub configuration script. For Multiboot kernels, they're dead simple, you can pretty much use the example script provided, just make sure you know which parts do what. The most basic config file can just have the multiboot command or something like it, to boot straight into your OS, but it's probably better to set up a menu entry, it's dead easy anyway, and you probably already do it if you're making grub-mkrescue CDROM images.

Hopefully this isn't way too late, I saw you responded to my post, but I was hoping I could directly address some of the question you had, or more directly explain some of the steps to get you going.
ashishkumar4
Member
Member
Posts: 73
Joined: Wed Dec 23, 2015 10:42 pm

Re: How to create a bootable HARDDISK Image with GRUB2?

Post by ashishkumar4 »

It wasnt working until now. I had been doing the same thing but still :/ At the end, Out of frustration I started over again after cleaning everything. I just did it the way the wiki said. Then I copied over my kernel and grub.cfg to the image and 'synced' everything :p It WORKED!!!
The Reason I think It worked is that This time, I had put my Kernel file as '.bin. file (my kernel file: "Aqeous.bin"). Earlier I had used nonsence extentions like Aqeous.aqeous (xD) and Aqeous (no extention :p ) and Aqeous.elf xD. I think Grub only reads this extention :p Because I was doing everything else just as I had been doing before. This worked only after I did this change. Thanks everyone!!!
The best method for accelerating a computer is the one that boosts it by 9.8 m/s2.
My OS : https://github.com/AshishKumar4/Aqeous
Post Reply