Documentation\blockdev\ramdisk

Chinese translated version of  Documentation\blockdev\ramdisk

If you have any comment or update to the content, please contact the
original document maintainer directly.  However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
help.  Contact the Chinese maintainer if this translation is outdated
or if there is a problem with the translation.

Chinese maintainer: 金丽丽 819153113@qq.com

 ---------------------------------------------------------------------
 Documentation\blockdev\ramdisk 的中文翻译

如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
译存在问题,请联系中文版维护者。

中文版维护者: 金丽丽 819153113@qq.com

中文版翻译者: 赵晶  金丽丽 819153113@qq.com

中文版校译者: 赵晶  anana53@qq.com

以下为正文
---------------------------------------------------------------------

Using the RAM disk block device with Linux
使用RAM磁盘块设备与Linux
------------------------------------------
Contents:
目录:
 
1) Overview
1)概述
 
2) Kernel Command Line Parameters
2)内核命令行参数
 
3) Using "rdev -r"
3)使用运行“rdev -r”
 
4) An Example of Creating a Compressed RAM Disk
4)创建压缩RAM磁盘的示例

1) Overview
   概述
-----------
The RAM disk driver is a way to use main system memory as a block device. 
RAM磁盘驱动程序可以将主系统内存用作块设备。

It is required for initrd, an initial filesystem used if you need to load modules in order to access the root filesystem (see Documentation/initrd.txt). 
如果你需要使用加载模块,就会需要初始的文件系统initrd来访问根文件系统(见Documentation/initrd.txt)。

It can also be used for a temporary filesystem for crypto work, since the contents are erased on reboot.
它也可以用于临时文件系统加密的工作,这是因为临时文件系统的内容会在重启时被清除。


The RAM disk dynamically grows as more space is required.
RAM磁盘会动态增长,需要更多的空间。

It does this by using RAM from the buffer cache.
这是通过使用高速缓存RAM实现的。

The driver marks the buffers it is using as dirty so that the VM subsystem does not try to reclaim them later.
驱动程序将它正在使用的缓冲区标记为脏位,因此VM子系统不会尝试将该缓冲区收回。

The RAM disk supports up to 16 RAM disks by default, and can be reconfigured to support an unlimited number of RAM disks (at your own risk). 
在默认情况下,RAM磁盘支持多达16个RAM磁盘,也可以重新配置使它支持无限数量的RAM磁盘(需要你自己承担风险)。

Just change the configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu and (re)build the kernel.
只需更改块设备配置列表中的配置符号BLK_DEV_RAM_COUNT,(重新)启动内核即可。

To use RAM disk support with your system, run './MAKEDEV ram' from the /dev directory. 
为了使RAM磁盘与系统兼容,需要在/dev目录下运行'./MAKEDEV ram'。

RAM disks are all major number 1, and start with minor number 0 for /dev/ram0, etc. 
/dev/ram0等目录下,RAM磁盘的所有主要数字为1,次要数字为0。

If used, modern kernels use /dev/ram0 for an initrd.
如果使用,现代的内核都使用在/ dev/ram0目录下的initrd 。

The new RAM disk also has the ability to load compressed RAM disk images,allowing one to squeeze more programs onto an average installation or rescue floppy disk.
新的RAM磁盘也可以加载压缩RAM磁盘映像,使它获得比平均安装数或救援软盘数更多的程序。

2)Kernel Command Line Parameters
  内核命令行参数
---------------------------------
ramdisk_size=N
==============
This parameter tells the RAM disk driver to set up RAM disks of N k size.  The default is 4096 (4 MB) (8192 (8 MB) on S390).
这个参数告诉RAM磁盘驱动程序来设置RAM磁盘的N K尺寸。默认值是4096(4 MB)(S390为8192(8 MB))。

ramdisk_blocksize=N
===================
This parameter tells the RAM disk driver how many bytes to use per block.  The default is 1024 (BLOCK_SIZE).
这个参数告诉RAM磁盘驱动程序每块使用了多少字节。默认值是1024(BLOCK_SIZE) 。

3) Using "rdev -r"
使用运行“rdev -r”
------------------
The usage of the word (two bytes) that "rdev -r" sets in the kernel image is as follows. The low 11 bits (0 -> 10) specify an offset (in 1 k blocks) of up to 2 MB (2^11) of where to find the RAM disk (this used to be the size).
在内核镜像中设置运行"rdev -r"的方法类似于字(1个字=2个字节)的用法。低11位(0 -> 10)设定的偏移量(在一个块中)的大小可以达到2 MB (即2^11位),而偏移量则用于找到相应的RAM磁盘(这之前被用作尺寸大小)。

Bit 14 indicates that a RAM disk is to be loaded, and bit 15 indicates whether a prompt/wait sequence is to be given before trying to read the RAM disk.
第14位表明RAM磁盘是否被加载,第15位表明在尝试读取RAM磁盘时是否有提示/等待序列。

Since the RAM disk dynamically grows as data is being written into it, a size field is not required. Bits 11 to 13 are not currently used and may as well be zero.
由于RAM磁盘随着数据的写入可以动态增长,一个大小字段不是必需的。 第11至第13位目前还没有使用,可能为零。

These numbers are no magical secrets, as seen below:
这几位的数字一般情况下都固定为0,示例如下:

./arch/x86/kernel/setup.c: #define RAMDISK_IMAGE_START_MASK     0x07FF
./arch/x86/kernel/setup.c: #define RAMDISK_PROMPT_FLAG          0x8000
./arch/x86/kernel/setup.c: #define RAMDISK_LOAD_FLAG            0x4000

Consider a typical two floppy disk setup, where you will have the kernel on disk one, and have already put a RAM disk image onto disk #2.
考虑一个典型的两个软盘的安装,其中一个磁盘加载内核,另一个磁盘加载了一个RAM磁盘镜像。

Hence you want to set bits 0 to 13 as 0, meaning that your RAM disk starts at an offset of 0 kB from the beginning of the floppy.
因此,要设定第0至第13位为0,就意味着RAM磁盘启动软盘从一开始就为0 KB的偏移。

The command line equivalent is: "ramdisk_start=0"
等效的命令行是:“ ramdisk_start = 0 ”

You want bit 14 as one, indicating that a RAM disk is to be loaded.
第14位为1,表明一个RAM磁盘被加载。

The command line equivalent is: "load_ramdisk=1"
等效的命令行是: “ load_ramdisk = 1 ”

You want bit 15 as one, indicating that you want a prompt/keypress sequence so that you have a chance to switch floppy disks.
第15位为1,表明希望有一个提示/按键顺序,使用户有机会切换软盘。

The command line equivalent is: "prompt_ramdisk=1"
等效的命令行是: “ prompt_ramdisk = 1 ”

Putting that together gives 2^15 + 2^14 + 0 = 49152 for an rdev word.
将这些位加起来即为2^15 + 2^14 + 0 = 49152作为rdev的一个字。

So to create disk one of the set, you would do:
因此要创建一个磁盘,要进行的操作为:

/usr/src/linux# cat arch/x86/boot/zImage > /dev/fd0 /usr/src/linux# rdev /dev/fd0 /dev/fd0     /usr/src/linux# rdev -r /dev/fd0 49152

If you make a boot disk that has LILO, then for the above, you would use:
如果想要制作一个包含LILO的启动盘,完成上述操作后,要做以下操作:

append = "ramdisk_start=0 load_ramdisk=1 prompt_ramdisk=1"

Since the default start = 0 and the default prompt = 1, you could use: 
由于默认启动= 0和默认提示= 1 ,可以使用:

append = "load_ramdisk=1"

4) An Example of Creating a Compressed RAM Disk
4)创建压缩RAM磁盘的示例
----------------------------------------------

To create a RAM disk image, you will need a spare block device to construct it on.
要创建一个RAM磁盘镜像,将需要一个备用块设备来构建它。

This can be the RAM disk device itself, or an unused disk partition (such as an unmounted swap partition). For this example, we will use the RAM disk device, "/dev/ram0".
备用块设备可以是RAM磁盘设备本身,也可以是未使用的磁盘分区(如卸载的交换分区) 。

Note: This technique should not be done on a machine with less than 8 MB of RAM. If using a spare disk partition instead of /dev/ram0, then this restriction does not apply.
注:此技术不应该在内存小于8 MB的RAM的机器上做。如果使用的是备用磁盘分区,却不是在/ dev/ram0 目录下,则此限制条件不适用。

a) Decide on the RAM disk size that you want. Say 2 MB for this example.
a)在RAM盘上决定你想要的大小。以2 MB为例:

Create it by writing to the RAM disk device. (This step is not currently required, but may be in the future.)
通过写入RAM磁盘设备来创建。(这一步可能在当前不是必须的,但可能在之后的步骤中用到。)

It is wise to zero out the area (esp. for disks) so that maximal compression is achieved for the unused blocks of the image that you are about to create.
将区域归零(特别是磁盘)从而使你想要创建的未使用的块的镜像达到最大的压缩程度,这是明智的。

dd if=/dev/zero of=/dev/ram0 bs=1k count=2048

b) Make a filesystem on it. Say ext2fs for this example.

 mke2fs -vm0 /dev/ram0 2048
b)创建文件系统。以ext2fs为例:mke2fs -vm0 /dev/ram0 2048

c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
   and unmount it again.
c) 安装,并复制你需要的文件(例如: /etc/* /dev/* ...)
,并将其再次卸载。

d) Compress the contents of the RAM disk.
d) 压缩RAM磁盘内容。

The level of compression
 will be approximately 50% of the space used by the files.
压缩的程度将约为50%的文件所使用的空间。

Unused space on the RAM disk will compress to almost nothing. 
RAM磁盘上未被使用的空间会被压缩到上几乎没有。

dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz

 e) Put the kernel onto the floppy

 dd if=zImage of=/dev/fd0 bs=1k

e) 将内核载入软盘:dd if=zImage of=/dev/fd0 bs=1k

f) Put the RAM disk image onto the floppy, after the kernel.
f) 将内核载入软盘后,将RAM磁盘的镜像载入软盘。

Use an offset that is slightly larger than the kernel, so that you can put another (possibly larger) kernel onto the same floppy later without overlapping the RAM disk image.
使用的偏移量略大于内核,这样当把另一个(可能更大)内核载入同一张软盘时不需要重复加载RAM磁盘的镜像。

An offset of 400 kB for kernels about 350 kB in size would be reasonable.
一个偏移量为400 kB、大约为350 kB大小的内核将是合理的。

Make sure offset+size of ram_image.gz is not larger than the total space on your floppy (usually 1440 kB).

确保ram_image.gz的偏移与大小的和不超过软盘的总空间(一般为1440 kB)。 

dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400

 g) Use "rdev" to set the boot device, RAM disk offset, prompt flag, etc.
 g)使用“rdev”来设置启动设备、RAM磁盘偏移、提示标志等。

For prompt_ramdisk=1, load_ramdisk=1, ramdisk_start=400, one would have 2^15 + 2^14 + 400 = 49552.


对于prompt_ramdisk= 1,load_ramdisk=1,ramdisk_start= 400,将有2^15+2^14+400=49552。

rdev /dev/fd0 /dev/fd0
 rdev -r /dev/fd0 49552

That is it.
命令为:rdev /dev/fd0 /dev/fd0
 
        rdev -r /dev/fd0 49552

You now have your boot/root compressed RAM disk floppy.
你现在有你的boot/root压缩RAM磁盘软盘。

Some
users may wish to combine steps (d) and (f) by using a pipe.
一些用户不妨合并步骤(d)及(f)。

 ------------------------------------------------------------------------- Paul Gortmaker 12/95

 Changelog:

----------

更新日志:
----------

10-22-04 :Updated to reflect changes in command line options, remove
 obsolete references, general cleanup.
James Nelson  (james4765@gmail.com)
10-22-04:更新了命令行选项,删除过时的参考资料,属于一般清理。 詹姆斯·尼尔森(james4765@gmail.com
  

12-95 : Original Document

12-95:原稿

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值