Creating a RAM Disk on a Linux Instance of AWS

This information has already been conveyed in another post regarding a method to overcome MySQL memory resource problems, especially when being installed on a CentOS system that is known for modest RAM allocations such as the micro instance of the AWS free tier. This work-around useful enough to be reiterated at this time with more details.

# Check memory & swap file

[root@1.1.1.1 kimconnect.com]# free -m
total used free shared buff/cache available
Mem: 990 272 83 12 634 530
 
# Check available disk space

[root@1.1.1.1 kimconnect.com]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvdb1 30G 16G 15G 53% /
devtmpfs 474M 0 474M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 14M 483M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
overlay 30G 16G 15G 53% /var/lib/docker/overlay2/e00a170a94c1e18a1e7b41546cec6ddd68b7ea2fa5e0d8cf6dc81e645560a41f/merged
overlay 30G 16G 15G 53% /var/lib/docker/overlay2/7df0d56376a029799f7a73162371f98bfb481ed77e09fa18abad505587100fcc/merged
shm 64M 0 64M 0% /var/lib/docker/containers/f9b235680fa299980bda9aea59510a08e69491e108b4eeab40bf6416722e30ae/mounts/shm
shm 64M 0 64M 0% /var/lib/docker/containers/4a91a766b3dbd88df7bc7cb6813bdf0338216acf25ec5aeb8ce8733a3826f9df/mounts/shm
tmpfs 100M 0 100M 0% /run/user/1000
overlay 30G 16G 15G 53% /var/lib/docker/overlay2/1b9d1297df49c6d349e90e7c69187ab3bdeaefebed8f123e6af88380480e8418/merged
shm 64M 0 64M 0% /var/lib/docker/containers/6c65da0f8c1d399ff9b02f808ec5a9bf13ac098906dbfb9cce25fd8ec1efca27/mounts/shm
 
# Allocate swapfile, set appropriate permissions, create swapfile

sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB    #allocate
chmod 600 /swapfile        #secure the directory
mkswap /swapfile        #make swapfile in the /swapfile directory
swapon /swapfile        #configure system to use /swapfile
 
# Check swapfile settings

[root@1.1.1.1 kimconnect.com]# swapon -s
Filename Type Size Used Priority
/swapfile file 4194300 550912 -1
# Make permanent by editing the fstab file
vim /etc/fstab

# add this line
/swapfile none swap defaults 0 0
# Verify that system is using the allocated swap file

[root@1.1.1.1 kimconnect.com]# free -m
total used free shared buff/cache available
Mem: 990 347 58 13 583 454
Swap: 4095 533 3562
Posted on Categories Linux

Leave a Reply

Your email address will not be published. Required fields are marked *