UPDATE: I recommend setting up a ram device with tmpfs as I’ve described here: http://black-pixel.net/ram-device-with-tmpfs.html

I had some performance problems with my Minecraft server and decided to run it on a ramdisk. This is a tutorial on how to set it up on CentOS.

Since Linux Kernel 2.4 ramdisk support is built-in.

To see the names of the ramdisk devices:

ls -l /dev/ram*
brw-rw----. 1 root disk 1,  0 Sep 16 20:40 /dev/ram0
brw-rw----. 1 root disk 1,  1 Sep 16 20:36 /dev/ram1
brw-rw----. 1 root disk 1, 10 Sep 16 20:36 /dev/ram10
brw-rw----. 1 root disk 1, 11 Sep 16 20:36 /dev/ram11
brw-rw----. 1 root disk 1, 12 Sep 16 20:36 /dev/ram12
brw-rw----. 1 root disk 1, 13 Sep 16 20:36 /dev/ram13
brw-rw----. 1 root disk 1, 14 Sep 16 20:36 /dev/ram14
brw-rw----. 1 root disk 1, 15 Sep 16 20:36 /dev/ram15
brw-rw----. 1 root disk 1,  2 Sep 16 20:36 /dev/ram2
brw-rw----. 1 root disk 1,  3 Sep 16 20:36 /dev/ram3
brw-rw----. 1 root disk 1,  4 Sep 16 20:36 /dev/ram4
brw-rw----. 1 root disk 1,  5 Sep 16 20:36 /dev/ram5
brw-rw----. 1 root disk 1,  6 Sep 16 20:36 /dev/ram6
brw-rw----. 1 root disk 1,  7 Sep 16 20:36 /dev/ram7
brw-rw----. 1 root disk 1,  8 Sep 16 20:36 /dev/ram8
brw-rw----. 1 root disk 1,  9 Sep 16 20:36 /dev/ram9

The standard ramdisk size is very low ( < 20MB) so you may need to increase it.

To increase it, in my case to 128MB, you have to edit the /etc/grub.conf and add ramdisk_size=131072 at the end of the kernel line:

 kernel /boot/vmlinuz-2.6.32-71.29.1.el6.x86_64 ro root=/dev/md2 <strong>ramdisk_size=131072</strong> 

Now reboot so the changes take effect.

Once rebooted, format one of the ramdisk devices:

mke2fs -m 0 /dev/ram0

Now create a folder, mount the device and set the appropriate owner.

mkdir /home/user/ramdisk 

mount /dev/ram0 /home/user/ramdisk 

chown user:user /home/user/ramdisk

That’s it. Remember that everything you put onto the ramdisk is lost after rebooting. So back it up before you reboot the server or better set up a cron job to do regular backups for you.

If you want the ramdisk to be set up automatically after a reboot add the following to your /etc/rc.local file:

mke2fs -m 0 /dev/ram0 

mount /dev/ram0 /home/user/ramdisk 

chown user:user /home/user/ramdisk 

# Example for copying the backup back on the ramdisk 

# cp -R /home/user/backup/* /home/user/ramdisk/