1*4882a593Smuzhiyun========================================== 2*4882a593SmuzhiyunUsing the RAM disk block device with Linux 3*4882a593Smuzhiyun========================================== 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun.. Contents: 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun 1) Overview 8*4882a593Smuzhiyun 2) Kernel Command Line Parameters 9*4882a593Smuzhiyun 3) Using "rdev" 10*4882a593Smuzhiyun 4) An Example of Creating a Compressed RAM Disk 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun1) Overview 14*4882a593Smuzhiyun----------- 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunThe RAM disk driver is a way to use main system memory as a block device. It 17*4882a593Smuzhiyunis required for initrd, an initial filesystem used if you need to load modules 18*4882a593Smuzhiyunin order to access the root filesystem (see Documentation/admin-guide/initrd.rst). It can 19*4882a593Smuzhiyunalso be used for a temporary filesystem for crypto work, since the contents 20*4882a593Smuzhiyunare erased on reboot. 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunThe RAM disk dynamically grows as more space is required. It does this by using 23*4882a593SmuzhiyunRAM from the buffer cache. The driver marks the buffers it is using as dirty 24*4882a593Smuzhiyunso that the VM subsystem does not try to reclaim them later. 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunThe RAM disk supports up to 16 RAM disks by default, and can be reconfigured 27*4882a593Smuzhiyunto support an unlimited number of RAM disks (at your own risk). Just change 28*4882a593Smuzhiyunthe configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu 29*4882a593Smuzhiyunand (re)build the kernel. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunTo use RAM disk support with your system, run './MAKEDEV ram' from the /dev 32*4882a593Smuzhiyundirectory. RAM disks are all major number 1, and start with minor number 0 33*4882a593Smuzhiyunfor /dev/ram0, etc. If used, modern kernels use /dev/ram0 for an initrd. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunThe new RAM disk also has the ability to load compressed RAM disk images, 36*4882a593Smuzhiyunallowing one to squeeze more programs onto an average installation or 37*4882a593Smuzhiyunrescue floppy disk. 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun2) Parameters 41*4882a593Smuzhiyun--------------------------------- 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun2a) Kernel Command Line Parameters 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun ramdisk_size=N 46*4882a593Smuzhiyun Size of the ramdisk. 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunThis parameter tells the RAM disk driver to set up RAM disks of N k size. The 49*4882a593Smuzhiyundefault is 4096 (4 MB). 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun2b) Module parameters 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun rd_nr 54*4882a593Smuzhiyun /dev/ramX devices created. 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun max_part 57*4882a593Smuzhiyun Maximum partition number. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun rd_size 60*4882a593Smuzhiyun See ramdisk_size. 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun3) Using "rdev" 63*4882a593Smuzhiyun--------------- 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun"rdev" is an obsolete, deprecated, antiquated utility that could be used 66*4882a593Smuzhiyunto set the boot device in a Linux kernel image. 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunInstead of using rdev, just place the boot device information on the 69*4882a593Smuzhiyunkernel command line and pass it to the kernel from the bootloader. 70*4882a593Smuzhiyun 71*4882a593SmuzhiyunYou can also pass arguments to the kernel by setting FDARGS in 72*4882a593Smuzhiyunarch/x86/boot/Makefile and specify in initrd image by setting FDINITRD in 73*4882a593Smuzhiyunarch/x86/boot/Makefile. 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunSome of the kernel command line boot options that may apply here are:: 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun ramdisk_start=N 78*4882a593Smuzhiyun ramdisk_size=M 79*4882a593Smuzhiyun 80*4882a593SmuzhiyunIf you make a boot disk that has LILO, then for the above, you would use:: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun append = "ramdisk_start=N ramdisk_size=M" 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun4) An Example of Creating a Compressed RAM Disk 85*4882a593Smuzhiyun----------------------------------------------- 86*4882a593Smuzhiyun 87*4882a593SmuzhiyunTo create a RAM disk image, you will need a spare block device to 88*4882a593Smuzhiyunconstruct it on. This can be the RAM disk device itself, or an 89*4882a593Smuzhiyununused disk partition (such as an unmounted swap partition). For this 90*4882a593Smuzhiyunexample, we will use the RAM disk device, "/dev/ram0". 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunNote: This technique should not be done on a machine with less than 8 MB 93*4882a593Smuzhiyunof RAM. If using a spare disk partition instead of /dev/ram0, then this 94*4882a593Smuzhiyunrestriction does not apply. 95*4882a593Smuzhiyun 96*4882a593Smuzhiyuna) Decide on the RAM disk size that you want. Say 2 MB for this example. 97*4882a593Smuzhiyun Create it by writing to the RAM disk device. (This step is not currently 98*4882a593Smuzhiyun required, but may be in the future.) It is wise to zero out the 99*4882a593Smuzhiyun area (esp. for disks) so that maximal compression is achieved for 100*4882a593Smuzhiyun the unused blocks of the image that you are about to create:: 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun dd if=/dev/zero of=/dev/ram0 bs=1k count=2048 103*4882a593Smuzhiyun 104*4882a593Smuzhiyunb) Make a filesystem on it. Say ext2fs for this example:: 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun mke2fs -vm0 /dev/ram0 2048 107*4882a593Smuzhiyun 108*4882a593Smuzhiyunc) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...) 109*4882a593Smuzhiyun and unmount it again. 110*4882a593Smuzhiyun 111*4882a593Smuzhiyund) Compress the contents of the RAM disk. The level of compression 112*4882a593Smuzhiyun will be approximately 50% of the space used by the files. Unused 113*4882a593Smuzhiyun space on the RAM disk will compress to almost nothing:: 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz 116*4882a593Smuzhiyun 117*4882a593Smuzhiyune) Put the kernel onto the floppy:: 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun dd if=zImage of=/dev/fd0 bs=1k 120*4882a593Smuzhiyun 121*4882a593Smuzhiyunf) Put the RAM disk image onto the floppy, after the kernel. Use an offset 122*4882a593Smuzhiyun that is slightly larger than the kernel, so that you can put another 123*4882a593Smuzhiyun (possibly larger) kernel onto the same floppy later without overlapping 124*4882a593Smuzhiyun the RAM disk image. An offset of 400 kB for kernels about 350 kB in 125*4882a593Smuzhiyun size would be reasonable. Make sure offset+size of ram_image.gz is 126*4882a593Smuzhiyun not larger than the total space on your floppy (usually 1440 kB):: 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400 129*4882a593Smuzhiyun 130*4882a593Smuzhiyung) Make sure that you have already specified the boot information in 131*4882a593Smuzhiyun FDARGS and FDINITRD or that you use a bootloader to pass kernel 132*4882a593Smuzhiyun command line boot options to the kernel. 133*4882a593Smuzhiyun 134*4882a593SmuzhiyunThat is it. You now have your boot/root compressed RAM disk floppy. Some 135*4882a593Smuzhiyunusers may wish to combine steps (d) and (f) by using a pipe. 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun Paul Gortmaker 12/95 139*4882a593Smuzhiyun 140*4882a593SmuzhiyunChangelog: 141*4882a593Smuzhiyun---------- 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunSEPT-2020 : 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun Removed usage of "rdev" 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun10-22-04 : 148*4882a593Smuzhiyun Updated to reflect changes in command line options, remove 149*4882a593Smuzhiyun obsolete references, general cleanup. 150*4882a593Smuzhiyun James Nelson (james4765@gmail.com) 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun12-95 : 153*4882a593Smuzhiyun Original Document 154