How to Configure Linux Binary Compatibility on FreeBSD

Linux binary operations on FreeBSD began in 1995. These applications used the Linux executable format and provided a special Linux system call table. Early Linux binaries were used to play the video game, Doom. Gradually, many Linux applications and libraries were packaged and made available through the FreeBSD Ports Collection. However, because the FreeBSD tools do not understand Linux package dependencies, this process was time consuming and manually configured.

Now that we know how to work with the ports collection let’s have a look another option you have in FreeBSD: Sometimes it might be required to run unmodified Linux binaries on FreeBSD and to achieve this, FreeBSD comes with a Linux compatibility layer. This is optional and not enabled by default, but pretty easy to setup and use. Before you do that, please check if the functionality you’re looking for is not already there as either a package or the ports collection. If it is there, use it from there.

post image

How to Install Linux Binary

Use the FreeBSD ports system to install Linux Binary

root@ns1:~ # cd /usr/ports/emulators/linux_base-c7
root@ns1:/usr/ports/emulators/linux_base-c7 # make install clean

After that you open the /etc/fstab file and edit its contents by inserting the script above into the /etc/fstab file. For convenience, use the "ee" editor to insert the script above.

root@ns1:~ # ee /etc/fstab
linprocfs   /compat/linux/proc     linprocfs       rw      0       0
linsysfs    /compat/linux/sys      linsysfs        rw      0       0
tmpfs       /compat/linux/dev/shm  tmpfs           rw,mode=1777 0 0
devfs       /compat/linux/dev      devfs           rw,late 0 0
fdescfs     /compat/linux/dev/fd   fdescfs         rw,late,linrdlnk 0 0

The next step is to create a /compat/linux folder according to the script above.

root@ns1:~ # mkdir -p /compat/linux/dev/shm
root@ns1:~ # mkdir -p /compat/linux/proc
root@ns1:~ # mkdir -p /compat/linux/sys
root@ns1:~ # mkdir -p /compat/linux/dev/fd

Run the "mount" command to activate the above script.

root@ns1:~ # mount /compat/linux/proc
root@ns1:~ # mount /compat/linux/sys
root@ns1:~ # mount /compat/linux/dev/shm
root@ns1:~ # mount /compat/linux/dev/fd

Next proceed to create a ZFS data set for Linux binary files.

root@ns1:~ # zfs create -o compression=on -o mountpoint=/compat zroot/compat
root@ns1:~ # zfs snapshot -r zroot/compat@2025-02-01

The above script will create a ZFS filesystem in the /compat folder. The next step is to install linux-sublime-text4. Follow the steps below to install linux-sublime-text4.

root@ns1:~ # cd /usr/ports/editors/linux-sublime-text4
root@ns1:/usr/ports/editors/linux-sublime-text4 # make install clean

Enabling Linux Binary

Even though we have installed the Linux binary package, it cannot be activated yet. Okay, now we will activate the Linux binary package on the FreeBSD system. Open and edit the /boot/loader.conf file and then enter the following script.

root@ns1:~ # ee /boot/loader.conf
zfs_load="YES"

linux_load="YES"
linux64_load="YES"
fdescfs_load="YES"
linprocfs_load="YES"
tmpfs_load="YES"
linsysfs_load="YES"

The above script will read the Linux kernel and ZFS file system when the computer is shut down or restarted. After that, we create a startup script rc.d in the /etc/rc.conf file.

root@ns1:~ # ee /etc/rc.conf
zfs_enable="YES"
kld_list="linux linux64 cuse fusefs /boot/modules/i915kms.ko"
linux_enable="YES"

After the rc.d startup script is successfully created, now you restart/reboot the computer.

root@ns1:~ # reboot

Nice. If you have the requirement to use Linux tools on FreeBSD, this can be very helpful.