Chinaunix首页 | 论坛 | 博客
  • 博客访问: 405675
  • 博文数量: 23
  • 博客积分: 6136
  • 博客等级: 准将
  • 技术积分: 992
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-16 15:02
文章存档

2012年(1)

2011年(1)

2010年(7)

2009年(7)

2008年(7)

分类: BSD

2009-01-10 08:17:04

Tips for Running Linux Binaries on FreeBSD

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 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.
阅读(1016) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~