April 9, 2021
What is Linuxulator?
Dr. Emmett Brown’s similar-sounding Flux Capacitor from the movie Back to the Future bridged the dimension of time, uniting past, present, and future for the McFlys. Similarly, the FreeBSDⓇ Linuxulator project also bridges dimensions – in our case, these are LinuxⓇ and FreeBSD.
Linuxulator provides Linux ABI (application binary interface) compatibility so FreeBSD users can run many unmodified Linux applications and libraries without the need for virtualization or emulation. It provides the binaries with kernel interfaces identical to those provided by a Linux kernel, similar to the way 32-bit FreeBSD binaries run on top of 64-bit FreeBSD kernel. Since Linuxulator doesn’t rely on virtual machines or emulation, these apps often run as fast, and sometimes even faster, on FreeBSD as on Linux.
It might not surprise you to learn that the initial motivation for Linuxulator was to play the game Doom on FreeBSD. From this noble beginning in FreeBSD 2.1 (1995 for those keeping score at home), uses of the compatibility tool now range from desktop apps like Steam, Tor, and Firefox, to any number of server workloads like databases, development languages, and caches.1
Linuxulator is not without controversy, but let’s be honest, what in Open Source *is*? In a recent online discussion, some community members disagreed that continued Linuxulator improvement matters for the growth of FreeBSD.2 One reader commented that ongoing investment in Linuxulator would simply encourage people to run the Linux versions of apps and thereby diminish interest in FreeBSD versions. However, this argument was overpowered by counter arguments like this one:
I use FreeBSD exclusively for my development, but there are a few pieces of proprietary software that are only available as Linux binaries (like FPGA toolchains), and having a viable Linux ABI layer means that I do not need to resort to having an entire second operating system in a VM or another machine.
FreeBSD Foundation Investment in Linuxulator
Recognizing its importance, the FreeBSD Foundation eagerly approved two separate Grant applications from longtime FreeBSD contributor and community member Edward Tomasz Napierała in 2019 and 2020 to update and improve Linuxulator. We caught up with Edward working from his home in Cambridge, UK to learn more about his work.
Edward’s interest in Linuxulator began a few years ago when conducting preliminary research on how to run Android apps on FreeBSD as part of Robert Watson’s team at the University of Cambridge. Edward soon discovered that this goal, albeit fascinating (and yes, a University of Cambridge Smartphone would be eminently on-brand), was a bit too ambitious given the state of the Linuxulator code. Nevertheless, the value of the binary interface project was immediately apparent to Edward, who saw some important ways he could make it more stable and useful.
And this wasn’t Edward’s first brush with Linuxulator. Prior to his Android initiative, the FreeBSD Foundation contracted with Edward to review and help integrate the 64 bit compatibility patch from intrepid Linuxulator contributor Dmitry Chagin. Even though it was a significant patch, Edward recalls that the code was very good, and the review went quite quickly. Although the review itself did not take long, the patch had sat awaiting review for some months. Had the Foundation not stepped in to enlist Edward’s assistance, there was a feeling the Linuxulator project could have stalled.
In the process of working on Android apps for FreeBSD, Edward realized that there were many (often undocumented) steps needed to get Linuxulator running. This motivated him to submit his 2019 Grant proposal to keep Linuxulator from regressing.
For instance, he discovered that there was no good way to trace Android (and by extension, Linux) programs in a FreeBSD environment. Linux apps use strace, and so one aspect of Edward’s FreeBSD Foundation-supported work in 2019 was to get strace working in Linuxulator. In this same vein, Edward added a port for Linux Test Project as a way to measure the overall health of Linuxulator. Much of the rest of his 2019 work was maintenance – bug fixes and modernization – so that Linuxulator can execute contemporary Linux binaries. Ask users of the most recent FreeBSD-based GhostBSD desktop OS, and they’ll say “Mission Accomplished!”
Notable to GhostBSD 20.11.28 are fixes to the “Linuxulator” support from FreeBSD that allows for running Linux binaries on BSD. With the fixes in this release there should be better performance for running the Linux build of Steam. That should help in allowing more Linux games to run atop GhostBSD 18.104.22.168
With the code base modernized and stabilized, in 2020 Edward submitted, and the FreeBSD Foundation approved and funded, another Grant proposal to investigate running under the Linuxulator a number of popular client-facing and server related Linux applications, and to fix or document identified issues.
“With the solid base we built in 2019, this year’s work is more focused on things that will be useful to users,” Edward commented. He divided the 2020 project into two parts. The first half focused on command line apps, such as Python, SSH, VIM, and git, and the second on graphical apps like VLC and Chromium.
Edward likens FreeBSD Foundation Grant projects to declarative programming. In the proposal, you describe the desired end state, but inevitably, the route you take to get there ends up being very hard to predict.
For instance, last year Edward discovered that it was unnecessarily difficult to start working with Linuxulator. Doing so required multiple steps, such as installing Linux in a virtual machine, then copying over its entire root filesystem to a FreeBSD machine, etc. Edward addressed this by making it easier to use debootstrap to install Ubuntu. Now, anyone who wants to experiment with Linuxulator just needs to create a Linux jail, then use apt, and run it. In this same lane, Edward also developed some automations to streamline the user experience.
In the second half of last year, as he began to merge updates to graphical apps like Chromium, the project began to gain momentum and attract additional contributors. Ultimately, this is the goal of many FreeBSD Foundation Grants – to address those areas of FreeBSD that are important to the project’s success and that, for various reasons, are not receiving sufficient community contributions. Edward is quick to point out that his Foundation-supported work builds on that of the many contributors before him and depends on active ongoing participation from the community for Linuxulator to reach its potential.
With Linuxulator, Edward was excited to see other developers step in to fix bugs that he had researched and documented the root cause. For example, while working on linuxulator-steam-utils, Alex S. tracked down the root cause of a number of problems. While linuxulator-steam-utils patches over Linuxulator bugs in userspace, Alex’s analysis made it possible to fix them in Linuxulator itself.
Looking ahead in 2021, Edward is planning to continue his work on graphical app support in Linuxulator. He encourages people interested in making FreeBSD their primary system, and who need or want to run the occasional Linux application, to consider getting involved with Linuxulator. A great place to start is https://wiki.freebsd.org/Linuxulator.