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