Posts Tagged ‘format’

Tips to create ramdisk in a linux system

November 28, 2008 14 comments

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 /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 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: , , ,