This is a brief article about how to setup a RamDisk on a RedHat 6.0 system. It should be very similar for other Linux distributions.
What is a RamDisk? A RamDisk is a portion of memory that you allocate to use as a partition. Or, in other words, you are taking memory, pretending to treat it as a hard drive, and you are saving your files to it. Why would you want to use a RamDisk? Well, if you know that certain files you have are constantly going to be used, putting the files into memory will increase the performance of your computer since your memory is faster than your hard drive. Things like web servers with lots of data can be sped up this way. Or, if you are insane, and you have a PII 550 Mhz computer with 1 gig of memory and an old 500 meg hard drive, you can use it just to increase your hard drive space. Then again, if you want an almost diskless machine, it might not be that crazy afterall.
Here are some more resources to help you.
-
http://metalab.unc.edu/LDP/HOWTO/Kernel-HOWTO.html
-
http://metalab.unc.edu/LDP/HOWTO/mini/LILO.html
- /usr/src/linux/Documentation/ramdisk.txt
How to use RamDisk
Well, it is very easy to use a ramdisk. First of all, the default installation of RedHat 6.0 comes with ramdisk support. All you have to do is format a ramdisk and then mount it to a directory. To find out all the ramdisks you have available, do a "ls -al /dev/ram*". This gives you the preset ramdisks available to your liking. These ramdisks don't actually grab memory until you use them somehow (like formatting them). Here is a very simple example of how to use a ramdisk.
# create a mount point:
mkdir /tmp/ramdisk0
# create a filesystem:
mke2fs /dev/ram0
# mount the ramdisk:
mount /dev/ram0 /tmp/ramdisk0
Those three commands will make a directory for the ramdisk , format the ramdisk (create a filesystem), and mount the ramdisk to the directory "/tmp/ramdisk0". Now you can treat that directory as a pretend partition! Go ahead and use it like any other directory or as any other partition.
If the formatting of the ramdisk faild then you might have no support for ramdisk compiled into the Kernel. The Kernel configuration option for ramdisk is CONFIG_BLK_DEV_RAM
.
The default size of the ramdisk is 4Mb=4096 blocks. You saw what ramdisk size you got while you were running mke2fs. mke2fs /dev/ram0
should have produced a message like this:
mke2fs 1.14, 9-Jan-1999 for EXT2 FS 0.5b, 95/08/09
Linux ext2 filesystem format
Filesystem label=
1024 inodes, 4096 blocks
204 blocks (4.98%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group
Running df -k /dev/ram0
tells you how much of that you can really use (The filesystem takes also some space):
>df -k /dev/ram0
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/ram0 3963 13 3746 0% /tmp/ramdisk0
What are some catches? Well, when the computer reboots, it gets wiped. Don't put any data there that isn't copied somewhere else. If you make changes to that directory, and you need to keep the changes, figure out some way to back them up.
Changing the size of the ramdisks
To use a ram disk you either need to have ramdisk support compiled into the Kernel or you need to compile it as loadable module. The Kernel configuration option is CONFIG_BLK_DEV_RAM
. Compiling the ramdisk a loadable module has the advantage that you can decide at load time what the size of your ramdisks should be.
Okay, first the hard way. Add this line to your lilo.conf file:
ramdisk_size=10000 (or ramdisk=10000 for old kernels)
and it will make the default ramdisks 10 megs after you type the "lilo" command and reboot the computer. Here is an example of my /etc/lilo.conf file.
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
image=/boot/vmlinuz
label=linux
root=/dev/hda2
read-only
ramdisk_size=10000
Actually, I got a little over 9 megs of usable space as the filesystem takes also a little space.
When you compile ramdisk support as loadable module then you can decide at load time what the size should be. This is done either with an option line in the /etc/conf.modules file:
options rd rd_size=10000
or as a command line parameter to ismod:
insmod rd rd_size=10000
Here is an example which shows how to use the module:
- Unmount the ramdisk mounted in the previous chapter,
umount /tmp/ramdisk0
.
- Unload the module (it was automatically loaded in the previous chapter),
rmmod rd
- Load the ramdisk module and set the size to 20Mb,
insmod rd rd_size=20000
- create a file system,
mke2fs /dev/ram0
- mount the ramdisk,
mount /dev/ram0 /tmp/ramdisk0
Example of how to use a RamDisk for a webserver.
Okay, here is an example of how to use 3 ramdisks for a webserver. Let us say you are 99% confident that your default installation of Apache for RedHat 6.0 won't use more than 9 megs for its cgi-scripts, html, and icons. Here is how to install one.
First, issue this command to move the real copy of the document root directory of your webserver to a different place. Also, make the directories to mount the ramdisks .
mv /home/httpd/ /home/httpd_real
mkdir /home/httpd
mkdir /home/httpd/cgi-bin
mkdir /home/httpd/html
mkdir /home/httpd/icons
Then, add these commands to the start procedure in your /etc/rc.d/init.d/httpd.init (or where ever the httpd gets started on your system):
### Make the ramdisk partitions
/sbin/mkfs -t ext2 /dev/ram0
/sbin/mkfs -t ext2 /dev/ram1
/sbin/mkfs -t ext2 /dev/ram2
### Mount the ramdisks to their appropriate places
mount /dev/ram0 /home/httpd/cgi-bin
mount /dev/ram1 /home/httpd/icons
mount /dev/ram2 /home/httpd/html
### Copying real directory to ramdisks (the
### data on the ramdisks is lost after a reboot)
tar -C /home/httpd_real -c . | tar -C /home/httpd -x
### After this you can start the web-server.
Comments
- Please remember one thing, BACKUP YOUR DATA if you change it and you need it. When the computer reboots, any changes are lost.
A cron job should do it. Have it check every 10 minutes and see if any files have changed and backup any changes. Another thing you could do is make your changes to the real directory, and then copy over the changes to the ramdisks. That is much safer.
- A cool use of this would be to have a computer with 1 gig of memory and then use 256 megs for "/tmp". If you have lots of processes that use "/tmp", it should help speed up your system. Also, anything in /tmp would get lost when the computer reboots, which can be a good thing.
- Linux uses all the memory that is not in use by programs as a unified disk-cache but my experience is that ramdisks give you despite that still some speed increase.
分享到:
相关推荐
在提供的文件列表中,"ramdisk for server"可能是Superspeed Ramdisk服务器版的安装程序。安装程序会引导用户完成设置过程,配置内存大小、虚拟磁盘参数等,以便根据服务器的具体需求进行优化。64位版本的安装程序在...
在Linux环境下创建与管理RAMdisk是一项关键技能,尤其对于嵌入式系统开发人员而言。RAMdisk,即在RAM中创建的文件系统,提供了一种快速、高效的存储解决方案,但其内容在系统重启或断电后会丢失。下面,我们将深入...
Linux 下 ramdisk 的制作过程 Linux 下 ramdisk 的制作过程是指在 Linux 系统中创建和修改 ramdisk 的方法, ramdisk 是一种基于内存的文件系统,可以快速地存储和访问文件。ramdisk 的制作过程主要有两种方法,一...
Ramdisk for Windows 2003 Server是一款专为Windows 2003 Server操作系统设计的内存虚拟磁盘软件。它允许用户将一部分物理内存作为高速的临时存储空间,即RAM Disk,来提升系统的运行速度和效率。这个技术的核心在于...
Linux Ramdisk驱动是一种在Linux操作系统中使用的特殊类型的内存驱动,它允许系统将一部分RAM(随机存取存储器)模拟成一个磁盘驱动器。这种方式创建的磁盘被称为“RAM磁盘”或“ramdisk”,其主要优点是速度极快,...
RAM盘是通过使用软件将RAM模拟当做硬盘来使用的一种技术。 相对于传统的硬盘文件访问来说,这种技术可以极大的提高在其上进行的文件访问的速度。但是RAM的易失性也意味着当关闭电源后的数据将会丢失。...
Linux 搭建 NFS 和 Ramdisk 文件系统定义 本文档主要介绍了 Linux 下如何搭建 NFS(Network File System)和 Ramdisk 文件系统,旨在帮助开发者快速了解并搭建这两种文件系统。 1. Linux 建立文件系统 Linux 文件...
在Linux系统中,Ramdisk是一种将内存作为磁盘来使用的技术。它允许系统将一部分物理内存作为临时存储空间,类似于传统的硬盘驱动器。Ramdisk在内存中创建一个虚拟的文件系统,提供快速的读写速度,但数据不会持久化...
本文档详细描述了如何制作一个嵌入式Linux的根文件系统Ramdisk,并且提及了LabVIEW的相关内容,尽管与本文主题不太相关,我们将集中讨论Ramdisk的制作过程。 在制作过程中,首先需要了解什么是Ramdisk。Ramdisk是一...
一个A RamDisk 是你用作一个硬盘分区的一部分内存空间。或者换句话说,你是把内存假设为一个硬盘驱动器,并且你在它的上面存储文件。为什么我们要使用 RamDisk? 好的,如果你知道通常将要使用的文件是被调入内存以...
基于Ramdisk的全内存式Linux系统的设计与实现.pdf 本文主要介绍基于Ramdisk的全内存式Linux系统的设计与实现方案,该方案将整个操作系统运行于内存中,提高了Web服务器在数据读写、响应速度等方面的性能。 关键...
Ramdisk for X86 是一个专为X86架构的计算机设计的内存盘软件。这种技术的核心理念是利用内存的高速特性,替代传统的机械硬盘或固态硬盘,从而实现数据存取的显著加速。 在X86平台上,由于处理器普遍支持PAE...
mkimage -A ppc -O linux -T ramdisk -C gzip -a 0x200000 -e 0x200000 -n "ramdiskimage" -d /tmp/ram_image.gz uRamDisk ``` 这个命令的主要参数解释如下: - `-A ppc`:指定目标架构为PowerPC。 - `-O linux`:...
Linux中的Ramdisk和Initrd是两种在早期启动过程中利用内存创建临时文件系统的技术。它们都是为了在系统启动时提供一个可操作的文件系统环境,但它们的用途和工作方式有所不同。 ## Ramdisk简介 Ramdisk是一种将...
Linux 下 Ramdisk 根文件系统 Linux 下 Ramdisk 根文件系统是将文件系统存储在 RAM 中,以提高文件系统的读写速度和响应速度。下面我们将详细介绍如何在 Linux 中建立 Ramdisk 根文件系统。 1. 已建立好的文件系统...
Linux系统下的ramdisk驱动是一种特殊的存储技术,它利用系统的RAM(随机存取内存)作为临时的文件系统。这种技术在需要快速读写速度且对数据持久性不敏感的应用场景下非常有用,例如系统启动时的临时文件存储、系统...
RamDisk for Vista是一款专为Windows Vista操作系统设计的内存磁盘软件。它利用计算机的RAM(随机存取存储器)创建一个虚拟硬盘,将这个高速的内存空间作为临时存储区域,从而提升系统的运行速度和效率。在本文中,...
Ramdisk是一种在Linux操作系统中使用的虚拟内存磁盘技术,它将一部分系统的物理内存模拟成一个磁盘驱动器,提供快速的存储访问。这种方式利用了内存的高速读写特性,为临时存储或者快速启动应用程序提供了便利。在...
【嵌入式Linux与RAMDisk】嵌入式Linux系统设计中,RAMDisk是一种创新的实现方式,它利用了Linux内核的初始化内存盘(INITRD)技术和对压缩文件系统映像的支持。INITRD允许系统从一个小的内存盘启动,将部分内存作为...
To use these ramdisk files, add > import /init.spectrum.rc to the top of your device's main ramdisk file. Next, add your kernel name to the app. Open init.spectrum.rc and change "Electron" in > ...