Friday, February 5, 2010

How to mount RAMFS, TMPFS in Centos, RHEL, Fedora, Ubuntu, Linux

How to Use and mount RAMFS / TMPFS in Centos, RHEL, Fedora, Ubuntu?
Definition :
RAMFS Random Access Memory Filing System
TMPFS Temporary File System / Temporary File Storage

RAMFS / TMPFS is used to assign or allocate a part of physical memory to be used as a individual partition which can be used for storing data (Reading, Writing) like all other Disk partition on a system. As the data is stored in RAM (Random Access Memory) it is much faster than that of writing or reading from a System Physical disk Partition.
Performance can be measured when writing or Reading a large file from this partition (Small File size wont give you the performance). Mounting RAMFS and TMPFS is same on almost all linux distribution RHEL, Centos, Ubuntu, Fedora.

1. How to mount Tmpfs

# mkdir -p /mnt/tmp
# mount -t tmpfs -o size=200m tmpfs /tmp/ashfs

The last line in the following df -h shows the above mounted /tmp/tmpfs tmpfs file system.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 24G 11G 12G 47% /
/dev/hda1 99M 12M 83M 12% /boot
tmpfs 248M 0 248M 0% /dev/shm
tmpfs 200M 0 200M 0% /tmp/ashfs

2. How do I mount Ramfs on the System?

# mkdir -p /tmp/ashfs

# mount -t ramfs -o size=200m ramfs /tmp/ashfs

You can change the size of the partition on the Fly.

# mount -o remount,size=2G /tmp/ashfs
It grows dynamically
You can verify the mount using

# mount
/dev/hda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
tmpfs on /tmp/ashfs type tmpfs (rw,size=200m)


By adding the partition in /etc/fstab they RAMFS/TMPFS can be mounted on boot time.







RAMFS
Uses RAM of a System
It grows dynamically
Allows to write data above the partition created
After Full Usage system may hang or stop working.
Data would be deleted once system is rebooted or incase of crashing.
You have to make a process to transfer data from RAMFS to Physical disk periodically to loose data
Suitable to have less data and read intensive
TMPFS
Uses Swap of a System.
It doesn't grow dynamically.
Doesn't allow to write data above the partition created.
System would give an error display “No space left on device”.
Data would be deleted once system is rebooted or incase of crashing.
You have to make a process to transfer data from RAMFS to Physical disk periodically to loose data.
Suitable if you want to write very fast Write intensive.


Example : You have a system with 2GB RAM and 2 GB Swap Space
RAMFS : When a partition of 1 GB is created and mounted users can even write more than 1GB till the total RAM size is exhausted as the parition is made on RAM.

TMPFS : When a partition of 1 Gb is created and mounted users wont be able to use more than 1GB space as designated on the partition. If required the space can be extended on a fly. Useses dont need to worry to control the process that writes on tmpfs partition

2 comments:

  1. Why didnt I think of this? I hear precisely what youre stating and Im so delighted that I came around your blog. You really know what youre discussing, and you made me think like I need to find out much more about this. Many thanks for this; Im officially a massive fan of your respective weblog.

    ReplyDelete
  2. Nicely, this can be my initial pay a visit to for your webpage! We're a group of volunteers and starting a brand new initiative inside a community in identical niche. Your webpage offered us valuable details to perform on. You've done a marvellous career!

    ReplyDelete