How to go about writing an OS and bootloader to disk?

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
chronium
Posts: 2
Joined: Thu May 11, 2017 4:37 am
Libera.chat IRC: Chronium

How to go about writing an OS and bootloader to disk?

Post by chronium »

Hello everyone.

So, after I get myself an ATA driver or something to be able to read and and write to and from the disk, how exactly do I go about writing things like the MBR, a bootloader and my kernel to the disk?
The bootloader I'm aiming for is GRUB2, on normal BIOS.
I do not exactly understand how they all fit together, what needs to get written where, things like that.
And another question, is there a way for me to write a GRUB2 module for my own file system?

Cheers,
Chronium.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Writing an OS and bootloader to disk.

Post by dozniak »

chronium wrote:Hello everyone.

So, after I get myself an ATA driver or something to be able to read and and write to and from the disk, how exactly do I go about writing things like the MBR, a bootloader and my kernel to the disk?
grub-install does grub installation for you, just give it a drive specification (hd0) etc - see GRUB manual for that, it's all detailed there.
chronium wrote: I do not exactly understand how they all fit together, what needs to get written where, things like that.
If you're using grub, you can write the kernel anywhere on a fileystem that is understood by grub.
chronium wrote: And another question, is there a way for me to write a GRUB2 module for my own file system?
Yes, it is possible. Get grub sources https://www.gnu.org/software/grub/grub-download.html and look for implementation of filesystem modules, it's fairly straightforward. E.g. grub-core/fs/fat.c defines a FAT filesystem driver.
Learn to read.
chronium
Posts: 2
Joined: Thu May 11, 2017 4:37 am
Libera.chat IRC: Chronium

Re: How to go about writing an OS and bootloader to disk?

Post by chronium »

I don't want to install it using external tools. I'm interested on how to do the installation from inside my kernel. There should be a way to get the stage 1 and 2 files, write the stage 1 where it should be and then do the rest for stage 2, but that's what I don't quite get how to do.

Where exactly each part of the bootloader should go
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: How to go about writing an OS and bootloader to disk?

Post by Geri »

the first ,,stage'' goes to the first sector.

the second goes
Image
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: How to go about writing an OS and bootloader to disk?

Post by dozniak »

chronium wrote: Where exactly each part of the bootloader should go
You can inspect the sources of grub-install and figure where, how and why it is written.

Learn to read already.
Learn to read.
Post Reply