• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Linux

How to create RAM disk in Linux

Published: June 2, 2017 | Modified: June 24, 2020



Short tutorial explaining what is RAM disk and how to create a RAM disk in Linux. It also includes differences between ramfs and tmpfs.

RAM disk in Linux

Recently one of our readers asked “how to create a RAM disk in Linux?”. So I thought of writing this small tutorial which will help you to understand what is a RAM disk, what is the use of it and how to create a RAM disk in Linux.

What is RAM disk?

Roughly RAM disk can be termed as a portion of your RAM mounted as a directory. It uses tmpfs or ramfs. Refer below table for the difference between ramfs and tmpfs.

ramfs
tmpfs
Old type New type and replacing ramfs now
Can not be limited in size Size limit can be defined
Since can not be limited may lead to system crash Once limit reached, disk full error written. No system crash issue.
Entry is not visible in ‘df’ output. Need to calculate by using ‘Cached’ number in ‘free’ output. Can be seen in ‘df’ command output
Work mechanism as file system cache Work mechanism is as partition of physical disk

RAM disk is a very high speed, high performance and almost zero latency area to store application files. Due to its performance-oriented nature, its mostly used for temporary data like caching application files.

How to create RAM disk?

RAM disk can be created in simple two steps. One is to create a directory on which it should be mounted and the second step is to mount it on that directory using specific FS type. Make sure you have enough free RAM on the system so that portion of it can be used in RAM disk. You can check it using free command.

Lets create directory /mnt/ram_disk and mount RAM disk on it.

# mkdir /mnt/ram_disk
# mount -t tmpfs -o size=1024m new_ram_disk /mnt/ram_disk

In above mount command, -t should be followed by tmpfs or ramfs type. For ramfs, size is the starting size of RAM disk since ramfs have limitless size. Size followed by the name of the disk (of your choice ex. new_ram_disk). You can verify if it mounted properly using df command.

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      5.8G  2.9G  2.7G  53% /
tmpfs           498M     0  498M   0% /dev/shm
new_ram_disk          1.0G     0  1.0G   0% /mnt/ram_disk

You can see newly created tmpfs of 1GB size is mounted on /mnt/ram_disk (highlighted above).

You can add below entry in /etc/fstab as well to persist it over reboots as well. But keep in mind that data within RAM disk flushes for each reboot since its backed memory is volatile.

new_ram_disk    /mnt/ram_disk   tmpfs    nodev,nosuid,noexec,nodiratime,size=1024M   0 





⇠ Previous article
Network routes in Linux
Next article ⇢
Why HPUX loosing market grip

Related stuff:

  • Understanding /etc/hosts file
  • How to change process priority in Linux or Unix
  • LVM commands tutorial : Part 1 : Physical Volume (pvcreate, pvdisplay)
  • How to rename volume group
  • Linux mascot penguin: TUX
  • Why and how to disable SELinux in your Linux distro
  • RHEL 8 BETA installation with screenshots
  • Basics of LVM legends
  • Difference between /etc/passwd and /etc/shadow
  • What’s new in RHEL 8
  • Understanding /etc/services file in Linux
  • All you need to know about hostname in Linux

Filed Under: Linux Tagged With: memfs and tmpfs, memfs v/s tmpfs, ram disk in linux, what are limitations of memfs, what is ram disk

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Comments

  1. Roberto says

    June 4, 2020 at 4:55 pm

    Great tutorial, clear en easy to follow. I’m a very new Linux adopter. Thanks.

    Using Windows, one can direct specific apps to use the ram disk. I don’t know if it really makes a difference as opposed to not doing it, because I use it that way and the app that is configured for that really feels faster (browser).

    I would like to know if there is a way to configure a specific app to use ram disk in Linux. My main goal is to make Zoom work with ram disk, because I’m using a very old netbook with AntiX flawlessly, and it is the only app that I use regularly that is having a hard time to function properly.

    Roberto

    Reply
  2. gabriel says

    January 7, 2021 at 9:41 pm

    Thanks for the info.

    It would be great if I could access this ram disk through my file manager ( thunar ). It doesn’t show up like my external usb drives show up in the file manager.

    Thanks for any pointers.

    Reply

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.