RAM disk is part of the main memory (RAM) which is used as hard disk. This means that part of the main memory dedicates to user to put files (mainly cache files). The main advantage of the RAM disk is its speed. In comparison with hard disk, RAM is faster thousands time than hard drive and this gives fast response to the user request. The only obvious drawback of RAM disk is that, it cannot hold data permanently and once you reset or shutdown the system all information in RAM (including RAM disk) will be erased. In this post I will explain two different ways of creating RAM disk in Linux.
Creating RAM disk with mkfs command
In order to create RAM disk with mkfs command, you should first of all determine your needed space with the command like below.
$ sudo mkfs -q /dev/ram0 65536
The above command make file system which has 64MB capacity.
Now you should mount your RAM disk in order to be accessible. So it is better to create directory in your favorite path (/mnt
or /media
is recommended) and then mount your RAM disk. See following commands.
$ sudo mkdir -p /mnt/rmdisk
$ sudo mount /dev/ram0 /mnt/rmdisk
Now your RAM disk is ready to use.
Creating RAM disk with tmpfs
This way provides more straight forward way to create RAM disk and you do not need to bother yourself with firstly creating partition with mkfs and then mount it. In this way you just need to mount a file system which is know as tmpfs. Generally, tmpfs is a file system which lives in RAM. For creating RAM disk in this way. Firstly is better to create directory as mount point of RAM disk exactly like previous way.
$ sudo mkdir -p /mnt/rmdisk
Now you need to mount tmpfs file system to your mount point with following command.
$ sudo mount -o size=512M -t tmpfs none /mnt/rmdisk
The above command assign 512MB of your RAM for your use and now this capacity is available.
For more information please refer to following links.