COMPAT_FREEBSD(8) OpenBSD System Manager's Manual COMPAT_FREEBSD(8) NAME compat_freebsd - setup for running FreeBSD binaries under emulation DESCRIPTION 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 binaries 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 program 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 sufficient 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 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 freebsd_lib in the emulators category. The freebsd_lib port contains the shared libraries, binaries, and other related files necessary to run FreeBSD applications. 2. Access to a FreeBSD 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 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 /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: /emul/freebsd/usr/X11R6/lib/libXext.so.6.0 /emul/freebsd/usr/X11R6/lib/libX11.so.6.0 /emul/freebsd/usr/lib/libc.so.2.1 /emul/freebsd/usr/lib/libm.so.2.0 /emul/freebsd/usr/lib/libgcc.so.261.0 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: /emul/freebsd/usr/lib/libc.so.2.0 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: /emul/freebsd/usr/lib/libc.so.2.1 Finally, the FreeBSD runtime linker and its config files must be present on the system. These files should be copied from the FreeBSD system to their appropriate place on the OpenBSD system (in the /emul/freebsd tree): usr/libexec/ld-elf.so.1 usr/libexec/ld.so var/run/ld-elf.so.hints var/run/ld.so.hints 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 various files is appended below. Retrieve the following files (from _one_ ftp site to avoid any version mismatches), and install them under /emul/freebsd (i.e. foo/bar is installed as /emul/freebsd/foo/bar): sbin/ldconfig usr/bin/ldd usr/lib/libc.so.x.y.z usr/libexec/ld-elf.so.1 usr/libexec/ld.so 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 ldd-freebsd. 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 ldconfig; 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 ldconfig program should be rerun each time a new shared library is added. 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 produce something like: me@openbsd% ldd-freebsd `which ldd-freebsd` /usr/local/bin/ldd-freebsd: -lc.2 => /usr/lib/libc.so.2.1 (0x1001a000) This being done, new FreeBSD binaries can now be installed. Whenever 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 extra library is needed. Which library this is, is shown in <majorname>, 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 subdirectories with gzipped tar files in them. The primary ftp site for the distribution is: ftp.freebsd.org:/pub/FreeBSD Mirror sites are described at: www.freebsdmirrors.org This distribution consists of a number of tar-ed and gzipped files. Normally, they're controlled by an install program, but the files can be retrieved "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 needed: Needed Files ld.so 5.0-RELEASE/base/base.?? ldconfig 5.0-RELEASE/base/base.?? ldd 5.0-RELEASE/base/base.?? libc.so.6 5.0-RELEASE/base/base.?? libX11.so.6 5.0-RELEASE/packages/x11/XFree86-libraries-?? libXt.so.6 5.0-RELEASE/packages/x11/XFree86-libraries-?? 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 unnecessary files). BUGS The information about FreeBSD distributions may become outdated. OpenBSD 4.9 October 22, 2009 OpenBSD 4.9