xref: /netbsd-src/share/man/man8/compat_linux.8 (revision 11b9cb2b2b6ed956072bfa8f9f115512ff97f0cb)
1.\"	$NetBSD: compat_linux.8,v 1.46 2021/11/28 18:08:51 ryo 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 26, 2021
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 aarch64, alpha, amd64, arm, i386, m68k, and powerpc systems for now.
42Both the a.out and ELF binary formats are supported.
43Most programs should work.
44.Nx
45aarch64 and amd64 can execute both 32-bit and 64-bit Linux programs.
46Programs that will not work include some that use
47i386-specific calls, such as enabling virtual 8086 mode.
48Currently, sound is supported through OSSv3 compat.
49.Pp
50The Linux compatibility feature is active
51for kernels compiled with the
52.Dv COMPAT_LINUX
53option enabled.
54If support for Linux a.out executables is desired, the
55.Dv EXEC_AOUT
56option should be enabled in addition to option
57.Dv COMPAT_LINUX .
58Similarly, if support for Linux 32-bit and/or 64-bit ELF executables
59is desired, the
60.Dv EXEC_ELF32
61and/or
62.Dv EXEC_ELF64
63options (respectively) should be enabled in addition to
64.Dv COMPAT_LINUX .
65If sound support is desired,
66.Dv COMPAT_OSSAUDIO
67should be enabled.
68.Pp
69A lot of programs are dynamically linked.
70This means that you will also need the Linux shared libraries that the
71program depends on, and the runtime linker.
72Also, you will need to create a
73.Dq shadow root
74directory for Linux binaries on your
75.Nx
76system.
77This directory is named
78.Pa /emul/linux
79or
80.Pa /emul/linux32
81for 32-bit emulation on 64-bit systems.
82Any file operations done by Linux programs run under
83.Nx
84will look in this directory first.
85So, if a Linux program opens, for example,
86.Pa /etc/passwd ,
87.Nx
88will
89first try to open
90.Pa /emul/linux/etc/passwd ,
91and if that does not exist open the
92.Sq real
93.Pa /etc/passwd
94file.
95It is recommended that you install
96Linux packages that include configuration files, etc under
97.Pa /emul/linux ,
98to avoid naming conflicts with possible
99.Nx
100counterparts.
101Shared libraries should also be installed in the shadow tree.
102Filenames that start "/../" are only looked up in the real root.
103.Pp
104Generally, you will need to look for the shared libraries that Linux
105binaries depend on only the first few times that you install a Linux
106program on your
107.Nx
108system.
109After a while, you will have a sufficient
110set of Linux shared libraries on your system to be able to run newly
111imported Linux binaries without any extra work.
112.Ss Setting up shared libraries
113Find the dependencies of a Linux binary using
114.Xr readelf 1 :
115.Bd -literal
116$ readelf -d ./runner | grep Shared
117 0x00000001 (NEEDED)                     Shared library: [libstdc++.so.6]
118 0x00000001 (NEEDED)                     Shared library: [libz.so.1]
119 0x00000001 (NEEDED)                     Shared library: [libXxf86vm.so.1]
120 0x00000001 (NEEDED)                     Shared library: [libGL.so.1]
121 0x00000001 (NEEDED)                     Shared library: [libopenal.so.1]
122 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
123 0x00000001 (NEEDED)                     Shared library: [librt.so.1]
124 0x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
125 0x00000001 (NEEDED)                     Shared library: [libdl.so.2]
126 0x00000001 (NEEDED)                     Shared library: [libcrypto.so.1.0.0]
127 0x00000001 (NEEDED)                     Shared library: [libXext.so.6]
128 0x00000001 (NEEDED)                     Shared library: [libX11.so.6]
129 0x00000001 (NEEDED)                     Shared library: [libXrandr.so.2]
130 0x00000001 (NEEDED)                     Shared library: [libGLU.so.1]
131 0x00000001 (NEEDED)                     Shared library: [libssl.so.1.0.0]
132 0x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
133 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
134.Ed
135.Pp
136For x86, you can simply install the openSUSE shared libraries using the
137.Pa pkgsrc/emulators/suse131_*
138or
139.Pa pkgsrc/emulators/suse131_32_*
140packages.
141.Pp
142For example, an application which requires
143.Pa libcrypto.so.1.0.0 ,
144.Pa libXext.so.6 ,
145and
146.Pa libGL.so.1
147will require
148.Dv openssl ,
149.Dv x11 ,
150and
151.Dv glx ,
152in addition to the
153.Dv base
154SUSE package.
155.Pp
156Otherwise, you may have to obtain shared libraries from another Linux
157system, and copy them to e.g.
158.Pa /emul/linux/lib64 .
159.Ss Setting up procfs
160Some Linux binaries expect procfs to be mounted and that it
161contains some Linux-specific extensions.
162If it's not the case, they behave unexpectedly or even crash.
163.Pp
164Mount procfs on
165.Nx
166using following command:
167.Bl -tag -width 123 -offset indent
168.It $ mount_procfs procfs /emul/linux/proc
169.El
170.Pp
171You can also set up your system so that procfs is mounted automatically
172on system boot, by putting an entry like the one below to
173.Pa /etc/fstab .
174.Bl -tag -width 123 -offset indent
175.It procfs /emul/linux/proc procfs ro
176.El
177.Pp
178Note:
179.Xr mount_procfs 8
180defaults to Linux flavored procfs since
181.Nx 5.0 .
182Ensure you do not mount procfs with
183.Ar nolinux .
184.Pp
185See
186.Xr mount_procfs 8
187for further information.
188.Ss Setting up other files
189Newer version of Linux use
190.Pa /etc/nsswitch.conf
191for network information, such as NIS and DNS.
192You must create or get a valid copy of this file and put it in
193.Pa /emul/linux/etc .
194.Sh CAVEATS
195.Nm
196is generally not enabled in
197.Dv GENERIC
198kernels for security reasons,
199but is available as a module.
200It must be added to
201.Xr modules.conf 5
202to be used.
203It will not be loaded automatically.
204.Sh BUGS
205The information about Linux distributions will become outdated.
206.Pp
207Absolute pathnames pointed to by symbolic links are only looked up in the
208shadow root when the symbolic link itself was found by an absolute
209pathname inside the shadow root.
210This is not consistent.
211.Pp
212Linux executables cannot handle directory offset cookies > 32 bits.
213Should such an offset occur, you will see the message
214.Dq linux_getdents: dir offset too large for emulated program .
215Currently, this can only
216happen on NFS mounted file systems, mounted from servers that return
217offsets with information in the upper 32 bits.
218These errors should rarely happen, but can be avoided by mounting this
219file system with offset translation enabled.
220See the
221.Fl X
222option to
223.Xr mount_nfs 8 .
224The
225.Fl 2
226option to
227.Xr mount_nfs 8
228will also have the desired effect, but is less preferable.
229