3

I have an embedded device where i need to put my /var and /tmp in ram in order to diminish the number of writes on the drive (Compact flash). I know how to do it with /tmp as i don't have to recover anything whenever i reboot or shutdown.

But the /var directory has important stuff. I have been researching and i found this, but it doesn't seem to be working.

Here is the script:

# insert this on file 'rc.sys.init'
# after the mount of the root file system
# to create the /var on ramdisk


echo "Create ramdisk........."
#dd if=/dev/zero of=/dev/ram0 bs=1k count=16384
mkfs.ext2 -j -m 0 -q -L ramdisk /dev/ram0
if [ ! -d /mnt/ramdisk ]; then
     mkdir -p /mnt/ramdisk
fi
mount /dev/ram0 /mnt/ramdisk
if [ -L /var ]; then
     tar -xf /vartmp.tar -C /mnt/ramdisk
else
    tar -C / -cf /vartmp.tar var
    cp -a /var /mnt/ramdisk
    rm -rf /var
    ln -s /mnt/ramdisk/var /var
fi  

# insert this into file 'halt'
# to stop the ram disk properly on shutdown.
#

if [ -e /vartmp.tar ]; then
     rm -f /vartmp.tar
fi;
tar -C /mnt/ramdisk -cf /vartmp.tar var

Is there any problem with this script? If not, in which inicialization and termination script should i include them?

manlio
  • 18,345
  • 14
  • 76
  • 126

2 Answers2

0

For all that have the same problem i do i have solved my problem (kind of)

The two scripts i posted are correct and accomplish the job. What you have to be careful is where you put them.

In Slackware the first run script is rc.S. At first i copy pasted my first script into the middle of that one. It definitely should be there, just not where i put it. You have to see where does the script rc.S call for a particular directory or file from /var. The creation of the ramdisk should be before those lines.

the shutdown script should be added in the bottom of the rc.6 script (shutdown script)

Also i should point out that although this improves the life expectancy of the drive, it is a little volatile and sometimes randomly reboots, so be careful.

0

Nice script...but it seems to me that it is volatile for several reasons. First did you tell the system max ramdisk size...first as a kernel argument.....linux /vmlinuz ramdisk_size=204800......then in rc mke2fs -t ext2 /dev/ram1 204800.....and maybe use ram1 not ram0.......also use a script for manual saving of ramdisk contents to /var.....cp -a /mnt/ramdisk/var/. /var........backup real /var to another directoryusin tar compression, but introducing tar compression to reduce data size probably introduces lag, latency and instability. Just seems to me to be so.

Jayram
  • 18,820
  • 6
  • 51
  • 68
Marcos
  • 1