Page 1 of 1

Bootable FAT16 Image

Posted: Fri Jun 19, 2015 5:44 pm
by cmp
Hi,

I've successfully developed a FDC driver and a basic FAT16 driver with a VFS, so I think it's time to put it to use. However, I'm confused about how to set this up for qemu. How can I have a FAT16 file system with my OS and grub (I use grub with multiboot)? I'm just confused about the process and idea of having a fat partition or something along with grub and my OS in a single image.

Thanks for the help, I really appreciate it.

Re: Bootable FAT16 Image

Posted: Sat Jun 20, 2015 2:51 am
by Octocontrabass
cmp wrote:I've successfully developed a FDC driver and a basic FAT16 driver
Floppy disks are too small to hold a valid FAT16 filesystem. Use FAT12, or switch to a hard disk.

(FAT16 might fit with 128-byte sectors, but then your disk won't boot or work in emulators.)

Re: Bootable FAT16 Image

Posted: Sat Jun 20, 2015 8:04 am
by embryo2
cmp wrote:How can I have a FAT16 file system with my OS and grub
The best way is to get used to the FAT layout and just write what you need as a simple stream ending with an image file. Basically it's very simple, first goes MBR(master boot record), next goes VBR (volume boot record), next go some unused blocks (reserved) and finally go 2 FAT tables followed by the actual storage area where all files and directories are. In case of floppy there is no MBR, so it's even simpler to create such image. Grub's binaries are located somewhere in reserved area (reserved blocks), the actual offset is defined by Grub developers and should be present on the Grub's site on documentation page.

So, you need to know how to write VBR, in VBR you can declare the number of reserved blocks and fill them with Grub binaries. Next write 2 FAT tables with information about just one directory with just one file - your OS image. Next write the directory and image blocks. Just as simple.

Re: Bootable FAT16 Image

Posted: Sat Jun 20, 2015 8:09 pm
by cmp
Ok, so I should probably just make a hard disk image instead. However, when I create a fat16 img using a loop device, install grub to it, and boot it using "qemu-system-i386 -cdrom disk.img" or using x86_64, qemu just says it couldn't read the CD drive (0005). I didn't put my OS on it yet, I just wanted to see if I could get grub booting. So I'll just forget my FDC code if it doesn't help with hard disk images, that's ok.

So I suppose my new question is, how would I properly go about creating a FAT16 hard disk image that boots with grub into my OS?
Thanks.

Re: Bootable FAT16 Image

Posted: Sun Jun 21, 2015 12:09 am
by Octocontrabass
cmp wrote:hard disk

"qemu-system-i386 -cdrom disk.img"
If it's not a CD, why are you telling qemu it's a CD?

Re: Bootable FAT16 Image

Posted: Tue Jun 23, 2015 9:13 am
by cmp
Good point...
Well I'm trying out the qemu command -hdb fat:rw./floppydir right now. I'm not really seeing much that I can do with it, however since it's running can I assume the fat disk is accessible? If so, I'm back to the point where I was before. How can I access it, ie read bytes from it? It seems my FDC driver I wrote is essentially useless unless I'm using a floppy (-fda).
The full command I'm using for testing is as follows:

Code: Select all

qemu-system-x86_64 myos.iso -hdb fat:rw:./hello
Thanks

Re: Bootable FAT16 Image

Posted: Tue Jun 23, 2015 10:14 am
by Brendan
Hi,
cmp wrote:It seems my FDC driver I wrote is essentially useless unless I'm using a floppy (-fda).
Well, yes - floppy drivers only work for floppies, and FAT16 isn't normally used with floppies. You'd either have to implement another storage device driver (e.g. a hard disk driver, RAM disk driver) so that you can use/test your FAT16 code, or you'd to have to implement a different file system (e.g. FAT12) so that you can use floppy.

However, I can't think of anything that would actually prevent you from using FAT16 on a floppy. It won't be ideal (it'd be more efficient to use FAT12 as it'd waste less space for the cluster allocation table), and it's definitely not "standard practice" (mostly because it's less efficient and goes against Microsoft's guidelines), and I wouldn't necessarily expect other OSs (e.g. Windows, Linux) or other software (e.g. GRUB) to support it; but there's no practical/technical problem that would make it impossible.


Cheers,

Brendan

Re: Bootable FAT16 Image

Posted: Tue Jun 23, 2015 6:01 pm
by cmp
Looks like I'll be writing a hard disk driver then.