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