[lug] RAM based files, file systems

Jordan Crouse jordan at cosmicpenguin.net
Tue Jan 27 22:07:50 MST 2004


> is it really done in ram or is it done in a file?  e.g. I assume I can
> use dd to create a 512MB file, mount it via the loopback device and then
> format it.  When I write to the loopback mounted file, aren't I making
> changes to the original file on disk? 

Yes.  The loopback device is really a cheap substitute for real physical media.  Its a great way to check out small filesystems that for one reason or another aren't pratical to put on the media (such as an CD image you just burned, or something for an embedded device).  I've mounted some pretty big images as loopback before, so I would assume that some sort of read caching must go on in the background.  Any write changes would probably be cached until you unmount or sync.  More on that later....
 
> Here's the counter-example to my question:
> 
> I know knoppix does something related to this.  There's an iso image
> that is cramfs'ified and then mounted via the loopback.  I'm just not
> sure how it does the whole in memory only thing (obviously you can't
> write to a cdr which is where the crammed iso image lives).

Recall that you have the option to mount a filesystem either read-only or read-write.  Linux is smart enough to know if you are using read-only media (such as a CD) or a read-only filesystem (such as cramfs for example).  The end result of all this cleverness is that you can't mount it if it isn't read-writeable.

> So how does the in RAM fs work (it's obvious that knoppix is exceeding
> the 4k limit

Well, the loopback works by setting up a complete file system cache in memory, which gets commited back to the filesystem when you unmount (or sync).  Just like in real life.

A ramdisk is a similar beast, except that instead of reading the filesystem and reproducing it in memory, a ramdisk acts like a real device (with its own device nodes, even), except for of course, it doesn't exist but for a figment of our imagination.

So while you need a existing filesystem to mount on a loopback device, you can use and abuse a ramdisk just like any other device, only without the evidence sticking around... :)

So the answer to your question is that Knoppix is probably using a loopback device, and not a ramdisk.  Short answer, long story.

Jordan




More information about the LUG mailing list