Use ramdisk under Linux ...

xiaoxiao2021-03-06  53

First, what is ramdisk

As the name, RAM: memory, Disk: Disk, Ramdisk means using a part of memory space to simulate a hard disk partition. However, this is not very useful today, but now the memory is getting cheaper now. For some we want to have a high speed, you can still try it.

Second, create a ramdisk

In fact, it is very simple to create a ramdisk, because Redhat Linux 6.0 supports ramdisk in default installation, you only need to format a ramdisk and you can put it on a directory.

1, check all available ramdisk:

LS -AL / dev / ram *

This will list the ramdisk you are now available, which don't take up memory now, unless you format it.

2. Create a ramdisk:

MKE2FS / DEV / RAM0

Execute this command will appear the following prompt

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

If the operation failed, it may be because your kernel does not support RamDisk, then you only have reconfiguration, compile the kernel. Sets config_blk_dev_ram to enable when configured.

3, use it on MOUNT:

MKDIR / TMP / RAMDISK0 New Contents

Mount / dev / ram0 / tmp / ramdisk0 puts its mount to the newly created directory

In this way, we can use this new Ramdisk - / TMP / RAMDISK0

Also, we can perform a DF command to see the size of the RAMDisk:

> DF-K / DEV / RAM0

FileSystem 1K-block Used Available Use% MOUNTED ON

/ DEV / RAM0 3963 13 3746 0% / TMP / RAMDISK0

It should be noted that this part is refreshed when this part is memory, and will refresh this area when the system is restarted. So don't put any data without copying in this area. If you have modified this directory and need to retain these modifications, some methods are taken for backup. That is, this directory can only be used to temporarily store data in order to improve access speed.

Third, create a size suitable ramdisk

Above we created a ramdisk, but could not specify the size, now let's learn how to create a size of Ramdisk.

1, use the LILO configuration:

We join a line in the lilo.conf file:

Ramdisk_size = 10000 (if it is an old version of the kernel, write ramdisk = 10000)

Then run / sbin / lilo to generate new LILO.

This way when you restart your computer, RamDisk's default size will be 10m.

2, use /etc/conf.modules configuration:

If your kernel compiles ramdisk in the form of a module, then determine the size of RAMDISK when loading. That is, you can do it by modifying /etc/conf.modules, add: options rd rd_size = 10000

Of course, you can also specify parameters to ISMOD in the command line:

INSMOD RD RD_SIZE = 10000

When using the above two methods, we have to perform the following commands to use it:

MKE2FS / DEV / RAM0

MKDIR / TMP / RAMDISK0

Mount / dev / ram0 / tmp / ramdisk0

And when not in use, it should be performed:

Umount / TMP / RAMDISK0

If you use INSMOD to load the module, you should execute it:

RMMOD RD

Fourth, use a instance of Ramdisk

Below, we explain its application through an instance of using RAMDISK to do a web server.

1. First move the web server to another place

MV / Home / httpd / / home / httpd_real

MKDIR / HOME / HTTPD

MKDIR / HOME / HTTPD / CGI-BIN

MKDIR / HOME / HTTPD / HTML

MKDIR / HOME / HTTPD / ICONS

2, add the following command to /etc/rc.d/init.d/httpd.init:

/ SBIN / MKFS -T EXT2 / DEV / RAM0

/ SBIN / MKFS -T EXT2 / DEV / RAM1

/ sbin / mkfs -t ext2 / dev / ram2

Mount / dev / ram0 / home / httpd / cgi-bin

Mount / dev / ram1 / home / httpd / icons

Mount / dev / ram2 / home / httpd / html

Tar -c / home / httpd_real -c. | tar -c / home / httpd -x

This is ok, but keep in mind that when you update the data, you should update the httpd_real directory without updating the httpd directory, otherwise all updates will be lost when the system is restarted. You'd better set a stron process so that it monitors whether HTTPD_REAL has changed, and a change will copy it to ramdisk.

V. Use ramdisk to do / TMP directory

I still want to recommend a more cool way. If your memory is too much, you can do some of them as a / tmp directory, which will greatly improve your system execution speed. Moreover, / TMP will be deleted when the system is restarted, how comfortable.

转载请注明原文地址:https://www.9cbs.com/read-115177.html

New Post(0)