요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
Parameters
ramdisk.rst:40-61Size, device count와 partition number parameter를 정리합니다.
Boot parameters
ramdisk.rst:62-83Obsolete rdev 대신 bootloader·FDARGS·FDINITRD를 사용합니다.
Compressed image example
ramdisk.rst:84-1362-MiB ext2 image를 gzip하고 kernel 뒤 400-KiB offset에 배치합니다.
Document history
ramdisk.rst:137-1531995 원문과 2004·2020 갱신을 기록합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
==========================================
Using the RAM disk block device with Linux
==========================================
.. Contents:
1) Overview
2) Kernel Command Line Parameters
3) Using "rdev"
4) An Example of Creating a Compressed RAM Disk
1) Overview
-----------
The RAM disk driver is a way to use main system memory as a block device. It
is required for initrd, an initial filesystem used if you need to load modules
in order to access the root filesystem (see Documentation/admin-guide/initrd.rst). It can
also be used for a temporary filesystem for crypto work, since the contents
are erased on reboot.
The RAM disk dynamically grows as more space is required. It does this by using
RAM from the buffer cache. The driver marks the buffers it is using as dirty
so that the VM subsystem does not try to reclaim them later.
The RAM disk supports up to 16 RAM disks by default, and can be reconfigured
to support an unlimited number of RAM disks (at your own risk). Just change
the configuration symbol BLK_DEV_RAM_COUNT in the Block drivers config menu
and (re)build the kernel.
To use RAM disk support with your system, run './MAKEDEV ram' from the /dev
directory. RAM disks are all major number 1, and start with minor number 0
for /dev/ram0, etc. If used, modern kernels use /dev/ram0 for an initrd.
The new RAM disk also has the ability to load compressed RAM disk images,
allowing one to squeeze more programs onto an average installation or
rescue floppy disk.
2) Parameters
---------------------------------
2a) Kernel Command Line Parameters
ramdisk_size=N
Size of the ramdisk.
This parameter tells the RAM disk driver to set up RAM disks of N k size. The
default is 4096 (4 MB).
2b) Module parameters
rd_nr
/dev/ramX devices created.
max_part
Maximum partition number.
rd_size
See ramdisk_size.
3) Using "rdev"
---------------
"rdev" is an obsolete, deprecated, antiquated utility that could be used
to set the boot device in a Linux kernel image.
Instead of using rdev, just place the boot device information on the
kernel command line and pass it to the kernel from the bootloader.
You can also pass arguments to the kernel by setting FDARGS in
arch/x86/boot/Makefile and specify in initrd image by setting FDINITRD in
arch/x86/boot/Makefile.
Some of the kernel command line boot options that may apply here are::
ramdisk_start=N
ramdisk_size=M
If you make a boot disk that has LILO, then for the above, you would use::
append = "ramdisk_start=N ramdisk_size=M"
4) An Example of Creating a Compressed RAM Disk
-----------------------------------------------
To create a RAM disk image, you will need a spare block device to
construct it on. This can be the RAM disk device itself, or an
unused disk partition (such as an unmounted swap partition). For this
example, we will use the RAM disk device, "/dev/ram0".
Note: This technique should not be done on a machine with less than 8 MB
of RAM. If using a spare disk partition instead of /dev/ram0, then this
restriction does not apply.
a) Decide on the RAM disk size that you want. Say 2 MB for this example.
Create it by writing to the RAM disk device. (This step is not currently
required, but may be in the future.) It is wise to zero out the
area (esp. for disks) so that maximal compression is achieved for
the unused blocks of the image that you are about to create::
dd if=/dev/zero of=/dev/ram0 bs=1k count=2048
b) Make a filesystem on it. Say ext2fs for this example::
mke2fs -vm0 /dev/ram0 2048
c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
and unmount it again.
d) Compress the contents of the RAM disk. The level of compression
will be approximately 50% of the space used by the files. Unused
space on the RAM disk will compress to almost nothing::
dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
e) Put the kernel onto the floppy::
dd if=zImage of=/dev/fd0 bs=1k
f) Put the RAM disk image onto the floppy, after the kernel. Use an offset
that is slightly larger than the kernel, so that you can put another
(possibly larger) kernel onto the same floppy later without overlapping
the RAM disk image. An offset of 400 kB for kernels about 350 kB in
size would be reasonable. Make sure offset+size of ram_image.gz is
not larger than the total space on your floppy (usually 1440 kB)::
dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
g) Make sure that you have already specified the boot information in
FDARGS and FDINITRD or that you use a bootloader to pass kernel
command line boot options to the kernel.
That is it. You now have your boot/root compressed RAM disk floppy. Some
users may wish to combine steps (d) and (f) by using a pipe.
Paul Gortmaker 12/95
Changelog:
----------
SEPT-2020 :
Removed usage of "rdev"
10-22-04 :
Updated to reflect changes in command line options, remove
obsolete references, general cleanup.
James Nelson (james4765@gmail.com)
12-95 :
Original Document
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
RAM disk block device 개요
1-39RAM disk driver는 main system memory를 block device로 사용합니다. Root filesystem에 접근하기 위해 module을 먼저 load해야 할 때 쓰는 initial filesystem인 initrd에 필요하며 `Documentation/admin-guide/initrd.rst`를 참조합니다. Reboot 때 내용이 지워지므로 crypto 작업용 temporary filesystem으로도 쓸 수 있습니다.
RAM disk는 공간이 필요할수록 buffer cache의 RAM을 사용해 동적으로 커집니다. Driver는 사용 중인 buffer를 dirty로 표시해 VM subsystem이 나중에 reclaim하지 않도록 합니다.
기본적으로 RAM disk 16개를 지원합니다. 위험을 감수하면 Block drivers config menu의 `BLK_DEV_RAM_COUNT`를 바꾸고 kernel을 rebuild해 제한 없이 늘릴 수 있습니다.
System에서 RAM disk를 사용하려면 `/dev`에서 `./MAKEDEV ram`을 실행합니다. 모두 major number 1이고 `/dev/ram0`은 minor 0에서 시작합니다. Modern kernel은 initrd가 있으면 `/dev/ram0`을 사용합니다.
Compressed RAM-disk image도 load할 수 있어 installation/rescue floppy에 더 많은 program을 넣을 수 있습니다.
Buffer-cache page를 block device로 노출하고 reboot 때 폐기합니다.
기본 device count와 major/minor 규칙입니다.
Kernel command-line·module parameter
40-61Command line과 module parameter의 크기·개수·partition 설정입니다.
Rdev 대신 bootloader parameter 사용
62-83`rdev`는 Linux kernel image의 boot device를 설정하던 obsolete·deprecated·antiquated utility입니다. 대신 kernel command line에 boot-device 정보를 두고 bootloader가 kernel에 전달합니다.
`arch/x86/boot/Makefile`의 `FDARGS`로 kernel argument를 전달하고 `FDINITRD`로 initrd image를 지정할 수도 있습니다.
Some of the kernel command line boot options that may apply here are::
ramdisk_start=N
ramdisk_size=M
If you make a boot disk that has LILO, then for the above, you would use::
append = "ramdisk_start=N ramdisk_size=M"
Rdev 대신 bootloader 또는 build-time floppy 변수로 정보를 전달합니다.
Compressed RAM-disk floppy 만들기
84-136RAM-disk image를 만들려면 `/dev/ram0` 자체나 unmounted swap partition 같은 spare block device가 필요합니다. 예제는 `/dev/ram0`을 사용합니다. RAM이 8 MB 미만인 machine에서는 이 기법을 쓰면 안 되지만 spare disk partition을 사용하면 제한이 없습니다.
A) 예제 크기 2 MB를 정하고 `/dev/ram0`에 zero를 2048 KiB 씁니다. 현재는 꼭 필요하지 않지만 unused block도 잘 압축되도록 특히 disk에서는 zeroing이 좋습니다. B) 2048-block ext2 filesystem을 만듭니다. C) Mount해 `/etc/*`, `/dev/*` 등 필요한 file을 복사하고 unmount합니다.
D) RAM disk 내용을 gzip level 9로 압축합니다. File이 실제로 사용한 공간은 약 50%로 압축되고 unused zero space는 거의 사라집니다. E) Kernel `zImage`를 floppy 처음에 씁니다.
F) Kernel 뒤 offset에 compressed image를 씁니다. 약 350 KiB kernel에는 400 KiB offset이 합리적이어서 나중에 조금 더 큰 kernel로 교체해도 image와 겹치지 않습니다. `offset + size(ram_image.gz)`가 보통 1440 KiB인 floppy 전체 크기를 넘지 않아야 합니다.
G) `FDARGS`·`FDINITRD`에 boot 정보를 미리 지정했거나 bootloader로 kernel command-line option을 전달하도록 확인합니다. Step D와 F는 pipe로 합칠 수도 있습니다.
a) Decide on the RAM disk size that you want. Say 2 MB for this example.
Create it by writing to the RAM disk device. (This step is not currently
required, but may be in the future.) It is wise to zero out the
area (esp. for disks) so that maximal compression is achieved for
the unused blocks of the image that you are about to create::
dd if=/dev/zero of=/dev/ram0 bs=1k count=2048
b) Make a filesystem on it. Say ext2fs for this example::
mke2fs -vm0 /dev/ram0 2048
c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
and unmount it again.
d) Compress the contents of the RAM disk. The level of compression
will be approximately 50% of the space used by the files. Unused
space on the RAM disk will compress to almost nothing::
dd if=/dev/ram0 bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
e) Put the kernel onto the floppy::
dd if=zImage of=/dev/fd0 bs=1k
f) Put the RAM disk image onto the floppy, after the kernel. Use an offset
that is slightly larger than the kernel, so that you can put another
(possibly larger) kernel onto the same floppy later without overlapping
the RAM disk image. An offset of 400 kB for kernels about 350 kB in
size would be reasonable. Make sure offset+size of ram_image.gz is
not larger than the total space on your floppy (usually 1440 kB)::
dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
g) Make sure that you have already specified the boot information in
FDARGS and FDINITRD or that you use a bootloader to pass kernel
command line boot options to the kernel.
That is it. You now have your boot/root compressed RAM disk floppy. Some
users may wish to combine steps (d) and (f) by using a pipe.
Filesystem construction부터 floppy layout까지의 순서입니다.
Kernel과 compressed RAM-disk image가 겹치지 않도록 배치합니다.
저자와 changelog
137-153원문은 Paul Gortmaker가 1995년 12월 작성했습니다. 2004년 10월 22일 James Nelson <james4765@gmail.com>이 command-line option 변경을 반영하고 obsolete reference를 제거하며 정리했습니다. 2020년 9월에는 `rdev` 사용을 제거했습니다.
문서의 주요 갱신 시점입니다.
RAM-backed block device
ramdisk.rst:1-39Buffer-cache RAM을 동적 block device와 initrd로 사용합니다.