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


    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

  • 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 0:30
  • 1
    I do not believe this question is off-topic. It could be reworded to be more clear and specific though. – user26112 May 30 '13 at 0:41
  • 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. – user26112 May 30 '13 at 0:53

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.

| improve this answer | |
  • 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

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.

| improve this answer | |
  • 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 0: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 8: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

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.