X
    Categories: Linux

Linux RAM Disk

Linux RAM Disk

Linux RAM Disk is nothing but the Space from the server RAM which can acts as the disk partition. I.e. we take some portion of the memory and treating as of HDD of the system.  Then the question can comes to your mind that, what is the advantage we will be making here by doing it so?

First of all the RAM memory is faster than our HDD which makes execution faster for producing faster results. Let’s say you have the web server having multiple images on the pages. If these images were stored at the RAM DISK then we will get the speed advantage since compression & decompression happens faster in RAM rather than storing in HDD.

One more advantage we can take using RAM disk is that we can mount devices such as floppy disk or CD on the RAM Disk which makes the access faster rather mounting these device on the HDD mount point and accessing them.

So let’s start with RAM Disk activity …

Steps:

  1. Check the RAM DISK on your System.
[root@kalwa2 ~]# ls -l /dev/ram*
brw-rw----. 1 root disk 1, 0 Jun 19 21:24 /dev/ram0
brw-rw----. 1 root disk 1, 1 Jun 16 08:16 /dev/ram1
brw-rw----. 1 root disk 1, 10 Jun 16 08:16 /dev/ram10
brw-rw----. 1 root disk 1, 11 Jun 16 08:16 /dev/ram11
brw-rw----. 1 root disk 1, 12 Jun 16 08:16 /dev/ram12
brw-rw----. 1 root disk 1, 13 Jun 16 08:16 /dev/ram13
brw-rw----. 1 root disk 1, 14 Jun 16 08:16 /dev/ram14
brw-rw----. 1 root disk 1, 15 Jun 16 08:16 /dev/ram15
brw-rw----. 1 root disk 1, 2 Jun 16 08:16 /dev/ram2
brw-rw----. 1 root disk 1, 3 Jun 16 08:16 /dev/ram3
brw-rw----. 1 root disk 1, 4 Jun 16 08:16 /dev/ram4
brw-rw----. 1 root disk 1, 5 Jun 16 08:16 /dev/ram5
brw-rw----. 1 root disk 1, 6 Jun 16 08:16 /dev/ram6
brw-rw----. 1 root disk 1, 7 Jun 16 08:16 /dev/ram7
brw-rw----. 1 root disk 1, 8 Jun 16 08:16 /dev/ram8
brw-rw----. 1 root disk 1, 9 Jun 16 08:16 /dev/ram9
[root@kalwa2 ~]#

2.   Next step we need to create the mount point.

[root@kalwa2 ~]# mkdir /tmp/ram_disk_test

3. Now create the file system.

[root@kalwa2 ~]# mke2fs /dev/ram0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
4096 inodes, 16384 blocks
819 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=16777216
2 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
 8193
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@kalwa2 ~]#

From the above output you can get the block size of the RAM DISK. Which 16M= 16384

4.  Now let’s mount the RAM Disk.

[root@kalwa2 ~]# mount /dev/ram0 /tmp/ram_disk_test
[root@kalwa2 ~]#

5. Now its time to check the actual size that you are getting for storing the files.

[root@kalwa2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 16G 2.2G 13G 15% /
tmpfs 1002M 276K 1002M 1% /dev/shm
/dev/sda1 291M 32M 244M 12% /boot
/dev/sr0 3.4G 3.4G 0 100% /tmp/cdrom
/dev/ram0 16M 140K 15M 1% /tmp/ram_disk_test
[root@kalwa2 ~]#

So here you are getting 15 M space that can be used as local HDD mount point with much faster speed.

6. Now here you can save/drop your website images or pages in different ram disks (from ram0 to ram15) so that they can accessible with faster speed.

7. Since these contents (from the mount point)are available till the system reboot to make this changes persistent across reboot add the below lines in the “/etc/rc.local” init script.

#Steps for RAM DISK format & auto mount after reboot.
mke2fs /dev/ram0
mount /dev/ram0 /tmp/ram_disk_test

 

View Comments (1)

  • The expert developer can help you in getting the most efficient project and provide the user
    with various benefits with excellent technology. Comes to the Amazon Appstore for Android Tomorrow, Followed
    by Plants vs. On the other hand, businessmen have invested heavily in Android development and the result is a wide range of business applications, games and other commercial software.

Related Post