注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

gmd20的个人空间

// 编程和生活

 
 
 

日志

 
 

Linux系统的Ramdisk(转)  

2008-08-09 10:12:23|  分类: linux相关 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

原文被放在 :http://lxr.linux.no/linux/Documentation/ramdisk.txt#L29

Ramdisk说明,应该是Linux内核源码自带的文档 linux/Documentation/ramdisk.txt

   1Using the RAM disk block device with Linux   2------------------------------------------   3   4Contents:   5   6        1) Overview   7        2) Kernel Command Line Parameters   8        3) Using "rdev -r"   9        4) An Example of Creating a Compressed RAM Disk  10  11  121) Overview  13-----------  14  15The RAM disk driver is a way to use main system memory as a block device.  It  16is required for initrd, an initial filesystem used if you need to load modules  17in order to access the root filesystem (see Documentation/initrd.txt).  It can  18also be used for a temporary filesystem for crypto work, since the contents  19are erased on reboot.  20  21The RAM disk dynamically grows as more space is required. It does this by using  22RAM from the buffer cache. The driver marks the buffers it is using as dirty  23so that the VM subsystem does not try to reclaim them later.  24  25Also, the RAM disk supports up to 16 RAM disks out of the box, and can  26be reconfigured to support up to 255 RAM disks - change "#define NUM_RAMDISKS"  27in drivers/block/rd.c.  To use RAM disk support with your system, run  28'./MAKEDEV ram' from the /dev directory.  RAM disks are all major number 1, and  29start with minor number 0 for /dev/ram0, etc.  If used, modern kernels use  30/dev/ram0 for an initrd.  31  32The old "ramdisk=<ram_size>" has been changed to "ramdisk_size=<ram_size>" to  33make it clearer.  The original "ramdisk=<ram_size>" has been kept around for  34compatibility reasons, but it may be removed in the future.  35  36The new RAM disk also has the ability to load compressed RAM disk images,  37allowing one to squeeze more programs onto an average installation or  38rescue floppy disk.  39  40  412) Kernel Command Line Parameters  42---------------------------------  43  44        ramdisk_size=N  45        ==============  46  47This parameter tells the RAM disk driver to set up RAM disks of N k size.  The  48default is 4096 (4 MB) (8192 (8 MB) on S390).  49  50        ramdisk_blocksize=N  51        ===================  52  53This parameter tells the RAM disk driver how many bytes to use per block.  The  54default is 1024 (BLOCK_SIZE).  55  56  573) Using "rdev -r"  58------------------  59  60The usage of the word (two bytes) that "rdev -r" sets in the kernel image is  61as follows. The low 11 bits (0 -> 10) specify an offset (in 1 k blocks) of up  62to 2 MB (2^11) of where to find the RAM disk (this used to be the size). Bit  6314 indicates that a RAM disk is to be loaded, and bit 15 indicates whether a  64prompt/wait sequence is to be given before trying to read the RAM disk. Since  65the RAM disk dynamically grows as data is being written into it, a size field  66is not required. Bits 11 to 13 are not currently used and may as well be zero.  67These numbers are no magical secrets, as seen below:  68  69./arch/i386/kernel/setup.c:#define RAMDISK_IMAGE_START_MASK     0x07FF  70./arch/i386/kernel/setup.c:#define RAMDISK_PROMPT_FLAG          0x8000  71./arch/i386/kernel/setup.c:#define RAMDISK_LOAD_FLAG            0x4000  72  73Consider a typical two floppy disk setup, where you will have the  74kernel on disk one, and have already put a RAM disk image onto disk #2.  75  76Hence you want to set bits 0 to 13 as 0, meaning that your RAM disk  77starts at an offset of 0 kB from the beginning of the floppy.  78The command line equivalent is: "ramdisk_start=0"  79  80You want bit 14 as one, indicating that a RAM disk is to be loaded.  81The command line equivalent is: "load_ramdisk=1"  82  83You want bit 15 as one, indicating that you want a prompt/keypress  84sequence so that you have a chance to switch floppy disks.  85The command line equivalent is: "prompt_ramdisk=1"  86  87Putting that together gives 2^15 + 2^14 + 0 = 49152 for an rdev word.  88So to create disk one of the set, you would do:  89  90        /usr/src/linux# cat arch/i386/boot/zImage > /dev/fd0  91        /usr/src/linux# rdev /dev/fd0 /dev/fd0  92        /usr/src/linux# rdev -r /dev/fd0 49152  93  94If you make a boot disk that has LILO, then for the above, you would use:  95        append = "ramdisk_start=0 load_ramdisk=1 prompt_ramdisk=1"  96Since the default start = 0 and the default prompt = 1, you could use:  97        append = "load_ramdisk=1"  98  99 1004) An Example of Creating a Compressed RAM Disk 101---------------------------------------------- 102 103To create a RAM disk image, you will need a spare block device to 104construct it on. This can be the RAM disk device itself, or an 105unused disk partition (such as an unmounted swap partition). For this 106example, we will use the RAM disk device, "/dev/ram0". 107 108Note: This technique should not be done on a machine with less than 8 MB 109of RAM. If using a spare disk partition instead of /dev/ram0, then this 110restriction does not apply. 111 112a) Decide on the RAM disk size that you want. Say 2 MB for this example. 113   Create it by writing to the RAM disk device. (This step is not currently 114   required, but may be in the future.) It is wise to zero out the 115   area (esp. for disks) so that maximal compression is achieved for 116   the unused blocks of the image that you are about to create. 117 118        dd if=/dev/zero of=/dev/ram0 bs=1k count=2048 119 120b) Make a filesystem on it. Say ext2fs for this example. 121 122        mke2fs -vm0 /dev/ram0 2048 123 124c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...) 125   and unmount it again. 126 127d) Compress the contents of the RAM disk. The level of compression 128   will be approximately 50% of the space used by the files. Unused 129   space on the RAM disk will compress to almost nothing. 130 131        dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz 132 133e) Put the kernel onto the floppy 134 135        dd if=zImage of=/dev/fd0 bs=1k 136 137f) Put the RAM disk image onto the floppy, after the kernel. Use an offset 138   that is slightly larger than the kernel, so that you can put another 139   (possibly larger) kernel onto the same floppy later without overlapping 140   the RAM disk image. An offset of 400 kB for kernels about 350 kB in 141   size would be reasonable. Make sure offset+size of ram_image.gz is 142   not larger than the total space on your floppy (usually 1440 kB). 143 144        dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400 145 146g) Use "rdev" to set the boot device, RAM disk offset, prompt flag, etc. 147   For prompt_ramdisk=1, load_ramdisk=1, ramdisk_start=400, one would 148   have 2^15 + 2^14 + 400 = 49552. 149 150        rdev /dev/fd0 /dev/fd0 151        rdev -r /dev/fd0 49552 152 153That is it. You now have your boot/root compressed RAM disk floppy. Some 154users may wish to combine steps (d) and (f) by using a pipe. 155 156-------------------------------------------------------------------------- 157                                                Paul Gortmaker 12/95 158 159Changelog: 160---------- 161 16210-22-04 :      Updated to reflect changes in command line options, remove 163                obsolete references, general cleanup. 164                James Nelson (james4765@gmail.com) 165 166 16712-95 :         Original Document 168
  评论这张
 
阅读(443)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017