[ Bloke.com || Linux || JavaScript || Java || Volleyball || Link Me ]
Free: [ Guestbook || MessageBot || Plugins || Counter || AusPrices || Advertise ]

Home - Linux - ramdisk

There is a lot of talk of using ram disks at boot time. This is because it is often needed to load special device drivers (eg scsi drivers).

But I wanted a file system that is held in memory for speed purposes. I'm open to suggestions on how to make this better, and also note that the kernel will keep files in memory if they are accessed commonly.

By default, ram disks are 4megs in Red Hat. If this is what you want, then you can just do:

[root@tiger root]# /sbin/mkfs -t ext2 -m 0 /dev/ram1 4096
[root@tiger root]# mkdir -p /mnt/ram1
[root@tiger root]# mount -t ext2 /dev/ram1 /mnt/ram1
where /mnt/ram1 is where you wanted to mount it (can be any directory that exists (and should be empty)).

There are 20 ramdisks setup by default, so you can use and mount these in a similar way (their names are /dev/ram0 - /dev/ram19). And you can make more with

[root@tiger root]# mknod -m 660 /dev/ram21 b 1 1
[root@tiger root]# dd if=/dev/zero of=/dev/ram21 bs=1k count=4k
If you want to change the default size of the ram disk, then for lilo, add ramdisk=8192 to the kernel entry (I didn't test this, since I no longer use lilo):
for Grub, you can just do the same thing (I made a new entry rather than change the current one).
title RH RamDisk 8M (2.4.9-31)
        root (hd0,1)
        kernel /vmlinuz-2.4.9-31 ro root=/dev/hda3 hdb=ide-scsi ramdisk=8192
        initrd /initrd-2.4.9-31.img
Of course once you increase the size and (unfortunately) reboot, then use the new size when making the filesystem.
[root@tiger root]# /sbin/mkfs -t ext2 -m 0 /dev/ram1 8192
[root@tiger root]# mkdir -p /mnt/ram1
[root@tiger root]# mount -t ext2 /dev/ram1 /mnt/ram1
The downside to using ramdisks this way is that it always chews up this amount of memory (which could be a good thing in some cases). File Systems of the type ramfs will only use up the memory they need. And also you can specify the size of the ram disk at creating time (no need to reboot). And it's a whole lot easier!! In this example I want the dir /www/tmp/jobq to be in memory only
[root@tiger /]# mkdir /www/tmp/jobq
[root@tiger /]# mount -t ramfs none /www/tmp/jobq -o maxsize=8192 
So once the directory is made, you can add this file to /etc/fstab so that it is ready at boot time:
none                    /www/tmp/jobq           ramfs   maxsize=8192    0 0
As noted here always include the -o maxsize=... argument, or you could easily chew up half the memory (and if you have two...)

So for me, the trick now is to figure out what would be best put into memory. Be careful if you are using this with a web server (and some other software) which may keep commonly accessed files in memory (so you would end up having the file in memory twice). And it's a no brainer that if the machine reboots or crashes, you loose the data in these directories!


Last Change: Monday, 10-Jan-2005 07:41:41 EST


The information provided within these pages is provided AS IS, and without any warranty. Following these directions may (but not limited to) crash your computer, delete all the information on your hard disk, open up security holes or cause your house to burn down. I made these pages to provide some information about the setup that I have done, but I did not proofread it for correctness, and in most cases did not test it. There are commands in these pages that would definately delete or corrupt all the data on your computer (especially the dualboot section). In fact it happened to me.... So you are on your own!

Cameron Gregory