A bit confused with linkng the bootloader and kernel

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
kr651129
Posts: 18
Joined: Fri Dec 02, 2011 11:02 pm

A bit confused with linkng the bootloader and kernel

Post by kr651129 »

So I'm new to this and I'm trying to do the Basic C kernel tutorial. I executed the following

Code: Select all

nasm -f aout kernel_start.asm -o ks.o
gcc -c kernel.c -o kernel.o
ld -T link.ld -o kernel.bin ks.o kernel.o
Here's my question, how do I load this on my disk so it will boot?!

Code: Select all

sudo dd if=kernel.bin of=/dev/sdb bs=512 count=1
Didn't work, I've tried everything else and can't seem to get anywhere
User avatar
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: A bit confused with linkng the bootloader and kernel

Post by Muneer »

You specified "count = 1" which only copies one block(the first) and "bs = 512" means each block is 512 bytes. So you end up writing only the bootloader to your /dev/sdb and not your kernel.
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
kr651129
Posts: 18
Joined: Fri Dec 02, 2011 11:02 pm

Re: A bit confused with linkng the bootloader and kernel

Post by kr651129 »

So would I need to say count=2 and bs=1024 to get this to work correctly and still be bootable?
User avatar
eryjus
Member
Member
Posts: 286
Joined: Fri Oct 21, 2011 9:47 pm
Libera.chat IRC: eryjus
Location: Tustin, CA USA

Re: A bit confused with linkng the bootloader and kernel

Post by eryjus »

kr651129 wrote:Here's my question, how do I load this on my disk so it will boot?!

Code: Select all

sudo dd if=kernel.bin of=/dev/sdb bs=512 count=1
Didn't work, I've tried everything else and can't seem to get anywhere
Your command will write your linked file (kernel.bin) to your second hard drive (sdb) in the Master Boot Record (MBR). When you say it didn't work, the error message would help us help you. I would bet you do not have 2 hard disks.

Try:

Code: Select all

sudo dd if=kernel.bin of=disk.bin bs=512 count=1
which will create a disk file to use with an emulator like QEMU or

Code: Select all

sudo dd if=kernel.bin of=/dev/fda bs=512 count=1
which will write to floppy disk A.
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: A bit confused with linkng the bootloader and kernel

Post by Brendan »

Hi,
eryjus wrote:Your command will write your linked file (kernel.bin) to your second hard drive (sdb) in the Master Boot Record (MBR). When you say it didn't work, the error message would help us help you. I would bet you do not have 2 hard disks.
Unfortunately, modern Linux likes to pretend that lots of devices are SCSI, including everything that isn't SCSI (e.g. SATA, USB flash, USB external hard drives, etc). This is done to confuse the unsuspecting user, and to increase the chance of the same device name refers to completely different devices at different times. ;)
kr651129 wrote:So I'm new to this and I'm trying to do the Basic C kernel tutorial. I executed the following

Code: Select all

nasm -f aout kernel_start.asm -o ks.o
gcc -c kernel.c -o kernel.o
ld -T link.ld -o kernel.bin ks.o kernel.o
Why would anyone want to link a kernel with a boot loader in the first place?


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: A bit confused with linkng the bootloader and kernel

Post by Combuster »

Have you read (and done) everything your tutorial reference has to say on GRUB? The way the compilation instructions are listed I have to assume you haven't done anything on the bootloader side (that besides the fact that you have a pretty bad tutorial for recommending a.out and no GCC Cross-Compiler).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply