Tips for Running Linux Binaries on FreeBSD
Author: Angie Van Osdol
Last modified: Fri Nov 14 2003 14:08:15 GMT-0500 (EST)
Source URL: [https://www.cs.unc.edu/~jeffay/dirt/FAQ/linuxBinaryTips.html]
Running Linux Binaries in FreeBSD should be simple as long as the linux
compatibility package is installed.
This can be checked by:
pkg_info | grep linux
One version of this is:
linux_base-7.1_2 The base set of packages needed in Linux mode
There's an option to turn on in /etc/rc.conf, as well:
linux_enable="YES"
In general, these things should already be installed/setup as part of the basic
FreeBSD install.
The binary should be statically compiled, if you're creating it from scratch on
a linux system, using the -static compile flag.
If you run the file and see an error message like the following, then this page is
all about how to fix it. If the problem is something else, there's a great FAQ page
at www.FreeBSD.org that describes the reasons behind some of these things in greater
detail. See the handbook.
Error message:
goldberg.cs.unc.edu(vanosdol)> ./prog.e
ELF binary type "0" not known.
Abort
Find the Binary Type of the Executable
To find out what type the file is, execute this command:
readelf -e prog.e
The output will look like this:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 03 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - Linux
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x80480e0
Start of program headers: 52 (bytes into file)
Start of section headers: 758872 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 3
Size of section headers: 40 (bytes)
Number of section headers: 22
Section header string table index: 19
.... (cut) ..
The line that says: Version: UNIX - Linux is the line you're interested in.
Find Out What Executable Types are Supported
brandelf -l
The output will look like this:
known ELF types are: FreeBSD(9) Linux(3) Solaris(6) SVR4(0)
So, in this cause the Linux type IS compatible. If you statically compile this on
swan.cs.unc.edu, for example, you will have an unsupported type in the output above,
and you'll need to change the type of the executable.
Change the Executable Type, if Necessary
To change the type of the executable to one of the above recognized types, execute
the following
brandelf -t Linux prog.e
The executable type will then be recognized and it will execute on the target FreeBSD
machine.