xref: /netbsd-src/share/man/man8/compat_linux.8 (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1.\"	$NetBSD: compat_linux.8,v 1.36 2007/12/02 21:45:59 wiz Exp $
2.\"
3.\" Copyright (c) 1995 Frank van der Linden
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"      This product includes software developed for the NetBSD Project
17.\"      by Frank van der Linden
18.\" 4. The name of the author may not be used to endorse or promote products
19.\"    derived from this software without specific prior written permission
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.\"
32.Dd April 30, 2007
33.Dt COMPAT_LINUX 8
34.Os
35.Sh NAME
36.Nm compat_linux
37.Nd setup procedure for running Linux binaries
38.Sh DESCRIPTION
39.Nx
40supports running Linux binaries.
41This applies to amd64, arm, alpha, i386, m68k, and powerpc systems for now.
42Both the a.out and ELF binary formats are supported.
43Most programs should work, including the ones that use the Linux SVGAlib (only
44on i386).
45.Nx
46amd64 can execute both 32bit and 64bit linux programs.
47Programs that will not work include some that use
48i386-specific calls, such as enabling virtual 8086 mode.
49Currently, sound is only partially supported for Linux binaries (they will
50probably run, depending on what Linux sound support features are used).
51.Pp
52The Linux compatibility feature is active
53for kernels compiled with the
54.Dv COMPAT_LINUX
55option enabled.
56If support for Linux a.out executables is desired, the
57.Dv EXEC_AOUT
58option should be enabled in addition to option
59.Dv COMPAT_LINUX .
60Similarly, if support for Linux 32-bit and/or 64-bit ELF executables
61is desired, the
62.Dv EXEC_ELF32
63and/or
64.Dv EXEC_ELF64
65options (respectively) should be enabled in addition to
66.Dv COMPAT_LINUX .
67.Pp
68A lot of programs are dynamically linked.
69This means that you will also need the Linux shared libraries that the
70program depends on, and the runtime linker.
71Also, you will need to create a
72.Dq shadow root
73directory for Linux binaries on your
74.Nx
75system.
76This directory is named
77.Pa /emul/linux
78or
79.Pa /emul/linux32
80for 32bit emulation on 64bit systems.
81Any file operations done by Linux programs run under
82.Nx
83will look in this directory first.
84So, if a Linux program opens, for example,
85.Pa /etc/passwd ,
86.Nx
87will
88first try to open
89.Pa /emul/linux/etc/passwd ,
90and if that does not exist open the
91.Sq real
92.Pa /etc/passwd
93file.
94It is recommended that you install
95Linux packages that include configuration files, etc under
96.Pa /emul/linux ,
97to avoid naming conflicts with possible
98.Nx
99counterparts.
100Shared libraries should also be installed in the shadow tree.
101Filenames that start "/../" are only looked up in the real root.
102.Pp
103Generally, you will need to look for the shared libraries that Linux
104binaries depend on only the first few times that you install a Linux
105program on your
106.Nx
107system.
108After a while, you will have a sufficient
109set of Linux shared libraries on your system to be able to run newly
110imported Linux binaries without any extra work.
111.Ss Setting up shared libraries
112How to get to know which shared libraries Linux binaries need, and where
113to get them? Basically, there are 2 possibilities (when following
114these instructions: you will need to be root on your
115.Nx
116system to
117do the necessary installation steps).
118.Bl -enum
119.It
120For i386, you can simply install the SuSE shared libs using the
121.Pa pkgsrc/emulators/suse100_linux
122package(s).
123On PowerPC ports, the
124.Pa pkgsrc/emulators/linuxppc_lib
125will install the needed libraries.
126If you are on other platforms, or this doesn't supply you with all
127the needed libraries, read on.
128.It
129You have access to a Linux system.
130In this case you can temporarily install the binary there, see what
131shared libraries it needs, and copy them to your
132.Nx
133system.
134Example: you have just ftp-ed the Linux binary of Doom.
135Put it on the Linux system you have access to, and check which shared libraries it
136needs by running
137.Sq ldd linuxxdoom :
138.Pp
139.Bl -tag -width 123 -compact -offset indent
140.It (me@linux) ldd linuxxdoom
141.nf
142libXt.so.3 (DLL Jump 3.1) =\*[Gt] /usr/X11/lib/libXt.so.3.1.0
143libX11.so.3 (DLL Jump 3.1) =\*[Gt] /usr/X11/lib/libX11.so.3.1.0
144libc.so.4 (DLL Jump 4.5pl26) =\*[Gt] /lib/libc.so.4.6.29
145.fi
146.El
147.Pp
148You would need go get all the files from the last column, and
149put them under
150.Pa /emul/linux ,
151with the names in the first column
152as symbolic links pointing to them.
153This means you eventually have these files on your
154.Nx
155system:
156.Bl -item -compact
157.It
158.Pa /emul/linux/usr/X11/lib/libXt.so.3.1.0
159.It
160.Pa /emul/linux/usr/X11/lib/libXt.so.3
161(symbolic link to the above)
162.It
163.Pa /emul/linux/usr/X11/lib/libX11.so.3.1.0
164.It
165.Pa /emul/linux/usr/X11/lib/libX11.so.3
166(symbolic link to the above)
167.It
168.Pa /emul/linux/lib/libc.so.4.6.29
169.It
170.Pa /emul/linux/lib/libc.so.4
171(symbolic link to the above)
172.El
173.Pp
174Note that if you already have a Linux shared library with a
175matching major revision number to the first column of the
176.Xr ldd 1
177output, you won't need to copy the file named in the last column
178to your system, the one you already have should work.
179It is advisable to copy the shared library anyway if it is a newer version,
180though.
181You can remove the old one, as long as you make the symbolic
182link point to the new one.
183So, if you have these libraries on your system:
184.Pp
185.Bl -item -compact
186.It
187.Pa /emul/linux/lib/libc.so.4.6.27
188.It
189.Pa /emul/linux/lib/libc.so.4
190-\*[Gt]
191.Pa /emul/linux/lib/libc.so.4.6.27
192.El
193.Pp
194and you find that the
195.Ic ldd
196output for a new binary you want to install is:
197.nf
198.Pp
199libc.so.4 (DLL Jump 4.5pl26) =\*[Gt] /lib/libc.so.4.6.29
200.fi
201.Pp
202you won't need to worry about copying
203.Pa /lib/libc.so.4.6.29
204too, because the program should work fine with the slightly older version.
205You can decide to replace the libc.so anyway, and that should leave
206you with:
207.Bl -item -compact
208.It
209.Pa /emul/linux/lib/libc.so.4.6.29
210.It
211.Pa /emul/linux/lib/libc.so.4
212-\*[Gt]
213.Pa /emul/linux/lib/libc.so.4.6.29
214.El
215.Pp
216Please note that the symbolic link mechanism is
217.Em only
218needed for Linux binaries, the
219.Nx
220runtime linker takes care of
221looking for matching major revision numbers itself, you
222don't need to worry about that.
223.Pp
224Finally, you must make sure that you have the Linux runtime linker
225and its config files on your system.
226You should copy these
227files from the Linux system to their appropriate place on your
228.Nx
229system (in the
230.Pa /emul/linux
231tree):
232.Bl -item -compact
233.It
234.Pa /lib/ld.so
235.It
236.Pa /etc/ld.so.cache
237.It
238.Pa /etc/ld.so.config
239.El
240.It
241You don't have access to a Linux system.
242In that case, you should get the extra files you need from various ftp sites.
243Information on where to look for the various files is appended below.
244For now, let's assume you know where to get the files.
245.Pp
246Retrieve the following files (from _one_ ftp site to avoid
247any version mismatches), and install them under
248.Pa /emul/linux
249(i.e.
250.Pa /foo/bar
251is installed as
252.Pa /emul/linux/foo/bar ) :
253.Pp
254.Bl -item -compact
255.It
256.Pa /sbin/ldconfig
257.It
258.Pa /usr/bin/ldd
259.It
260.Pa /lib/libc.so.x.y.z
261.It
262.Pa /lib/ld.so
263.El
264.Pp
265.Ic ldconfig
266and
267.Ic ldd
268don't necessarily need to be under
269.Pa /emul/linux ,
270you can install them elsewhere in the system too.
271Just make sure they don't conflict with their
272.Nx
273counterparts.
274A good idea would be to install them in
275.Pa /usr/local/bin
276as
277.Ic ldconfig-linux
278and
279.Ic ldd-linux .
280.Pp
281Create the file
282.Pa /emul/linux/etc/ld.so.conf ,
283containing the directories in which the Linux runtime linker should look
284for shared libs.
285It is a plain text file, containing a directory name on each line.
286.Pa /lib
287and
288.Pa /usr/lib
289are standard, you could add the following:
290.Bl -item -compact
291.It
292.Pa /usr/X11/lib
293.It
294.Pa /usr/local/lib
295.El
296.Pp
297Note that these are mapped to
298.Pa /emul/linux/XXXX
299by
300.Nx Ap s
301compat
302code, and should exist as such on your system.
303.Pp
304Run the Linux
305.Ic ldconfig
306program.
307It should be statically
308linked, so it doesn't need any shared libraries by itself.
309It will create the file
310.Pa /emul/linux/etc/ld.so.cache
311You should rerun the Linux version of
312.Ic ldconfig
313each time you add a new shared library.
314.Pp
315You should now be set up for Linux binaries which only need
316a shared libc.
317You can test this by running the Linux
318.Ic ldd
319on itself.
320Suppose that you have it installed as
321.Ic ldd-linux ,
322it should produce something like:
323.Pp
324.Bl -tag -width 123 -compact -offset indent
325.It (me@netbsd) ldd-linux `which ldd-linux`
326libc.so.4 (DLL Jump 4.5pl26) =\*[Gt] /lib/libc.so.4.6.29
327.El
328.Pp
329This being done, you are ready to install new Linux binaries.
330Whenever you install a new Linux program, you should check
331if it needs shared libraries, and if so, whether you have
332them installed in the
333.Pa /emul/linux
334tree.
335To do this, you run the Linux
336.Ic ldd
337on the new program, and watch its output.
338.Ic ldd
339(see also the manual page for
340.Xr ldd 1 )
341will print a list
342of shared libraries that the program depends on, in the
343form
344.Aq majorname
345.Pq Aq jumpversion
346=\*[Gt]
347.Aq fullname .
348.Pp
349If it prints
350.Dq not found
351instead of
352.Aq fullname
353it means that you need an extra library.
354Which library this is, is shown in
355.Aq majorname ,
356which will be of the form libXXXX.so.\*[Lt]N\*[Gt]
357You will need to find a libXXXX.so.\*[Lt]N\*[Gt].\*[Lt]mm\*[Gt] on a
358Linux ftp site, and install it on your system.
359The XXXX (name) and
360.Aq N
361(major revision number) should match; the minor number(s)
362.Aq mm
363are less important, though it is advised to take the most recent version.
364.It
365Set up linux specific devices:
366.Pp
367.Bl -tag -width 123 -compact -offset indent
368.It (me@netbsd) cd /usr/share/examples/emul/linux/etc
369.br
370.It (me@netbsd) cp LINUX_MAKEDEV /emul/linux/dev
371.br
372.It (me@netbsd) cd /emul/linux/dev \*[Am]\*[Am] sh LINUX_MAKEDEV all
373.El
374.El
375.Ss Setting up procfs
376Some Linux binaries expect procfs to be mounted and that it would
377contain some Linux specific stuff.
378If it's not the case, they behave unexpectedly or even crash.
379.Pp
380Mount procfs on
381.Nx
382using following command:
383.Bl -tag -width 123 -offset indent
384.It (me@netbsd) mount_procfs -o linux procfs /emul/linux/proc
385.El
386.Pp
387You can also set up your system so that procfs is mounted automatically
388on system boot, by putting an entry like the one below to
389.Pa /etc/fstab .
390.Bl -tag -width 123 -offset indent
391.It procfs /emul/linux/proc procfs ro,linux
392.El
393.Pp
394See
395.Xr mount_procfs 8
396for further information.
397.Ss Setting up other files
398Newer version of Linux use
399.Pa /etc/nsswitch.conf
400for network information, such as
401.Tn NIS
402and DNS.
403You must create or get a valid copy of this file and put it in
404.Pa /emul/linux/etc .
405.Ss Finding the necessary files
406.Em Note :
407the information below is valid as of the time this
408document was first written (March, 1995), but certain details
409such as names of ftp sites, directories and distribution names
410may have changed by the time you read this.
411.Pp
412Linux is distributed by several groups that make their own set
413of binaries that they distribute.
414Each distribution has its own name, like
415.Dq Slackware
416or
417.Dq Yggdrasil .
418The distributions are
419available on a lot of ftp sites.
420Sometimes the files are unpacked,
421and you can get the individual files you need, but mostly they
422are stored in distribution sets, usually consisting of subdirectories
423with gzipped tar files in them.
424The primary ftp sites for the distributions are:
425.Bl -item -compact -offset indent
426.It
427.Pa sunsite.unc.edu:/pub/Linux/distributions
428.It
429.Pa tsx-11.mit.edu:/pub/linux/distributions
430.El
431.Pp
432Some European mirrors:
433.Bl -item -compact -offset indent
434.It
435.Pa ftp.luth.se:/pub/linux/distributions
436.It
437.Pa ftp.demon.co.uk:/pub/linux/distributions
438.It
439.Pa src.doc.ic.ac.uk:/packages/linux/distributions
440.El
441.Pp
442For simplicity, let's concentrate on Slackware here.
443This distribution
444consists of a number of subdirectories, containing separate packages.
445Normally, they're controlled by an install program, but you can
446retrieve files
447.Dq by hand
448too.
449First of all, you will need to look in the
450.Pa contents
451subdir of the distribution.
452You will find a lot of small textfiles here describing the contents of
453the separate packages.
454The fastest way to look something up is to retrieve all the files in the
455contents subdirectory, and grep through them for the file you need.
456Here is an example of a list of files that you might need, and
457in which contents-file you will find it by grepping through them:
458.Pp
459.Bd -literal -offset indent
460Needed                  Package
461
462ld.so                   ldso
463ldconfig                ldso
464ldd                     ldso
465libc.so.4               shlibs
466libX11.so.6.0           xf_lib
467libXt.so.6.0            xf_lib
468libX11.so.3             oldlibs
469libXt.so.3              oldlibs
470.Ed
471.Pp
472So, in this case, you will need the packages ldso, shlibs, xf_lib and oldlibs.
473In each of the contents-files for these packages, look for a line saying
474.Dq PACKAGE LOCATION ,
475it will tell you on which
476.Sq disk
477the package is,
478in our case it will tell us in which subdirectory we need to look.
479For our example, we would find the following locations:
480.Pp
481.Bd -literal -offset indent
482Package                 Location
483
484ldso                    diska2
485shlibs                  diska2
486oldlibs                 diskx6
487xf_lib                  diskx9
488.Ed
489.Pp
490The locations called
491.Pa diskXX
492refer to the
493.Pa slakware/XX
494subdirectories
495of the distribution, others may be found in the
496.Pa contrib
497subdirectory.
498In this case, we could now retrieve the packages we need by retrieving
499the following files (relative to the root of the Slackware distribution
500tree):
501.Bl -item -compact
502.It
503.Pa slakware/a2/ldso.tgz
504.It
505.Pa slakware/a2/shlibs.tgz
506.It
507.Pa slakware/x6/oldlibs/tgz
508.It
509.Pa slakware/x9/xf_lib.tgz
510.El
511.Pp
512Extract the files from these gzipped tarfiles in your /emul/linux directory
513(possibly omitting or afterwards removing files you don't need), and you
514are done.
515.Ss Programs using SVGAlib
516SVGAlib binaries require some extra care.
517You need to have
518.Cd options WSDISPLAY_COMPAT_USL
519in your kernel (see
520.Xr wscons 4 ) ,
521and you will also have to create
522some symbolic links in the
523.Pa /emul/linux/dev
524directory, namely:
525.Bl -item -compact
526.It
527.Pa /emul/linux/dev/console
528-\*[Gt]
529.Pa /dev/tty
530.It
531.Pa /emul/linux/dev/mouse
532-\*[Gt] whatever device your mouse is connected to
533.It
534.Pa /emul/linux/dev/ttyS0
535-\*[Gt]
536.Pa /dev/tty00
537.It
538.Pa /emul/linux/dev/ttyS1
539-\*[Gt]
540.Pa /dev/tty01
541.El
542.Pp
543Be warned: the first link mentioned here makes SVGAlib binaries
544work, but may confuse others, so you may have to remove it again at
545some point.
546.Sh BUGS
547The information about Linux distributions may become outdated.
548.Pp
549Absolute pathnames pointed to by symbolic links are only looked up in the
550shadow root when the symbolic link itself was found by an absolute
551pathname inside the shadow root.
552This is not consistent.
553.Pp
554Linux executables cannot handle directory offset cookies \*[Gt] 32 bits.
555Should such an offset occur, you will see the message
556.Dq linux_getdents: dir offset too large for emulated program .
557Currently, this can only
558happen on NFS mounted file systems, mounted from servers that return
559offsets with information in the upper 32 bits.
560These errors should rarely happen, but can be avoided by mounting this
561file system with offset translation enabled.
562See the
563.Fl X
564option to
565.Xr mount_nfs 8 .
566The
567.Fl 2
568option to
569.Xr mount_nfs 8
570will also have the desired effect, but is less preferable.
571