0

Following lots of "How to build your own Operating system" tutorials,
I'm supposed to write custom loader to floppy disk boot sector via

#include <sys/types.h> /* unistd.h needs this */
#include <unistd.h>    /* contains read/write */
#include <fcntl.h>

int main()
{
    char boot_buf[512];
    int floppy_desc, file_desc;

    file_desc = open("./boot", O_RDONLY);
    read(file_desc, boot_buf, 510);
    close(file_desc);

    boot_buf[510] = 0x55;
    boot_buf[511] = 0xaa;

    floppy_desc = open("/dev/fd0", O_RDWR);
    lseek(floppy_desc, 0, SEEK_CUR);
    write(floppy_desc, boot_buf, 512);
    close(floppy_desc);
}

I didn't have PC with floppy drive and I prefer to try whole of project on virtual machine via VirtualBox.

So How to write custom boot sector to a virtual CD image that will be invoked by my virtual machine ? :)
If you have any alternative way please suggest it :)

Siguza
  • 21,155
  • 6
  • 52
  • 89
Ahmed Ghoneim
  • 6,834
  • 9
  • 49
  • 79

1 Answers1

0

(note: this assumes you are on linux)

Instead of writing to /dev/fd0, which requires a real floppy drive, you could write to some a disk image which could be used to boot VirtualBox. However, you need to pad the file to 1.44MiB, since that's what the typical floppy is.

An even better way would be to first create the bootsector binary (with the 0xAA55 'magic code'), and then do something like dd if=MyBootsectorBin of=Floppy.flp bs=512 count=2880 to create the output file, Floppy.flp. This could be then booted via VirtualBox (or my preference, QEMU, via qemu -fda Floppy.flp).

I'm not sure about virtual CDs, but you can easily create an ISO to write to the disk. The required program for this is mkisofs, and more can be read about it from here.

idraumr
  • 36
  • 4