How to use the / dev / shm RAM disk directory.

RAM Disk is a portion of the physical capacity of RAM formatted as a file system. From this sytsem file you can mount it to a folder and use it as a hard drive partition.

This folder is often used for the purpose of storing long-term files, easy to change content, overwrite, delete and small.

Most operating systems Linux currently available RAM disk. this is a module in Kernel. Operating system Ubuntu &CentOS normally attach it to the directory by default / dev / shm. And with half the capacity RAM that you are.
View capacity:

$ df -h /dev/shm

Filesystem Size Used Avail Use% Mounted on
tmpfs 920M 0 920M 0% /dev/shm

To change this size, you can change the / etc / fstab file or add the following line:

$ mount -o remount,size=1G /dev/shm

Check :

Filesystem Size Used Avail Use% Mounted on
/dev/vda1 55G 26G 27G 49% /
devtmpfs 909M 0 909M 0% /dev
tmpfs 1.0G 64K 1.0G 1% /dev/shm
tmpfs 920M 8.5M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs 184M 0 184M 0% /run/user/0

You can see that the / dev / shm directory is currently 1GB in size.

Save configuration permanently:

Edit or add the following configuration line to the file: / etc / fstab

none      /dev/shm        tmpfs   defaults,size=1G        0 0


Create the same ramdisk directory.

Also similar to other ramdisk directories, you can also use the command mount as follows to create a new ramdisk. For example, I need a ramdisk directory with the path: / tmp / ramdisk /

$ mkdir /tmp/ramdisk; chmod 777 /tmp/ramdisk 
$ mount -t tmpfs -o size=256M tmpfs /tmp/ramdisk/

Overcoming disadvantages of data loss when shutdown

Note: When you reboot, all data on ramdisk will be lost.

You should create a directory with the same content as RAM disk. Then use rsync to synchronize data. Can also be combined with cron to periodically synchronize data. To upload data when the machine is turned on, one needs to be created scriptand put it in the directory /etc/init.d. Then use the command update-rc.d to add to the list of software that need to be started with Linux.