1*11b9cb2bSryo.\" $NetBSD: compat_linux.8,v 1.46 2021/11/28 18:08:51 ryo Exp $ 2c233e441Sfvdl.\" 3c233e441Sfvdl.\" Copyright (c) 1995 Frank van der Linden 4c233e441Sfvdl.\" All rights reserved. 5c233e441Sfvdl.\" 6c233e441Sfvdl.\" Redistribution and use in source and binary forms, with or without 7c233e441Sfvdl.\" modification, are permitted provided that the following conditions 8c233e441Sfvdl.\" are met: 9c233e441Sfvdl.\" 1. Redistributions of source code must retain the above copyright 10c233e441Sfvdl.\" notice, this list of conditions and the following disclaimer. 11c233e441Sfvdl.\" 2. Redistributions in binary form must reproduce the above copyright 12c233e441Sfvdl.\" notice, this list of conditions and the following disclaimer in the 13c233e441Sfvdl.\" documentation and/or other materials provided with the distribution. 14c233e441Sfvdl.\" 3. All advertising materials mentioning features or use of this software 15c233e441Sfvdl.\" must display the following acknowledgement: 16c233e441Sfvdl.\" This product includes software developed for the NetBSD Project 17c233e441Sfvdl.\" by Frank van der Linden 18c233e441Sfvdl.\" 4. The name of the author may not be used to endorse or promote products 19c233e441Sfvdl.\" derived from this software without specific prior written permission 20c233e441Sfvdl.\" 21c233e441Sfvdl.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22c233e441Sfvdl.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23c233e441Sfvdl.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24c233e441Sfvdl.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25c233e441Sfvdl.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26c233e441Sfvdl.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27c233e441Sfvdl.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28c233e441Sfvdl.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29c233e441Sfvdl.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30c233e441Sfvdl.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31c233e441Sfvdl.\" 32f7f2d033Snia.Dd September 26, 2021 33c233e441Sfvdl.Dt COMPAT_LINUX 8 3439b11db8Sgarbled.Os 35c233e441Sfvdl.Sh NAME 361009df02Smikel.Nm compat_linux 37c233e441Sfvdl.Nd setup procedure for running Linux binaries 38c233e441Sfvdl.Sh DESCRIPTION 3934a98169Sperry.Nx 4072560fa3Swizsupports running Linux binaries. 41aa98bec6SryoThis applies to aarch64, alpha, amd64, arm, i386, m68k, and powerpc systems for now. 4272560fa3SwizBoth the a.out and ELF binary formats are supported. 434986201eSniaMost programs should work. 44f9f8a4cbSwiz.Nx 45*11b9cb2bSryoaarch64 and amd64 can execute both 32-bit and 64-bit Linux programs. 466035c6f8SmanuPrograms that will not work include some that use 476035c6f8Smanui386-specific calls, such as enabling virtual 8086 mode. 484986201eSniaCurrently, sound is supported through OSSv3 compat. 497c792961Swiz.Pp 500bb2a5f4SfvdlThe Linux compatibility feature is active 51c233e441Sfvdlfor kernels compiled with the 521009df02Smikel.Dv COMPAT_LINUX 53c233e441Sfvdloption enabled. 54e99f8a7cScgdIf support for Linux a.out executables is desired, the 551009df02Smikel.Dv EXEC_AOUT 568afa2826Sjdolecekoption should be enabled in addition to option 571009df02Smikel.Dv COMPAT_LINUX . 58e99f8a7cScgdSimilarly, if support for Linux 32-bit and/or 64-bit ELF executables 59e99f8a7cScgdis desired, the 601009df02Smikel.Dv EXEC_ELF32 61e99f8a7cScgdand/or 621009df02Smikel.Dv EXEC_ELF64 63e99f8a7cScgdoptions (respectively) should be enabled in addition to 641009df02Smikel.Dv COMPAT_LINUX . 654986201eSniaIf sound support is desired, 664986201eSnia.Dv COMPAT_OSSAUDIO 674986201eSniashould be enabled. 681009df02Smikel.Pp 6972560fa3SwizA lot of programs are dynamically linked. 7072560fa3SwizThis means that you will also need the Linux shared libraries that the 7172560fa3Swizprogram depends on, and the runtime linker. 7272560fa3SwizAlso, you will need to create a 737c792961Swiz.Dq shadow root 7434a98169Sperrydirectory for Linux binaries on your 7534a98169Sperry.Nx 7672560fa3Swizsystem. 7772560fa3SwizThis directory is named 78bfe36c5bSdsl.Pa /emul/linux 79bfe36c5bSdslor 80bfe36c5bSdsl.Pa /emul/linux32 814986201eSniafor 32-bit emulation on 64-bit systems. 827c792961SwizAny file operations done by Linux programs run under 8334a98169Sperry.Nx 8472560fa3Swizwill look in this directory first. 8572560fa3SwizSo, if a Linux program opens, for example, 867c792961Swiz.Pa /etc/passwd , 8734a98169Sperry.Nx 8834a98169Sperrywill 897c792961Swizfirst try to open 907c792961Swiz.Pa /emul/linux/etc/passwd , 917c792961Swizand if that does not exist open the 927c792961Swiz.Sq real 937c792961Swiz.Pa /etc/passwd 9472560fa3Swizfile. 9572560fa3SwizIt is recommended that you install 967c792961SwizLinux packages that include configuration files, etc under 977c792961Swiz.Pa /emul/linux , 9834a98169Sperryto avoid naming conflicts with possible 9934a98169Sperry.Nx 10072560fa3Swizcounterparts. 10172560fa3SwizShared libraries should also be installed in the shadow tree. 102bfe36c5bSdslFilenames that start "/../" are only looked up in the real root. 103c233e441Sfvdl.Pp 104c233e441SfvdlGenerally, you will need to look for the shared libraries that Linux 105c233e441Sfvdlbinaries depend on only the first few times that you install a Linux 10634a98169Sperryprogram on your 10734a98169Sperry.Nx 10872560fa3Swizsystem. 10972560fa3SwizAfter a while, you will have a sufficient 110c233e441Sfvdlset of Linux shared libraries on your system to be able to run newly 111c233e441Sfvdlimported Linux binaries without any extra work. 112c233e441Sfvdl.Ss Setting up shared libraries 1134986201eSniaFind the dependencies of a Linux binary using 1144986201eSnia.Xr readelf 1 : 115c76e625fSnjoly.Bd -literal 1164986201eSnia$ readelf -d ./runner | grep Shared 1174986201eSnia 0x00000001 (NEEDED) Shared library: [libstdc++.so.6] 1184986201eSnia 0x00000001 (NEEDED) Shared library: [libz.so.1] 1194986201eSnia 0x00000001 (NEEDED) Shared library: [libXxf86vm.so.1] 1204986201eSnia 0x00000001 (NEEDED) Shared library: [libGL.so.1] 1214986201eSnia 0x00000001 (NEEDED) Shared library: [libopenal.so.1] 1224986201eSnia 0x00000001 (NEEDED) Shared library: [libm.so.6] 1234986201eSnia 0x00000001 (NEEDED) Shared library: [librt.so.1] 1244986201eSnia 0x00000001 (NEEDED) Shared library: [libpthread.so.0] 1254986201eSnia 0x00000001 (NEEDED) Shared library: [libdl.so.2] 1264986201eSnia 0x00000001 (NEEDED) Shared library: [libcrypto.so.1.0.0] 1274986201eSnia 0x00000001 (NEEDED) Shared library: [libXext.so.6] 1284986201eSnia 0x00000001 (NEEDED) Shared library: [libX11.so.6] 1294986201eSnia 0x00000001 (NEEDED) Shared library: [libXrandr.so.2] 1304986201eSnia 0x00000001 (NEEDED) Shared library: [libGLU.so.1] 1314986201eSnia 0x00000001 (NEEDED) Shared library: [libssl.so.1.0.0] 1324986201eSnia 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] 1334986201eSnia 0x00000001 (NEEDED) Shared library: [libc.so.6] 134c76e625fSnjoly.Ed 135c233e441Sfvdl.Pp 1364986201eSniaFor x86, you can simply install the openSUSE shared libraries using the 1374986201eSnia.Pa pkgsrc/emulators/suse131_* 1384986201eSniaor 1394986201eSnia.Pa pkgsrc/emulators/suse131_32_* 1404986201eSniapackages. 141c233e441Sfvdl.Pp 1424986201eSniaFor example, an application which requires 1434986201eSnia.Pa libcrypto.so.1.0.0 , 1444986201eSnia.Pa libXext.so.6 , 1457c792961Swizand 1464986201eSnia.Pa libGL.so.1 1474986201eSniawill require 1484986201eSnia.Dv openssl , 1494986201eSnia.Dv x11 , 1507c792961Swizand 1514986201eSnia.Dv glx , 1524986201eSniain addition to the 1534986201eSnia.Dv base 1544986201eSniaSUSE package. 155c233e441Sfvdl.Pp 1564986201eSniaOtherwise, you may have to obtain shared libraries from another Linux 1574986201eSniasystem, and copy them to e.g. 1584986201eSnia.Pa /emul/linux/lib64 . 1598afa2826Sjdolecek.Ss Setting up procfs 1604986201eSniaSome Linux binaries expect procfs to be mounted and that it 1614986201eSniacontains some Linux-specific extensions. 16272560fa3SwizIf it's not the case, they behave unexpectedly or even crash. 1638afa2826Sjdolecek.Pp 1642ae0f429SwizMount procfs on 1652ae0f429Swiz.Nx 1662ae0f429Swizusing following command: 1678afa2826Sjdolecek.Bl -tag -width 123 -offset indent 168f7f2d033Snia.It $ mount_procfs procfs /emul/linux/proc 1698afa2826Sjdolecek.El 1708afa2826Sjdolecek.Pp 17149a68c44SjmmvYou can also set up your system so that procfs is mounted automatically 17249a68c44Sjmmvon system boot, by putting an entry like the one below to 1738afa2826Sjdolecek.Pa /etc/fstab . 1748afa2826Sjdolecek.Bl -tag -width 123 -offset indent 175f7f2d033Snia.It procfs /emul/linux/proc procfs ro 1768afa2826Sjdolecek.El 1778afa2826Sjdolecek.Pp 178f7f2d033SniaNote: 179f7f2d033Snia.Xr mount_procfs 8 180f7f2d033Sniadefaults to Linux flavored procfs since 181f7f2d033Snia.Nx 5.0 . 182f7f2d033SniaEnsure you do not mount procfs with 183f7f2d033Snia.Ar nolinux . 184f7f2d033Snia.Pp 18549a68c44SjmmvSee 1868afa2826Sjdolecek.Xr mount_procfs 8 1878afa2826Sjdolecekfor further information. 18803d18700Sfvdl.Ss Setting up other files 1897c792961SwizNewer version of Linux use 1907c792961Swiz.Pa /etc/nsswitch.conf 191592cf6b9Swizfor network information, such as NIS and DNS. 19272560fa3SwizYou must create or get a valid copy of this file and put it in 1937c792961Swiz.Pa /emul/linux/etc . 194592cf6b9Swiz.Sh CAVEATS 1954986201eSnia.Nm 1964986201eSniais generally not enabled in 1974986201eSnia.Dv GENERIC 198da66f631Sandvarkernels for security reasons, 1994986201eSniabut is available as a module. 2004986201eSniaIt must be added to 2014986201eSnia.Xr modules.conf 5 2024986201eSniato be used. 203d6f5a14bSniaIt will not be loaded automatically. 204c233e441Sfvdl.Sh BUGS 2054986201eSniaThe information about Linux distributions will become outdated. 20603d18700Sfvdl.Pp 207bfe36c5bSdslAbsolute pathnames pointed to by symbolic links are only looked up in the 208bfe36c5bSdslshadow root when the symbolic link itself was found by an absolute 209bfe36c5bSdslpathname inside the shadow root. 21072560fa3SwizThis is not consistent. 2113b90a0efSfvdl.Pp 21201869ca4SwizLinux executables cannot handle directory offset cookies > 32 bits. 2137c792961SwizShould such an offset occur, you will see the message 2147c792961Swiz.Dq linux_getdents: dir offset too large for emulated program . 2157c792961SwizCurrently, this can only 2163b90a0efSfvdlhappen on NFS mounted file systems, mounted from servers that return 21772560fa3Swizoffsets with information in the upper 32 bits. 21872560fa3SwizThese errors should rarely happen, but can be avoided by mounting this 21972560fa3Swizfile system with offset translation enabled. 22072560fa3SwizSee the 2213b90a0efSfvdl.Fl X 2223b90a0efSfvdloption to 2233b90a0efSfvdl.Xr mount_nfs 8 . 2243b90a0efSfvdlThe 2253b90a0efSfvdl.Fl 2 2263b90a0efSfvdloption to 2273b90a0efSfvdl.Xr mount_nfs 8 2283b90a0efSfvdlwill also have the desired effect, but is less preferable. 229