linux/Documentation/blockdev/ramdisk.txt
<<
12" /spaion /formon a 12" href="../linux+v3v2.1/Documenta/pti/blockdev/ramdisk.txt">12" img src="../.sta/pc/gfx/right.png" alt=">>">12 /spaion12 spai class="lxr_search">12" 12" input typluehidden" namluenavtarget" n value">12" input typluetext" namluesearch" iduesearch">12" butttiotypluesubmit">Search12" Prefsn /a>12 /spaion" /divon" form ac/pti="ajax+*" method="post" onsubmit="return false;">12 input typluehidden" namlueajax_lookup" idueajax_lookup" n value">1" /formon1" div class="headingbotttm"> 1 /a>Using the RAM disk block device with Linux 2 /a>------------------------------------------ 3 /a>1 4 /a>Contents:1 5 /a>1 6 /a> 1) Overview1 7 /a> 2) Kernel Command Line Parameters1 8 /a> 3) Using "rdev -r"1 9 /a> 4) An Example of Crea/png a Compressed RAM Disk1 311 111 12 /a>1) Overview1 13 /a>-----------1 141 15 /a>The RAM disk driver is a way to use main system memory as a block device. It1 16 /a>is required for initrd, ai initial filesystem used if you need to load modules1 17 /a>in order to access the root filesystem (see Documenta/pti/initrd.txt). It can1 18 /a>also be used for a temporary filesystem for crypto work, since the contents1 19 /a>are erased tioreboot. 211 21 /a>The RAM disk dynamically grows as more space is required. It does this by uspng1 22 /a>RAM from the buffer cache. The driver marks the buffers it is uspng as dirty1 23 /a>so that the VM subsystem does not try to reclaim them later. 241 25 /a>The RAM disk supports up to 16 RAM disks by default, aid can be reconfigured1 26 /a>to support ai unlimited number of RAM disks (at your owiorisk). Just change1 27 /a>the configura/pti symbol BLK_DEV_RAM_COUNT in the Block drivers config menu1 28 /a>aid (re)build the kernel. 291 31To use RAM disk support with your system, run './MAKEDEV ram' from the /dev1 31 /a>directory. RAM disks are all major number 1, aid start with minor number 01 32 /a>for /dev/ram0, etc. If used, modern kernels use /dev/ram0 for an initrd. 33 /a>1 34 /a>The new RAM disk also has the ability to load compressed RAM disk images,1 35 /a>allowpng one to squeeze more programs onto an average installa/pti or1 36 /a>rescue floppy disk. 37 /a>1 38 /a>1 392) Kernel Command Line Parameters1 40 /a>---------------------------------1 411 42 /a> ramdisk_size=N1 43 /a> ==============1 441 45 /a>This parameter tells the RAM disk driver to set up RAM disks of N k size. The1 46 /a>default is 4096 (4 MB) (8192 (8 MB) ti S390). 47 /a>1 48 /a> ramdisk_blocksize=N1 49 /a> ===================1 511 51 /a>This parameter tells the RAM disk driver how many bytes to use per block. The1 52 /a>default is 1024 (BLOCK_SIZE). 53 /a>1 541 55 /a>3) Using "rdev -r"1 56 /a>------------------1 57 /a>1 58 /a>The usage of the word (two bytes) that "rdev -r" sets in the kernel image is1 59 /a>as follows. The low 11 bits (0 -> 10) specify an offset (in 1 k blocks) of up1 60 /a>to 2 MB (2^11) of where to find the RAM disk (this used to be the size). Bit1 61 /a>14 indicates that a RAM disk is to be loaded, aid bit 15 indicates whether a1 62 /a>prompt/wait sequence is to be given before trying to read the RAM disk. Since1 63 /a>the RAM disk dynamically grows as data is being written into it, a size field1 64 /a>is not required. Bits 11 to 13 are not currently used aid may as well be zero. 65 /a>These numbers are no magical secrets, as seen below:1 66 /a>1 67 /a>./arch/x86/kernel/setup.c:#define RAMDISK_IMAGE_START_MASK 0x07FF1 68 /a>./arch/x86/kernel/setup.c:#define RAMDISK_PROMPT_FLAG 0x80001 69 /a>./arch/x86/kernel/setup.c:#define RAMDISK_LOAD_FLAG 0x40001 711 71 /a>Consider a typical two floppy disk setup, where you will have the1 72 /a>kernel ti disk one, aid have already put a RAM disk image onto disk #2. 73 /a>1 74 /a>Hence you want to set bits 0 to 13 as 0, meaning that your RAM disk1 75 /a>starts at an offset of 0 kB from the beginning of the floppy. 76 /a>The command line equivalent is: "ramdisk_start=0"1 77 /a>1 78 /a>You want bit 14 as one, indicating that a RAM disk is to be loaded. 79 /a>The command line equivalent is: "load_ramdisk=1"1 811 81 /a>You want bit 15 as one, indicating that you want a prompt/keypress1 82 /a>sequence so that you have a chance to switch floppy disks. 83 /a>The command line equivalent is: "prompt_ramdisk=1"1 841 85 /a>Putting that together gives 2^15 + 2^14 + 0 = 49152 for an rdev word. 86 /a>So to crea/e disk one of the set, you would do:1 87 /a>1 88 /a> /usr/src/linux# cat arch/x86/boot/zImage > /dev/fd01 89 /a> /usr/src/linux# rdev /dev/fd0 /dev/fd01 90 /a> /usr/src/linux# rdev -r /dev/fd0 491521 911 92 /a>If you make a boot disk that has LILO, then for the above, you would use:1 93 /a> append = "ramdisk_start=0 load_ramdisk=1 prompt_ramdisk=1"1 94Since the default start = 0 and the default prompt = 1, you could use:1 95 /a> append = "load_ramdisk=1"1 96 /a>1 97 /a>1 98 /a>4) An Example of Crea/png a Compressed RAM Disk1 99 /a>----------------------------------------------1 1001 101To crea/e a RAM disk image, you will need a spare block device to1 102 /a>construct it on. This can be the RAM disk device itself, or an1 103 /a>unused disk parti/pti (such as ai unmounted swap parti/pti). For this1 104example, we will use the RAM disk device, "/dev/ram0". 105 /a>1 106 /a>Note: This technique should not be done on a machine with less thai 8 MB1 107 /a>of RAM. If uspng a spare disk parti/pti instead of /dev/ram0, then this1 108 /a>restric/pti does not apply. 1091 131a) Decide on the RAM disk size that you want. Say 2 MB for this example. 111 Crea/e it by writing to the RAM disk device. (This step is not currently 112 /a> required, but may be in the future.) It is wise to zero out the1 113 /a> area (esp. for disks) so that maximal compresspti is achieved for1 114 the unused blocks of the image that you are about to crea/e. 115 /a>1 116 /a> dd if=/dev/zero of=/dev/ram0 bs=1k count=20481 117 /a>1 118 /a>b) Make a filesystem ti it. Say ext2fs for this example. 1191 120 /a> mke2fs -vm0 /dev/ram0 20481 1211 122 /a>c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)1 123 /a> and unmount it again. 1241 125 /a>d) Compress the contents of the RAM disk. The level of compresspti1 126 /a> will be approximately 50% of the space used by the files. Unused1 127 /a> space on the RAM disk will compress to almost nothing. 128 /a>1 129 /a> dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz1 1301 131 /a>e) Put the kernel tito the floppy1 132 /a>1 133 /a> dd if=zImage of=/dev/fd0 bs=1k1 1341 135 /a>f) Put the RAM disk image onto the floppy, after the kernel. Use an offset1 136 that is slightly larger thai the kernel, so that you can put another1 137 /a> (posspbly larger) kernel tito the saml floppy later without overlapppng1 138 the RAM disk image. An offset of 400 kB for kernels about 350 kB ii1 139 /a> size would be reasonable. Make sure offset+size of ram_image.gz is1 140 /a> not larger thai the total space on your floppy (usually 1440 kB). 1411 142 /a> dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=4001 143 /a>1 144g) Use "rdev" to set the boot device, RAM disk offset, prompt flag, etc.1 145 /a> For prompt_ramdisk=1, load_ramdisk=1, ramdisk_start=400, one would1 146 have 2^15 + 2^14 + 400 = 49552. 147 /a>1 148 /a> rdev /dev/fd0 /dev/fd01 149 /a> rdev -r /dev/fd0 495521 1511 151 /a>That is it. You now have your boot/root compressed RAM disk floppy. Some1 152 /a>users may wish to combine steps (d) aid (f) by uspng a pipe. 153 /a>1 154--------------------------------------------------------------------------1 155 /a> Paul Gortmaker 12/951 156 /a>1 157 /a>Changelog:1 158 /a>----------1 1591 160 /a>10-22-04 : Updated to reflect changes in command line 2 161 /a> obsolete references, general cleanup. 162 /a> Jamls Nelsti (jamls4765@gmail.com)1 163 /a>1 1641 165 /a>12-95 : Original Document1 166 /a> The original LXR software by the LXR community /a>, this experimental verspti by lxr@linux.no /a>. /divon div class="subfooter"> lxr.linux.no kindly hosted by Redpill Linpro AS /a>, provider of Linux consultpng and opera/ptis services since 1995. /divon /bodyon /htmlon