-FreeBSD provides binary compatibility with Linux(R), allowing users to install and run most Linux(R) binaries on a FreeBSD system without having to first modify the binary.
-It has even been reported that, in some situations, Linux(R) binaries perform better on FreeBSD than they do on Linux(R).
+FreeBSD provides optional binary compatibility with Linux(R), allowing users to install
+and run unmodified Linux(R) binaries, similar to how 32-bit i386 binaries can be run
+on 64-bit amd64 kernel. It is available for i386, amd64, and arm64 architectures.
-However, some Linux(R)-specific operating system features are not supported under FreeBSD.
-For example, Linux(R) binaries will not work on FreeBSD if they overly use i386(TM) specific calls, such as enabling virtual 8086 mode.
-
-[NOTE]
-====
-Support for 64-bit binary compatibility with Linux(R) was added in FreeBSD 10.3.
-====
+Some Linux(R)-specific operating system features are not yet supported;
+this mostly happens with functionality specific to hardware or related
+to system management, such as cgroups or namespaces.
After reading this chapter, you will know:
@@ -76,70 +73,60 @@
[[linuxemu-lbc-install]]
== Configuring Linux(R) Binary Compatibility
-By default, Linux(R) libraries are not installed and Linux(R) binary compatibility is not enabled.
-Linux(R) libraries can either be installed manually or from the FreeBSD Ports Collection.
-
-Before attempting to build the port, load the Linux(R) kernel module, otherwise the build will fail:
+By default, Linux binary compatibility is not enabled. To enable it at boot time,
+add this line to [.filename]#/etc/rc.conf#:
-[source,shell]
+[.programlisting]
....
-# kldload linux
+linux_enable="YES"
....
-For 64-bit compatibility:
-
+To enable it without rebooting, run this command:
[source,shell]
....
-# kldload linux64
+# service linux start
....
-To verify that the module is loaded:
+The [.filename]#/etc/rc.d/linux# script will load neccessary kernel modules and mount filesystems
+expected by Linux applications under [.filename]#/compat/linux#. This is enough for statically
+linked Linux binaries to work. They can be started in the same way native FreeBSD binaries can;
+they behave almost exactly like native processes and can be traced and debugged the usual way.
+
+Linux binaries linked dynamically (which is the vast majority) also require Linux shared libraries
+to be installed. The easiest way to do that is to install the package:emulators/linux_base-c7[]
+package or port:
[source,shell]
....
-% kldstat
- Id Refs Address Size Name
- 1 2 0xc0100000 16bdb8 kernel
- 7 1 0xc24db000 d000 linux.ko
+# pkg install emulators/linux_base-c7
....
-The package:emulators/linux_base-c7[] package or port is the easiest way to install a base set of Linux(R) libraries and binaries on a FreeBSD system.
-To install the port:
-
+FreeBSD provides packages for some of the Linux binary applications. For example, to install
+Sublime Text, run this command:
[source,shell]
....
-# pkg install emulators/linux_base-c7
+# pkg install linux-sublime
....
-For Linux(R) compatibility to be enabled at boot time, add this line to [.filename]#/etc/rc.conf#:
+Some applications require specific filesystems to be mounted.
+This is normally handled by [.filename]#/etc/rc.d/linux# script, but can be disabled
+by adding this line to [.filename]#/etc/rc.conf#:
[.programlisting]
....
-linux_enable="YES"
+linux_mounts_enable="NO"
....
-On 64-bit machines, [.filename]#/etc/rc.d/abi# will automatically load the module for 64-bit emulation.
-
-Since the Linux(R) binary compatibility layer has gained support for running both 32- and 64-bit Linux(R) binaries (on 64-bit x86 hosts), it is no longer possible to link the emulation functionality statically into a custom kernel.
-
-For some applications, [.filename]#/compat/linux/proc#, [.filename]#/compat/linux/sys#, and [.filename]#/compat/linux/dev/shm# may need to be mounted.
-Add this line to [.filename]#/etc/fstab#:
-
+Filesystems mounted by the rc script will not work for Linux processes
+inside chroots or jails; one can manually configure them in [.filename]#/etc/fstab#:
+Since the Linux(R) binary compatibility layer has gained support for running both 32- and 64-bit Linux(R) binaries (on 64-bit x86 hosts), it is no longer possible to link the emulation functionality statically into a custom kernel.
+
This section describes how Linux(R) binary compatibility works and is based on an email written to {freebsd-chat} by Terry Lambert mailto:tlambert@primenet.com[tlambert@primenet.com] (Message ID: `<199906020108.SAA07001@usr09.primenet.com>`).
FreeBSD has an abstraction called an "execution class loader".