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.

8
  • 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, 2013 at 18:06
  • Also if you don't already know, then there's a hobby os development forum at forum.osdev.org which may me more helpful than stack overflow, as it's dedicated to one domain only.
    – Skeen
    Nov 13, 2013 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, 2013 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, 2013 at 18:12
  • 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, 2013 at 12:16

1 Answer 1

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à!

1
  • 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, 2013 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.