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:Hu Feijun <935620544@qq.com>
---------------------------------------------------------------------
Documentation/blockdev/ramdisk 的中文翻译

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

中文版维护者: 胡飞军  Hu Feijun <935620544@qq.com>
中文版翻译者: 胡飞军  Hu Feijun <935620544@qq.com>
中文版校译者: 胡飞军  Hu Feijun <935620544@qq.com>

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

Using the RAM disk block device with Linux
------------------------------------------

Contents:

 1) Overview
 2) Kernel Command Line Parameters
 3) Using "rdev -r"
 4) An Example of Creating a Compressed RAM Disk

在Linux上使用RAM磁盘块设备
------------------------------------------

内容:
    1)概述
    2)Kernel命令行参数
    3)使用“rdev -r”
    4)创建压缩RAM磁盘的例子 

 
 
1) Overview
-----------

1)概述
-----------

 


The RAM disk driver is a way to use main system memory as a block device.  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).  It can
also be used for a temporary filesystem for crypto work, since the contents
are erased on reboot.

RAM磁盘驱动器是利用主系统内存作为块设备。如果你需要装载模块来获得根文件
系统(见Documentation/initrd.txt),那么就必须使用初始化文件系统,而这又需要
用到RAM磁盘驱动器。RAM磁盘驱动器作为加密工作的临时文件系统,因为当重启是磁
盘上的内容全都被擦去。

 

The RAM disk dynamically grows as more space is required. It does this by using
RAM from the buffer cache. The driver marks the buffers it is using as dirty
so that the VM subsystem does not try to reclaim them later.

RAM磁盘能够动态地增加空间,这是通过使用缓冲区的RAM实现的。驱动器将缓冲区标示
为正在使用中,因此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).  Just change
the configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu
and (re)build the kernel.

在默认情况下,RAM磁盘支持多达16个RAM磁盘,在重新配置后可以支持无限数量
的RAM磁盘(在你自己的磁盘上)。只要改变块驱动器config菜单中的 BLK_DEV_RAM_COUNT,
然后重建kernel。

 

To use RAM disk support with your system, run './MAKEDEV ram' from the /dev
directory.  RAM disks are all major number 1, and start with minor number 0
for /dev/ram0, etc.  If used, modern kernels use /dev/ram0 for an initrd.

要使用RAM磁盘支持文件系统,你需要运行/dev目录下的'./MAKEDEV ram'。大多数
RAM磁盘都是数字1,你要启动的是数字0的RAM磁盘。如果使用了,现代内核使用
/dev/ram0 来初始化。

 

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).

 ramdisk_blocksize=N
 ===================

This parameter tells the RAM disk driver how many bytes to use per block.  The
default is 1024 (BLOCK_SIZE).

2)Kernel命令行参数
---------------------------------

    ramdisk_size=N
 ==============

这个参数告诉RAM磁盘驱动器建立一个N k大小的RAM磁盘。默认情况下是4096(4MB)
(在S390上是8192(8MB) )。

 

3) Using "rdev -r"
------------------

3)使用"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). 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. 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.
These numbers are no magical secrets, as seen below:

./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

内核映象中的"rdev -r"这个词(2bytes)的作用如下所述。低11为(0 -> 10)指定一个
0到2 MB(2^11)的偏移量(在1 k块中),表示到哪里去找RAM磁盘(也是磁盘的大小)。
第14位表示RAM磁盘将要被装载,第15位表示在试图读RAM磁盘前是否需要给予提示/等待
序列。由于RAM磁盘随着数据的写入动态地增加空间,所以不需要表示磁盘大小的字段。
位11到13目前未使用,也可以设置为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.

考虑一个典型的两个软盘的设置,你将kernel安装在软盘1上,也已将RAM磁盘
映象安装到软盘2上。

 

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.
The command line equivalent is: "ramdisk_start=0"

因此设置位0到13为0,表示RAM磁盘是从软盘的开始处偏移量为0 KB
处开始的。相关的命令行等式为:"ramdisk_start=0"。

 

You want bit 14 as one, indicating that a RAM disk is to be loaded.
The command line equivalent is: "load_ramdisk=1"

设置位14为1,表示RAM磁盘将要被装载。相关的命令行等式
为"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.
The command line equivalent is: "prompt_ramdisk=1"

设置位15为1,表示需要一个提示/键盘按键队列,以便有机会开关软盘。
相关的命令行等式为: "prompt_ramdisk=1"。

Putting that together gives 2^15 + 2^14 + 0 = 49152 for an rdev word.
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

对于字rdev,将这些放在一起就有了 2^15 + 2^14 + 0 = 49152 。因此创建一个
磁盘,你将要做:


 /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:
 append = "ramdisk_start=0 load_ramdisk=1 prompt_ramdisk=1"
Since the default start = 0 and the default prompt = 1, you could use:
 append = "load_ramdisk=1"

如果你创建的引导盘有LILO,那么对于以上内容,你将使用:
    append = "ramdisk_start=0 load_ramdisk=1 prompt_ramdisk=1"
由于默认 start = 0, prompt = 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. 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磁盘映像。这个备用的块设备可以是
RAM磁盘设备本身,也可以是一个没有使用的磁盘分区(如卸载交换分区)。在
这个例子中,我们将使用RAM磁盘设备,"/dev/ram0"。

 

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.

注意:这一操作不可以在RAM少于8 MB 的机器上使用。如果使用备用的磁盘分
区来替代 /dev/ram0,那么就没有这一限制。

a) Decide on the RAM disk size that you want. Say 2 MB for this example.
   Create it by writing to the RAM disk device. (This step is not currently
   required, but may be in the future.) 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

c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
   and unmount it again.

d) Compress the contents of the RAM disk. The level of compression
   will be approximately 50% of the space used by the files. Unused
   space on the RAM disk will compress to almost nothing.

 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

f) Put the RAM disk image onto the floppy, after the kernel. 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. An offset of 400 kB for kernels about 350 kB in
   size would be reasonable. Make sure offset+size of ram_image.gz is
   not larger than the total space on your floppy (usually 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.
   For prompt_ramdisk=1, load_ramdisk=1, ramdisk_start=400, one would
   have 2^15 + 2^14 + 400 = 49552.

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

 
 
a)确定你需要的RAM磁盘大小。例如2 MB。通过将其写入RAM磁盘设备来创建。
  (现不需要这一步,但以后可能需要。)将这一区域清零是一种明智的做法(
  尤其是对磁盘),以便使你将要创建的映射块达到最大的压缩量。

    dd if=/dev/zero of=/dev/ram0 bs=1k count=2048
 
b)在磁盘上创建一个文件系统。在这个例子中为 ext2fs。

    mke2fs -vm0 /dev/ram0 2048
 
c)挂载它,复制你想要挂载的文件(如: /etc/* /dev/* ...),然后再卸载它。

d)压缩RAM磁盘的内容。压缩的级别大约为文件所使用的空间的50%。RAM上未
  使用的空间压缩后将不存在。

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

e)将kernel载入软盘中。

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

f)载入kernel后,将RAM磁盘映射载入软盘中。使用比kernel要大一点的偏移量,
  以便你稍后中将另一个(可能更大)kernel载入同一个软盘,而不会将RAM磁
  盘映射重叠。给一个359 KB大小的kernel 400 KB的偏移量是比较合理的。确保
  ram_image.gz的offset+size小于软盘的大小(通常为1440 KB).
 
    dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
 
g)使用"rdev" 设置引导设备,RAM磁盘便宜,提示标志等。如果
  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. You now have your boot/root compressed RAM disk floppy. Some
users may wish to combine steps (d) and (f) by using a pipe.

--------------------------------------------------------------------------
      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)


12-95 :  Original Document

 

以上就是RAM磁盘驱动。你现在已有了boot/root压缩RAM磁盘软盘。有些使用者可
能希望使用导管将步骤(d)和(f)合并。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值