Page 1 of 2

Booting my kernel [Fixed]

Posted: Fri Jan 09, 2009 7:26 am
by computafreak
I've been working away on a kernel of mine for a little while now, and it's mostly working (no gxx or ld errors). I've got a fair amount done, but hit a roadblock: How do I boot my multiboot-compliant kernel, either using Bochs, or on a physical computer? I don't have a floppy disk drive, and don't use Linux, which discounts the vast majority of what I found on the internet. Ideally, I would like to be able to use my memory stick / pen drive on a real computer (my BIOS settings allow this), but GrUB doesn't seem to work when I copy Stage1 to the boot sector and Stage2 and my a.out kernel to the root directory. I feel like I'm missing something really obvious - could someone give me a few pointers please?

Re: Booting my kernel

Posted: Fri Jan 09, 2009 7:48 am
by stephenj
You should be able to emulate a floppy drive (a virtual floppy drive) in most emulators. All you should have to do is create a file representing a floppy disk.

I know Bochs and Qemu allow this...

Re: Booting my kernel

Posted: Fri Jan 09, 2009 7:51 am
by Combuster
Grub needs to install itself when you use a filesystem. For that you need... GRUB :(

Three options:
1. Get a linux liveCD to configure grub properly on your USB key
2. Destroy the filesystem. put stage1 on the first sector, stage 2 directly after it, and your kernel starting at some magic sector number and use that sector number to boot it again later.
3. Consider booting from (rewritable) CD. You can use a special El-torito version of grub that can be set up with mkisofs

To allow yourself to test the exact same thing on both an emulator and real hardware, a CD is probably the best choice.

Re: Booting my kernel

Posted: Fri Jan 09, 2009 12:51 pm
by computafreak
Thanks for the help; I've decided to boot from a CD. I created the ISO file using a script I've put together, and everything compiles, links, etc. From running it in a virtual machine, I can see a command line; based on the operating system kernels I downloaded, shouldn't there be a list of kernels to boot? I have a lst file set up in the same directory as the stage2_eltorito file. Based on the floppy disk installation, I would follow these instructions, but I don't see how it would be possible to write to a CD as the install command implies; how would these steps change?

On a final note, if anyone saw the previous post I made and then deleted, it didn't contain anything of use; merely a few problems I had when I mistyped the command line entries

Re: Booting my kernel

Posted: Fri Jan 09, 2009 2:08 pm
by thegamefreak0134
Once you have an ISO going, you're almost done. In order for GRUB to find your kernel, on the ISO's filesystem should be a file at grub/menu.lst

Inside this file is a list of kernels, their names, and the locations of the bin to run. For instance, I keep my kernel on the root of the filesystem, at "kernel2.sys", so my menu.lst file looks like this:

Code: Select all

timeout 10
default 0

title SimpleOS
kernel /kernel2.sys
Default tells GRUB which item in the list to load (SimpleOS is the only item, at location 0) and timeout is how long to wait for user input before booting the default one. It's all fairly self explanitory. Without this information, GRUB will load in command line form, and you'll need to provide it with the address of the kernel on your own, which can be difficult.

Personally, I use mkisofs to make my ISO, what are you using to make your CD? (I'm compiling under windows here)

-Nick

Re: Booting my kernel

Posted: Sat Jan 10, 2009 2:52 am
by computafreak
Once again, thanks. I use genisoimage in Cygwin to generate the ISO file. I've added the menu.lst file, and my directory structure is like this now:

ISO image
-Uncompressed
--Boot
---GrUB
----menu.lst
----stage2_eltorito
--kernel.bin
-CreateISO.bat
-Final.iso

My menu.lst looks like this:

Code: Select all

timeout 10
default 0

title My kernel
kernel /kernel.bin
But GrUB doesn't seem to find the file, or parse it. I tried to manually load kernel.bin using kernel /kernel.bin, but came up against a File Not Found error. Virtual PC triple-faults when I use the ioprobe command. What's going on

Re: Booting my kernel

Posted: Sat Jan 10, 2009 3:19 am
by xyzzy
What's the exact command are you using to create the ISO image?

Re: Booting my kernel

Posted: Sat Jan 10, 2009 3:24 am
by computafreak
I'm running a script from the ISO image directory

Code: Select all

genisoimage -R -b Boot/GrUB/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o Final.iso Uncompressed

Re: Booting my kernel

Posted: Sat Jan 10, 2009 5:37 am
by xyzzy
You should use lower-case names for everything on the CD. I'm not entirely sure but I think Rock Ridge names are case-sensitive (you're creating the ISO image with Rock Ridge information), and GRUB expects the path to its configuration file to be lower case.

Re: Booting my kernel

Posted: Sat Jan 10, 2009 7:44 am
by computafreak
Brilliant. My boot menu's working perfectly in Virtual PC, and I'm looking forward to trying it on a real computer. Thank you to everybody who posted

Re: Booting my kernel

Posted: Sat Jan 10, 2009 8:10 am
by xDDunce
AlexExtreme wrote:You should use lower-case names for everything on the CD. I'm not entirely sure but I think Rock Ridge names are case-sensitive (you're creating the ISO image with Rock Ridge information), and GRUB expects the path to its configuration file to be lower case.
in my experience, all file and folder names need to be upper-case. but they can be however you want them on your drive because the iso generators generally change all paths to upper-case anyway. and so GRUB cant be expecting it's config file to be lower case. :D

Re: Booting my kernel

Posted: Sat Jan 10, 2009 9:34 am
by xyzzy
Looking at the GRUB source, it does expect it to be lower case. The ISO9660 code uses Rock Ridge where available, which should allow case-insensitive names. If I build my ISO image without the -R switch (without Rock Ridge), GRUB sees all names as upper case and does not pick up the config file.

Re: Booting my kernel

Posted: Sat Jan 10, 2009 10:09 am
by xDDunce
hmmm.... guess i was wrong then. ah well, were all learning though aren't we? :lol:

Re: Booting my kernel

Posted: Sat Jan 10, 2009 10:56 am
by computafreak
Carrying on from my last post, there's a small problem. GrUB is throwing error 13, file in wrong format. I had a search through the wiki and forum, and concluded that I need to make the GCC cross-compiler. I'm trying that now, but is there another way to work around this error, or a way for me to create an ELF file? My ld linker script is at the bottom of this post, followed by my Cygwin build and link script

Linker script:

Code: Select all

ENTRY(start)
SECTIONS
{
  .text 0x100000 :
  {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(4096);
  }

  .data :
  {
      __CTOR_LIST__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) * (.ctors) LONG(0) __CTOR_END__ = .;
      __DTOR_LIST__ = .; LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) * (.dtors) LONG(0) __DTOR_END__ = .;
     data = .; _data = .; __data = .;
     *(.data)
     *(.rodata)
     . = ALIGN(4096);
  }

  .bss :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(4096);
  }

  end = .; _end = .; __end = .;
}
Cygwin build script:

Code: Select all

#!/bin/csh
nasm -f aout -o Boot.o Assembly/Boot.s
nasm -f aout -o Interrupts.o Assembly/Interrupts.s
nasm -f aout -o DescriptorTables.o Kernel/DTables.s

g++ -c Kernel/Boot.cpp -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Main.o
g++ -c Kernel/Common.cpp -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Common.o
g++ -c Kernel/Console.cpp -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Console.o
g++ -c Kernel/DTables.cpp -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o CDescriptorTables.o
g++ -c Kernel/ISR.cpp -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o ISR.o
g++ -c Kernel/Timer.cpp -nostdlib -fno-builtin -fno-rtti -fno-exceptions -o Timer.o

ld -T Link.ld -o Output/kernel Boot.o Interrupts.o DescriptorTables.o Main.o Common.o Console.o CDescriptorTables.o ISR.o Timer.o
rm *.o

Re: Booting my kernel

Posted: Sat Jan 10, 2009 12:07 pm
by xyzzy
Somebody correct me if I'm wrong, but AFAIK Cygwin's toolchain does not support ELF binaries. You'll probably have to build a cross-compiler.