162306a36Sopenharmony_ci==========================================
262306a36Sopenharmony_ciUsing the RAM disk block device with Linux
362306a36Sopenharmony_ci==========================================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci.. Contents:
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci	1) Overview
862306a36Sopenharmony_ci	2) Kernel Command Line Parameters
962306a36Sopenharmony_ci	3) Using "rdev"
1062306a36Sopenharmony_ci	4) An Example of Creating a Compressed RAM Disk
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci1) Overview
1462306a36Sopenharmony_ci-----------
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ciThe RAM disk driver is a way to use main system memory as a block device.  It
1762306a36Sopenharmony_ciis required for initrd, an initial filesystem used if you need to load modules
1862306a36Sopenharmony_ciin order to access the root filesystem (see Documentation/admin-guide/initrd.rst).  It can
1962306a36Sopenharmony_cialso be used for a temporary filesystem for crypto work, since the contents
2062306a36Sopenharmony_ciare erased on reboot.
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciThe RAM disk dynamically grows as more space is required. It does this by using
2362306a36Sopenharmony_ciRAM from the buffer cache. The driver marks the buffers it is using as dirty
2462306a36Sopenharmony_ciso that the VM subsystem does not try to reclaim them later.
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciThe RAM disk supports up to 16 RAM disks by default, and can be reconfigured
2762306a36Sopenharmony_cito support an unlimited number of RAM disks (at your own risk).  Just change
2862306a36Sopenharmony_cithe configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu
2962306a36Sopenharmony_ciand (re)build the kernel.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciTo use RAM disk support with your system, run './MAKEDEV ram' from the /dev
3262306a36Sopenharmony_cidirectory.  RAM disks are all major number 1, and start with minor number 0
3362306a36Sopenharmony_cifor /dev/ram0, etc.  If used, modern kernels use /dev/ram0 for an initrd.
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciThe new RAM disk also has the ability to load compressed RAM disk images,
3662306a36Sopenharmony_ciallowing one to squeeze more programs onto an average installation or
3762306a36Sopenharmony_cirescue floppy disk.
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci2) Parameters
4162306a36Sopenharmony_ci---------------------------------
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci2a) Kernel Command Line Parameters
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci	ramdisk_size=N
4662306a36Sopenharmony_ci		Size of the ramdisk.
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciThis parameter tells the RAM disk driver to set up RAM disks of N k size.  The
4962306a36Sopenharmony_cidefault is 4096 (4 MB).
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci2b) Module parameters
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci	rd_nr
5462306a36Sopenharmony_ci		/dev/ramX devices created.
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci	max_part
5762306a36Sopenharmony_ci		Maximum partition number.
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	rd_size
6062306a36Sopenharmony_ci		See ramdisk_size.
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci3) Using "rdev"
6362306a36Sopenharmony_ci---------------
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci"rdev" is an obsolete, deprecated, antiquated utility that could be used
6662306a36Sopenharmony_cito set the boot device in a Linux kernel image.
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ciInstead of using rdev, just place the boot device information on the
6962306a36Sopenharmony_cikernel command line and pass it to the kernel from the bootloader.
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ciYou can also pass arguments to the kernel by setting FDARGS in
7262306a36Sopenharmony_ciarch/x86/boot/Makefile and specify in initrd image by setting FDINITRD in
7362306a36Sopenharmony_ciarch/x86/boot/Makefile.
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ciSome of the kernel command line boot options that may apply here are::
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci  ramdisk_start=N
7862306a36Sopenharmony_ci  ramdisk_size=M
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciIf you make a boot disk that has LILO, then for the above, you would use::
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci	append = "ramdisk_start=N ramdisk_size=M"
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci4) An Example of Creating a Compressed RAM Disk
8562306a36Sopenharmony_ci-----------------------------------------------
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ciTo create a RAM disk image, you will need a spare block device to
8862306a36Sopenharmony_ciconstruct it on. This can be the RAM disk device itself, or an
8962306a36Sopenharmony_ciunused disk partition (such as an unmounted swap partition). For this
9062306a36Sopenharmony_ciexample, we will use the RAM disk device, "/dev/ram0".
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ciNote: This technique should not be done on a machine with less than 8 MB
9362306a36Sopenharmony_ciof RAM. If using a spare disk partition instead of /dev/ram0, then this
9462306a36Sopenharmony_cirestriction does not apply.
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cia) Decide on the RAM disk size that you want. Say 2 MB for this example.
9762306a36Sopenharmony_ci   Create it by writing to the RAM disk device. (This step is not currently
9862306a36Sopenharmony_ci   required, but may be in the future.) It is wise to zero out the
9962306a36Sopenharmony_ci   area (esp. for disks) so that maximal compression is achieved for
10062306a36Sopenharmony_ci   the unused blocks of the image that you are about to create::
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	dd if=/dev/zero of=/dev/ram0 bs=1k count=2048
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cib) Make a filesystem on it. Say ext2fs for this example::
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci	mke2fs -vm0 /dev/ram0 2048
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_cic) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
10962306a36Sopenharmony_ci   and unmount it again.
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_cid) Compress the contents of the RAM disk. The level of compression
11262306a36Sopenharmony_ci   will be approximately 50% of the space used by the files. Unused
11362306a36Sopenharmony_ci   space on the RAM disk will compress to almost nothing::
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_cie) Put the kernel onto the floppy::
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci	dd if=zImage of=/dev/fd0 bs=1k
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_cif) Put the RAM disk image onto the floppy, after the kernel. Use an offset
12262306a36Sopenharmony_ci   that is slightly larger than the kernel, so that you can put another
12362306a36Sopenharmony_ci   (possibly larger) kernel onto the same floppy later without overlapping
12462306a36Sopenharmony_ci   the RAM disk image. An offset of 400 kB for kernels about 350 kB in
12562306a36Sopenharmony_ci   size would be reasonable. Make sure offset+size of ram_image.gz is
12662306a36Sopenharmony_ci   not larger than the total space on your floppy (usually 1440 kB)::
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_cig) Make sure that you have already specified the boot information in
13162306a36Sopenharmony_ci   FDARGS and FDINITRD or that you use a bootloader to pass kernel
13262306a36Sopenharmony_ci   command line boot options to the kernel.
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ciThat is it. You now have your boot/root compressed RAM disk floppy. Some
13562306a36Sopenharmony_ciusers may wish to combine steps (d) and (f) by using a pipe.
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci						Paul Gortmaker 12/95
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ciChangelog:
14162306a36Sopenharmony_ci----------
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ciSEPT-2020 :
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci                Removed usage of "rdev"
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci10-22-04 :
14862306a36Sopenharmony_ci		Updated to reflect changes in command line options, remove
14962306a36Sopenharmony_ci		obsolete references, general cleanup.
15062306a36Sopenharmony_ci		James Nelson (james4765@gmail.com)
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci12-95 :
15362306a36Sopenharmony_ci		Original Document
154