3

Is there a way map a portion of my memory to act like a directory on my hard drive with the exception that the data is not permanently stored. So for example, I save a file in /home/user/directory/filename.txt in gedit and it can be opened in nano. I do not need the files to be stored permanently and I need them to be quickly written and read.

3 Answers 3

8

Yes there is, it's called a ram-disk on Linux. There are two types: a raw block device that you can create, backed by memory, which allows you format it with any file system (e.g. ext3). The other type are file systems which automatically use RAM as a backing store, but are still fully capable of being mounted.

Ram disks are usually available automatically on Linux as, and can be mounted and formatted just like a regular hard-disk:

* /dev/ram0
* /dev/ram1
* ...

And there are file systems that use RAM as a backing store:

* tmpfs (e.g.: mount -t tmpfs -o size=1G,nr_inodes=10k tmpfs /my/tmp)
* there are also some build on FUSE.
1
  • 1
    The ramdisc block device is only useful for special purposes, for example creating disc images; it is not as good as tmpfs, in particular it is not resizable on the fly and uses memory even if empty.
    – MarkR
    Aug 2, 2010 at 21:44
5

Yes, there is an in-memory filesystem called tmpfs.

It is a completely normal filesystem, but each time Linux asks it to flush on the disk, in answers "wait just a little bit more" and Linux keeps caching.

It is heavily used in Linux live CDs.

3
mount -t tmpfs tmpfs /home/user/directory

If you want this to take effect even after reboots, add an entry to your /etc/fstab.

3
  • What would the entry look like?
    – Hengjie
    Dec 3, 2012 at 23:02
  • @Hengjie tmpfs /home/user/directory tmpfs defaults 0 0 Dec 3, 2012 at 23:07
  • Thanks, but how would you define how big that tmpfs is? Say if I want to limit it to 32MB?
    – Hengjie
    Dec 4, 2012 at 2:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .