LINUX RamDisk



LINUX RamDisk

A RAM disk is a portion of RAM which is being used as if it were a disk drive. RAM disks have fixed sizes, and act like regular disk partitions. Access time is much faster for a RAM disk than for a real, physical disk. RAM disks are used to store temporary data in a high performance directory. All data is lost when the system is powered off and/or rebooted.

Beginning with Linux kernel version 2.4 has built-in support for ramdisks. Ramdisks are useful for a number of things, including:

( Working with the unencrypted data from encrypted documents

( Serving certain types of web content

( Mounting Loopback file systems (such as run-from-floppy/CD distributions)

Red Hat creates 16 ramdisks by default, although they are not "active" or using any RAM. It lists devices ram0 - ram 19, but only ram0 - ram15 are usable by default.

1) To check these block devices out with the command:

ls –al /dev/ram*

grep through dmesg output to find out what size the ramdisks are:

dmesg | grep RAMDISK

2) If you want to increase ramdisk, the next step is to configure Linux to use a larger ramdisk size during boot. Ramdisk size is controlled by a command-line option that is passed to the kernel during boot in the /etc/grub.conf with the kernel option.

The kernel option for ramdisk size is:  ramdisk_size=xxxxx, where xxxxx is the size expressed in 1024-byte blocks. Here is how to modify /etc/grub.conf to configure 16 MB ramdisks:

# 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,0)

# kernel /vmlinuz-version ro root=/dev/hda5

# initrd /initrd-version.img

#boot=/dev/hda

default=0

timeout=10

splashimage=(hd0,0)/grub/splash.xpm.gz

title Red Hat Linux (2.4.20-20.9)

root (hd0,0)

kernel /vmlinuz-2.4.20-20.9 ro root=LABEL=/ hdc=ide-scsi ramdisk_size=16000

initrd /initrd-2.4.20-20.9.img

3) Save the file and reboot your system. After the reboot, a look at the dmesg output should confirm the change has taken effect with the command: dmesg | grep RAMDISK

4) There is no need to format the ramdisk as a journaling file system, so simply use the ext2 file system with the follwing command: mke2fs -m 0 /dev/ram0.

The -m 0 option keeps mke2fs from reserving any space on the file system for the root user, which is the default behavior. I want all of the ramdisk space available to a regular user for working with encrypted files.

5) Now that you have formatted the ramdisk, you must create a mount point for it. Then you can mount your ramdisk and use it. A standard is to use the directory /mnt/rdX for this operation.

mkdir /mnt/rd0

mount /dev/ram0 /mnt/rd0

The ownership and permissions on the ramdisk filesystem/directory should be tailored to the particular needs. You can copy, move, delete, edit, and list files on the ramdisk exactly as if they were on a physical disk partiton. If the server is powered down, all files created on the ramdisk are lost.

If you unmount and remount the ramdisk, your data will still be there. Once memory has been allocated to the ramdisk, it is flagged so that the kernel will not try to reuse the memory later.

You cannot "reclaim" ramdisk memory; it can only be recovered by a reboot. So you will want to be careful not to allocate more memory to the ramdisk than is absolutely necessary.

If you need to create and mount a ramdisk every time your system boots, you can automate the process by adding some commands to your /etc/rc.d/rc.local init script as follows:

# Formats, mounts, and sets permissions on ramdisk

/sbin/mke2fs -q -m 0 /dev/ram0

/bin/mount /dev/ram0 /mnt/rd0

/bin/chown root /mnt/rd0

/bin/chmod 0750 /mnt/rd0

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download