0001 ==========================================
0002 Using the RAM disk block device with Linux
0003 ==========================================
0004
0005 .. Contents:
0006
0007 1) Overview
0008 2) Kernel Command Line Parameters
0009 3) Using "rdev"
0010 4) An Example of Creating a Compressed RAM Disk
0011
0012
0013 1) Overview
0014 -----------
0015
0016 The RAM disk driver is a way to use main system memory as a block device. It
0017 is required for initrd, an initial filesystem used if you need to load modules
0018 in order to access the root filesystem (see Documentation/admin-guide/initrd.rst). It can
0019 also be used for a temporary filesystem for crypto work, since the contents
0020 are erased on reboot.
0021
0022 The RAM disk dynamically grows as more space is required. It does this by using
0023 RAM from the buffer cache. The driver marks the buffers it is using as dirty
0024 so that the VM subsystem does not try to reclaim them later.
0025
0026 The RAM disk supports up to 16 RAM disks by default, and can be reconfigured
0027 to support an unlimited number of RAM disks (at your own risk). Just change
0028 the configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu
0029 and (re)build the kernel.
0030
0031 To use RAM disk support with your system, run './MAKEDEV ram' from the /dev
0032 directory. RAM disks are all major number 1, and start with minor number 0
0033 for /dev/ram0, etc. If used, modern kernels use /dev/ram0 for an initrd.
0034
0035 The new RAM disk also has the ability to load compressed RAM disk images,
0036 allowing one to squeeze more programs onto an average installation or
0037 rescue floppy disk.
0038
0039
0040 2) Parameters
0041 ---------------------------------
0042
0043 2a) Kernel Command Line Parameters
0044
0045 ramdisk_size=N
0046 Size of the ramdisk.
0047
0048 This parameter tells the RAM disk driver to set up RAM disks of N k size. The
0049 default is 4096 (4 MB).
0050
0051 2b) Module parameters
0052
0053 rd_nr
0054 /dev/ramX devices created.
0055
0056 max_part
0057 Maximum partition number.
0058
0059 rd_size
0060 See ramdisk_size.
0061
0062 3) Using "rdev"
0063 ---------------
0064
0065 "rdev" is an obsolete, deprecated, antiquated utility that could be used
0066 to set the boot device in a Linux kernel image.
0067
0068 Instead of using rdev, just place the boot device information on the
0069 kernel command line and pass it to the kernel from the bootloader.
0070
0071 You can also pass arguments to the kernel by setting FDARGS in
0072 arch/x86/boot/Makefile and specify in initrd image by setting FDINITRD in
0073 arch/x86/boot/Makefile.
0074
0075 Some of the kernel command line boot options that may apply here are::
0076
0077 ramdisk_start=N
0078 ramdisk_size=M
0079
0080 If you make a boot disk that has LILO, then for the above, you would use::
0081
0082 append = "ramdisk_start=N ramdisk_size=M"
0083
0084 4) An Example of Creating a Compressed RAM Disk
0085 -----------------------------------------------
0086
0087 To create a RAM disk image, you will need a spare block device to
0088 construct it on. This can be the RAM disk device itself, or an
0089 unused disk partition (such as an unmounted swap partition). For this
0090 example, we will use the RAM disk device, "/dev/ram0".
0091
0092 Note: This technique should not be done on a machine with less than 8 MB
0093 of RAM. If using a spare disk partition instead of /dev/ram0, then this
0094 restriction does not apply.
0095
0096 a) Decide on the RAM disk size that you want. Say 2 MB for this example.
0097 Create it by writing to the RAM disk device. (This step is not currently
0098 required, but may be in the future.) It is wise to zero out the
0099 area (esp. for disks) so that maximal compression is achieved for
0100 the unused blocks of the image that you are about to create::
0101
0102 dd if=/dev/zero of=/dev/ram0 bs=1k count=2048
0103
0104 b) Make a filesystem on it. Say ext2fs for this example::
0105
0106 mke2fs -vm0 /dev/ram0 2048
0107
0108 c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
0109 and unmount it again.
0110
0111 d) Compress the contents of the RAM disk. The level of compression
0112 will be approximately 50% of the space used by the files. Unused
0113 space on the RAM disk will compress to almost nothing::
0114
0115 dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
0116
0117 e) Put the kernel onto the floppy::
0118
0119 dd if=zImage of=/dev/fd0 bs=1k
0120
0121 f) Put the RAM disk image onto the floppy, after the kernel. Use an offset
0122 that is slightly larger than the kernel, so that you can put another
0123 (possibly larger) kernel onto the same floppy later without overlapping
0124 the RAM disk image. An offset of 400 kB for kernels about 350 kB in
0125 size would be reasonable. Make sure offset+size of ram_image.gz is
0126 not larger than the total space on your floppy (usually 1440 kB)::
0127
0128 dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
0129
0130 g) Make sure that you have already specified the boot information in
0131 FDARGS and FDINITRD or that you use a bootloader to pass kernel
0132 command line boot options to the kernel.
0133
0134 That is it. You now have your boot/root compressed RAM disk floppy. Some
0135 users may wish to combine steps (d) and (f) by using a pipe.
0136
0137
0138 Paul Gortmaker 12/95
0139
0140 Changelog:
0141 ----------
0142
0143 SEPT-2020 :
0144
0145 Removed usage of "rdev"
0146
0147 10-22-04 :
0148 Updated to reflect changes in command line options, remove
0149 obsolete references, general cleanup.
0150 James Nelson (james4765@gmail.com)
0151
0152 12-95 :
0153 Original Document