8

I have been reading BrokenThorn's OS development tutorial and am at the part of creating and loading the second stage bootloader. The tutorial is for Windows, but I am doing this in Linux(Ubuntu 13.04).

This is what I have done:

  • Created file floppy.img under ~/Documents/floppy with the mkfs.vfat command
  • Compiled by boot.asm file using nasm giving me boot.bin
  • Then I ran this command : dd if=boot.bin of=~/Documents/floppy/floppy.img bs=512 count=1

Thus I have the floppy image with the first stage bootloader. On starting that using qemu, it works fine.

However, after I create the second stage bootloader, (if I am correct)I would have to mount the floppy.img and copy stage 2 on to the mounted filesystem. In such a case, how can one boot a mounted floppy using qemu ? Is it even possible ? If not, how do I work with the second stage bootloader.

Please forgive me for any stupid assumption/question as I am new with this.

Cygnus
  • 3,222
  • 9
  • 35
  • 65
  • So the reason for splitting the bootloader in two, has to do with how the bios acts, basically when booting a disk, it reads the first sector, and starts running it. So in the first sector you'll put the bootstrap code to load more sectors from the floppy, aka. The second stage loader, which will actually load the systems. – Skeen Nov 13 '13 at 18:06
  • Also if you don't already know, then there's a hobby os development forum at http://forum.osdev.org/ which may me more helpful than stack overflow, as it's dedicated to one domain only. – Skeen Nov 13 '13 at 18:08
  • So to answer your question, the stage 1 boot loader will have to access the floppy controller and read the stage2 bootloader. You may decide to load a static amount of sectors for your stage 2 loader, to keep everything simple. Once the stage 2 loader is in memory, simply jump to it's entry point. – Skeen Nov 13 '13 at 18:11
  • As for whether to mount to move stage2 to it (I'm assuming you're talking about mounting it in Linux). Then I'll say, if you wanna keep stuff simple, then simply dd that onto the disk as well, instead of using fat. But if you do want to have a file system, then yes, do mount it and copy it. However then your bootloader will need to deal with the fat layout. – Skeen Nov 13 '13 at 18:12
  • Also in the is development community there's a great discussion as to whether one should start with the bootloader or the kernel. – Skeen Nov 13 '13 at 18:18
  • @Skeen : Thanks a lot. Yes, i meant mounting it in Linux. Please have a look at the edited question. I have added more details on what I have done. – Cygnus Nov 14 '13 at 14:33
  • If you've mounted the floppy in Linux, and copied the stage two to it. Then mounting it to qemu should be no different than with stage 1 only, that is using -fda – Skeen Nov 15 '13 at 01:30
  • 1
    A little tip: ditch floppy. Start using sane options, like booting off a HDD, CD or DVD. Floppies are dead, stop biting them. – Griwes Nov 16 '13 at 12:16

1 Answers1

8

Where is your problem? You mount the image:

mount -oloop ~/Documents/floppy.img /mnt/floppy

Copy the stage2:

cp stage2.bin /mnt/floppy

Unmount it:

umount /mnt/floppy

And launch it with QEMU:

qemu -fda ~/Documents/floppy.img

Voilà!

elaforma
  • 652
  • 1
  • 9
  • 29
  • Yes, I got it cleared form the comments and some testing of my own. But thank you, will be useful for future reference ! – Cygnus Dec 31 '13 at 07:19