Creating a Linux RAM disk (tmpfs)
Note
This post may be partially machine- or AI-translated. If there is any discrepancy, the Korean version takes precedence.
Note
This post might be outdated and some links might not be available.
This post explains how to use a RAM disk (tmpfs) on Linux.
Use it carefully because the contents of the RAM disk are deleted when the device powers off.
Check available RAM
Check the system’s free RAM.
$ free --mega
total used free shared buff/cache available
Mem: 8071 2426 4778 85 867 5314
Swap: 0 0 0The available column shows that 5314 MB is available.
I will use 3 GB of it.
Create and mount the mount point
Create the directory to use as the RAM disk mount point.
$ sudo mkdir /mnt/ramdiskMount the RAM disk.
$ sudo mount -t tmpfs -o size=3G tmpfs /mnt/ramdiskYou can check the mounted RAM disk with the following command.
$ df -h
Filesystem Size Used Avail Use% Mounted on
...
tmpfs 3.0G 0 3.0G 0% /mnt/ramdiskConfigure /etc/fstab
Configure the RAM disk to be mounted automatically on boot.
Edit /etc/fstab with the following command.
$ sudo nano /etc/fstabAdd the following line to /etc/fstab.
tmpfs /mnt/ramdisk tmpfs defaults,size=3G 0 0From now on, the RAM disk will be mounted automatically on each boot.
Extra: Unmount and remove the RAM disk
This explains how to unmount and remove the RAM disk.
Use the following commands to delete the RAM disk contents and unmount it.
$ sudo rm -rf /mnt/ramdisk/*
$ sudo umount /mnt/ramdiskRemove the line added to /etc/fstab.
$ sudo nano /etc/fstabRemove the mount point.
$ sudo rmdir /mnt/ramdisk