Page 1 of 1
A bit confused with linkng the bootloader and kernel
Posted: Fri Dec 02, 2011 11:15 pm
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
Re: A bit confused with linkng the bootloader and kernel
Posted: Fri Dec 02, 2011 11:35 pm
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.
Re: A bit confused with linkng the bootloader and kernel
Posted: Fri Dec 02, 2011 11:47 pm
by kr651129
So would I need to say count=2 and bs=1024 to get this to work correctly and still be bootable?
Re: A bit confused with linkng the bootloader and kernel
Posted: Sat Dec 03, 2011 12:16 am
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.
Re: A bit confused with linkng the bootloader and kernel
Posted: Sat Dec 03, 2011 1:09 am
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
Re: A bit confused with linkng the bootloader and kernel
Posted: Sat Dec 03, 2011 2:44 am
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).