OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [Documentation/] [ramdisk.txt] - Blame information for rev 1766

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
Using the RAM disk block device with Linux
2
------------------------------------------
3
 
4
Contents:
5
 
6
        1) Overview
7
        2) Kernel Command Line Parameters
8
        3) Using "rdev -r" With New Kernels
9
        4) An Example of Creating a Compressed RAM Disk
10
 
11
 
12
1) Overview
13
-----------
14
 
15
As of kernel v1.3.48, the RAM disk driver was substantially changed.
16
 
17
The older versions would grab a chunk of memory off the top before
18
handing the remainder to the kernel at boot time. Thus a size parameter
19
had to be specified via "ramdisk=1440" or "rdev -r /dev/fd0 1440" so
20
that the driver knew how much memory to grab.
21
 
22
Now the RAM disk dynamically grows as more space is required. It does
23
this by using RAM from the buffer cache. The driver marks the buffers
24
it is using with a new "BH_Protected" flag so that the kernel does
25
not try to reuse them later. This means that the old size parameter
26
is no longer used, new command line parameters exist, and the behavior
27
of the "rdev -r" or "ramsize" (usually a symbolic link to "rdev")
28
command has changed.
29
 
30
Also, the new RAM disk supports up to 16 RAM disks out of the box, and can
31
be reconfigured in rd.c to support up to 255 RAM disks.  To use multiple
32
RAM disk support with your system, run 'mknod /dev/ramX b 1 X' and chmod
33
(to change its permissions) it to your liking.  The default /dev/ram(disk)
34
uses minor #1, so start with ram2 and go from there.
35
 
36
The old "ramdisk=" has been changed to "ramdisk_size="
37
to make it clearer.  The original "ramdisk=" has been kept around
38
for compatibility reasons, but it will probably be removed in 2.1.x.
39
 
40
The new RAM disk also has the ability to load compressed RAM disk images,
41
allowing one to squeeze more programs onto an average installation or
42
rescue floppy disk.
43
 
44
Notes: You may have "/dev/ram" or "/dev/ramdisk" or both. They are
45
equivalent from the standpoint of this document. Also, the new RAM disk
46
is a config option. When running "make config", make sure you enable
47
RAM disk support for the kernel with which you intend to use the RAM disk.
48
 
49
 
50
2) Kernel Command Line Parameters
51
---------------------------------
52
 
53
        ramdisk_start=NNN
54
        =================
55
 
56
To allow a kernel image to reside on a floppy disk along with a compressed
57
RAM disk image, the "ramdisk_start=" command was added. The kernel
58
can't be included into the compressed RAM disk filesystem image, because
59
it needs to be stored starting at block zero so that the BIOS can load the
60
boot sector and then the kernel can bootstrap itself to get going.
61
 
62
Note: If you are using an uncompressed RAM disk image, then the kernel can
63
be a part of the filesystem image that is being loaded into the RAM disk,
64
and the floppy can be booted with LILO, or the two can be separate as
65
is done for the compressed images.
66
 
67
If you are using a two-disk boot/root setup (kernel on #1, RAM disk image
68
on #2) then the RAM disk would start at block zero, and an offset of
69
zero would be used. Since this is the default value, you would not need
70
to actually use the command at all.
71
 
72
If instead, you have a "zImage" of about 350 kB, and a "fs_image.gz" of
73
say about 1 MB, and you want them both on the same disk, then you
74
would use an offset. If you stored the "fs_image.gz" onto the floppy
75
starting at an offset of 400 kB, you would use "ramdisk_start=400".
76
 
77
 
78
        load_ramdisk=N
79
        ==============
80
 
81
This parameter tells the kernel whether it is to try to load a
82
RAM disk image or not. Specifying "load_ramdisk=1" will tell the
83
kernel to load a floppy into the RAM disk. The default value is
84
zero, meaning that the kernel should not try to load a RAM disk.
85
 
86
 
87
        prompt_ramdisk=N
88
        ================
89
 
90
This parameter tells the kernel whether or not to give you a prompt
91
asking you to insert the floppy containing the RAM disk image. In
92
a single floppy configuration the RAM disk image is on the same floppy
93
as the kernel that just finished loading/booting and so a prompt
94
is not needed. In this case one can use "prompt_ramdisk=0". In a
95
two floppy configuration, you will need the chance to switch disks,
96
and thus "prompt_ramdisk=1" can be used. Since this is the default
97
value, it doesn't really need to be specified.
98
 
99
        ramdisk_size=N
100
        ==============
101
 
102
This parameter tells the RAM disk driver to set up RAM disks of N k size.  The
103
default is 4096 (4 MB).
104
 
105
3) Using "rdev -r" With New Kernels
106
-----------------------------------
107
 
108
The usage of the word (two bytes) that "rdev -r" sets in the kernel image
109
has changed. The low 11 bits (0 -> 10) specify an offset (in 1 k blocks)
110
of up to 2 MB (2^11) of where to find the RAM disk (this used to be the
111
size). Bit 14 indicates that a RAM disk is to be loaded, and bit 15
112
indicates whether a prompt/wait sequence is to be given before trying
113
to read the RAM disk. Since the RAM disk dynamically grows as data is
114
being written into it, a size field is no longer required. Bits 11
115
to 13 are not currently used and may as well be zero. These numbers
116
are no magical secrets, as seen below:
117
 
118
./arch/i386/kernel/setup.c:#define RAMDISK_IMAGE_START_MASK     0x07FF
119
./arch/i386/kernel/setup.c:#define RAMDISK_PROMPT_FLAG          0x8000
120
./arch/i386/kernel/setup.c:#define RAMDISK_LOAD_FLAG            0x4000
121
 
122
Consider a typical two floppy disk setup, where you will have the
123
kernel on disk one, and have already put a RAM disk image onto disk #2.
124
 
125
Hence you want to set bits 0 to 13 as 0, meaning that your RAM disk
126
starts at an offset of 0 kB from the beginning of the floppy.
127
The command line equivalent is: "ramdisk_start=0"
128
 
129
You want bit 14 as one, indicating that a RAM disk is to be loaded.
130
The command line equivalent is: "load_ramdisk=1"
131
 
132
You want bit 15 as one, indicating that you want a prompt/keypress
133
sequence so that you have a chance to switch floppy disks.
134
The command line equivalent is: "prompt_ramdisk=1"
135
 
136
Putting that together gives 2^15 + 2^14 + 0 = 49152 for an rdev word.
137
So to create disk one of the set, you would do:
138
 
139
        /usr/src/linux# cat arch/i386/boot/zImage > /dev/fd0
140
        /usr/src/linux# rdev /dev/fd0 /dev/fd0
141
        /usr/src/linux# rdev -r /dev/fd0 49152
142
 
143
If you make a boot disk that has LILO, then for the above, you would use:
144
        append = "ramdisk_start=0 load_ramdisk=1 prompt_ramdisk=1"
145
Since the default start = 0 and the default prompt = 1, you could use:
146
        append = "load_ramdisk=1"
147
 
148
 
149
4) An Example of Creating a Compressed RAM Disk
150
----------------------------------------------
151
 
152
To create a RAM disk image, you will need a spare block device to
153
construct it on. This can be the RAM disk device itself, or an
154
unused disk partition (such as an unmounted swap partition). For this
155
example, we will use the RAM disk device, "/dev/ram".
156
 
157
Note: This technique should not be done on a machine with less than 8 MB
158
of RAM. If using a spare disk partition instead of /dev/ram, then this
159
restriction does not apply.
160
 
161
a) Decide on the RAM disk size that you want. Say 2 MB for this example.
162
   Create it by writing to the RAM disk device. (This step is not currently
163
   required, but may be in the future.) It is wise to zero out the
164
   area (esp. for disks) so that maximal compression is achieved for
165
   the unused blocks of the image that you are about to create.
166
 
167
        dd if=/dev/zero of=/dev/ram bs=1k count=2048
168
 
169
b) Make a filesystem on it. Say ext2fs for this example.
170
 
171
        mke2fs -vm0 /dev/ram 2048
172
 
173
c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
174
   and unmount it again.
175
 
176
d) Compress the contents of the RAM disk. The level of compression
177
   will be approximately 50% of the space used by the files. Unused
178
   space on the RAM disk will compress to almost nothing.
179
 
180
        dd if=/dev/ram bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
181
 
182
e) Put the kernel onto the floppy
183
 
184
        dd if=zImage of=/dev/fd0 bs=1k
185
 
186
f) Put the RAM disk image onto the floppy, after the kernel. Use an offset
187
   that is slightly larger than the kernel, so that you can put another
188
   (possibly larger) kernel onto the same floppy later without overlapping
189
   the RAM disk image. An offset of 400 kB for kernels about 350 kB in
190
   size would be reasonable. Make sure offset+size of ram_image.gz is
191
   not larger than the total space on your floppy (usually 1440 kB).
192
 
193
        dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
194
 
195
g) Use "rdev" to set the boot device, RAM disk offset, prompt flag, etc.
196
   For prompt_ramdisk=1, load_ramdisk=1, ramdisk_start=400, one would
197
   have 2^15 + 2^14 + 400 = 49552.
198
 
199
        rdev /dev/fd0 /dev/fd0
200
        rdev -r /dev/fd0 49552
201
 
202
That is it. You now have your boot/root compressed RAM disk floppy. Some
203
users may wish to combine steps (d) and (f) by using a pipe.
204
 
205
--------------------------------------------------------------------------
206
                                                Paul Gortmaker 12/95

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.