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