Make a superfast RAM disk

Ever wanted a super fast disk? The steps below show you how. Fast ram disks have a disadvantage that they do not preserve data on restart. When the computer shuts down all data on the disk is gone. However sometimes it can be handy to use such a disk. I use ram disks for video encoding. I copy my raw video file to the ram disk, edit it and when encoding it is much faster than a normal disk. So how do we do this.

I use Ubuntu but this should work on any Linux distribution. The tmpfs filesystem is a ramdisk. The following commands will create a 2 GB ramdisk that is available on computer startup.

sudo mkdir -p /media/ramdisk mount -t tmpfs -o size=2048M tmpfs /media/ramdisk

The ramdisk folder is owned by root as it is to be available on reboot. The ramdisk permissions should be writable by everyone. The tmpfs default permissions (chmod 1777) are correct.

Make a superfast ram disk in Ubuntu

To make the ramdisk permanently available, add it to /etc/fstab.

grep /media/ramdisk /etc/mtab | sudo tee -a /etc/fstab

You will see the line moved from mtab to fstab. It will look something like this.

tmpfs /media/ramdisk tmpfs rw,size=2048M 0 0

The ramdisk will not consume any memory until you use it. Double check your memory requirements during maximum system load. If the ramdisk is too large, your system will consume swap storage to make up the difference.

To adjust the size of the ramdisk, edit /etc/fstab and verify by remounting the ramdisk. You will lose any data on the ramdisk just like you would in a reboot! The following code will change the size of the ramdisk to 512M.

# Check the existing ramdisk size
df /media/ramdisk
# Change size=512M for a 512 MB ram drive.
sudo vi /etc/fstab
# Remount the ramdisk, you will lose any existing data that is on it.
sudo mount -a /media/ramdisk
# Verify the new ramdisk size.
df /media/ramdisk

As you can see the setup of a permanent ram disk is very easy. There are a lot of situations where this might come in handy, like video conversions. Always keep in mind that any data on a ram disk is lost on reboot or shutdown.