bootable floppy image

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
phoboss
Posts: 3
Joined: Sun Jan 13, 2008 7:21 pm

bootable floppy image

Post by phoboss »

greetings to all fellow developers!
i gotta a slight problem deploying my little operating system. i managed to get it run using a GRUB bootloader and now i'm trying to develop my own, 2 stage, loader. i have a blank, FAT formatted floppy image which i want to make bootable. when i was using GRUB floppy, i simply mounted it, copied my kernel.bin and umounted... the problem is that now, when i transfer raw stage1 binary data to the image

Code: Select all

dd if=stage1.bin of=floppy.img
then mount it (it doesn't complain about missing filesystem, 'cause i have the boot device properties well set), i cannot copy my stage2 binary to the floppy because the shell complains that it's full,which is nonsense... i tried to reverse the process (i.e. first mount - copy stage2 binary - umount and then dd my stage1 to the image) and stage1 is working well until i query it for the stage2 binary, which it don't find on the disk. i suppose there is something wrong with the raw data copy to the bootsector (that it destroys the FAT or so) does anyone here met this before? or better, doesn't somewhere lay a tool similar to iso image editors which would allow me to edit the bootsector and add files to the floppy image? i searched the web but not found anything for linux. windows has plenty of utils available but i'd prefer to continue developing under linux 'cause i have now quite a large shell-script toolbox for building my OS which won't be fully portable to win.
thanx for any useful answer![/code]
bad guys always have better technology
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post by thepowersgang »

It complains that the disk is full because the disk image is only the size of your stage 1 image. What you need to do is run

Code: Select all

dd if=/dev/null of=floppy.img bs=1024 count=1440
This will create a 1.44Mb blank image which can be formated and have your boot sector copied to it.
phoboss
Posts: 3
Joined: Sun Jan 13, 2008 7:21 pm

Post by phoboss »

but my initial floppy image is already formated and big enough. it becomes "full" when i try to paste the bootsector on it... the code you provided will just create new, unformatted device, won't it? after i would create it as you suggested i'd still need to move the bootsector there which will end up the very same way, no? i tried it and it creates a 0B file which can't be formatted using fdformat (i haven't tried anything else yet). shouldn't it be 1.44M big anyway?

EDIT: it shoult be /dev/zero not /dev/null. this solves the 0B problem
bad guys always have better technology
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post by thepowersgang »

I assumed that you were creating a disk image. Have you got the FAT information in you boot-sector and if so is this information correct for the size of disk?

And thanks for the edit on the device, I don't use those devices often so I forget their names.
phoboss
Posts: 3
Joined: Sun Jan 13, 2008 7:21 pm

Post by phoboss »

ok so i finally solved the problem so there it is for those experiencing the same issue in the future:
i realized that the dd tool rewrites the output file (marked by the 'of' directive) and truncates it to the size of written data. however, one can ask it to leave the rest of output file unchanged by adding an additional parameter:

Code: Select all

dd if=stage1.bin of=floppy.img conv=notrunc
the conv=notrunc directive makes the tool do just exactly what it is supposed to do in this case: copy the 512B long bootsector to the beggining of the image file and quit without performing the out. file truncation, thus leaving the FAT untouched.[/b][/code]
bad guys always have better technology
Post Reply