File: UserModeLinux-HOWTO-2.html

package info (click to toggle)
user-mode-linux-doc 20060501-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 2,360 kB
  • ctags: 517
  • sloc: makefile: 36; sh: 7
file content (342 lines) | stat: -rw-r--r-- 10,070 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.21">
 <TITLE>User Mode Linux HOWTO : Compiling the kernel and modules</TITLE>
 <LINK HREF="UserModeLinux-HOWTO-3.html" REL=next>
 <LINK HREF="UserModeLinux-HOWTO-1.html" REL=previous>
 <LINK HREF="UserModeLinux-HOWTO.html#toc2" REL=contents>
</HEAD>
<BODY>
<A HREF="UserModeLinux-HOWTO-3.html">Next</A>
<A HREF="UserModeLinux-HOWTO-1.html">Previous</A>
<A HREF="UserModeLinux-HOWTO.html#toc2">Contents</A>
<HR>
<H2><A NAME="compile"></A> <A NAME="s2">2.</A> <A HREF="UserModeLinux-HOWTO.html#toc2">Compiling the kernel and modules</A></H2>

<P> </P>

<H2><A NAME="ss2.1">2.1</A> <A HREF="UserModeLinux-HOWTO.html#toc2.1">Compiling the kernel</A>
</H2>


<P>Compiling the user mode kernel is just like compiling any other
kernel.  Let's go through the steps, using 2.4.0-prerelease (current
as of this writing) as an example:</P>
<P>
<OL>
<LI> Download the latest UML patch from

<A HREF="http://user-mode-linux.sourceforge.net/dl-sf.html">the download page</A> 

In this example, the file is uml-patch-2.4.0-prerelease.bz2.

</LI>
<LI> Download the matching kernel from your favourite kernel mirror,
such as:
http://ftp.ca.kernel.org/linux/kernel/
<A HREF="http://ftp.ca.kernel.org/linux/kernel/"> http://ftp.ca.kernel.org/linux/kernel/ </A> .

</LI>
<LI> Make a directory and unpack the kernel into it.

<BLOCKQUOTE><CODE>
<PRE>
host% 
mkdir ~/uml
</PRE>
</CODE></BLOCKQUOTE>

<BLOCKQUOTE><CODE>
<PRE>
host% 
cd ~/uml
</PRE>
</CODE></BLOCKQUOTE>

<BLOCKQUOTE><CODE>
<PRE>
host% 
tar -xjvf linux-2.4.0-prerelease.tar.bz2
</PRE>
</CODE></BLOCKQUOTE>


</LI>
<LI> Apply the patch using

<BLOCKQUOTE><CODE>
<PRE>
host% 
cd ~/uml/linux
</PRE>
</CODE></BLOCKQUOTE>

<BLOCKQUOTE><CODE>
<PRE>
host% 
bzcat uml-patch-2.4.0-prerelease.bz2 | patch -p1
</PRE>
</CODE></BLOCKQUOTE>


</LI>
<LI> Run your favorite config; `make xconfig ARCH=um' is the most
convenient.  `make config ARCH=um' and 'make menuconfig ARCH=um' will
work as well.  The defaults will give you a useful kernel.  If you
want to change something, go ahead, it probably won't hurt anything.
<P> 
Note:  If the host is configured with a 2G/2G address space split
rather than the usual 3G/1G split, then the packaged UML binaries will
not run.  They will immediately segfault.  See 
<A HREF="UserModeLinux-HOWTO-4.html#2G-2G">UML on 2G/2G hosts</A>  for the scoop on
running UML on your system.</P>


</LI>
<LI> Finish with `make linux ARCH=um': the result is a file called `linux'
in the top directory of your source tree.

You may notice that the final binary is pretty large (many 10's of
megabytes for a debuggable UML).  This is almost entirely symbol
information.  The actual binary is comparable in size to a native
kernel.  You can run that huge binary, and only the actual code and
data will be loaded into memory, so the symbols only consume disk
space unless you are running UML under gdb.  You can strip UML:
<BLOCKQUOTE><CODE>
<PRE>
host% strip linux
</PRE>
</CODE></BLOCKQUOTE>

to see the true size of the UML kernel.</LI>
</OL>
</P>
<P>Make sure that you don't build this
kernel in /usr/src/linux.  On some distributions, /usr/include/asm
is a link into this pool.  The user-mode build changes the other end
of that link, and things that include &lt;asm/anything.h&gt; stop compiling.</P>
<P> The sources are also available from cvs. You can  
<A HREF="http://www.user-mode-linux.org/cvs">browse</A>  the CVS pool
or access it anonymously via
<BLOCKQUOTE><CODE>
<PRE>
 cvs -d:pserver:anonymous@www.user-mode-linux.org:/cvsroot/user-mode-linux
cvs command
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P> If you get the CVS sources, you will have to check them out into an
empty directory. You will then have to copy each file into the corresponding
directory in the appropriate kernel pool.</P>
<P> If you don't have the latest kernel pool, you can get the corresponding
user-mode sources with 
<BLOCKQUOTE><CODE>
<PRE>
host% cvs co -r v_2_3_x linux
</PRE>
</CODE></BLOCKQUOTE>

where 'x' is the version in your pool. Note that you will not get the bug
fixes and enhancements that have gone into subsequent releases.</P>
<P> 
If you build your own kernel, and want to boot it from one of the
filesystems distributed from this site, then, in nearly all cases,
devfs must be compiled into the kernel and mounted at boot time.  The
exception is the tomsrtbt filesystem.  For this,
devfs must either not be in the kernel at all, or &quot;devfs=nomount&quot; must
be on the kernel command line.  Any disagreement between the kernel
and the filesystem being booted about whether devfs is being used will
result in the boot getting no further than single-user mode.</P>
<P> 
If you don't want to use devfs, you can remove the need for it from a
filesystem by copying /dev from someplace, making a bunch of
/dev/ubd devices:
<BLOCKQUOTE><CODE>
<PRE>
UML# 
for i in 0 1 2 3 4 5 6 7; do mknod ubd$i b 98 $[ $i * 16 ]; done
</PRE>
</CODE></BLOCKQUOTE>

and changing /etc/fstab and /etc/inittab to refer to the non-devfs devices.</P>


<H2><A NAME="ss2.2">2.2</A> <A HREF="UserModeLinux-HOWTO.html#toc2.2">Compiling and installing kernel modules</A>
</H2>

<P>UML modules are built in the same way as the native kernel (with the
exception of the 'ARCH=um' that you always need for UML):
<BLOCKQUOTE><CODE>
<PRE>
host% make modules ARCH=um
</PRE>
</CODE></BLOCKQUOTE>

Any modules that you want to load into this kernel need to
be built in the user-mode pool.  Modules from the native kernel won't
work.  If you notice that the modules you get are much larger than
they are on the host, see the note above about the size of the final
UML binary.</P>
<P>You can install them by using ftp or something to copy them into the
virtual machine and dropping them into /lib/modules/`uname -r`.</P>
<P>You can also get the kernel build process to install them as
follows:
<OL>
<LI>with the kernel not booted, mount the root filesystem in the top level
of the kernel pool:
<BLOCKQUOTE><CODE>
<PRE>
host% mount root_fs mnt -o loop
</PRE>
</CODE></BLOCKQUOTE>


</LI>
<LI>run 
<BLOCKQUOTE><CODE>
<PRE>
host% 
make modules_install INSTALL_MOD_PATH=`pwd`/mnt ARCH=um
</PRE>
</CODE></BLOCKQUOTE>


</LI>
<LI>unmount the filesystem
<BLOCKQUOTE><CODE>
<PRE>
host% umount mnt
</PRE>
</CODE></BLOCKQUOTE>


</LI>
<LI>boot the kernel on it
</LI>
</OL>
</P>
<P>If you can't mount the root filesystem on the host for some reason
(like it's a COW file), then an alternate approach is to mount the
UML kernel tree from the host into the UML with  
<A HREF="http://user-mode-linux.sourceforge.net/hostfs.html">hostfs</A>  and run the modules_install inside
UML:
<OL>
<LI>With UML booted, mount the host kernel tree inside UML at the same
location as on the host:
<BLOCKQUOTE><CODE>
<PRE>
UML# mount none -t hostfs path to UML pool -o
path to UML pool
</PRE>
</CODE></BLOCKQUOTE>

</LI>
<LI>Run make modules_install:
<BLOCKQUOTE><CODE>
<PRE>
UML# cd path to UML pool ; make modules_install
</PRE>
</CODE></BLOCKQUOTE>

</LI>
</OL>

The depmod at the end may complain about unresolved symbols because
there is an incorrect or missing System.map installed in the UML
filesystem.  This appears to be harmless.  insmod or modprobe should
work fine at this point.</P>

<P> 
When the system is booted, you can use insmod as usual to get the modules
into the kernel.  A number of things have been loaded into UML as
modules, especially filesystems and network protocols and filters, so
most symbols which need to be exported probably already are.  However,
if you do find symbols that need exporting, let  
<A HREF="http://user-mode-linux.sourceforge.net/contacts.html">us</A>  know, and they'll be &quot;taken care of&quot;.</P>

<P> 
If you try building an external module against a UML tree, you will
find that it doesn't compile because of missing includes.  There are
less obvious problems with the CFLAGS that the module Makefile or
script provides which would make it not run even if it did build.  To
get around this, you need to provide the same CFLAGS that the UML
kernel build uses.</P>
<P> 
A reasonably slick way of getting the UML CFLAGS is
<BLOCKQUOTE><CODE>
<PRE>
 
cd uml-tree ; make script 'SCRIPT=@echo $(CFLAGS)' ARCH=um
</PRE>
</CODE></BLOCKQUOTE>

If the module build process has something that looks like
<BLOCKQUOTE><CODE>
<PRE>
 $(CC) $(CFLAGS) file
</PRE>
</CODE></BLOCKQUOTE>

then you can define CFLAGS in a script like this
<BLOCKQUOTE><CODE>
<PRE>
 
CFLAGS=`cd uml-tree ; make script 'SCRIPT=@echo $(CFLAGS)' ARCH=um`
</PRE>
</CODE></BLOCKQUOTE>

and like this in a Makefile
<BLOCKQUOTE><CODE>
<PRE>
 
CFLAGS=$(shell cd uml-tree ; make script 'SCRIPT=@echo
$$(CFLAGS)' ARCH=um)
</PRE>
</CODE></BLOCKQUOTE>
</P>


<H2><A NAME="ss2.3">2.3</A> <A HREF="UserModeLinux-HOWTO.html#toc2.3">Compiling and installing uml_utilities</A>
</H2>

<P>Many features of the UML kernel require a user-space helper program, 
so a uml_utilities package is distributed separately from the kernel 
patch which provides these helpers. Included within this is:
<UL>
<LI>port-helper - Used by consoles which connect to xterms or ports
</LI>
<LI>tunctl - Configuration tool to create and delete tap devices
</LI>
<LI>uml_net - Setuid binary for automatic tap device configuration
</LI>
<LI>uml_switch - User-space virtual switch required for daemon transport
</LI>
</UL>

The uml_utilities tree is compiled with:
<BLOCKQUOTE><CODE>
<PRE>
host#  
make &amp;&amp; make install
</PRE>
</CODE></BLOCKQUOTE>

Note that UML kernel patches may require a specific version of the 
uml_utilities distribution. If you don't keep up with the mailing lists, 
ensure that you have the latest release of uml_utilities if you are 
experiencing problems with your UML kernel, particularly when dealing 
with consoles or command-line switches to the helper programs</P>







<HR>
<A HREF="UserModeLinux-HOWTO-3.html">Next</A>
<A HREF="UserModeLinux-HOWTO-1.html">Previous</A>
<A HREF="UserModeLinux-HOWTO.html#toc2">Contents</A>
</BODY>
</HTML>