Booting my kernel [Fixed]

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.
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Booting my kernel [Fixed]

Post 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?
Last edited by computafreak on Sun Jan 11, 2009 1:34 pm, edited 1 time in total.
User avatar
stephenj
Member
Member
Posts: 140
Joined: Wed Jul 23, 2008 1:37 am
Location: Canada

Re: Booting my kernel

Post 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...
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: Booting my kernel

Post 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.
"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 ]
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Booting my kernel

Post 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
thegamefreak0134
Posts: 14
Joined: Thu Jan 08, 2009 1:54 am

Re: Booting my kernel

Post 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
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Booting my kernel

Post 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
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Booting my kernel

Post by xyzzy »

What's the exact command are you using to create the ISO image?
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Booting my kernel

Post 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
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Booting my kernel

Post 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.
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Booting my kernel

Post 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
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: Booting my kernel

Post 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
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Booting my kernel

Post 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.
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: Booting my kernel

Post by xDDunce »

hmmm.... guess i was wrong then. ah well, were all learning though aren't we? :lol:
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Booting my kernel

Post 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
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Booting my kernel

Post 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.
Post Reply