Page 1 of 1
Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 8:24 am
by helino
Hi,
I've followed the steps of
http://wiki.osdev.org/Bare_bones and I'm successfully booting my kernel (yay
).
However, it will get tiresome to write the commands for locating the kernel and booting at the grub prompt in bochs every time I want to start my kernel. That is, I don't want to type
every time.
Does anyone know how to do this? If anyone has a solution that doesn't rely on using sudo, it would be even nicer (since I can't use sudo at the computers in my school)!
Re: Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 8:43 am
by Jezze
Code: Select all
#!/bin/sh
dd if=/dev/zero of=kernel.img bs=512 count=2880
dd if=boot/grub/stage1 conv=notrunc of=kernel.img bs=512 seek=0
dd if=boot/grub/stage2 conv=notrunc of=kernel.img bs=512 seek=1
dd if=menu.lst conv=notrunc of=kernel.img bs=512 seek=200
dd if=boot/kernel conv=notrunc of=kernel.img bs=512 seek=300
dd if=boot/initrd conv=notrunc of=kernel.img bs=512 seek=400
grub <<EOF
device (fd0) kernel.img
install (fd0)0+1 (fd0) (fd0)1+199 (fd0)200+1
EOF
I think this is sufficiant. It was a long time ago I used this but I think it is correct. It creates an image with a kernel and a menu.lst (with optional initrd). Grub will automatically find your menu.lst file and boot the kernel.
Re: Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 9:08 am
by helino
Thanks for your quick answer!
I understand what the dd commands do, but I don't understand the last part of the script does?
More specifically, the lines I don't understand are:
Code: Select all
grub <<EOF
device (fd0) kernel.img
install (fd0)0+1 (fd0) (fd0)1+199 (fd0)200+1
EOF
I also wonder what menu.lst should contain?
Once again, thanks for your help!
Re: Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 9:13 am
by Solar
The Bare Bones tutorial creates a floppy image, because it is easiest (i.e., keeping the tutorial short).
Your next step should be to set up not a floppy image, but a
hard drive image, where the kernel image is written to a partition. (Eventually, you will want your OS to boot from hard disk, not floppy.) Then set up GRUB in the "normal" way - i.e. not booting into the GRUB command line, but using a configuration file to display a boot menu (or, if you prefer, booting from the image directly, but still under control of the grub.cfg). Because, again, in the end you'll want to have the GRUB on your
real hard drive to select between operating systems.
Check out the
GRUB Wiki page.
More specifically, the lines I don't understand are:
Code: Select all
grub <<EOF
device (fd0) kernel.img
install (fd0)0+1 (fd0) (fd0)1+199 (fd0)200+1
EOF
I also wonder what menu.lst should contain?
I'd try the GRUB documentation...
Re: Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 9:27 am
by Jezze
Oops sorry. Forgot the menu.lst
Code: Select all
title MyOS
root (fd0)
kernel 300+100
module 400+300
If you are not using a initrd - remove the module section. Also remember that depending on the size of your executables you might need to adjust the limits.
Re: Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 10:01 am
by helino
Solar wrote:The Bare Bones tutorial creates a floppy image, because it is easiest (i.e., keeping the tutorial short).
Your next step should be to set up not a floppy image, but a hard drive image, where the kernel image is written to a partition. (Eventually, you will want your OS to boot from hard disk, not floppy.)
I don't think I fully understand this part, if my OS is very small (it will probably not have support for creating nor writing files), why is booting from a floppy a bad idea?
Jezze and Solar, thanks for taking your time and answering my questions, I really appreciate it!
Re: Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 10:04 am
by Solar
Most modern computers don't even have a floppy drive anymore.
Floppy images are somewhat useful for the first few steps when using an emulator, but their usefulness quickly diminishes. As soon as your OS would have to load further binaries from its boot media - do you really want to write a floppy driver? Given the fact that there is no floppy drive that your OS will ever be booted from?
Re: Automate the grub instructions when booting
Posted: Mon Jan 16, 2012 11:06 am
by helino
Ok, it seems reasonable to use some other form of media, not floppy.
Based on my limited experience with this, a bootable CD seems like a good option, what do you think about that?
Which one of the following tutorials would you recommend?
Or do you have any other literature that you think is better (tutorial, guide, wiki) on how to create a bootable CD?
Once again, thanks for your help Solar!
EDIT: Fixed formatting
Re: Automate the grub instructions when booting
Posted: Tue Jan 17, 2012 5:38 am
by Solar
Erm... is it even possible to have a floppy with the GRUB stage(s) and a functioning filesystem installed?
(I skipped the floppy / FAT part, but I think I recall that installing GRUB on a floppy more or less annihilates the filesystem...)
Re: Automate the grub instructions when booting
Posted: Tue Jan 17, 2012 7:20 am
by thepowersgang
@Solar: It is, I've been running a FAT/Grub floppy for years. Don't really know how to make one from scratch, but I'm reasonably sure it is still possible.
Re: Automate the grub instructions when booting
Posted: Tue Jan 17, 2012 7:22 am
by Velko
With GRUB2 it is pretty easy to build an ISO image:
Code: Select all
grub-mkrescue -o ostest.iso runimage/
With
runimage/ directory's contents being:
Code: Select all
runimage/boot/grub/grub.cfg
runimage/boot/kernel.bin
And
grub.cfg containing:
Code: Select all
set default=0
set timeout=0
menuentry "My OS" {
set root='(hd96)'
multiboot /boot/kernel.bin
}
Have fun!
Re: Automate the grub instructions when booting
Posted: Tue Jan 17, 2012 10:13 am
by helino
Thanks for all the great replies!
For now, I ended up using the floppy disk with GRUB preloaded onto it from JamesM's kernel tutorial (see the link in the beginning of
http://www.jamesmolloy.co.uk/tutorial_h ... setup.html).
However, ISO images seems like a nicer alternative, so I will probably look into Velkos suggestions when I have time.
If you have any more ideas about how to solve this problem, please post them, I will continue to follow this thread!
Re: Automate the grub instructions when booting
Posted: Thu Jan 19, 2012 7:02 am
by Kevin
thepowersgang wrote:@Solar: It is, I've been running a FAT/Grub floppy for years. Don't really know how to make one from scratch, but I'm reasonably sure it is still possible.
Create the FAT file system on the floppy image, copy all the files there (including a /boot/grub directory containing stage1, stage2 and your menu.lst) and then run this in a grub shell:
Code: Select all
device (fd0) $IMAGE_PATH
root (fd0)
setup (fd0)