OS Development - booting from floppy drive using qemu
Asked Answered
M

1

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.

Margarine answered 13/11, 2013 at 18:3 Comment(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.Theatrician
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.Theatrician
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.Theatrician
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.Theatrician
Also in the is development community there's a great discussion as to whether one should start with the bootloader or the kernel.Theatrician
@Theatrician : 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.Margarine
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 -fdaTheatrician
A little tip: ditch floppy. Start using sane options, like booting off a HDD, CD or DVD. Floppies are dead, stop biting them.Nightingale
U
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à!

Unending answered 30/12, 2013 at 11:18 Comment(1)
Yes, I got it cleared form the comments and some testing of my own. But thank you, will be useful for future reference !Margarine

© 2022 - 2024 — McMap. All rights reserved.