Tuesday, May 20, 2014

Ram disk creation on Linux

Ramdisks are very useful in the case of web servers for some heavily accessing contents.

The steps for crating Ramdisk is as follows,
Step 1: 

Edit the file /boot/grub/grub.cfg and add the entry "ramdisk_size={size in  KB}". For example if you need to crate 4GB of RAM disk, the entry should look like,


 ### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.32-21-server' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod ext2
    set root='(hd0,1)'
    search --no-floppy --fs-uuid --set ab3827ac-8003-4bed-81c0-9248d64362b0
    linux    /vmlinuz-2.6.32-21-server root=UUID=bbfccfa9-f878-4c42-83c1-0d82c3b2f44b ro quiet  ramdisk_size=4194304
    initrd    /initrd.img-2.6.32-21-server


Make sure the above entry made is in end of the linux kernel entry and it should be in a single line.

Once you done this, do a reboot and make the kernel read the parameter while next boot.

Step 2:

You can create the ramdisk using the following command,
      mkfs -q /dev/ram1 {size of ramdisk to me created in KB}
Create a folder to act as the mount point for above created ramdisk.
      mkdir -p /ramcache 
Mount the ramdisk to /ramcache
      mount /dev/ram1 /ramcache 
Following command will display the mounted partitions including the ramdisk.
      df -H 

No comments:

Post a Comment