Home > linux tips > Tips to create ramdisk in a linux system

Tips to create ramdisk in a linux system

This is a tip for those who have excess amount of unused RAM memory in

their Linux system.A linux kernel supports something called ramdisk.

A ramdisk is a part of RAM which is being used as if it were a disk drive.

All the recent Linux kernels has in-built  support for ramdisks.
A ramdisk can have a number of uses some of them are mentioned below:

  • It is very fast.Access time is in the order of nano seconds for RAM,while it is in the order of milli-seconds for hard disk
  • A ramdisk is volatile which means files contained in it are gone without a trace when you shut down the system.This is very useful for security reasons

Now let us get into the process of actually creating a ramdisk.
step 1: check whether your Linux system has support for ramdisk.To do this type the
following in the terminal:

ls /dev/ram*

if your system supports ramdisk then the output will be like:


/dev/ram11  /dev/ram14  /dev/ram3  /dev/ram6 /dev/ram9 /dev/ram1   /dev/ram12  /dev/ram15

/dev/ram4  /dev/ram7/dev/ram10  /dev/ram13  /dev/ram2   /dev/ram5  /dev/ram8

my ubuntu system supports upto 15 ramdisks.

step 2:now check the size of your ramdisks through the command:

dmesg | grep RAMDISK

the output will be like:

RAMDISK driver initialized: 16 RAM disks of 65536K size 1024 blocksize

by default my ramdisks are of size 64MB you can increase this to any size you want.For this you have to

modify the boot configuration file.open /boot/grub/menu.lst file in root mode.

look for line starts with kernel.

title  Ubuntu 8.04.1, kernel 2.6.24-21-genericroot  (hd0,6)

kernel  /boot/vmlinuz-2.6.24-21-genericroot=UUID=a67b0fbe-9257-4443-8d04-01624003107f ro quietsplash

initrd  /boot/initrd.img-2.6.24-21-genericquiet

this may vary according to your distribution.

Now add ramdisk_size=xxxxxx for eg:to increase the size to 256MB add it to end of

kernel line which looks like:

title  Ubuntu 8.04.1, kernel 2.6.24-21-genericroot  (hd0,6)

kernel  /boot/vmlinuz-2.6.24-21-genericroot=UUID=a67b0fbe-9257-4443-8d04-01624003107f ro quiet splash ramdisk_size=262144

initrd  /boot/initrd.img-2.6.24-21-genericquiet

step 3:now format the ramdisk by typing the following,you can select any ramdisk you want by changing the number next to /dev/ram,i have choosen to use /dev/ram0:

sudo mke2fs /dev/ram0

the output will look like:

mke2fs 1.40.8 (13-Mar-2008)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment

size=1024 (log=0)16384 inodes, 65536 blocks3276 blocks (5.00%) reserved for the super

userFirst data block=1Maximum filesystem blocks=671088648 block groups8192 blocks per group,

8192 fragments per group2048 inodes per groupSuperblock backups stored on blocks:  8193,

24577, 40961, 57345Writing inode tables: done                            Writing superblocks

and filesystem accounting information: doneThis filesystem will be automatically checked

every 35 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.

step 4:now you have to mount the ramdisk somewhere in your system to make it available for use.

For this firstcreate a mount point by typing the following:

sudo mkdir /media/ramdisk

and now mount the ramdisk at this mount point by typing the following:

sudo mount /dev/ram0 /media/ramdisk

you can mount it anywhere as you wish.

step 5:now you have created and mounted a ramdisk.now you have to change

the ownership and make it writable by typing the following:

sudo chown {your-user-name}: root /media/ramdisk
sudo chmod -R 770 /media/ramdisk

step 6: Now a ramdisk has been created and available for use.

to unmount it type the following:

sudo umount /dev/ram0

i hope this would be useful for you.

WARNING:Make sure to backup your files before editing.

Categories: linux tips Tags: , , ,
  1. July 7, 2013 at 8:12 pm

    I have learn some good stuff here. Definitely price bookmarking for revisiting.
    I wonder how so much effort you place to make any such wonderful informative site.

  2. Kaustubh
    July 21, 2013 at 9:39 am

    Hi I have two questions can you please help.
    – How do I know if particular ramdisk device is in use, for example /dev/ram1 is already used so I should use /dev/ram2 which is free to use. I want to achieve this in a shell script for some mount tests.

    – How do I mark /dev/ram{n} as free after my tests so it can be reused?

    • July 21, 2013 at 11:35 am

      -you can check which ramdisk is mounted by using df command in terminal.
      It’ll show which ramdisk is in use under ‘FIlesystem’ tab, and mount point in ‘Mounted on’ tab.
      -so u can grep the output of df command for /dev/ram like, ‘df | grep /dev/ram’ and then choose to increment n of /dev/ram{n} and use the next ramdisk /dev/ram{n+1}.

  3. kaustubh
    July 22, 2013 at 7:50 am

    thanks, thought so, I used the output of mount command, hope that is also fine? Was wondering if there is specific command to check the status of /dev/ram* but think this is good enough. Thanks a lot !!

    • July 23, 2013 at 9:35 pm

      @kaustubh mount command is also fine, it’ll also give the type of filesystem used and type of mount like rw or read only…which is very useful in some cases….and there is no specific ramdisk command as such

  4. toshiba laptop battery
    March 20, 2014 at 7:55 pm

    Have you ever thought about publishing an ebook or guest authoring on other websites?
    I have a blog centered on the same subjects you discuss
    and would love to have you share some stories/information.
    I know my readers would appreciate your work.

    If you are even remotely interested, feel free to send
    me an e mail.

  5. Muhammad Shahzad Kamran
    June 8, 2014 at 12:16 pm

    Really useful info… thanks for sharing..

  6. June 24, 2014 at 7:49 pm

    Everything is very open wit a really clear description of the issues.
    It was definitely informative. Your website is very useful.
    Thanks for sharing!

  7. Kanith
    July 10, 2014 at 2:44 pm

    This is useful information.
    I’ve a question that if we use the /dev/ram15, will this point actually which physical memory address?

  8. seo bognor regis
    September 2, 2016 at 8:06 am

    Ӏ was wondering if үou evdr tɦouǥht of changing tɦe pаgе layout of yоur site?

    Its very welⅼ wгitten; I love ᴡһat youve gⲟt tо sɑy.
    But maүbe yօu cߋuld ɑ lіttle more inn the way of cοntent sօ people ϲould connect
    աith it better. Youve ggot аn awful lot of text fߋr only haᴠing one or twо images.
    Ꮇaybe you coulԁ space it out bᥱtter?

  9. April 3, 2017 at 4:09 pm

    really helpful!
    One question :

    how can i redirect “/var/log” to “/dev/ram0”.. i need to log all files to “/dev/ram0” ..

    • April 20, 2017 at 5:01 pm

      You could directly mount your ram disk to /var/log in that way your existing log files will be untouched.

      But you shouldn’t really use ramdisk and should look at using tmpfs which is a more improved implementation of ramdisk

  10. May 26, 2017 at 10:21 pm

    First of all I want to say awesome blog! I had a quick question which
    I’d like to ask if you don’t mind. I was interested to find out how you center yourself and clear your
    mind before writing. I’ve had a difficult time clearing
    my thoughts in getting my ideas out there. I do take pleasure in writing however it just seems
    like the first 10 to 15 minutes are lost just trying
    to figure out how to begin. Any ideas or tips? Cheers!

  1. November 2, 2015 at 8:50 am

Leave a Reply to relentlessdevelopment.wordpress.Com Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: