Merlin wrote:if your operating system needs some kind of file to read the filesystem you get a catch 22. initrd filesystems are not mean to be layed to disk as is. they just need the bare minimum config and utilities to mount the rest of your system. an example is the "mount" command in unix systems. the kernel does not have the command built in, its part of the filesystem. how does it mount the filesystem to get the mount command? it lets the bootloader add an initrd that has a mount program in it. then it uses that to setup the rest of the system. if you choose to do this differently, you *might* not need an initrd.
I'm sorry, but I think you are mistaken. The kernel has to initialy mount some file system itself. It can be a file system on disk, or it can be a file system in memory, but the kernel initialy mounts some file system without any help or instructions from user space. In the initrd case, the bootloader loads the kernel and initrd into memory and passes some information to the kernel, including where to find the initrd. In Linux's case, the kernel creates a in memory file system called tmpfs, and extracts the contents of initrd into it. The initrd is primarily meant to contain loadable kernel modules. It loads the modules needed for the machine it booted on. This is done so that the kernel must not have ALL the driver's compiled in, to successfully boot on every different machine. It just loads those modules from initrd, that are needed for the system. AFAIK that's how it is.
In most of the cases, after all of the boot procedures ar done, the system's root file system is on disk, but some more exotic Linux distributions use tmpfs as their root file system.
Now in a hobby OS, having a initrd instead of mounting a file system on disk may be useful if you don't want to make room on disk for your OS. Or, just like in Linux case, to load needed modules. there may be other use cases. Maybe even Linux uses it for something more, but I did not remember to mention it.
Edit: I guess I should try to answer the OP's questions.
clavin123 wrote:do we need a virtual filesystem to read a filesystem?
Virtual file system? No, you don't need that to read a file system. But I'm afraid that by "virtual" you mean a file system in memory, which is not correct. But anyway, you do not need a file system in memory to read a file system (I think you mean on disk). If you're not sure what I mean by virtual file system, check this
http://en.wikipedia.org/wiki/Virtual_file_system.
clavin123 wrote:will i be correct in taking this initrd as an analogy to a disk that is formatted with our own filesystem and being loaded as a module?
Yes, as far as I understand you, you are correct. You can look at the initrd as a file system. It does not matter whether a file system is on a disk or loaded to memory. The kernel should be equally capable to use it in either case. Only that initrd is by design read only, I think, look at my other answer.
clavin123 wrote:if my analogy is correct is it possible to write to this initrd from within my kernel and how?
I did not read JamesM's tutorial's part about the initrd, but I don't think you can write to it. Usually, initrd is some sort of archive. You can create an archive from a collection of files and directories, but once it is created, there is no way to write something into it. You'd have to extract the contents add new files, or remove some, and then put it all into archive again. One could look at an archive as a read only file system. To write to initrd, it would have to be a read/write file system. Or you could do it the Linux way I already mentioned - extracting the archive into a file system in memory. Maybe later you could archive that back into initrd and store it to load another time. I'm not saying that it's good to do that or that you should do that, just that it's a possibility, that came to my mind now.
clavin123 wrote:another question is suppose i have another floppy drive which i want to read using my kernel
so is it possible for me to format this floppy drive with the file system i created for my initrd and then be able to read and write to it?
if yes how may i proceed?
As I said, archives, that are usually loaded as initrd's, ar read only, so no, you'd have to create a read/write file system on floppy to be able to not only read, but write to it. If you want to do that, you could look here
http://wiki.osdev.org/Floppy_Disk_Controller , here
http://wiki.osdev.org/FAT , and here
http://wiki.osdev.org/SFS.