OpenBSD manual page server

Manual Page Search Parameters

COMPAT_LINUX(8) System Manager's Manual COMPAT_LINUX(8)

compat_linuxsetup for running Linux binaries under emulation

OpenBSD 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.

The Linux compatibility feature is active for kernels compiled with the COMPAT_LINUX option and kern.emul.linux sysctl(8) enabled.

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 OpenBSD system will have to be created. This directory is named /emul/linux. Any file operations done by Linux programs run under OpenBSD will look in this directory first. So, if a Linux program opens, for example, /etc/passwd, OpenBSD will first try to open /emul/linux/etc/passwd, and if that does not exist open the `real' /etc/passwd file. It is recommended that Linux packages that include configuration files, etc., be installed under /emul/linux, to avoid naming conflicts with possible OpenBSD counterparts. Shared libraries should also be installed in the shadow tree.

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 OpenBSD 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.

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 OpenBSD system to perform the necessary installation steps).

  1. Access to the OpenBSD ports(7) system: Install the port named fedora/base in the emulators category. The 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.
  2. Access to a Linux system: In this case temporarily install the binary there, see what shared libraries it needs, and copy them to the OpenBSD 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':

    (me@linux) ldd linuxxdoom
    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

    Get all the files from the last column, and put them under /emul/linux, with the names in the first column as symbolic links pointing to them. The following files would therefore be required on the OpenBSD system:

    /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)

    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 OpenBSD 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:

    /emul/linux/lib/libc.so.4.6.27
    /emul/linux/lib/libc.so.4 -> /emul/linux/lib/libc.so.4.6.27

    and the ldd output for a new binary is:

    libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29

    it isn't necessary to copy /lib/libc.so.4.6.29 too, because the program should work fine with the slightly older version. libc.so can be replaced anyway, and that should leave:

    /emul/linux/lib/libc.so.4.6.29
    /emul/linux/lib/libc.so.4 -> /emul/linux/lib/libc.so.4.6.29

    Please note that the symbolic link mechanism is only needed for Linux binaries, the OpenBSD runtime linker takes care of looking for matching major revision numbers itself.

    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 OpenBSD system (in the /emul/linux tree):

    /lib/ld.so
    /etc/ld.so.cache
    /etc/ld.so.config
  3. 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.

    Retrieve the following files (from _one_ ftp site to avoid any version mismatches), and install them under /emul/linux (i.e. /foo/bar is installed as /emul/linux/foo/bar):

    /sbin/ldconfig
    /usr/bin/ldd
    /lib/libc.so.x.y.z
    /lib/ld.so

    ldconfig and ldd don't necessarily need to be under /emul/linux, they can be installed elsewhere in the system too. Just make sure they don't conflict with their OpenBSD counterparts. A good idea would be to install them in /usr/local/bin as ldconfig-linux and ldd-linux.

    Create the file /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. /lib and /usr/lib are standard; the following could be added:

    /usr/X11/lib
    /usr/local/lib

    Note that these are mapped to /emul/linux/XXXX by the OpenBSD compat code, and should exist as such on the OpenBSD system.

    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 /emul/linux/etc/ld.so.cache. The Linux version of the ldconfig program should be rerun each time a new shared library is added.

    The OpenBSD 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:

    % ldd-linux `which ldd-linux`

    libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29

    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 /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 <majorname> (<jumpversion>) => <fullname>.

    If it prints "not found" instead of <fullname> it means that an extra library is needed. Which library this is, is shown in <majorname>, which will be of the form libXXXX.so.<N>. Find a libXXXX.so.<N>.<mm> on a Linux ftp site, and install it on the OpenBSD system. The XXXX (name) and <N> (major revision number) should match; the minor number(s) <mm> are less important, though it is advised to take the most recent version.

: 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 OpenBSD ports(7) system (possibility 1, above).

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:

ftp.ibiblio.org:/pub/Linux/distributions
distro.ibiblio.org:/pub/Linux/distributions

Some European mirrors:

ftp.sunet.se:/pub/Linux/distributions
src.doc.ic.ac.uk:/packages/linux

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 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:

Needed                  Package

ld-2.2.5.so             glibc
ldconfig                glibc
ldd                     glibc
libc.so.6               glibc
libX11.so.6             xfree
libXt.so.6              xfree

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):

slackware/l/glibc-2.2.5-i386.2.tgz
slackware/x/xfree-4.2.0-i386.5.tgz

Extract the files from these gzipped tarfiles in the /emul/linux directory (possibly omitting or afterwards removing unnecessary files).

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 /emul/linux/dev directory will have to be created, namely:

/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

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.

Only the DSP device is emulated, the following link should be created:

/emul/linux/dev/dsp -> /dev/audio

CD-ROM support requires a link to the CD-ROM device, similar to:

/emul/linux/dev/cdrom -> /dev/cd0a (first CD-ROM)

Many Linux binaries expect /proc to have procfs mounted on it. Some binaries will require it to be mounted using the -o linux option.

The information about Linux distributions may become outdated.

compat_linux is currently only supported on the i386.

October 22, 2009 OpenBSD-5.1