All Forums
 Embedded Linux
 Linux FAQ
 Storing temporary files in a RAM file system.
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

jlackey

213 Posts

Posted - 08 Oct 2003 :  15:19:49  Show Profile  Email Poster
Storing temporary files in a RAM file system.

Using a flash based file system instead of a ramdisk is a good way to
  • save RAM
  • increase the size of the root file system
  • preserve file changes after a reboot

Given these benefits, it is still desirable to put some files in a RAM based file system to
  • allow memory mapped files to be used
  • avoid flash write cycles for files that do not need to be preserved
  • allow files to be created and written when using a read-only root file systems.

Temporary files are an obvious example. This command
mount -t ramfs ramfs /tmp -o size=4m
mounts a RAM file system on /tmp and limits it to 4 MB. (Leaving off '-o size=4m' will let it grow as long as there is RAM available.)

To mount /tmp during initialization, modify /etc/fstab and one of the system start up scripts in the flash file system. In /etc/fstab, add a line like this:
ramfs           /tmp            ramfs           size=4m 0 0
Then add a line in /etc/inittab or /etc/rc.d/rc.sysinit to mount the RAM file system:
mount /tmp
Now when the system starts, /tmp files will exist in RAM instead of in on-board flash memory.

If the contents of /var do not need to be preserved between reboots, they can be moved to the RAM file system, too. Using an existing /var as a template, follow these steps:

Create an archive of /var and store it in the flash file system like this:
cd /var
tar cf /var.tar .
You may want to empty the log files and remove unneeded files before performing this step.

Then create a script that copies the contents of the archive to /var:
mkdir /tmp/var
cd /var
tar xf /var.tar
Next, edit /etc/inittab or /etc/rc.d/rc.sysinit to call the script after /tmp has been mounted.

Replace the /var directory with a link to the one in the RAM file system:
rm -rf /var
ln -s /tmp/var /var
Now when the system starts, a var directory is created under /tmp and /var links to /tmp/var. Since the RAM file system is mounted on /tmp, var files are stored in RAM instead of in on-board flash.
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.02 seconds. Snitz Forums 2000