brintos

brintos / linux-shallow public Read only

0
0
Text · 4.9 KiB · 9ce6101 Raw
154 lines · plain
1==========================================2Using the RAM disk block device with Linux3==========================================4 5.. Contents:6 7	1) Overview8	2) Kernel Command Line Parameters9	3) Using "rdev"10	4) An Example of Creating a Compressed RAM Disk11 12 131) Overview14-----------15 16The RAM disk driver is a way to use main system memory as a block device.  It17is required for initrd, an initial filesystem used if you need to load modules18in order to access the root filesystem (see Documentation/admin-guide/initrd.rst).  It can19also be used for a temporary filesystem for crypto work, since the contents20are erased on reboot.21 22The RAM disk dynamically grows as more space is required. It does this by using23RAM from the buffer cache. The driver marks the buffers it is using as dirty24so that the VM subsystem does not try to reclaim them later.25 26The RAM disk supports up to 16 RAM disks by default, and can be reconfigured27to support an unlimited number of RAM disks (at your own risk).  Just change28the configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu29and (re)build the kernel.30 31To use RAM disk support with your system, run './MAKEDEV ram' from the /dev32directory.  RAM disks are all major number 1, and start with minor number 033for /dev/ram0, etc.  If used, modern kernels use /dev/ram0 for an initrd.34 35The new RAM disk also has the ability to load compressed RAM disk images,36allowing one to squeeze more programs onto an average installation or37rescue floppy disk.38 39 402) Parameters41---------------------------------42 432a) Kernel Command Line Parameters44 45	ramdisk_size=N46		Size of the ramdisk.47 48This parameter tells the RAM disk driver to set up RAM disks of N k size.  The49default is 4096 (4 MB).50 512b) Module parameters52 53	rd_nr54		/dev/ramX devices created.55 56	max_part57		Maximum partition number.58 59	rd_size60		See ramdisk_size.61 623) Using "rdev"63---------------64 65"rdev" is an obsolete, deprecated, antiquated utility that could be used66to set the boot device in a Linux kernel image.67 68Instead of using rdev, just place the boot device information on the69kernel command line and pass it to the kernel from the bootloader.70 71You can also pass arguments to the kernel by setting FDARGS in72arch/x86/boot/Makefile and specify in initrd image by setting FDINITRD in73arch/x86/boot/Makefile.74 75Some of the kernel command line boot options that may apply here are::76 77  ramdisk_start=N78  ramdisk_size=M79 80If you make a boot disk that has LILO, then for the above, you would use::81 82	append = "ramdisk_start=N ramdisk_size=M"83 844) An Example of Creating a Compressed RAM Disk85-----------------------------------------------86 87To create a RAM disk image, you will need a spare block device to88construct it on. This can be the RAM disk device itself, or an89unused disk partition (such as an unmounted swap partition). For this90example, we will use the RAM disk device, "/dev/ram0".91 92Note: This technique should not be done on a machine with less than 8 MB93of RAM. If using a spare disk partition instead of /dev/ram0, then this94restriction does not apply.95 96a) Decide on the RAM disk size that you want. Say 2 MB for this example.97   Create it by writing to the RAM disk device. (This step is not currently98   required, but may be in the future.) It is wise to zero out the99   area (esp. for disks) so that maximal compression is achieved for100   the unused blocks of the image that you are about to create::101 102	dd if=/dev/zero of=/dev/ram0 bs=1k count=2048103 104b) Make a filesystem on it. Say ext2fs for this example::105 106	mke2fs -vm0 /dev/ram0 2048107 108c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)109   and unmount it again.110 111d) Compress the contents of the RAM disk. The level of compression112   will be approximately 50% of the space used by the files. Unused113   space on the RAM disk will compress to almost nothing::114 115	dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz116 117e) Put the kernel onto the floppy::118 119	dd if=zImage of=/dev/fd0 bs=1k120 121f) Put the RAM disk image onto the floppy, after the kernel. Use an offset122   that is slightly larger than the kernel, so that you can put another123   (possibly larger) kernel onto the same floppy later without overlapping124   the RAM disk image. An offset of 400 kB for kernels about 350 kB in125   size would be reasonable. Make sure offset+size of ram_image.gz is126   not larger than the total space on your floppy (usually 1440 kB)::127 128	dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400129 130g) Make sure that you have already specified the boot information in131   FDARGS and FDINITRD or that you use a bootloader to pass kernel132   command line boot options to the kernel.133 134That is it. You now have your boot/root compressed RAM disk floppy. Some135users may wish to combine steps (d) and (f) by using a pipe.136 137 138						Paul Gortmaker 12/95139 140Changelog:141----------142 143SEPT-2020 :144 145                Removed usage of "rdev"146 14710-22-04 :148		Updated to reflect changes in command line options, remove149		obsolete references, general cleanup.150		James Nelson (james4765@gmail.com)151 15212-95 :153		Original Document154