[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to use a ramdisk?



Eric House <ehouse@Eng.Sun.COM> writes:
| The HOWTOs talk about ramdisks as part of the install process, but not
| as something I can use every day.  Assuming that I *can* have a ramdisk
| on hamm, how do I set it up?
|
| So far, I've:
| put 'ramdisk=2000' in my /etc/lilo.conf file (and run lilo).  dmesg tells
| me that 16 2000K ramdisks were set up, but free shows that no memory is
| consumed so I assume there's another step to making them available.

I think the use of ramdisk=2000 has been deprecated in favor of
ramdisk_size=2000. But if you can live with the default 4MB size you
don't have to do anything. Last time I checked support was built in to
the Debian kernels as distributed in kernel-image-*.deb files.

| I want only one, BTW. :-)
|
| What's next?  I'd expect to need to put something in /etc/fstab, but
| what's the device file? (/dev/ramdisk?)  What if I want more than one?
| And what's the expected/traditional mount point?  The fstype?  Is
| there any further configuration to be done?

The device files are /dev/ram0, /dev/ram1, etc. You'll have to do more
than just put an entry in the fstab. Since these are raw virgin
devices every time you create them you'd have to build a file system
on them before you could mount them, e.g., mke2fs.

| How do I use ramdisks once they're created?  Just copy my files to the
| disk and symlink to them from where they're expected to be?  What do I
| do to ensure that the files are written to (real) disk on shutdown or
| at predefined intervals?

There's nothing, as far as I know, to do something like this
automatically for you. You'd have to write a script to do this at
shutdown and startup. Put the script in /etc/init.d and link to it
from /etc/rc0.d, and /etc/rc#.d (where '#' is the run level you run at
(default is 2 under Debian, I think)) making sure it gets called in
the correct order, e.g., during shutdown you'd want it to execute
before unmounting your disks, and making sure it handles the arguments 
'start' and 'stop' properly. Probably a good idea to poke around the
other scripts and see how they work if you're going to do this.

You'd probably also want a crontab entry calling that script
periodically if you wanted to write it do disk every so often.


| I'm so full of questions.  Surely there's documentation on this
| somewhere.  But: Where?

There's some info in the kernel source. If you have the Debian
kernel-source package installed, or you have your own virgin kernel
source look in

/usr/src/kernel-source-2.0.34/Documentation/ramdisk.txt

(of course the location will vary depending on what source you're
using and what version of the kernel you're using)

Here's the steps I just used to do what you want on my stock Debian
hamm system:

1) mke2fs /dev/ram0
2) mount /dev/ram0 /mnt

Done! I now have a 4MB RAM disk on /mnt. Of course if you did the
same, right now on your Debian system you'd get a 2MB RAM disk since
that's what you told the kernel the default size was.

Gary


Reply to: