What is a RamDisk?
A RamDisk is a portion of memory that you allocate to use as a partition. Or, in other words, you are taking memory, pretending to treat it as a hard drive, and you are saving your files to it. Why would you want to use a RamDisk? Well, if you know that certain files you have are constantly going to be used, putting the files into memory will increase the performance of your computer since your memory is faster than your hard drive. Things like web servers with lots of data can be sped up this way
How to use RamDisk
First of all, the default installation of RedHat comes with ramdisk support. All you have to do is format a ramdisk and then mount it to a directory. To find out all the ramdisks you have available, do a “ls -al /dev/ram*”. This gives you the preset ramdisks available to your liking. These ramdisks don’t actually grab memory until you use them somehow (like formatting them). Here is a very simple example of how to use a ramdisk.
# create a mount point:
# create a filesystem:
# mount the ramdisk:
mount /dev/ram0 /tmp/ramdisk0
Those three commands will make a directory for the ramdisk , format the ramdisk (create a filesystem), and mount the ramdisk to the directory “/tmp/ramdisk0”. Now you can treat that directory as a pretend partition! Go ahead and use it like any other directory or as any other partition.
If the formatting of the ramdisk faild then you might have no support for ramdisk compiled into the Kernel. The Kernel configuration option for ramdisk is CONFIG_BLK_DEV_RAM .
The default size of the ramdisk is 4Mb=4096 blocks. You saw what ramdisk size you got while you were running mke2fs. mke2fs /dev/ram0 should have produced a message like this:
mke2fs 1.14, 9-Jan-1999 for EXT2 FS 0.5b, 95/08/09
Linux ext2 filesystem format
1024 inodes, 4096 blocks
204 blocks (4.98%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group
Running df -k /dev/ram0 tells you how much of that you can really use (The filesystem takes also some space):
>df -k /dev/ram0
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/ram0 3963 13 3746 0% /tmp/ramdisk0
Changing the size of the ramdisks
Add this line to your lilo.conf file:
ramdisk_size=10000 (or ramdisk=10000 for old kernels)
and it will make the default ramdisks 10 megs after you type the “lilo” command and reboot the computer. Here is an example of my /etc/lilo.conf file.
Add the following to /etc/grub.conf so that it looks like the following:
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,4)
# kernel /vmlinuz-version ro root=/dev/hda8
# initrd /initrd-version.img
title Red Hat Linux (2.4.20-8)
kernel /vmlinuz-2.4.20-8 ro root=LABEL=/
title Linux RAMDISK
kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ ramdisk_size=10000
Reboot the server for the Ramdisks size to take effect.