.\" $OpenBSD: compat_linux.8,v 1.39 2008/06/06 15:17:48 jmc Exp $ .\" $NetBSD: compat_linux.8,v 1.2 1995/10/16 20:17:59 fvdl Exp $ .\" .\" Copyright (c) 1995 Frank van der Linden .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed for the NetBSD Project .\" by Frank van der Linden .\" 4. The name of the author may not be used to endorse or promote products .\" derived from this software without specific prior written permission .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .Dd $Mdocdate: June 6 2008 $ .Dt COMPAT_LINUX 8 .Os .Sh NAME .Nm compat_linux .Nd setup for running Linux binaries under emulation .Sh DESCRIPTION .Ox supports running Linux binaries. This only applies to i386 systems for now. Both the a.out and ELF binary formats are supported. Most programs should work, including the ones that use the Linux SVGAlib. Additionally, OSS audio is emulated, so Linux binaries can access the native audio transparently. Programs that will not work include those that use i386-specific calls, such as enabling virtual 8086 mode. .Pp The Linux compatibility feature is active for kernels compiled with the .Nm COMPAT_LINUX option and kern.emul.linux .Xr sysctl 8 enabled. .Pp A lot of programs are dynamically linked. This means that the Linux shared libraries that the programs depend on and the runtime linker are also needed. Additionally, a "shadow root" directory for Linux binaries on the .Ox system will have to be created. This directory is named .Pa /emul/linux . Any file operations done by Linux programs run under .Ox will look in this directory first. So, if a Linux program opens, for example, .Pa /etc/passwd , .Ox will first try to open .Pa /emul/linux/etc/passwd , and if that does not exist open the `real' .Pa /etc/passwd file. It is recommended that Linux packages that include configuration files, etc., be installed under .Pa /emul/linux , to avoid naming conflicts with possible .Ox counterparts. Shared libraries should also be installed in the shadow tree. .Pp Generally, it will only be necessary to look for the shared libraries that Linux binaries depend on the first few times that Linux programs are installed on the .Ox system. After a while, there will be a sufficient set of Linux shared libraries on the system to be able to run newly imported Linux binaries without any extra work. .Ss Setting up shared libraries How to get to know which shared libraries Linux binaries need, and where to get them? Basically, there are 3 possibilities. (When following these instructions, root privileges are required on the .Ox system to perform the necessary installation steps). .Bl -enum .It Access to the .Ox .Xr ports 7 system: Install the port named .Nm fedora/base in the .Nm emulators category. The .Nm fedora/base port contains the shared libraries, binaries, and other related files necessary to run Linux applications. Access to a Linux system is not needed. .It Access to a Linux system: In this case temporarily install the binary there, see what shared libraries it needs, and copy them to the .Ox system. Example: ftp the Linux binary of Doom. Put it on the Linux system, and check which shared libraries it needs by running `ldd linuxxdoom': .Pp .Dl (me@linux) ldd linuxxdoom .Bd -unfilled -offset indent libXt.so.3 (DLL Jump 3.1) => /usr/X11/lib/libXt.so.3.1.0 libX11.so.3 (DLL Jump 3.1) => /usr/X11/lib/libX11.so.3.1.0 libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29 .Ed .Pp Get all the files from the last column, and put them under .Pa /emul/linux , with the names in the first column as symbolic links pointing to them. The following files would therefore be required on the .Ox system: .Bd -unfilled -offset indent /emul/linux/usr/X11/lib/libXt.so.3.1.0 /emul/linux/usr/X11/lib/libXt.so.3 (symbolic link to the above) /emul/linux/usr/X11/lib/libX11.so.3.1.0 /emul/linux/usr/X11/lib/libX11.so.3 (symbolic link to the above) /emul/linux/lib/libc.so.4.6.29 /emul/linux/lib/libc.so.4 (symbolic link to the above) .Ed .Pp Note that if a Linux shared library with a matching major revision number to the first column of the 'ldd' output is already present, it isn't necessary to copy the file named in the last column to the .Ox system; the one already there should work. It is advisable to copy the shared library anyway, if it is a newer version. The old one can be removed, as long as the symbolic link points to the new one. So, if these libraries exist on the system: .Bd -unfilled -offset indent /emul/linux/lib/libc.so.4.6.27 /emul/linux/lib/libc.so.4 -> /emul/linux/lib/libc.so.4.6.27 .Ed .Pp and the ldd output for a new binary is: .Bd -unfilled -offset indent libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29 .Ed .Pp it isn't necessary to copy .Pa /lib/libc.so.4.6.29 too, because the program should work fine with the slightly older version. .Pa libc.so can be replaced anyway, and that should leave: .Bd -unfilled -offset indent /emul/linux/lib/libc.so.4.6.29 /emul/linux/lib/libc.so.4 -> /emul/linux/lib/libc.so.4.6.29 .Ed .Pp Please note that the symbolic link mechanism is only needed for Linux binaries, the .Ox runtime linker takes care of looking for matching major revision numbers itself. .Pp Finally, the Linux runtime linker and its config files must be present on the system. These files should be copied from the Linux system to their appropriate place on the .Ox system (in the .Pa /emul/linux tree): .Bd -unfilled -offset indent /lib/ld.so /etc/ld.so.cache /etc/ld.so.config .Ed .It No access to a Linux system: In that case, get the extra files from various ftp sites. Information on where to look for the various files is appended below. .Pp Retrieve the following files (from _one_ ftp site to avoid any version mismatches), and install them under .Pa /emul/linux (i.e.\& .Pa /foo/bar is installed as .Pa /emul/linux/foo/bar ) : .Bd -unfilled -offset indent /sbin/ldconfig /usr/bin/ldd /lib/libc.so.x.y.z /lib/ld.so .Ed .Pp ldconfig and ldd don't necessarily need to be under .Pa /emul/linux , they can be installed elsewhere in the system too. Just make sure they don't conflict with their .Ox counterparts. A good idea would be to install them in .Pa /usr/local/bin as ldconfig-linux and ldd-linux. .Pp Create the file .Pa /emul/linux/etc/ld.so.conf , containing the directories in which the Linux runtime linker should look for shared libs. It is a plain text file, containing a directory name on each line. .Pa /lib and .Pa /usr/lib are standard; the following could be added: .Bd -unfilled -offset indent /usr/X11/lib /usr/local/lib .Ed .Pp Note that these are mapped to .Pa /emul/linux/XXXX by the .Ox compat code, and should exist as such on the .Ox system. .Pp Run the Linux ldconfig program. It should be statically linked, so it doesn't need any shared libraries by itself. It will create the file .Pa /emul/linux/etc/ld.so.cache . The Linux version of the ldconfig program should be rerun each time a new shared library is added. .Pp The .Ox system should now be set up for Linux binaries which only need a shared libc. Test this by running the Linux ldd on itself. Suppose that it is installed as ldd-linux, it should produce something like: .Pp .Dl % ldd-linux `which ldd-linux` .Pp .D1 libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29 .Pp This being done, new Linux binaries can now be installed. Whenever a new Linux program is installed, it should be determined if it needs shared libraries, and if so, whether they are installed in the .Pa /emul/linux tree. To do this, run the Linux version ldd on the new program, and watch its output. ldd (see also the manual page for ldd(1)) will print a list of shared libraries that the program depends on, in the form () => . .Pp If it prints "not found" instead of it means that an extra library is needed. Which library this is, is shown in , which will be of the form libXXXX.so.. Find a libXXXX.so.. on a Linux ftp site, and install it on the .Ox system. The XXXX (name) and (major revision number) should match; the minor number(s) are less important, though it is advised to take the most recent version. .El .Ss Finding the necessary files .Sy Note : the information below is valid as of Feb 2003, but certain details such as names of ftp sites, directories and distribution names may have changed since then. It is much easier to use the .Ox .Xr ports 7 system (possibility 1, above). .Pp Linux is distributed by several groups that make their own set of binaries that they distribute. Each distribution has its own name, like "Slackware" or "Yggdrasil". The distributions are available on a lot of ftp sites. Sometimes the files are unpacked, and individual files can be retrieved, but mostly they are stored in distribution sets, usually consisting of subdirectories with gzipped tar files in them. The primary ftp sites for the distributions are: .Bd -unfilled -offset indent .Pa ftp.ibiblio.org:/pub/Linux/distributions .Pa distro.ibiblio.org:/pub/Linux/distributions .\" .Pa tsx-11.mit.edu:/pub/linux/distributions .Ed .Pp Some European mirrors: .Bd -unfilled -offset indent .\" .Pa ftp.luth.se:/pub/linux/distributions .\" .Pa ftp.demon.co.uk:/pub/linux/distributions .Pa ftp.sunet.se:/pub/Linux/distributions .Pa src.doc.ic.ac.uk:/packages/linux .Ed .Pp For simplicity, let's concentrate on Slackware here. This distribution consists of a number of subdirectories, containing separate packages. Normally, they're controlled by an install program, but the files can be retrieved "by hand" too. The fastest way to find something is to .Xr grep 1 the file FILELIST.TXT for the files needed. Here is an example of a list of files that might be needed, and in which package it can be found: .Bd -unfilled -offset indent Needed Package ld-2.2.5.so glibc ldconfig glibc ldd glibc libc.so.6 glibc libX11.so.6 xfree libXt.so.6 xfree .Ed .Pp So, in this case, the packages glibc and xfree will be needed. FILELIST.TXT also gives the location of the packages. Retrieve the packages needed from the following files (relative to the root of the Slackware distribution tree): .Bd -unfilled -offset indent slackware/l/glibc-2.2.5-i386.2.tgz slackware/x/xfree-4.2.0-i386.5.tgz .Ed .Pp Extract the files from these gzipped tarfiles in the .Pa /emul/linux directory (possibly omitting or afterwards removing unnecessary files). .Ss Programs using SVGAlib SVGAlib binaries require some extra care. The pcvt virtual console driver has to be in the kernel for them to work, and some symbolic links in the .Pa /emul/linux/dev directory will have to be created, namely: .Bd -unfilled -offset indent /emul/linux/dev/console -> /dev/tty /emul/linux/dev/mouse -> whatever device the mouse is connected to /emul/linux/dev/ttyS0 -> /dev/tty00 /emul/linux/dev/ttyS1 -> /dev/tty01 .Ed .Pp Be warned: the first link mentioned here makes SVGAlib binaries work, but may confuse others, so it may be necessary to remove it again at some point. .Ss Programs using OSS (Linux) audio Only the DSP device is emulated, the following link should be created: .Pp .D1 /emul/linux/dev/dsp -> /dev/audio .Ss Other links Linux binaries may require CD-ROM support requires a link to the CD-ROM device, similar to: .Pp .D1 /emul/linux/dev/cdrom -> /dev/cd0a (first CD-ROM) .Ss File systems Many Linux binaries expect .Pa /proc to have procfs mounted on it. Some binaries will require it to be mounted using the .Fl o Ar linux option. .Sh BUGS The information about Linux distributions may become outdated. .Pp .Nm is currently only supported on the i386.