Wednesday 6 July 2011

RAM Disk

RAM Disk/Drive

           Ram disk or ram drive is a portion of RAM which is used as a disk drive. It has fixed sizes and act as physical disk partitions. Its access time is much faster than a physical drive. The ram disk is very useful for those data which is access by number of users frequently. However, any data stored on a RAM disk is lost when the system is shut down or power off.
         The Linux kernel version 2.4 has built-in support for ram disks. Ram disks 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)
            In Red Hat Linux create 16 ram disks by default, but they are not active. Ram disk devices lists from ram0 – ram19, but only ram0 – ram15 (total 16) devices are usable by default. To check these block devices we can use the following command.
# ls -l /dev/ram*                    (It show ram disk block devices list)
# dmesg | grep RAMDISK            (It show the number of ram disk and its size)
            It show the default ram disk size is 4 MB.  It means we can create a ram disk that size only 4 MB. This is the default size of ram disk.

            Increase ram disk size: Ram disk size is controlled by a command-line option that is passed to the kernel during boot. The GRUB is the default boot loader of Red Hat Linux. So we will increase the ram disk size by modify new kernel option in “/etc/grub.conf” file.
            If we want to create a 32 MB of ram disk then go to the end of kernel line and enter “ramdisk_size=32000”.
# vi /etc/grub.conf

# 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=32000
        initrd /initrd-2.4.20-20.9.img
:wq
            Save the file and reboot the system. After reboot check again and confirm the changes of ram disk size.
# dmesg | grep RAMDISK                        (It show 16 RAM disks and size of 32000K or 32 MB)
            Creating File system on the ram disk: If we want to need only one ram disk, so we will format only “/dev/ram0”
# mke2fs -m 0 /dev/ram
            The -m 0 option keeps mke2fs from reserving any space on the file system for the root user.

            Mount the ram disk: First create a mount point then mount the ram drive on that mount point.
# mkdir /ramdisk
# mount /dev/ram0 /ramdrive
# df -h | grep ram0                          (Verify the new ram disk mount)
# tune2fs -l /dev/ram0                                (Show detail information of ram0 device)

            If we no more need to ram disk, unmount this but data will still be there.
# umount -v /ramdrive

            Automating ram disk creation:
            If we need to create and mount a ram disk automatically every time when boot, add some commands in the “/etc/rc.local” init script.
# vi /etc/rc.local
             # Format, mounts, and sets permissions on my 32MB ram disk.
            /sbin/mke2fs -q -m 0 /dev/ram0
            /bin/mount /dev/ram0 /ramdrive
            /bin/chmod 0750 /ramdrive
:wq
            After modify it Reboot the system.
            Now 32 MB RAM disk is create and mounted on /ramdisk.

No comments:

Post a Comment

Boot to UEFI Mode or legacy BIOS mode

Boot to UEFI Mode or legacy BIOS mode Choose UEFI or legacy BIOS modes while installing Windows. After Windows is installed, if you nee...