- How to Easily Create RAM Disk on Debian, Ubuntu, Linux Mint, CentOS
- What is RAM Disk?
- Why use RAM disk?
- How to Create a RAM Disk in Any Linux Distro
- Test RAM Disk Speed
- Auto-mount on System Boot
- How to Run VirtualBox VM on RAM Disk
- Wrapping Up
- How to Create and Use a Ramdisk on Ubuntu 18.04
- Creating a RAMDISK:
- Mounting RAMDISK Automatically on System Boot:
- Persisting RAMDISK Data:
- JamesCoyle.net Limited
- Create a RAM disk in Linux
- Create a RAM disk in Linux
How to Easily Create RAM Disk on Debian, Ubuntu, Linux Mint, CentOS
This tutorial will show you how to quickly create a RAM disk in any Linux distro (Debian, Ubuntu, Linux, Fedora, Arch Linux, CentOS, etc). Compared to commercial Windows RAM disk software that costs money, Linux can utilize this cool feature 100% free of charge.
What is RAM Disk?
RAM disk is also known as RAM drive. It’s a portion of your RAM that are formated with a file system. You can mount it to a directory on your Linux system and use it as a disk partition.
Why use RAM disk?
RAM is ultra-fast compared to even the fastest solid state drive (SSD). As you may know, the main performance bottleneck in today’s computer is the speed of hard drive, so moving programs and files to the RAM disk yields super fast computing experience.
Pros of RAM disk:
- Ultra-fast
- Can sustain countless reads and writes
Cons of RAM disk:
- RAM is volatile which means all data in RAM disk will be lost when the computer shutdowns or reboots. However, this can be a pro in some situations, if you use it wisely.
- RAM is expensive so it has limited capacity. You need to make sure not allocate too much space for RAM disk, or the operating system would run out of RAM.
You can do a lot of interesting things with RAM disk.
- RAM disk is best suited for temporary data or caching directories, such as Nginx FastCGI cache. If you use a SSD and there will be a lot of writes to a particular directory, you can mount that directory as a RAM disk to reduce wear out of SSD.
- I also use RAM disk to temporary store screenshots when writing articles on this blog, so when my computer shut down, those screenshots will automatically be deleted on my computer.
- You may not believe it, but I use RAM disk to run virtual machines inside VirtualBox. My SSD is about 250G. I can’t run many VMs directly on the SSD and I’m not happy about the speed of my 2TB mechanical hard drive (HDD). I can move the VM from HDD to RAM disk before starting the VM, so the VM can run much faster. After shutting down the VM, I move the VM files back to HDD, which takes less than 1 minute. This of course requires your computer to have a large capacity RAM.
How to Create a RAM Disk in Any Linux Distro
First make a directory which can be anywhere in the file system such as
If you want to let every user on your Linux system use the RAM disk, then change its permission to 777.
Next, check how much free RAM are left on your system with htop command line utility because we don’t want to use too much RAM.
Then all left to do is to specify the file system type, RAM disk size, device name and mount it to the above directory. You can see from the screenshot above that I have plenty of free RAM, so I can easily allocate 1GB for my RAM disk. This can be done with the following one-liner. It will be using tmpfs file system and its size is set to 1024MB. myramdisk is the device name I gave to it.
To allocate 10G for the RAM disk, run this instead.
If we issue the following command
We can see it’s successfully mounted.
Now if I copy my VirtualBox machines file (5.8G) into the RAM disk, my RAM usage suddenly goes up to 9.22G.
If I unmount RAM disk,
Everything in that directory will be lost and RAM usage goes down to original.
This is how you can test if your RAM disk is working.
Test RAM Disk Speed
To test write speed of RAM disk, you can use dd utility.
Which gave me 2.8GB/s write speed.
To test read speed, run:
Which gave me 3.1 GB/s read speed.
I also did a speed test on my SSD. The write speed is 534MB/s and read speed 1.6GB/s.
Auto-mount on System Boot
Edit /etc/fstab file.
Add an entry like this:
x-gvfs-show will let you see your RAM disk in file manager. Save and close the file. Your Linux system will automatically mount the RAM disk when your computer boots up.
To mount it immediately without reboot, run the following command.
How to Run VirtualBox VM on RAM Disk
Note that this requires a large-capacity RAM.
When you create a brand new virtual machine, you should set the machine folder to the RAM disk directory ( /tmp/ramdisk/ ). If you can’t find the Machine folder option, then you need to install the latest version of Virtualbox on your system.
If you have an existing VM, then select the VM in the main VirtualBox Manager window and go to the menu bar and select Machine -> Move, or right-click the VM and select Move from the context menu. You will be prompted to choose a new folder for the virtual machine. Select /tmp/ramdisk/ as the new folder.
Remember to move your VM back to the original folder before shutting down your computer, or your VM will be deleted.
Wrapping Up
And that’s the basics of creating RAM disk in Linux. If you found this post useful, then subscribe to our free newsletter or follow us Twitter or like our Facebook page. Thanks for visiting!
Источник
How to Create and Use a Ramdisk on Ubuntu 18.04
Does that mean we can’t store ordinary data on RAM? Well, we actually can. If you don’t care about your data being lost, then you can use RAM as disk. Which is called RAMDISK. This solution is very effective if your computer has backup power supply that can keep your computer running for a long time even when the power goes off.
There is actually a way to use RAMDISK to store files permanently. Let’s say you have a 4 GB RAMDISK setup. You can store and access files here very fast. Of course, this is temporary storage. To fix that problem, we can use a hard drive and sync all the files and directories of our RAMDISK automatically with specific backup softwares. Even though hard drive is slow, and it may take a while to sync a hard drive with a RAMDISK, at least the data will be stored permanently. So when you shutdown your computer, RAMDISK will be erased. When you start your computer again, all the data will be copied from your hard drive to your RAMDISK. This process will be slow. But after the data is copied, you can again access the data very fast. So basically RAMDISK is used as a cache here.
In this article, I will show you how to create and use RAMDISK on Ubuntu 18.04 LTS. To watch a video of this process see video below:
Creating a RAMDISK:
Creating a RAMDISK on Ubuntu 18.04 LTS is really easy. All the tools required is already pre-installed on Ubuntu 18.04 LTS.
First create a mount point where you will be mounting the RAMDISK with the following command:
Now you can mount the RAMDISK to the /mnt/ramdisk mount point with the following command:
NOTE: Here, size=2G means, the RAMDISK will be 2 GB in size. To create RAMDISK of several MB, use M. For example, to create 256 MB RAMDISK, put size=256M
Now to verify whether the RAMDISK is created, run the following command:
As you can see, the RAMDISK is created and mounted on /mnt/ramdisk as expected.
You can use the RAMDISK as you use ordinary hard drive partitions. As you can see from the screenshot below, I copied several files and directories into the RAMDISK. I can even edit text files directly from RAMDISK.
To unmount the RAMDISK, run the following command:
WARNING: All the files in your RAMDISK will be lost.
Mounting RAMDISK Automatically on System Boot:
You can use the /etc/fstab file to automatically mount the RAMDISK on system boot.
First, make a backup of /etc/fstab file with the following command:
A copy of the file /etc/fstab is saved to /etc/fstab.backup. Now If anything goes wrong on the way, you can just restore the /etc/fstab file.
Now open /etc/fstab file with the following command:
/etc/fstab file should be opened.
Now go to the end of the file and add the following line:
NOTE: Here size=2G means, the size of the RAMDISK will be 2 GB. To specify the size in MB, use M instead of G.
Now press + x and then press y and then press to save the file.
Now reboot your computer with the following command:
The RAMDISK should be mounted as you can see from the marked section of the screenshot below.
Persisting RAMDISK Data:
In this section, I will show you how to save RAMDISK data to hard drive on system shutdown and load data from hard drive to RAMDISK on system boot.
For this to work, the directory where the RAMDISK will be mounted and where the backup data will be saved must have the same file permission set. I will show you an easy trick. Stay tuned.
First create a directory where RAMDISK data will be saved on system shutdown with the following command:
If you’ve followed this article from the start, then the RAMDISK should be mounted on /mnt/ramdisk
Now create a system service file with the following command:
Now type in the following lines and replace shovon as marked in the screenshot below with your login username. Don’t forget this step as it won’t work otherwise. Now save the file.
Now enable the ramdisk-sync service with the following command:
The ramdisk-sync service is enabled. Now it will start automatically on system boot.
Now reboot your computer with the following command:
Once your computer starts, check whether the ramdisk-sync service is running with the following command:
As you can see, the service is running correctly.
As you can see, both the /mnt/ramdisk and /mnt/ramdisk_backup directories are empty.
Now I am going to copy some files to /mnt/ramdisk RAMDISK.
Now reboot your computer.
As you can see, once my computer boots, the files are available in my RAMDISK /mnt/ramdisk
Also the /mnt/ramdisk and /mnt/ramdisk_backup contains the same files.
That’s how you create and use RAMDISK on Ubuntu 18.04 LTS. Thanks for reading this article.
Источник
JamesCoyle.net Limited
Data Integration and Virtualisation
Create a RAM disk in Linux
Create a RAM disk in Linux
There are many reasons for creating a memory based file system in Linux, not least of which is to provide a near zero latency and extremely fast area to story files. A prime use of a RAM disk is for application caching directories or work areas.
There are two main types of RAM disk which can be used in Linux and each have their own benefits and weaknesses:
Check the amount of free RAM you have left on your machine before creating a RAM disk. Use the Linux command free to see the unused RAM. The below is an example of a 31GB of ram in a production server.
The free command shows the amount of RAM availale on your system in addition to the amount of memory used, free and used for caching. SWAP space is also displayed and shows if your system is writing memory to disk.
Create a folder to use as a mount point for your RAM disk.
Then use the mount command to create a RAM disk.
Substitute the following attirbutes for your own values:
- [TYPE] is the type of RAM disk to use; either tmpfs or ramfs.
- [SIZE] is the size to use for the file system. Remember that ramfs does not have a physical limit and is specified as a starting size.
- [FSTYPE] is the type of RAM disk to use; either tmpfs, ramfs, ext4, etc.
You can add the mount entry into /etc/fstab to make the RAM disk persist over reboots. Remember however, that the data will disappear each time the machine is restarted.
Источник