In my last project, I developed a real-time vision system using Raspberry Pi, which necessitates better read/write speeds for temporary data. After configuration, a small ramdisk will be created automatically when Raspberry Pi or Linux starts up.

What is RAMDisk?

A RAMDisk is a portion of RAM which is being used as if it were a disk drive. RAMDisk has fixed sizes, and acts like regular disk partitions. Access time is much faster for a RAMDisk than for a real, physical disk. However, any data stored on a RAMDisk is lost when the system is shut down or powered off. RAMDisk can be a great place to store temporary data.


It’s very easy to set up a RAMDisk in Raspberry Pi. For example, I want to mount the smallest ramdisk in /mnt/rd folder, here are steps:

1. Create a RAMDisk folder

It means that you want to create a ramdisk here. Go to Terminal and type following command:

# create a folder
$ sudo mkdir /mnt/rd

2. Auto-create RAMDisk when boot

Edit /etc/rc.local file:

$ sudo nano /etc/rc.local

You will see a script file, add the following code before exit 0:

/sbin/mke2fs -q -m 0 /dev/ram0
/bin/mount /dev/ram0 /mnt/rd
/bin/chown pi:root /mnt/rd
/bin/chmod 0750 /mnt/rd
rc.local file

You can change the code according to your ramdisk folder location and user.

3. Reboot Pi and check RAMDisk

After reboot your pi, you type df -h to check disk status, you will see ram0 with size 7.8mb, you can use it to boost your application now.

disk space