summaryrefslogtreecommitdiff
path: root/share/man/man8/compat_linux.8
blob: 7e0951f1d28079c66dc0c164ab206b8453b6df54 (plain)
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
.\"	$OpenBSD: compat_linux.8,v 1.38 2007/07/11 05:13:18 sturm Exp $
.\"	$NetBSD: compat_linux.8,v 1.2 1995/10/16 20:17:59 fvdl Exp $
.\"
.\" Copyright (c) 1995 Frank van der Linden
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"      This product includes software developed for the NetBSD Project
.\"      by Frank van der Linden
.\" 4. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: July 11 2007 $
.Dt COMPAT_LINUX 8
.Os
.Sh NAME
.Nm compat_linux
.Nd setup for running Linux binaries under emulation
.Sh DESCRIPTION
.Ox
supports running Linux binaries.
This only applies to i386 systems for now.
Both the a.out and ELF binary formats are supported.
Most programs should work, including the ones that use the Linux SVGAlib.
Additionally, OSS audio is emulated, so Linux binaries can access the
native audio transparently.
Programs that will not work include those that use i386-specific calls,
such as enabling virtual 8086 mode.
.Pp
The Linux compatibility feature is active
for kernels compiled with the
.Nm COMPAT_LINUX
option and kern.emul.linux
.Xr sysctl 8
enabled.
.Pp
A lot of programs are dynamically linked.
This means that the Linux shared libraries that the programs depend on
and the runtime linker are also needed.
Additionally, a "shadow root" directory for Linux binaries
on the
.Ox
system will have to be created.
This directory is named
.Pa /emul/linux .
Any file operations done by Linux programs run under
.Ox
will look in this directory first.
So, if a Linux program opens, for example,
.Pa /etc/passwd ,
.Ox
will first try to open
.Pa /emul/linux/etc/passwd ,
and if that does not exist open the `real'
.Pa /etc/passwd
file.
It is recommended that Linux packages that include configuration
files, etc., be installed under
.Pa /emul/linux ,
to avoid naming conflicts with possible
.Ox
counterparts.
Shared libraries should also be installed in the shadow tree.
.Pp
Generally, it will only be necessary to look for the shared libraries
that Linux binaries depend on the first few times that Linux programs
are installed on the
.Ox
system.
After a while, there will be a sufficient set of Linux shared libraries
on the system to be able to run newly imported Linux binaries without
any extra work.
.Ss Setting up shared libraries
How to get to know which shared libraries Linux binaries need, and where
to get them?
Basically, there are 3 possibilities.
(When following these instructions, root privileges are required on the
.Ox
system to perform the necessary installation steps).
.Bl -enum
.It
Access to the
.Ox
.Xr ports 7
system:
Install the port named
.Nm fedora/base
in the
.Nm emulators
category.
The
.Nm fedora/base
port contains the shared libraries, binaries, and other related files
necessary to run Linux applications.
Access to a Linux system is not needed.
.It
Access to a Linux system:
In this case temporarily install the binary there, see what
shared libraries it needs, and copy them to the
.Ox
system.
Example: ftp the Linux binary of Doom.
Put it on the Linux system, and check which shared
libraries it needs by running `ldd linuxxdoom':
.Pp
.Dl (me@linux) ldd linuxxdoom
.Bd -unfilled -offset indent
libXt.so.3 (DLL Jump 3.1) => /usr/X11/lib/libXt.so.3.1.0
libX11.so.3 (DLL Jump 3.1) => /usr/X11/lib/libX11.so.3.1.0
libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29
.Ed
.Pp
Get all the files from the last column, and put them under
.Pa /emul/linux ,
with the names in the first column
as symbolic links pointing to them.
The following files would therefore be required on the
.Ox
system:
.Bd -unfilled -offset indent
/emul/linux/usr/X11/lib/libXt.so.3.1.0
/emul/linux/usr/X11/lib/libXt.so.3 (symbolic link to the above)
/emul/linux/usr/X11/lib/libX11.so.3.1.0
/emul/linux/usr/X11/lib/libX11.so.3 (symbolic link to the above)
/emul/linux/lib/libc.so.4.6.29
/emul/linux/lib/libc.so.4 (symbolic link to the above)
.Ed
.Pp
Note that if a Linux shared library with a
matching major revision number to the first column of the 'ldd'
output is already present, it isn't necessary to copy the file named
in the last column to the
.Ox
system; the one already there should work.
It is advisable to copy the shared library anyway, if it is a newer version.
The old one can be removed, as long as the symbolic
link points to the new one.
So, if these libraries exist on the system:
.Bd -unfilled -offset indent
/emul/linux/lib/libc.so.4.6.27
/emul/linux/lib/libc.so.4 -> /emul/linux/lib/libc.so.4.6.27
.Ed
.Pp
and the ldd output for a new binary is:
.Bd -unfilled -offset indent
libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29
.Ed
.Pp
it isn't necessary to copy
.Pa /lib/libc.so.4.6.29
too, because the program should work fine with the slightly older version.
.Pa libc.so
can be replaced anyway, and that should leave:
.Bd -unfilled -offset indent
/emul/linux/lib/libc.so.4.6.29
/emul/linux/lib/libc.so.4 -> /emul/linux/lib/libc.so.4.6.29
.Ed
.Pp
Please note that the symbolic link mechanism is
only needed for Linux binaries, the
.Ox
runtime linker takes care of looking for matching major revision numbers
itself.
.Pp
Finally, the Linux runtime linker and its config files must be present
on the system.
These files should be copied from the Linux system to their appropriate
place on the
.Ox
system (in the
.Pa /emul/linux
tree):
.Bd -unfilled -offset indent
/lib/ld.so
/etc/ld.so.cache
/etc/ld.so.config
.Ed
.It
No access to a Linux system:
In that case, get the extra files from various ftp sites.
Information on where to look for the various files is appended
below.
.Pp
Retrieve the following files (from _one_ ftp site to avoid
any version mismatches), and install them under
.Pa /emul/linux
(i.e.\&
.Pa /foo/bar
is installed as
.Pa /emul/linux/foo/bar ) :
.Bd -unfilled -offset indent
/sbin/ldconfig
/usr/bin/ldd
/lib/libc.so.x.y.z
/lib/ld.so
.Ed
.Pp
ldconfig and ldd don't necessarily need to be under
.Pa /emul/linux ,
they can be installed elsewhere in the system too.
Just make sure they don't conflict with their
.Ox
counterparts.
A good idea would be to install them in
.Pa /usr/local/bin
as ldconfig-linux and ldd-linux.
.Pp
Create the file
.Pa /emul/linux/etc/ld.so.conf ,
containing the directories in which the Linux runtime linker should look
for shared libs.
It is a plain text file, containing a directory
name on each line.
.Pa /lib
and
.Pa /usr/lib
are standard; the following could be added:
.Bd -unfilled -offset indent
/usr/X11/lib
/usr/local/lib
.Ed
.Pp
Note that these are mapped to
.Pa /emul/linux/XXXX
by the
.Ox
compat code, and should exist as such on the
.Ox
system.
.Pp
Run the Linux ldconfig program.
It should be statically linked, so it doesn't need any shared libraries
by itself.
It will create the file
.Pa /emul/linux/etc/ld.so.cache .
The Linux version of the ldconfig program should be rerun
each time a new shared library is added.
.Pp
The
.Ox
system should now be set up for Linux binaries which only need
a shared libc.
Test this by running the Linux ldd on itself.
Suppose that it is installed as ldd-linux, it should produce
something like:
.Pp
.Dl % ldd-linux `which ldd-linux`
.Pp
.D1 libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29
.Pp
This being done, new Linux binaries can now be installed.
Whenever a new Linux program is installed, it should be determined
if it needs shared libraries, and if so, whether they are
installed in the
.Pa /emul/linux
tree.
To do this, run the Linux version ldd on the new program, and
watch its output.
ldd (see also the manual page for ldd(1)) will print a list
of shared libraries that the program depends on, in the
form  <majorname> (<jumpversion>) => <fullname>.
.Pp
If it prints "not found" instead of <fullname> it means that
an extra library is needed.
Which library this is, is shown
in <majorname>, which will be of the form libXXXX.so.<N>.
Find a libXXXX.so.<N>.<mm> on a Linux ftp site,
and install it on the
.Ox
system.
The XXXX (name) and <N> (major revision number) should match;
the minor number(s) <mm> are less important, though it is
advised to take the most recent version.
.El
.Ss Finding the necessary files
.Sy Note :
the information below is valid as of Feb 2003, but certain details
such as names of ftp sites, directories and distribution names
may have changed since then.
It is much easier to use the
.Ox
.Xr ports 7
system (possibility 1, above).
.Pp
Linux is distributed by several groups that make their own set
of binaries that they distribute.
Each distribution has its own name, like "Slackware" or "Yggdrasil".
The distributions are available on a lot of ftp sites.
Sometimes the files are unpacked, and individual files can be retrieved,
but mostly they are stored in distribution sets,
usually consisting of subdirectories with gzipped tar files in them.
The primary ftp sites for the distributions are:
.Bd -unfilled -offset indent
.Pa ftp.ibiblio.org:/pub/Linux/distributions
.Pa distro.ibiblio.org:/pub/Linux/distributions
.\" .Pa tsx-11.mit.edu:/pub/linux/distributions
.Ed
.Pp
Some European mirrors:
.Bd -unfilled -offset indent
.\" .Pa ftp.luth.se:/pub/linux/distributions
.\" .Pa ftp.demon.co.uk:/pub/linux/distributions
.Pa ftp.sunet.se:/pub/Linux/distributions
.Pa src.doc.ic.ac.uk:/packages/linux
.Ed
.Pp
For simplicity, let's concentrate on Slackware here.
This distribution consists of a number of subdirectories, containing
separate packages.
Normally, they're controlled by an install program, but the files can be
retrieved "by hand" too.
The fastest way to find something is to
.Xr grep 1
the file FILELIST.TXT for
the files needed.
Here is an example of a list of files that might be needed, and
in which package it can be found:
.Bd -unfilled -offset indent
Needed                  Package

ld-2.2.5.so             glibc
ldconfig                glibc
ldd                     glibc
libc.so.6               glibc
libX11.so.6             xfree
libXt.so.6              xfree
.Ed
.Pp
So, in this case, the packages glibc and xfree will be needed.
FILELIST.TXT also gives the location of the packages.
Retrieve the packages needed from the following files
(relative to the root of the Slackware distribution tree):
.Bd -unfilled -offset indent
slackware/l/glibc-2.2.5-i386.2.tgz
slackware/x/xfree-4.2.0-i386.5.tgz
.Ed
.Pp
Extract the files from these gzipped tarfiles in the
.Pa /emul/linux
directory
(possibly omitting or afterwards removing unnecessary files).
.Ss Programs using SVGAlib
SVGAlib binaries require some extra care.
The pcvt virtual console driver has to be in the kernel for them to work,
and some symbolic links in the
.Pa /emul/linux/dev
directory will have to be created, namely:
.Bd -unfilled -offset indent
/emul/linux/dev/console -> /dev/tty
/emul/linux/dev/mouse -> whatever device the mouse is connected to
/emul/linux/dev/ttyS0 -> /dev/tty00
/emul/linux/dev/ttyS1 -> /dev/tty01
.Ed
.Pp
Be warned: the first link mentioned here makes SVGAlib binaries
work, but may confuse others, so it may be necessary to remove it again at
some point.
.Ss Programs using OSS (Linux) audio
Only the DSP device is emulated, the following link should be created:
.Pp
.D1 /emul/linux/dev/dsp -> /dev/audio
.Ss Other links Linux binaries may require
CD-ROM support requires a link to the CD-ROM device, similar to:
.Pp
.D1 /emul/linux/dev/cdrom -> /dev/cd0a   (first CD-ROM)
.Ss File systems
Many Linux binaries expect
.Pa /proc
to have procfs mounted on it.
Some binaries will require it to be mounted using the
.Fl o Ar linux
option.
.Sh BUGS
The information about Linux distributions may become outdated.
.Pp
Linux ELF binaries may be detected as SVR4 binaries.
This can usually be fixed with
.Xr elf2olf 1
by setting the OLF opsys tag to Linux, e.g.\&
.Pp
.Dl % elf2olf -o linux <linux_binary>
.Pp
.Nm
is currently only supported on the i386.