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