Suppose neither of my computers has a floppy 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
dustpyle_x2
Posts: 1
Joined: Sat Mar 10, 2007 1:18 pm

Suppose neither of my computers has a floppy drive......

Post by dustpyle_x2 »

...and I don't want to use up all of my CD-Rs going through the baby steps of OS development. I want to use my usb flash drive to test my stuff. I know my computer can boot from USB, so all I need to know is how I would get my stuff on there and make it bootable. Can anyone help me out?
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

If you are working on UNIX/LINUX like system, there is a 'dd' command.

Example:dd if={mbr file} of=/dev/{your falsh} count=1 This will copy your MBR to the beginning of the flash

Example:dd if={kernel file} of=/dev/{your flash} count={kernel size in 512 byte blocks} seek={where you want to put your kernel} This will copy your kernel

For more info read the man page.
For reading from the flash you have to use int 13h ah=42h BIOS function or some function which doesn't use CHS.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

If you don't have a *nix system, get Cygwin. It's what I use for writing disk images to floppies for testing. It's also useful because it gives you a *nix-style shell on your Windows box.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

There only one way i have found that work, with all PC that can boot USB.
That is to make your kernel a mz exe or com file, so that it can load from DOS.
Than you put your usb in and let windows see it as a drive, you then format it and click to add sys file (which makes it bootable).
Next you add your exe kernel to the drive, once it boots to dos type the name of your kernel (or you can add it to autoexe.bat), this works with fdd or hdd emulation.
Note: if you go to pmode emultion stops, but if you go back to realmode it starts again.
As i have a pmode and a go back to realmode fdd and hdd drivers, i can read/write to USB keyfob in my OS.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

RE: usb kernel boot windows linux rawrite fat32

Post by Kevin McGuire »

(Overall)
Treat the USB drive in Windows or Linux just like it is a floppy drive.

(Detailed)
Dex almost had it I think. The format on the stick is going to be FAT32, and the BIOS should look at the drive as if it is a normal hard disk with a boot sector. You might __try__ http://www.tux.org/pub/dos/rawrite/.


I have never actually done this myself. It is just a suggestion.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

If you have money, go down to a second-hand hardware shop or a wholesaler, find a floppy drive and install it. As humbling as this experience may be, remember that your OS design will help you.

Also look into an emulator (Google: Bochs) and a method of using disk images (Google: vfdwin, winimage, cygwin). Read the Wiki/OSFAQ as well, they have some good information about disk images and emulators.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: RE: usb kernel boot windows linux rawrite fat32

Post by Dex »

kmcguire wrote:(Overall)
Treat the USB drive in Windows or Linux just like it is a floppy drive.

(Detailed)
Dex almost had it I think. The format on the stick is going to be FAT32, and the BIOS should look at the drive as if it is a normal hard disk with a boot sector. You might __try__ http://www.tux.org/pub/dos/rawrite/.


I have never actually done this myself. It is just a suggestion.
The format is down to size of fob, so most are formatted as fat16, but it will be called FAT under xp eg: if it says FAT12 its FAT12, if it says FAT32 its FAT32, if it says FAT its FAT16.
Why XP does not like saying FAT16 I do not know. :? .
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

You do not need to use neither FAT nor DOS to boot your kernel !

I'm using ext2fs file system and my own bootloder to run the kernel.
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: Suppose neither of my computers has a floppy drive......

Post by Combuster »

dustpyle_x2 wrote:...and I don't want to use up all of my CD-Rs
Ever considered using CD-RWs? :wink:
"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
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Dex wrote:There only one way i have found that work, with all PC that can boot USB.
That is to make your kernel a mz exe or com file, so that it can load from DOS.
Than you put your usb in and let windows see it as a drive, you then format it and click to add sys file (which makes it bootable).
Next you add your exe kernel to the drive, once it boots to dos type the name of your kernel (or you can add it to autoexe.bat), this works with fdd or hdd emulation.
Note: if you go to pmode emultion stops, but if you go back to realmode it starts again.
As i have a pmode and a go back to realmode fdd and hdd drivers, i can read/write to USB keyfob in my OS.
The bios doesn't know anything about the filesystem that you're using on your USB stick, nor if the code in the boot sector is actually bootable. It only checks the 0x55 0xAA signature and loads the rest of it. The code should use the method your bios supplies for accessing the USB stick for loading the rest of the disk, and then you're all set. There is NOTHING that windows can do that you can't do without it.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

@muisei and Candy, What i am saying is right from my experience, i do not say that the BIOS knows what file sys is on the USB or you need Dos.
But if you want to boot your OS from a USB key fob, from differant PC, the only way to do it is use Dos. Why this is the case is not for to tell you, just try it and see.
You may be lucky, but most likey you will get:

Eg: Try put your boot sector on the usb fob in windows of any hobby OS and booting,
You will most likey get "Operating system missing" ,Than try add sys file (dos) and see the differance ?.
I wish people would try things rather that just read some thing.

Here is some problems you get with your methord.
http://menuet.2.forumer.com/index.php?s ... =1112&st=0
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

I'm developing my OS on a flash drive and I've never encountered such probles.

I've written my own MBR which loads and executes the first 1024 bytes of the ext2fs file system.There is my first stage bootloader which enable A20 gate,create a memory map,reads the kernel from ext2fs,enter to PM and then execute it.

I've tried it on several PCs and it works great on all of them.
If you set your BIOS to emulate a HDD and use INT 13h AH=42h to read from the flash, I don't see why I have to be lucky.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Do you use linux to load it to the fob ?.
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

Dex, you are right it doesn't boot on all PCs. :shock:
I tested it on 5 laptops and on one quite new desktop PC and everything worked fine.
After your post I decided to test my OS on older PC(about 3 years old).It booted only MBR.I've tried 3 different method to read the block after the MBR and none of the worked.The first method is using the BIOS function int 13h AH=42h, the second is writing CHS data to the HDD ports and the third is writing LBA data to the HDD ports.
I tested them with qemu and all worked.On my laptop only the BIOS function worked.
I think that the problem is in the BIOS.

BTW I'm using FreeBSD 6.1
Attachments
mbr.asm
test program writen in NASM.It must be placed on the first block of the drive.Don't read the comments.I gathered the code from a couple of files and some of the comments are not correct;
(3.26 KiB) Downloaded 22 times
Post Reply