ramdisk.rst 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. ==========================================
  2. Using the RAM disk block device with Linux
  3. ==========================================
  4. .. Contents:
  5. 1) Overview
  6. 2) Kernel Command Line Parameters
  7. 3) Using "rdev"
  8. 4) An Example of Creating a Compressed RAM Disk
  9. 1) Overview
  10. -----------
  11. The RAM disk driver is a way to use main system memory as a block device. It
  12. is required for initrd, an initial filesystem used if you need to load modules
  13. in order to access the root filesystem (see Documentation/admin-guide/initrd.rst). It can
  14. also be used for a temporary filesystem for crypto work, since the contents
  15. are erased on reboot.
  16. The RAM disk dynamically grows as more space is required. It does this by using
  17. RAM from the buffer cache. The driver marks the buffers it is using as dirty
  18. so that the VM subsystem does not try to reclaim them later.
  19. The RAM disk supports up to 16 RAM disks by default, and can be reconfigured
  20. to support an unlimited number of RAM disks (at your own risk). Just change
  21. the configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu
  22. and (re)build the kernel.
  23. To use RAM disk support with your system, run './MAKEDEV ram' from the /dev
  24. directory. RAM disks are all major number 1, and start with minor number 0
  25. for /dev/ram0, etc. If used, modern kernels use /dev/ram0 for an initrd.
  26. The new RAM disk also has the ability to load compressed RAM disk images,
  27. allowing one to squeeze more programs onto an average installation or
  28. rescue floppy disk.
  29. 2) Parameters
  30. ---------------------------------
  31. 2a) Kernel Command Line Parameters
  32. ramdisk_size=N
  33. Size of the ramdisk.
  34. This parameter tells the RAM disk driver to set up RAM disks of N k size. The
  35. default is 4096 (4 MB).
  36. 2b) Module parameters
  37. rd_nr
  38. /dev/ramX devices created.
  39. max_part
  40. Maximum partition number.
  41. rd_size
  42. See ramdisk_size.
  43. 3) Using "rdev"
  44. ---------------
  45. "rdev" is an obsolete, deprecated, antiquated utility that could be used
  46. to set the boot device in a Linux kernel image.
  47. Instead of using rdev, just place the boot device information on the
  48. kernel command line and pass it to the kernel from the bootloader.
  49. You can also pass arguments to the kernel by setting FDARGS in
  50. arch/x86/boot/Makefile and specify in initrd image by setting FDINITRD in
  51. arch/x86/boot/Makefile.
  52. Some of the kernel command line boot options that may apply here are::
  53. ramdisk_start=N
  54. ramdisk_size=M
  55. If you make a boot disk that has LILO, then for the above, you would use::
  56. append = "ramdisk_start=N ramdisk_size=M"
  57. 4) An Example of Creating a Compressed RAM Disk
  58. -----------------------------------------------
  59. To create a RAM disk image, you will need a spare block device to
  60. construct it on. This can be the RAM disk device itself, or an
  61. unused disk partition (such as an unmounted swap partition). For this
  62. example, we will use the RAM disk device, "/dev/ram0".
  63. Note: This technique should not be done on a machine with less than 8 MB
  64. of RAM. If using a spare disk partition instead of /dev/ram0, then this
  65. restriction does not apply.
  66. a) Decide on the RAM disk size that you want. Say 2 MB for this example.
  67. Create it by writing to the RAM disk device. (This step is not currently
  68. required, but may be in the future.) It is wise to zero out the
  69. area (esp. for disks) so that maximal compression is achieved for
  70. the unused blocks of the image that you are about to create::
  71. dd if=/dev/zero of=/dev/ram0 bs=1k count=2048
  72. b) Make a filesystem on it. Say ext2fs for this example::
  73. mke2fs -vm0 /dev/ram0 2048
  74. c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
  75. and unmount it again.
  76. d) Compress the contents of the RAM disk. The level of compression
  77. will be approximately 50% of the space used by the files. Unused
  78. space on the RAM disk will compress to almost nothing::
  79. dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
  80. e) Put the kernel onto the floppy::
  81. dd if=zImage of=/dev/fd0 bs=1k
  82. f) Put the RAM disk image onto the floppy, after the kernel. Use an offset
  83. that is slightly larger than the kernel, so that you can put another
  84. (possibly larger) kernel onto the same floppy later without overlapping
  85. the RAM disk image. An offset of 400 kB for kernels about 350 kB in
  86. size would be reasonable. Make sure offset+size of ram_image.gz is
  87. not larger than the total space on your floppy (usually 1440 kB)::
  88. dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
  89. g) Make sure that you have already specified the boot information in
  90. FDARGS and FDINITRD or that you use a bootloader to pass kernel
  91. command line boot options to the kernel.
  92. That is it. You now have your boot/root compressed RAM disk floppy. Some
  93. users may wish to combine steps (d) and (f) by using a pipe.
  94. Paul Gortmaker 12/95
  95. Changelog:
  96. ----------
  97. SEPT-2020 :
  98. Removed usage of "rdev"
  99. 10-22-04 :
  100. Updated to reflect changes in command line options, remove
  101. obsolete references, general cleanup.
  102. James Nelson (james4765@gmail.com)
  103. 12-95 :
  104. Original Document