Howto setup Linux emulation in FreeBSD

I - Introduction

This HOWTO shows you how to setup Linux emulation in FreeBSD. The reasons why you want to have it are many:

  • Run closed source Linux software
  • Security
  • Research
  • Just for fun / because you can

II - Preparation

1) Load kernel modules

Load the linux kernel module:

root@bsdbox:/root # kldload linux

III - Installation

1) Install linux emulation from ports

We choose Fedora Core 10:

root@bsdbox:/root # cd /usr/ports/emulators/linux_base-f10/
root@bsdbox:/usr/ports/emulators/linux_base-f10 # make install clean
+++ Some programs may need linprocfs, please add it to /etc/fstab! +++

Running linux ldconfig...

This software is based in part on the work of the FreeType Team.
See <URL:http://www.freetype.org/>.

Installation of the Linux base system is finished. The Linux kernel
mode, which must be enabled for Linux binaries to run, is now
enabled. Linux mode can be enabled permanently with the linux_enable
variable of rc.conf(5).

If you want to use shared memory in Linux applications, you need to set up
a link from /dev/shm to a suitable place, e.g. by adding the following line
to /etc/devfs.conf (takes effect on each boot):
        link /tmp shm

To make use of NIS you have to adjust yp.conf and nsswitch.conf in
/compat/linux/etc/ accordingly. For example:

Set your yp-server and yp-domainname in yp.conf:
        domainname      my.yp.domainname
        ypserver        my.yp.server

Let your lists for hosts, passwd and group be resolved via nsswitch.conf:
        passwd: files nis
        shadow: files nis
        group:  files nis
        hosts:  files dns nis

WARNING: doing work which needs to chroot into the linux base may not work.
In such cases (e.g. cross-development) you are better suited with a linux_dist
port.

===>   Registering installation for linux_base-f10-10_5
root@bsdbox:/usr/ports/emulators/linux_base-f10 # 

IV - Tests

1) Test the emulation

Jump into Linux emulation:

root@bsdbox:/root # /compat/linux/bin/sh

Display system info:

sh # uname -a

V - Conclusion

We successfully managed to setup Linux emulation in FreeBSD. Plese let us know what you liked and what not. Thank you!