xref: /netbsd-src/share/man/man8/compat_linux.8 (revision da5f4674a3fc214be3572d358b66af40ab9401e7)
1.\"	$NetBSD: compat_linux.8,v 1.29 2003/05/14 07:50:50 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 March 29, 2002
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 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).
45Programs that will not work include some that use the Linux
46.Pa /proc
47filesystem (which is different from the optional
48.Nx
49.Pa /proc
50filesystem), and i386-specific calls, such as
51enabling virtual 8086 mode.
52Currently, sound is only partially supported for Linux binaries (they will
53probably run, depending on what Linux sound support features are used).
54.Pp
55The Linux compatibility feature is active
56for kernels compiled with the
57.Dv COMPAT_LINUX
58option enabled.
59If support for Linux a.out executables is desired, the
60.Dv EXEC_AOUT
61option should be enabled in addition to option
62.Dv COMPAT_LINUX .
63Similarly, if support for Linux 32-bit and/or 64-bit ELF executables
64is desired, the
65.Dv EXEC_ELF32
66and/or
67.Dv EXEC_ELF64
68options (respectively) should be enabled in addition to
69.Dv COMPAT_LINUX .
70.Pp
71A lot of programs are dynamically linked.
72This means that you will also need the Linux shared libraries that the
73program depends on, and the runtime linker.
74Also, you will need to create a
75.Dq shadow root
76directory for Linux binaries on your
77.Nx
78system.
79This directory is named
80.Pa /emul/linux .
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.
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/suse_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.El
364.Ss Setting up procfs
365Some Linux binaries expect procfs to be mounted and that it would
366contain some Linux specific stuff.
367If it's not the case, they behave unexpectedly or even crash.
368.Pp
369Mount procfs on
370.Nx
371using following command:
372.Bl -tag -width 123 -offset indent
373.It (me@netbsd) mount_procfs -o linux procfs /emul/linux/proc
374.El
375.Pp
376You can also set up your system so that procfs is mounted automatically
377on system boot, by putting an entry like the one below to
378.Pa /etc/fstab .
379.Bl -tag -width 123 -offset indent
380.It procfs /emul/linux/proc procfs ro,linux
381.El
382.Pp
383See
384.Xr mount_procfs 8
385for further information.
386.Ss Setting up other files
387Newer version of Linux use
388.Pa /etc/nsswitch.conf
389for network information, such as
390.Tn NIS
391and DNS.
392You must create or get a valid copy of this file and put it in
393.Pa /emul/linux/etc .
394.Ss Finding the necessary files
395.Em Note :
396the information below is valid as of the time this
397document was first written (March, 1995), but certain details
398such as names of ftp sites, directories and distribution names
399may have changed by the time you read this.
400.Pp
401Linux is distributed by several groups that make their own set
402of binaries that they distribute.
403Each distribution has its own name, like
404.Dq Slackware
405or
406.Dq Yggdrasil .
407The distributions are
408available on a lot of ftp sites.
409Sometimes the files are unpacked,
410and you can get the individual files you need, but mostly they
411are stored in distribution sets, usually consisting of subdirectories
412with gzipped tar files in them.
413The primary ftp sites for the distributions are:
414.Bl -item -compact -offset indent
415.It
416.Pa sunsite.unc.edu:/pub/Linux/distributions
417.It
418.Pa tsx-11.mit.edu:/pub/linux/distributions
419.El
420.Pp
421Some European mirrors:
422.Bl -item -compact -offset indent
423.It
424.Pa ftp.luth.se:/pub/linux/distributions
425.It
426.Pa ftp.demon.co.uk:/pub/linux/distributions
427.It
428.Pa src.doc.ic.ac.uk:/packages/linux/distributions
429.El
430.Pp
431For simplicity, let's concentrate on Slackware here.
432This distribution
433consists of a number of subdirectories, containing separate packages.
434Normally, they're controlled by an install program, but you can
435retrieve files
436.Dq by hand
437too.
438First of all, you will need to look in the
439.Pa contents
440subdir of the distribution.
441You will find a lot of small textfiles here describing the contents of
442the separate packages.
443The fastest way to look something up is to retrieve all the files in the
444contents subdirectory, and grep through them for the file you need.
445Here is an example of a list of files that you might need, and
446in which contents-file you will find it by grepping through them:
447.Pp
448.Bd -literal -offset indent
449Needed                  Package
450
451ld.so                   ldso
452ldconfig                ldso
453ldd                     ldso
454libc.so.4               shlibs
455libX11.so.6.0           xf_lib
456libXt.so.6.0            xf_lib
457libX11.so.3             oldlibs
458libXt.so.3              oldlibs
459.Ed
460.Pp
461So, in this case, you will need the packages ldso, shlibs, xf_lib and oldlibs.
462In each of the contents-files for these packages, look for a line saying
463.Dq PACKAGE LOCATION ,
464it will tell you on which
465.Sq disk
466the package is,
467in our case it will tell us in which subdirectory we need to look.
468For our example, we would find the following locations:
469.Pp
470.Bd -literal -offset indent
471Package                 Location
472
473ldso                    diska2
474shlibs                  diska2
475oldlibs                 diskx6
476xf_lib                  diskx9
477.Ed
478.Pp
479The locations called
480.Pa diskXX
481refer to the
482.Pa slakware/XX
483subdirectories
484of the distribution, others may be found in the
485.Pa contrib
486subdirectory.
487In this case, we could now retrieve the packages we need by retrieving
488the following files (relative to the root of the Slackware distribution
489tree):
490.Bl -item -compact
491.It
492.Pa slakware/a2/ldso.tgz
493.It
494.Pa slakware/a2/shlibs.tgz
495.It
496.Pa slakware/x6/oldlibs/tgz
497.It
498.Pa slakware/x9/xf_lib.tgz
499.El
500.Pp
501Extract the files from these gzipped tarfiles in your /emul/linux directory
502(possibly omitting or afterwards removing files you don't need), and you
503are done.
504.Ss Programs using SVGAlib
505SVGAlib binaries require some extra care.
506You need to have
507.Cd options WSDISPLAY_COMPAT_USL
508in your kernel (see
509.Xr wscons 4 ) ,
510and you will also have to create
511some symbolic links in the
512.Pa /emul/linux/dev
513directory, namely:
514.Bl -item -compact
515.It
516.Pa /emul/linux/dev/console
517-\*[Gt]
518.Pa /dev/tty
519.It
520.Pa /emul/linux/dev/mouse
521-\*[Gt] whatever device your mouse is connected to
522.It
523.Pa /emul/linux/dev/ttyS0
524-\*[Gt]
525.Pa /dev/tty00
526.It
527.Pa /emul/linux/dev/ttyS1
528-\*[Gt]
529.Pa /dev/tty01
530.El
531.Pp
532Be warned: the first link mentioned here makes SVGAlib binaries
533work, but may confuse others, so you may have to remove it again at
534some point.
535.Sh BUGS
536The information about Linux distributions may become outdated.
537.Pp
538Pathnames pointed to by symbolic links are not looked up in the
539shadow root when running a Linux executable.
540This is not consistent.
541.Pp
542Linux executables cannot handle directory offset cookies \*[Gt] 32 bits.
543Should such an offset occur, you will see the message
544.Dq linux_getdents: dir offset too large for emulated program .
545Currently, this can only
546happen on NFS mounted filesystems, mounted from servers that return
547offsets with information in the upper 32 bits.
548These errors should rarely happen, but can be avoided by mounting this
549filesystem with offset translation enabled.
550See the
551.Fl X
552option to
553.Xr mount_nfs 8 .
554The
555.Fl 2
556option to
557.Xr mount_nfs 8
558will also have the desired effect, but is less preferable.
559