← Documents Documentation/admin-guide/blockdev/ramdisk.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Block devices

Using the RAM disk block device with Linux

RAM-backed block device의 allocation·numbering·parameter, rdev 대체와 compressed initrd floppy 작성 절차를 설명합니다.

Source pathDocumentation/admin-guide/blockdev/ramdisk.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

RAM-backed block device

ramdisk.rst:1-39

Buffer-cache RAM을 동적 block device와 initrd로 사용합니다.

Parameters

ramdisk.rst:40-61

Size, device count와 partition number parameter를 정리합니다.

Boot parameters

ramdisk.rst:62-83

Obsolete rdev 대신 bootloader·FDARGS·FDINITRD를 사용합니다.

Compressed image example

ramdisk.rst:84-136

2-MiB ext2 image를 gzip하고 kernel 뒤 400-KiB offset에 배치합니다.

Document history

ramdisk.rst:137-153

1995 원문과 2004·2020 갱신을 기록합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

RAM disk block device 개요

1-39

RAM 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을 넣을 수 있습니다.

RAM-disk memory lifecycle
Allocate buffer-cache RAM on demandMark buffers dirty against VM reclaimExpose /dev/ramX block deviceUse as initrd or temporary filesystemErase contents on reboot

Buffer-cache page를 block device로 노출하고 reboot 때 폐기합니다.

RAM-disk device numbering
PropertyValue
Default count16
ConfigurationBLK_DEV_RAM_COUNT
Major number1
First device/dev/ram0, minor 0
Modern initrd device/dev/ram0

기본 device count와 major/minor 규칙입니다.

Kernel command-line·module parameter

40-61
RAM-disk parameters
ParameterMeaningDefault/reference
ramdisk_size=NRAM disk size in KiB4096 = 4 MB
rd_nr생성할 /dev/ramX device 수Module parameter
max_part최대 partition numberModule parameter
rd_sizeRAM disk sizeramdisk_size와 같음

Command 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"
RAM-disk boot parameters
Bootloaderramdisk_start=N ramdisk_size=MKernel command line
arch/x86/boot/MakefileFDARGS + FDINITRDBoot floppy image

Rdev 대신 bootloader 또는 build-time floppy 변수로 정보를 전달합니다.

Compressed RAM-disk floppy 만들기

84-136

RAM-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.
Create a compressed RAM-disk boot floppy
Zero 2 MiB /dev/ram0Create ext2 filesystemMount and copy filesUnmountgzip imageWrite kernel to floppyWrite image at seek=400Pass boot parameters

Filesystem construction부터 floppy layout까지의 순서입니다.

Example floppy layout
RegionExample position/sizeConstraint
Kernel zImageStart at 0 KiB; about 350 KiBWritten first
Reserved gapUntil 400 KiBAllows somewhat larger future kernel
ram_image.gzStart at seek=400 KiBoffset + image size <= 1440 KiB

Kernel과 compressed RAM-disk image가 겹치지 않도록 배치합니다.

저자와 changelog

137-153

원문은 Paul Gortmaker가 1995년 12월 작성했습니다. 2004년 10월 22일 James Nelson <[email protected]>이 command-line option 변경을 반영하고 obsolete reference를 제거하며 정리했습니다. 2020년 9월에는 `rdev` 사용을 제거했습니다.

RAM-disk document history
DateChange
December 1995Original document by Paul Gortmaker
2004-10-22Command-line update and cleanup by James Nelson
September 2020Removed usage of rdev

문서의 주요 갱신 시점입니다.