LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 03-20-2005, 03:09 PM   #1
Myrdos
LQ Newbie
 
Registered: Feb 2004
Location: Winnipeg, Canada
Distribution: Debian
Posts: 15

Rep: Reputation: 0
Arrow Mounting /var into a ramdisk


I've got a battery-operated PC that uses a compact flash card for a hard drive. The problem is that, should the battery ever die while I'm writing to the card, there's a chance it will be in an 'unrecoverable state'. ie, toss it and buy another.

I've been told that /var and /tmp need to be mounted into a ramdisk, because they contain files that can be written to by background processes.

So I can create a ramdisk like this: (can't figure out how to increase the size past 8 megs though)

ramdisk_size=32768
dd if=/dev/zero of=/dev/ram0 bs=1k count=4096
mke2fs -v -m 0 /dev/ram0
mount -t ext2 /dev/ram0 /mnt/ramdrive

Or like this: (seems to assign space dynamically)
mount -t ramfs none /mnt/ramdrive


So how do I get var and tmp into /mnt/ramdrive? I've been trying stuff like:
mount -t ramfs /var /mnt/ramdrive/var

Or maybe?:
mount -t ramfs /mnt/ramdrive/var /var

To be honest, I've completely confused myself here. They both seem to work, but I can't tell if /var is actually in RAM or not.

I'm running Debian Sarge with a 2.6 kernel, any help would be very appreciated!
 
Old 03-20-2005, 04:18 PM   #2
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 34
Well, you can bind directories, if needed, using the 'mount --bind' command............This will allow you to bind the /mnt/ramdrive directory to wherever you want.......The syntax is "mount --bind olddir newdir" (read the mount manpage for an explanation of the '--bind' option)...........

To simplify things, move the /tmp directory to /var/tmp (mv /tmp /var/tmp) and create a /tmp symlink to it (ln -sf /var/tmp/tmp /tmp)..........Then, after mounting ramfs to /mnt/ramdrive, bind /mnt/ramdrive to /var like so:

mount --bind /mnt/ramdrive /var -o defaults,noatime

Note: You can mount the ramfs directly to /var instead of /mnt/ramdrive and not have to bind anything.............

As for creating ramdisk sizes greater than 8 MB, you need to pass an kernel option when booting, as this is usually set to a default size when the kernel was compiled........The kernel parameter is 'ramdisk_size=' and can be included as an append line in your bootloader's config file.......Here's the relevant page in the Linux Bootdisk HOWTO: How do I increase the size of my ramdisks?

However, I must warn you, if you put /var into RAM, you will need more than 1 GB of RAM available to even consider this as an option in Debian, and set a very large value for the ramdisk size............The reason is this directory will fill up pretty quickly when using apt-get (or aptitude) while installing packages, unless you make a habit of removing/cleaning the downloaded packages stored in /var/cache/apt/archives.............Even then you will need enough room in /var to install/upgrade packages....

And then there's the problem of when the power is shut down, everything in the ramdisk is lost, which means the next time you start the computer, /var will be completely empty, so you will need to have a current copy of this on disk to populate the /var directory, which defeats the purpose of using the ramdisk for /var in the first place.......

Myself, I just use a separate, smaller partition dedicated for /var right next to the Linux swap partition, and mount it with the 'noatime' option, to increase performance..........
 
Old 03-20-2005, 08:35 PM   #3
Myrdos
LQ Newbie
 
Registered: Feb 2004
Location: Winnipeg, Canada
Distribution: Debian
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for the answer! Right now I'm still stuck trying to increase my ramdisk size. I edited /boot/grub/menu.lst and added this to the end:
ramdisk_size=32768

Then I create a ramdrive like this:
dd if=/dev/zero of=/dev/ram0 bs=1k count=4096
mke2fs -v -m 0 /dev/ram0
mount -t ext2 /dev/ram0 /mnt/ramdrive

But df is still giving me:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda1 938512 469621 418821 53% /
tmpfs 124408 0 124408 0% /dev/shm
/dev/ram0 7931 13 7918 1% /mnt/ramdrive

I tried to explicitly state how large the drive should be with mke2fs:
mke2fs -v -m 0 /dev/ram 32768

mke2fs 1.35 (28-Feb-2004)
mke2fs: Filesystem larger than apparent device size.
Proceed anyway? (y,n) n

I tried switching the line in menu.lst to ramdisk_size=32M, but still no luck.

So I'm totally stumped.
 
Old 03-21-2005, 12:58 AM   #4
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 34
Hmmm.......If I read you correctly, I think that should go with the other options passed to the kernel on the "kernel" line, and not on a separate line at the end of the file??.........Not very familiar with grub and much prefer lilo, but I seem to remember something along those lines.........

If by "to the end" you mean at the end of the "kernel" line, then that should've done the trick............





Okay, I just found this article which should be just what you're looking for: Linux Ramdisk mini-HOWTO

According to that article, the size passed to the kernel is in a block size of 1024 bytes, or 1k blocks, therefore a 32 MB ramdisk would be specified as "ramdisk_size=32768" (the first value you used)........Plus it shows how to format the ramdisk (recommending ext2 since it is a non-journaled fs and takes up less space to begin with) and mount it.....................Then you should be able to bind the mounted ramdisk like I showed you..............

Here's another older article, taken from a link in that Ramdisk Howto: How to use a Ramdisk for Linux.......This one tells tells you to make frequent backups of the ramdisk, if the data is needed upon reboot, and recommends setting up a cron job at 10-minute intervals for backing up the data to disk.........Actually using rsync for the backup job would be ideal in this situation, since rsync will only backup what has been changed (sync'ing the directories), thus speeding up the backup process considerably.........

HTH

Last edited by thegeekster; 03-21-2005 at 01:06 AM.
 
Old 03-21-2005, 08:42 PM   #5
Myrdos
LQ Newbie
 
Registered: Feb 2004
Location: Winnipeg, Canada
Distribution: Debian
Posts: 15

Original Poster
Rep: Reputation: 0
YES! We are having success. The problem was that I had indeed put ramdisk_size at the bottom of the menu.lst file, and not on the kernel line. Now that it is there, I have a nice ramdisk of size 128 megs. I used the command you supplied:
mount --bind /mnt/ramdrive/var /var -o defaults,noatime

And then ran a little test to make sure that /var was indeed on the ramdrive:

S0106004063d9cde7:/var# cp /home/myrdos/*.mov /mnt/ramdrive/var/cache
S0106004063d9cde7:/var# cd /var
S0106004063d9cde7:/var# cd cache
S0106004063d9cde7:/var/cache# ls
starwars.mov
S0106004063d9cde7:/var/cache# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda1 938512 469814 418628 53% /
tmpfs 124408 0 124408 0% /dev/shm
/dev/ram0 126931 13395 113536 11% /mnt/ramdrive
/mnt/ramdrive/var 126931 13395 113536 11% /var
S0106004063d9cde7:/var/cache# rm *.mov
S0106004063d9cde7:/var/cache# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda1 938512 469814 418628 53% /
tmpfs 124408 0 124408 0% /dev/shm
/dev/ram0 126931 25 126906 1% /mnt/ramdrive
/mnt/ramdrive/var 126931 25 126906 1% /var

I recreated the /var directories cache, backup, etc, because it seems the original /var folder has been shadowed or hidden by my ramdrive. I will have to unmount the ramdrive before using apt-get, which is fine with me. Thanks again for answering, I think I would have fought with this for a long time on my own.
If you are curious, here is a picture of what we have been working on: Some Pics

Next I will see if I can convince the /tmp directory to share the ramdrive with /var
 
Old 03-22-2005, 12:49 PM   #6
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 34
Great!!

Will this project have remote control later on?........

Quote:
Next I will see if I can convince the /tmp directory to share the ramdrive with /var
You should be able to move /tmp into /var/tmp and create a symlink called /tmp which points to it, like I showed you above:
Quote:
To simplify things, move the /tmp directory to /var/tmp (mv /tmp /var/tmp) and create a /tmp symlink to it (ln -sf /var/tmp/tmp /tmp)
I know this works, because I do it all the time..........I usually put /var on it's own separate partition, smaller and right next to the swap partition, and move /tmp into /var/tmp and create the symlink......Here's a command that will do it all:

mv /tmp /var/tmp && ln -sf /var/tmp/tmp /tmp

Now you have the /tmp directory included inside the /var directory and a symlink which points to it..........This will avoid the necessity of having to create a separate ram disk for the /tmp directory...........

Last edited by thegeekster; 03-22-2005 at 12:51 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RAMDISK: couldn't find valid ramdisk image starting at 0. iotc247 Slackware 10 12-10-2010 03:08 PM
Put /proc and /var into a ramdisk, but other stuff on drive? mabrodis Linux - General 2 01-12-2005 07:24 PM
Mounting /var/log as a tmpfs mr666white Linux - Laptop and Netbook 2 12-06-2004 08:07 PM
creating a ramdisk runtime from another ramdisk code123 Linux From Scratch 0 10-11-2004 08:59 AM
Mounting /var on a RAMdisk gamu829 Linux - General 2 09-04-2002 06:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 06:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration