3

I have written a simple operating system and I am trying to test it. I have VirtualBox installed and an eight GB flash drive, so I thought I would just use those. I am not sure how to make the USB drive bootable, however. I have followed a lot of tutorials on making a bootable iso image, but neither VirtualBox nor Disk Utility can read it. Can somebody give me a proven method to setup the USB drive to be bootable?

What I have

  • An eight GB flash drive

  • A VirtualBox VM

  • A .bin made from assembly code compiled with nasm.

What I need

  • Simple, clear information on how to fill the boot sector of a USB device

  • A nudge in the right direction if I need something in addition to the .bin

Existing Code

;*********************************************
;   Boot1.asm
;       - A Simple Bootloader
;
;   Operating Systems Development Tutorial
;*********************************************

org     0x7c00              ; We are loaded by BIOS at 0x7C00

bits    16                  ; We are still in 16 bit Real Mode

Start:

    cli                 ; Clear all Interrupts
    hlt                 ; halt the system

times 510 - ($-$$) db 0             ; We have to be 512 bytes. Clear the rest of the bytes with 0

dw 0xAA55                   ; Boot Signature

Tutorials I have followed

http://www.quilime.com/code/bootable_iso http://www.acm.uiuc.edu/sigops/roll_your_own/ http://www.brokenthorn.com/Resources/OSDevIndex.html http://www.brokenthorn.com/Resources/OSDev1.html http://www.brokenthorn.com/Resources/OSDev2.html http://www.brokenthorn.com/Resources/OSDev3.html

Justin
  • 173
  • 1
  • 8
  • 2
    From our FAQ: _Your questions should be reasonably scoped. If you can imagine an entire book that answers your question, you’re asking too much._. Entire books have been written on OS development. :) – Renan May 29 '13 at 23:23
  • Yes, but not about the "easy part" that is always skipped because of it's ease. That is all I want. – Justin May 29 '13 at 23:47
  • Can I just say real quick that this is NOT off-topic? Read past the title! I was only asking how to move some simple files to the correct part of the disk! That is perfectly within the scope of this site! I only included the OS thing so you all knew how to help. If you are going to close perfectly-reasonable questions, at least find a reason that isn't so obviously absurd! – Justin May 30 '13 at 00:30
  • 1
    I do not believe this question is off-topic. It could be reworded to be more clear and specific though. –  May 30 '13 at 00:41
  • @EvanTeitelman If you have any suggestions for modifications, I'm all ears. – Justin May 30 '13 at 00:42
  • 1
    Links to the tutorials you are reading may be helpful. Instead of saying, 'if anyone knows how to get a bootable operating system from working C and assembly code...' you could ask something along the lines of, 'how do I get my computer to boot a kernel image?' It would help if you could extend that to include information on the kernel you are trying to boot. Also, the LFS note wasn't really relevant to the main question. –  May 30 '13 at 00:53
  • Post a question on the stackexchange [meta site](http://meta.stackexchange.com) if wish to discuss the closing of your question with the community and its moderators. –  May 30 '13 at 00:59
  • This question is not related to administration thus it is off-topic here. It's not even OS-specific. I voted for migrating to Stackoverflow but the majority obviously just wanted it closed. You may ask that on SO yourself though. A small comment on your problem: It seems very strange to me that somebody who wants to write his own OS does not simply answer this question himself by looking at the Grub sources. – Hauke Laging May 30 '13 at 02:29
  • I don't think this is as trivial (or on-topic) as you think it is; you can't just move some files to the right spot on the disk and expect the system to boot. You need a bootloader of some sort, and however you do it, it doesn't seem like it would have anything to do with using or maintaining a Unix/Linux system – Michael Mrozek May 30 '13 at 04:16
  • @HaukeLaging I don't use Grub and I am simply looking for information on USING a Unix-based operating system to move some files to the boot sector of the disk. How is this difficult or off-topic? – Justin May 30 '13 at 13:56
  • @Renan Is this last edit good enough? – Justin May 30 '13 at 14:13

3 Answers3

2

Ok, you are up to a really minimal OS. Now you need to get some kind of machine to boot it.

No matter what machine you use (your laptop, a VirtualBox, etc.) when it starts up, it needs some ROM containing code to load and start the OS. This is usually something like a BIOS. This will usually simply fetch the boot sector of the configured boot media and run whatever it finds there.

Hence, simply put your minimalistic OS into the boot sector and everything is fine. If your OS is not minimalistic enough, the bootsector needs the code to load more of your OS.

michas
  • 21,190
  • 4
  • 63
  • 93
  • So, I put it on the boot sector by burning it to the disk, right? If so, is there a way I can make sure it writes to the correct sector? – Justin May 30 '13 at 00:11
  • What kind of "disk" are you trying to "burn" to? Just use an USB-stick or a image of VirtualBox. And please *read* about boot sectors. (What they are and where they are.) – michas May 30 '13 at 08:34
  • I was actually thinking of using the internal HD or a USB stick. I have excluded the idea of using the HD for safety reasons, because if something goes wrong I could lose data on my iMac even if I am using an emulator. – Justin May 30 '13 at 15:16
2

The typical way is to use dd. Here are the instructions from the syslinux bootloader for installing mbr.bin to /dev/sda.

dd bs=440 count=1 conv=notrunc if=mbr/mbr.bin of=/dev/sda

Here, /dev/sda is the target device. (of is "output file".)

You would replace this with the device name of your USB drive.

mattdm
  • 39,535
  • 18
  • 99
  • 133
  • I do not see how I can make this target my USB device. Does it try to do this automatically or something? – Justin May 30 '13 at 16:00
  • See edit. dd knows nothing about USB devices; that's up to your OS. – mattdm May 30 '13 at 16:02
  • Thanks. I'll try this right now and let you know if something goes wrong. – Justin May 30 '13 at 16:03
  • Be aware that you can erase your HD if you make a mistake. – mattdm May 30 '13 at 16:07
  • For once, there where no errors when setting this up. The only problem is that VirtualBox gave me a "No bootable medium found" when I tried to boot it up. – Justin May 30 '13 at 17:19
  • Try it with the known-good syslinux `mbr.bin` and see if you can get that working. – mattdm May 30 '13 at 17:22
  • Okay, I got it working. Basically, I ran that command (but changed 440 to 512) and used a hex editor to replace the first 512 bytes of an empty 1 MB .iso file. I now have a working, yet useless, OS of my own. I think I'll call it "Pffft" or something, so the world will know just how bad it is ;) – Justin May 30 '13 at 19:31
0

I know it's not you asked for, but there is simple way to boot .bin files in VirtualBox.

For first, you have to make .vfd file - VirtualBox virtual floppy disk. To make blank .vfd file, execute this in shell:

$ head -c 1474560 /dev/zero > bootloader.vfd

Then put this in shell in order to include compiled .bin in the .vfd file:

$ dd status=noxfer conv=notrunc if=[bin_name].bin of=bootloader.vfd

Now you've got virtual floppy. But what to do next?

In VirtualBox, make a new VM. As type, choose Other and as version, choose DOS. There is no need of hard drive.

After making VM, go to its settings, go to Storage tab and add output .vfd file as floppy.

And that's it!