COMPAT_FREEBSD(8) OpenBSD System Manager's Manual COMPAT_FREEBSD(8)
compat_freebsd - setup for running FreeBSD binaries under emulation
OpenBSD supports running FreeBSD binaries. Most binaries should work,
except for programs that use FreeBSD-specific features. These include
i386-specific calls, such as syscons utilities and audio devices.
The FreeBSD compatibility feature is active for kernels compiled with the
COMPAT_FREEBSD option and the kern.emul.freebsd sysctl(8) enabled.
A lot of programs are dynamically linked. This means that the FreeBSD
shared libraries that the programs depend on and the runtime linker are
also needed. Additionally, a "shadow root" directory for FreeBSD bina-
ries on the OpenBSD system will have to be created. This directory is
named /emul/freebsd. Any file operations done by FreeBSD programs run
under OpenBSD will look in this directory first. So, if a FreeBSD pro-
gram opens, for example, /etc/passwd, OpenBSD will first try to open
/emul/freebsd/etc/passwd, and if that does not exist open the `real'
/etc/passwd file. It is recommended that FreeBSD packages that include
configuration files, etc., be installed under /emul/freebsd, 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 FreeBSD binaries depend on the first few times that FreeBSD programs
are installed on the OpenBSD system. After a while, there will be a suf-
ficient set of FreeBSD shared libraries on the system to be able to run
newly imported FreeBSD binaries without any extra work.
Setting up shared libraries
How to get to know which shared libraries FreeBSD binaries need, and
where to get them? Basically, there are 3 possibilities. (When follow-
ing these instructions, root privileges are required on the OpenBSD sys-
tem to perform the necessary installation steps).
1. Access to the OpenBSD ports(7) system: Install the port named
freebsd_lib in the emulators category. The freebsd_lib port con-
tains the shared libraries, binaries, and other related files neces-
sary to run FreeBSD applications.
2. Access to a FreeBSD system: In this case temporarily install the bi-
nary there, see what shared libraries it needs, and copy them to the
OpenBSD system. Example: ftp the FreeBSD binary of SimCity. Put it
on the FreeBSD system, and check which shared libraries it needs by
running `ldd sim':
me@freebsd% ldd /usr/local/lib/SimCity/res/sim
-lXext.6 => /usr/X11R6/lib/libXext.so.6.0 (0x100c1000)
-lX11.6 => /usr/X11R6/lib/libX11.so.6.0 (0x100c9000)
-lc.2 => /usr/lib/libc.so.2.1 (0x10144000)
-lm.2 => /usr/lib/libm.so.2.0 (0x101a7000)
-lgcc.261 => /usr/lib/libgcc.so.261.0 (0x101bf000)
All the files from the last column should be placed under
/emul/freebsd. The following files would therefore be required on
the OpenBSD system:
Note that if a FreeBSD 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. So, if this library exists on the system:
and the ldd output for a new binary is:
-lc.2 => /usr/lib/libc.so.2.1 (0x10144000)
it isn't necessary to copy /usr/lib/libc.so.2.1 too, because the
program should work fine with the slightly older version. libc.so
can be replaced anyway, and that should leave:
Finally, the FreeBSD runtime linker and its config files must be
present on the system. These files should be copied from the FreeB-
SD system to their appropriate place on the OpenBSD system (in the
3. No access to a FreeBSD system: In that case, get the extra files
from various ftp sites. Information on where to look for the vari-
ous files is appended below.
Retrieve the following files (from _one_ ftp site to avoid any ver-
sion mismatches), and install them under /emul/freebsd (i.e.
foo/bar is installed as /emul/freebsd/foo/bar):
ldconfig and ldd don't necessarily need to be under /emul/freebsd,
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-freebsd and
Run the FreeBSD ldconfig program with directory arguments in which
the FreeBSD runtime linker should look for shared libs. /usr/lib is
standard. For example:
me@openbsd% mkdir -p /emul/freebsd/var/run
me@openbsd% touch /emul/freebsd/var/run/ld-elf.so.hints
me@openbsd% touch /emul/freebsd/var/run/ld.so.hints
me@openbsd% ldconfig-freebsd /usr/X11R6/lib /usr/local/lib
Note that argument directories of ldconfig are mapped to
/emul/freebsd/XXXX by OpenBSD's compat code, and should exist as
such on the OpenBSD system. Make sure
/emul/freebsd/var/run/ld.so.hints exists when running FreeBSD's ld-
config; if not, OpenBSD's /var/run/ld.so.hints could be lost.
FreeBSD ldconfig should be statically linked, so it doesn't need any
shared libraries by itself. It will create the file
/emul/freebsd/var/run/ld.so.hints. The FreeBSD version of the ld-
config program should be rerun each time a new shared library is
The OpenBSD system should now be set up for FreeBSD binaries which
only need a shared libc. Test this by running the FreeBSD ldd on
itself. Suppose that it is installed as ldd-freebsd, it should pro-
duce something like:
me@openbsd% ldd-freebsd `which ldd-freebsd`
-lc.2 => /usr/lib/libc.so.2.1 (0x1001a000)
This being done, new FreeBSD binaries can now be installed. Whenev-
er a new FreeBSD program is installed, it should be determined if it
needs shared libraries, and if so, whether they are installed in the
/emul/freebsd tree. To do this, run the FreeBSD 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 -l<majorname> => <fullname>.
If it prints "not found" instead of <fullname> it means that an ex-
tra library is needed. Which library this is, is shown in <major-
name>, which will be of the form XXXX.<N>. Find a
libXXXX.so.<N>.<mm> on a FreeBSD 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.
Finding the necessary files
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.
FreeBSD distribution is 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 subdirecto-
ries with gzipped tar files in them. The primary ftp site for the dis-
Mirror sites are described at:
This distribution consists of a number of tar-ed and gzipped files. Nor-
mally, they're controlled by an install program, but the files can be re-
trieved "by hand" too. The way to look something up is to retrieve all
the files in the distribution, and ``tar ztvf'' through them for the
files needed. Here is an example of a list of files that might be need-
The files called ``base.??'' are tar-ed, gzipped and split, so they can
be extracted with ``cat base.?? | tar zpxf -''.
The XFree86 libraries are compressed with bzip2 and can be extracted with
``bzcat <file> | tar pxf -''. Note: The bzip2 utilities are not part of
a base OpenBSD system. bzip2 can be added via packages(7) or ports(7).
Simply extract the files from these compressed tarfiles in the
/emul/freebsd directory (possibly omitting or afterwards removing unnec-
The information about FreeBSD distributions may become outdated.
OpenBSD 3.6 June 4, 1995 4