Running OS from USB drive

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
laveeshbansal
Posts: 2
Joined: Tue Jul 15, 2008 10:27 pm

Running OS from USB drive

Post by laveeshbansal »

I am new to OS development. I have a laptop which I plan to use for development purpose. I have installed Fedora 8. However, as my laptop does not have a floppy disk, I do not know where shall I load my OS and run it... All the tutorials that I have found on the internet suggest that we need to compile the OS and install it onto a floppy disk...
Is it possible to load the OS that I create on a USB flash drive (or any other device other than a floppy) ????? If it is possible, it would be great if some one could tell me how
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: Running OS from USB drive

Post by M-Saunders »

Hi,

You're right that very few PCs have floppy drives these days. But most beginning OS developers tend to work with floppy disk images -- that is, files representing floppy disks (myos.img). Then we test them in emulators such as QEMU, Bochs or VirtualBox. It's too much hassle to keep imaging a disk to a real floppy and testing it on a real PC, so I think most OS devers only do that occasionally.

Floppies are easy to work with, so when you're just starting, use floppy disk images and an emulator. Then you can move on to CDs, USB flash keys once you're settled in. (Of course, there may be a really easy way of OS deving with a USB key that someone else will explain!).

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Running OS from USB drive

Post by suthers »

I can be done, but I believe it requires considerably more drivers, why don't you just test it on an emulator like bochs?
Though it is advisable to occasionally test on a real machine, as somethings work on emulators that don't work on real machines and vise-versa.
Jules

edit: @M-Saunders: Damn it, you beet me to it... :lol:
laveeshbansal
Posts: 2
Joined: Tue Jul 15, 2008 10:27 pm

Re: Running OS from USB drive

Post by laveeshbansal »

thanks.... so which emulator would be better for use?? are there any simple OSes like the ones which print Hello World already created so that I can get started... where can I find such code??
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: Running OS from USB drive

Post by M-Saunders »

Any emulator you want, providing it can handle floppy disk images. I like QEMU personally, but those who are doing more in-depth OS coding prefer Bochs due to its better debugging support.

There are loads of simple bootloader-like OSes on the net which print out some text. Here's an example from my MikeOS documentation:

http://mikeos.berlios.de/handbook.html#makeintro

It shows you what you need to know about x86 assembly and the PC boot process, and then explains how to write a simple 'OS-like' boot loader which prints out a message.

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Running OS from USB drive

Post by Dex »

I think your best keeping away from emulators, as you may find a lot of problem when you try your OS on real PC.
To use a USB fob, you first find if your BIOS support it and how it emulates it (eg: floppy or hdd emulation ). You can do this by putting a USB fob in the pc/laptop rebooting and pressing F2 or Delete to enter the BIOS setup, then go to boot order and see what comes up in the list of boot devices.
Depending what it emulates it as, you need to set your USB up differanly.
If its a floppy you need to write a floppy image to the USB starting at the first sector.
If its does hdd booting you need to format it FAT (NOT FAT32) and put your boot sector on the first 'logical disk', but at the same time keeping the BPB intact.
Now this may sound complecated, so to help OS Dev's i am working on a windows program to do it from a nice GUI interface, this should be ready in about a week.
In the mean time you can do the same by Hand http://www.dex4u.com/USBboot.htm

Its also posable to use a floppy image and a CD-RW, along with your normal burn software, let me know if your interested.

Also note: if you use a boot loader like bootprog, you only need to do the above once, then you can add you updated kernel has you would any normal file.

Theres also away to do it in linux with DD
User avatar
Steve the Pirate
Member
Member
Posts: 152
Joined: Fri Dec 15, 2006 7:01 am
Location: Brisbane, Australia
Contact:

Re: Running OS from USB drive

Post by Steve the Pirate »

It's really not hard at all to set up Grub on a USB drive. Google is your friend on that one.

My OS already used GRUB (ie. was multiboot compliant), so I just had to copy the files over once I installed GRUB and it worked just as if it was on a CD or floppy.
My Site | My Blog
Symmetry - My operating system.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Running OS from USB drive

Post by Combuster »

Dex wrote:I think your best keeping away from emulators, as you may find a lot of problem when you try your OS on real PC.
Which limits the errors to a very restrictive set, depending on what happens. Not zeroing memory, no TLB invalidation, and temporal effects (read: race conditions) are the main causes that break OSes on real hardware. And they can be avoided with careful coding.

Same goes for hardware. While dirty hacks may work in bochs, they won't on real hardware.

Using an emulator finds almost all the bugs you want to have eradicated first, without the lengthy development cycles. When I need to test card-specific graphics code (bochs isn't 3d hardware) I need to rewrite floppies, and reboot a second computer. The testing cycle takes two minutes. VGA code (which bochs can do) has a 2 second testing cycle, because it needs only to recompile one binary and can keep everything in working memory up to when bochs starts, making it _fast_. Pretty useful when you want to tweak something.
Then consider burning CD's as part of the cycle.

While I agree that you should regularly test stuff on real hardware, emulators rock.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Running OS from USB drive

Post by Dex »

My answer to this would be that every OS, should be self supporting as soon as possible.
This is the only way to find the real bugs, that is to use it for its purpose, to this end i code, assemble and debug without rebooting from my own OS.
This is why linux is so good, because it was used to dev the kernel very early on in its dev stage from linux its self.
This is also a big mistake many hobby OS do, IF YOU DO NOT USE IT, how do you expect others to use it.
OS are made to stand on there own, there are place for emulators, but they should never be more than away to let other test your OS, without risking there main OS.
Post Reply