make bootable grub 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
pochito
Posts: 1
Joined: Thu Feb 15, 2018 12:49 pm

make bootable grub hd image

Post by pochito »

I'm trying to create a hd image with my own bootable os.

I have the following files:

Code: Select all

build/iso/
  - os.kernel
  - boot/grub/grub.cfg
  - a few extra files
I'm able to create a working bootable iso file with this:

Code: Select all

grub-mkrescue -o build/nopsys.iso build/iso
now, I want to create a hard disk image instead of an iso file. I didn't find a way to convert an iso to a fat32 hd image, so thought about
using grub-mkimage. However, I couldn't make it work.

I've tried the following with no luck, any help very much appreciated

Code: Select all

grub-mkimage -p build/iso -o build/nopsys.raw -O i386-pc fat
thanks for reading!

EDIT: there's one more requirement, I'd like to be able to avoid needing sudo, that's why I'm not trying mounting a loopback device.
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: make bootable grub hd image

Post by BenLunt »

This happens to be one of the most asked questions here. A FAQ in fact.

First, did you see https://wiki.osdev.org/Disk_Images?

One of the first things an OS Developer must do is create a disk image on some form of bootable media. To do so, he/she must understand the media as well as, and more importantly, the file system or storage array of the media. Where is my boot code? Where is my second stage code? Where is my kernel? etc.

Another very important part of media creation is how long and how difficult is it to change a file upon that media? For example, I have created my boot code, second/third/etc stage loader code, my kernel code, and some drivers, and have put them all on my media (which could simply be a hard drive image on the local host machine). However, I have made a simple change to the X-stage loader code and need to update the image file. Do I need to recreate the whole image or just the file in question? How many utilities do I need to do so?

Lots of questions.

So, here are a few solutions:
1) You need to following utilities to create/modify a FAT hard drive image:
a) A utility to create an empty image
b) A utility to create an empty FAT image on that image (format)
c) A utility to copy files to that formatted image
Utilities a) and b) can be combined as one if needed.

Now, when you make a modification to one of the files on the hard drive image, you only need utility c).

There are many utilities already created for this, or you can create your own.

I have created many myself, specifically for my specific needs. An older version of this set is at http://www.fysnet.net/mtools.htm, it comes with source code and hopefully can be mostly portable. I targeted Window XP since that is my development platform.

Those whom have a copy of one of my books, specifically Volumes 1 and 2 (http://www.fysnet.net/osdesign_book_series.htm), also have more detailed and updated utilities to do this.

For example, my current work involves a FAT12 image for testing and I use the mkdosfs utility from the latter URL above.

For your question, as far as placing Grub on that image, there are utilities, including the GRUB utility itself (I presume) that will do this.

Ben
- http://www.fysnet.net/osdesign_book_series.htm

P.S. I am not a Linux user, though I have dabbled with it on occasion, though I have found that you don't need full access to the host development machine, i.e.: sudo, to simply modify an image file and execute an emulator, do you?
Post Reply