Linux系统中的RAMdisk设置


内存盘:在你的内存有较多剩余的情况下,可以考虑使用RAMdisk的技术,将内存当作硬盘使用,提高程序运行速度。

搜索关键字:

http://search.aol.com/aol/search?q=centos+how+to+set+ramdisk

参考链接:

先总结处理步骤:

1.设定Ramdisk支持&内存盘大小(需重启)
# dmesg | grep RAMDISK

# ls -l /dev/ram*

# vi /etc/grub.conf
...
kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00 ramdisk_size=131072
...
2.格式化内存盘
# mke2fs -m 0 /dev/ram0
3.挂载内存盘至某一指定目录
# mount /dev/ram0 /home/ramdisk
4.修改目录权限
# chown -R crazy:root /home/ramdisk

====

Ramdisk: How do you install and set up Ramdisk under Linux (CentOS, RHEL, Fedora)?

Ramdisk is very good to have if you want something to stay in memory. Files in memory makes it so you can access them without having to access hard drive all the time. Perfect candidates would be things which do not change eg. web images or downloadable files, etc. If you have Linux Kernel 2.4 or later, you already have support of ramdisk built in.{Ramdisk对于某些特定的应用(比如:Web图片、下载文件)来说是非常有用的,它可以让某些内容待在内存而不是硬盘中,从而提高访问速度,如果你的Linux内核是2.4及以后版本的,那已经内建了Ramdisk功能} You can check if ramdisk is setup by doing:

# dmesg | grep RAMDISK
RAMDISK driver initialized: 16 RAM disks of 16384K size 1024 blocksize

You should get above output on CentOS and RHEL. Other linux flavors will have similar output as well. If you would like to see how they are named and what you would need to refer to, do the following:

# ls -l /dev/ram*
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ram -> ram1
brw-rw---- 1 root disk 1, 0 Apr 24 12:05 /dev/ram0
brw-rw---- 1 root disk 1, 1 Apr 24 12:05 /dev/ram1
brw-rw---- 1 root disk 1, 10 Apr 24 12:05 /dev/ram10
brw-rw---- 1 root disk 1, 11 Apr 24 12:05 /dev/ram11
brw-rw---- 1 root disk 1, 12 Apr 24 12:05 /dev/ram12
brw-rw---- 1 root disk 1, 13 Apr 24 12:05 /dev/ram13
brw-rw---- 1 root disk 1, 14 Apr 24 12:05 /dev/ram14
brw-rw---- 1 root disk 1, 15 Apr 24 12:05 /dev/ram15
brw-rw---- 1 root disk 1, 2 Apr 24 12:05 /dev/ram2
brw-rw---- 1 root disk 1, 3 Apr 24 12:05 /dev/ram3
brw-rw---- 1 root disk 1, 4 Apr 24 12:05 /dev/ram4
brw-rw---- 1 root disk 1, 5 Apr 24 12:05 /dev/ram5
brw-rw---- 1 root disk 1, 6 Apr 24 12:05 /dev/ram6
brw-rw---- 1 root disk 1, 7 Apr 24 12:05 /dev/ram7
brw-rw---- 1 root disk 1, 8 Apr 24 12:05 /dev/ram8
brw-rw---- 1 root disk 1, 9 Apr 24 12:05 /dev/ram9
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ramdisk -> ram0

All those ramdisks listed have same size. In above example, they are all 16MB. Let us change that so we have more space allowed. Note that I say allowed and not allocated. We allocate space in one of the later steps by formatting one of the drives above. Let us set it up so we have 128 MB. Since this has to be in multiples of 1024, we will setup Ramdisk to have 131072K.{单位是:KB}

# vi /etc/grub.conf

Find first line which looks similar to following:

kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00

add ramdisk_size=131072 to the end of the line. Now your line should look like:

kernel /vmlinuz-2.6.9-42.0.10.EL ro root=/dev/VolGroup00/LogVol00 ramdisk_size=131072

Save and exit grub.conf. At this point you have it configured to have ramdisk with new size but it does not take effect until you reboot your system. Once you have rebooted your system, we can start doing rest of configurations.

# mke2fs -m 0 /dev/ram0

This will format the ram0 ramdrive for us to use. At this point, kernel will allocate space for you. Let us setup Ramdisk mount point so we can use it. We will also have it be owned by user “sunny” so that user can read/write to that mount.

mkdir /home/ramdisk
mount /dev/ram0 /home/ramdisk
chown -R crazy:root /home/ramdisk

At this point you should be able to type: mount and see your new Ramdisk drive mounted on /home/ramdisk

Remember that everything you put on this drive will be gone if you reboot your server.{请牢记:你放在这个drive上的任何东西都会在重启服务器之后丢失} If you unmounted the Ramdisk drive and remounted it, your files will still be there. It is because your system has that much ram set aside for your Ramdisk and will not use it for anything else.{不过如果你只是先卸载Ramdisk分区然后再次挂载,你的文件并不会丢失,因为系统已经将那块内存分配给了内存盘所以不会挪作他用,文件等信息也就不会丢失了} If you would like to setup Ramdisk the same next time you boot up, add these lines to your /etc/rc.local files.{如果你想在每次开机启动的时候自动启动Ramdisk,你可以在“/etc/rc.local”文件中添加以下几行进行设置}

# vim /etc/rc.local

mke2fs -m 0 /dev/ram0
mount /dev/ram0 /home/ramdisk
chown -R crazy:root /home/ramdisk

===========

DISCLAIMER(免责声明): Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

,

《“Linux系统中的RAMdisk设置”》 有 1 条评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注