18c2ecf20Sopenharmony_ci==========================================
28c2ecf20Sopenharmony_ciUsing the RAM disk block device with Linux
38c2ecf20Sopenharmony_ci==========================================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci.. Contents:
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci	1) Overview
88c2ecf20Sopenharmony_ci	2) Kernel Command Line Parameters
98c2ecf20Sopenharmony_ci	3) Using "rdev"
108c2ecf20Sopenharmony_ci	4) An Example of Creating a Compressed RAM Disk
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci1) Overview
148c2ecf20Sopenharmony_ci-----------
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ciThe RAM disk driver is a way to use main system memory as a block device.  It
178c2ecf20Sopenharmony_ciis required for initrd, an initial filesystem used if you need to load modules
188c2ecf20Sopenharmony_ciin order to access the root filesystem (see Documentation/admin-guide/initrd.rst).  It can
198c2ecf20Sopenharmony_cialso be used for a temporary filesystem for crypto work, since the contents
208c2ecf20Sopenharmony_ciare erased on reboot.
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciThe RAM disk dynamically grows as more space is required. It does this by using
238c2ecf20Sopenharmony_ciRAM from the buffer cache. The driver marks the buffers it is using as dirty
248c2ecf20Sopenharmony_ciso that the VM subsystem does not try to reclaim them later.
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciThe RAM disk supports up to 16 RAM disks by default, and can be reconfigured
278c2ecf20Sopenharmony_cito support an unlimited number of RAM disks (at your own risk).  Just change
288c2ecf20Sopenharmony_cithe configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu
298c2ecf20Sopenharmony_ciand (re)build the kernel.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciTo use RAM disk support with your system, run './MAKEDEV ram' from the /dev
328c2ecf20Sopenharmony_cidirectory.  RAM disks are all major number 1, and start with minor number 0
338c2ecf20Sopenharmony_cifor /dev/ram0, etc.  If used, modern kernels use /dev/ram0 for an initrd.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciThe new RAM disk also has the ability to load compressed RAM disk images,
368c2ecf20Sopenharmony_ciallowing one to squeeze more programs onto an average installation or
378c2ecf20Sopenharmony_cirescue floppy disk.
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci2) Parameters
418c2ecf20Sopenharmony_ci---------------------------------
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci2a) Kernel Command Line Parameters
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	ramdisk_size=N
468c2ecf20Sopenharmony_ci		Size of the ramdisk.
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciThis parameter tells the RAM disk driver to set up RAM disks of N k size.  The
498c2ecf20Sopenharmony_cidefault is 4096 (4 MB).
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci2b) Module parameters
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	rd_nr
548c2ecf20Sopenharmony_ci		/dev/ramX devices created.
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	max_part
578c2ecf20Sopenharmony_ci		Maximum partition number.
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	rd_size
608c2ecf20Sopenharmony_ci		See ramdisk_size.
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci3) Using "rdev"
638c2ecf20Sopenharmony_ci---------------
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci"rdev" is an obsolete, deprecated, antiquated utility that could be used
668c2ecf20Sopenharmony_cito set the boot device in a Linux kernel image.
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciInstead of using rdev, just place the boot device information on the
698c2ecf20Sopenharmony_cikernel command line and pass it to the kernel from the bootloader.
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciYou can also pass arguments to the kernel by setting FDARGS in
728c2ecf20Sopenharmony_ciarch/x86/boot/Makefile and specify in initrd image by setting FDINITRD in
738c2ecf20Sopenharmony_ciarch/x86/boot/Makefile.
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciSome of the kernel command line boot options that may apply here are::
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci  ramdisk_start=N
788c2ecf20Sopenharmony_ci  ramdisk_size=M
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciIf you make a boot disk that has LILO, then for the above, you would use::
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	append = "ramdisk_start=N ramdisk_size=M"
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci4) An Example of Creating a Compressed RAM Disk
858c2ecf20Sopenharmony_ci-----------------------------------------------
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciTo create a RAM disk image, you will need a spare block device to
888c2ecf20Sopenharmony_ciconstruct it on. This can be the RAM disk device itself, or an
898c2ecf20Sopenharmony_ciunused disk partition (such as an unmounted swap partition). For this
908c2ecf20Sopenharmony_ciexample, we will use the RAM disk device, "/dev/ram0".
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ciNote: This technique should not be done on a machine with less than 8 MB
938c2ecf20Sopenharmony_ciof RAM. If using a spare disk partition instead of /dev/ram0, then this
948c2ecf20Sopenharmony_cirestriction does not apply.
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cia) Decide on the RAM disk size that you want. Say 2 MB for this example.
978c2ecf20Sopenharmony_ci   Create it by writing to the RAM disk device. (This step is not currently
988c2ecf20Sopenharmony_ci   required, but may be in the future.) It is wise to zero out the
998c2ecf20Sopenharmony_ci   area (esp. for disks) so that maximal compression is achieved for
1008c2ecf20Sopenharmony_ci   the unused blocks of the image that you are about to create::
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	dd if=/dev/zero of=/dev/ram0 bs=1k count=2048
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cib) Make a filesystem on it. Say ext2fs for this example::
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	mke2fs -vm0 /dev/ram0 2048
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cic) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
1098c2ecf20Sopenharmony_ci   and unmount it again.
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cid) Compress the contents of the RAM disk. The level of compression
1128c2ecf20Sopenharmony_ci   will be approximately 50% of the space used by the files. Unused
1138c2ecf20Sopenharmony_ci   space on the RAM disk will compress to almost nothing::
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cie) Put the kernel onto the floppy::
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	dd if=zImage of=/dev/fd0 bs=1k
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cif) Put the RAM disk image onto the floppy, after the kernel. Use an offset
1228c2ecf20Sopenharmony_ci   that is slightly larger than the kernel, so that you can put another
1238c2ecf20Sopenharmony_ci   (possibly larger) kernel onto the same floppy later without overlapping
1248c2ecf20Sopenharmony_ci   the RAM disk image. An offset of 400 kB for kernels about 350 kB in
1258c2ecf20Sopenharmony_ci   size would be reasonable. Make sure offset+size of ram_image.gz is
1268c2ecf20Sopenharmony_ci   not larger than the total space on your floppy (usually 1440 kB)::
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cig) Make sure that you have already specified the boot information in
1318c2ecf20Sopenharmony_ci   FDARGS and FDINITRD or that you use a bootloader to pass kernel
1328c2ecf20Sopenharmony_ci   command line boot options to the kernel.
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciThat is it. You now have your boot/root compressed RAM disk floppy. Some
1358c2ecf20Sopenharmony_ciusers may wish to combine steps (d) and (f) by using a pipe.
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci						Paul Gortmaker 12/95
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ciChangelog:
1418c2ecf20Sopenharmony_ci----------
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ciSEPT-2020 :
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci                Removed usage of "rdev"
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci10-22-04 :
1488c2ecf20Sopenharmony_ci		Updated to reflect changes in command line options, remove
1498c2ecf20Sopenharmony_ci		obsolete references, general cleanup.
1508c2ecf20Sopenharmony_ci		James Nelson (james4765@gmail.com)
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci12-95 :
1538c2ecf20Sopenharmony_ci		Original Document
154