How to Create a Ramdisk in Linux?

A RAM disk, also known as a RAM drive or RAMdisk, is a block of RAM (random access memory) that is used to emulate a hard disk drive. It allows the computer to use a portion of its RAM (separate hard drive), allowing the user to store and access data from the RAM as if it were a physical disk.

This article will explain various methods to create a ramdisk in Linux. The tutorial’s content is below:

Let’s start the creation of a ramdisk in Linux.

Using tmpfs to Create a Ramdisk in Linux

In Linux, the “tmpfs” file system is often used for creating a RAM disk. The “tmpfs” file system in Linux is a special file system that stores all its data in memory. It is often used to create a RAM disk because it is very fast and efficient, allowing the user to create a filesystem in memory that can store and access data.

Step 1: Creation of Ramdisk in Linux

To create a ramdisk in Linux, you can use the mount command with the “-t tmpfs” option to specify that you want to mount a temporary file system in memory. Here’s an example of how you can create a ramdisk with a size of 128 MB:

 First, create a directory that will be used as the mount point for the ramdisk. This is the location where you will access the files on the ramdisk.

$ mkdir /mnt/ramdisk

Step 2: Specify System Type and the Size of the Ramdisk

Use the mount command to create the ramdisk of 128 MB by specifying the tmpfs file system type and the size of the ramdisk with the “size” option.

$ sudo mount -t tmpfs -o size=128m tmpfs /mnt/ramdisk

Step 3: Reboot System

To configure all the changes, users need to reboot the operating system:

$ reboot

The ramdisk is automatically mounted at the specified mount point.

Using /etc/fstab File to Create a Ramdisk in Linux

To make the ramdisk, add an entry in the “/etc/fstab” file. The step-by-step procedure is provided below to create the ramdisk in Linux:

Step 1: Open the fstab File

To access the specified file, the sudo privilege is utilized as below:

$ sudo nano /etc/fstab

Step 2: Specify System Type and the Size of the Ramdisk

After opening the file with a text editor and adding a line like the following by specifying the 128MB for ramdisk:

$ tmpfs /mnt/ramdisk tmpfs defaults,size=128m 0 0

Save the file and reboot the system to configure all the changes.

Step 3: Reboot System

To configure all the changes, users need to reboot the operating system by executing the below script:

$ reboot

The ramdisk is automatically mounted at the specified mount point.

Note: The Ramdisk size is limited by the available RAM available on your system. Be sure to leave enough memory for other processes to run properly.

That’s how a Ramdisk is created in Linux.

Conclusion

Linux offers the “tmpfs” and “/etc/fstab” files to create a ramdisk in the operating system. It is useful to create a filesystem in memory that can be utilized for storing and accessing data. This article has explained all possible ways to create the “Ramdisk” in Linux.

Join 10 Select Businesses Growing with Us! 500M+ Views Across Our Blogs & YouTube Channels – Be Part of Our Success. Click here to learn more. Click here if you are interested. ×