HOWTO: Linux/i386 compatibility on FreeBSD/amd64

It has for a long time been possible to use Linux/i386 applications on FreeBSD/i386. This HOWTO intends to show how it's possible to run those Linux/i386 applications on FreeBSD/amd64 too.

I assume that you're running FreeBSD 5.3/amd64. Your uname -srp should say something like "FreeBSD 5.3 amd64".

1. Kernel

Make sure you have these options compiled into your kernel:

options LINPROCFS options COMPAT_43 options COMPAT_LINUX32

Note: None of these options is in the GENERIC kernel, so you will need to create a custom kernel.

Your kernel configuration dir is /usr/src/sys/amd64/conf

If you don't know how to recompile your kernel, it is explained in Chapter 8 of the FreeBSD Handbook.

2. Patching Various Ports

2.1. Background

A lot of the linux ports use rpm. Unfortunately, rpm checks the target os and architecture and fails if they differ from the machine where the package was built. It is possible to work around these checks by specifying --ignoreos and --ignorearch. The latter option is still missing from a lot of ports, so the Makefiles have to be changed. I have written a patch that adds this options for linux-aspell, linux_base-8, linux-gtk and linux-XFree86-libs.

Two other things in linux_base-8 needs patching. For one, linux_base-8 runs some linux binaries during installation, and sets kern.fallback_elf_brand appropriately. Under amd64 we have to use kern.elf32.fallback_brand however. For another, it appears that Red Hat's glibc package tries to run glibc_post_update after installing, which fails. The solution here is to install this package with --noscripts. My patch also fixes these two problems.

For linux-opera, my patch makes the installer script aware of the fact that FreeBSD runs on amd64 too :) .

2.2. Patching

You can download the patch here. Save it to /tmp/linux-opera-amd64.patch.gz. Then run these commands as root:

cd /tmp gunzip linux-opera-amd64.patch.gz patch -p0 < linux-opera-amd64.patch

3. Installing the Linux Compatibility Environment

This is simple. Run these commands as root:

cd /usr/ports/emulators/linux_base-8 make MACHINE_ARCH=i386 install clean

It is necessary to manually set MACHINE_ARCH for now, since this port is still marked as i386 only. I expect that eventually this will be modified so it is marked as working on both i386 and amd64 systems.

4. Installing Linux Applications

4.1. Opera with Flash 6

Run these commands as root:

cd /usr/ports/www/linux-opera make MACHINE_ARCH=i386 install clean cd /usr/ports/www/linux-flash6 make MACHINE_ARCH=i386 install clean

To get good looking fonts, make sure you have /usr/ports/x11-fonts/bitstream-vera and /usr/ports/x11-fonts/webfonts installed. Then edit /compat/linux/etc/fonts/fonts.conf so that the directory list near the beginning (about line 20) looks like this:

<dir>/usr/share/fonts</dir> <dir>/usr/X11R6/lib/X11/fonts/TTF</dir> <dir>/usr/X11R6/lib/X11/fonts/bitstream-vera</dir> <dir>/usr/X11R6/lib/X11/fonts/webfonts</dir> <dir>/usr/X11R6/lib/X11/fonts/Type1</dir> <dir>/usr/X11R6/lib/X11/fonts/OTF</dir> <dir>~/.fonts</dir>

If you have fonts stored in other directories, add those too. Then run this command:

/compat/linux/usr/bin/fc-cache

Now opera is ready for use.

4.2. Acrobat Reader

Run these commands as root:

cd /usr/ports/print/acroread5 make MACHINE_ARCH=i386 ARCH=i386 install clean

5. Notes

Copyright © 2004 Benjamin Lutz email address.

Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons Attribution 2.0 license.

This HOWTO is based on the information available on tjr's homepage. His method worked, however I disliked just dumping files into my system without being able to cleanly remove them again, so I went about trying to make the linux_base-8 port work. Without this page though I'd never have thought it possible to have Linux/i386 compatibility on FreeBSD/amd64 in the first place :) Thanks also to dkaplowitz who pointed me to that page.

I haven't tried to get Java working just yet, I'll extend this HOWTO when I successfully get it installed.

6. Changelog