Running x86 Programs on the Rasp Pi

Out of This World

© Lead Image © innovari, fotolia.com

© Lead Image © innovari, fotolia.com

Author(s):

Some of your favorite programs might not run on Raspberry Pi because no version is available for the ARM architecture. ExaGear Desktop changes that by acting as a translator between the ARM and x86 worlds.

The open source advantage was evident from the beginning with the Raspberry Pi: Since free software usually runs on many different platforms, almost all Debian packages could be ported to the new system in a very short time. In addition, there was software that exploited the Rasp Pi's special hardware features.

But for proprietary programs, including most Windows applications, the path to the Raspberry Pi is much less assured. Unless the developers want to port their code to the Rasp Pi, users are out in the cold – unless they know about ExaGear.

ExaGear is a tool that provides a special translation layer that converts x86 commands to ARM equivalents. You can use ExaGear to run software written for x86 systems on the ARM-based Raspberry Pi. Support for the Wine integration layer means you can even run old Windows programs directly on the Rasp Pi.

Installation

For a proprietary program, the download and installation is extremely easy [1]: ExaGear can be found in the Raspbian package sources. You can thus install it conveniently via the package manager and then start the emulator (Listing 1).

Listing 1

Installing ExaGear Desktop

$ sudo apt update
$ sudo apt install exagear-desktop
$ exagear
Starting /bin/bash in the guest image /opt/exagear/images/debian-8

The last command in Listing 1 switches to the x86 environment. The first time you call it, a form appears, prompting you for your name and email address (Figure 1). The trial version can then be used in full for 72 hours. The license is tied to the CPU's serial number, which prevents users from simply reinstalling.

Figure 1: As a trial version, ExaGear can be used in full for three days without a paid license.

With a full license, the procedure is somewhat different (see the "Versions" box). Download a tarball specific to the Rasp Pi model used and unpack it in the same directory as the license file. Then start the installation command (Listing 2). (Eltechs kindly provided us with a license for this article.)

Versions

ExaGear Desktop costs between EUR11.95 for the Pi Zero/RPi1-compatible basic version and EUR40.95 for the RPi3-compatible enterprise version, depending on the platform and scope of functions. However, there are always special offers; for example, at the beginning of the 2018 FIFA World Cup, you could get two licenses for the price of one.

In addition to the focus on a specific Rasp Pi model, the versions also differ in terms of flexibility and support. The basic version is tied to a specific device – if your Rasp Pi dies, the license is also lost. The Pro version, on the other hand, allows you to transfer the license to another device of the same class. The basic version costs EUR23.95 Euro, and the pro version costs and additional 12 euros. The enterprise version supports use in the enterprise, offers better support, and simplifies the installation via volume licenses.

The cheapest license (for the Rasp Pi Zero/RPi1) is not really all that useful even for general use. Many programs fail due to meager resources. For special programs, however, the combination of Pi Zero and ExaGear can be a sensible alternative to a dusty Windows XP PC that only runs because there is no modern replacement for the beloved old laboratory software.

Listing 2

Installation Command

exagear-desktop-v-2-2/exagear-desktop-rpi3.tar.gz
$ tar -xvzpf exagear-desktop-v-2-2/exagear-desktop-rpi3.tar.gz
$ sudo ./install-exagear.sh

The tarball essentially contains a number of deb packages with guest systems, from which the installation script then selects the most suitable alternative for the installation. It also checks the license and activates the program.

First Steps

After starting the ExaGear environment with the command exagear, nothing happens except a welcome message. The output of the commands uname -a and cat /etc/os-release (Figure 2) show that the system now runs – with identical kernel versions – under an x86 architecture instead of an armv7l architecture. With the command exit, you leave the x86 environment again.

Figure 2: The system will identify itself as an x86 environment after you start ExaGear.

Later on, you can avoid the detour via the exagear command for installed x86 programs, because the kernel identifies the binary format and launches the wrapper automatically. Of course, this is not automatically the case, but needs to be configured using the ExaGear installer.

Installing ExaGear puts a minimal Debian "Jessie" distribution on your system. Unlike real emulators or virtual machines, the x86 environment makes use of the host system environment – ExaGear is thus explicitly unsuitable for clean program isolation.

The Jessie filesystem is located below /opt/exagear/images/debian-8/. From the normal Raspbian system, you can access the data stored there without any problems. Conversely, you can access the home directories of the host system: ExaGear integrates both /home/ and /dev/.

If you need access to the complete host system, simply remount the original root partition completely (Listing 3). After that, the guest system sees the complete host filesystem below /host – whether or not this makes sense is up to you to decide.

Listing 3

Remounting the Original Root Partition

$ sudo mkdir /opt/exagear/images/debian-8/host
$ sudo mount /dev/mmcblk0p2 /opt/exagear/images/debian-8/wirt

The dpkg -l command shows the few installed packages of the frugal ExaGear Debian. However, the retroactive installation of further software works without problems and – in the usual Raspbian style – relies on the command:

sudo apt-get install <package>

The guest system also relies on the host for services and udev rules. It would thus be pointless to reinstall services like cron inside the emulator. It only makes sense that the software prevents this.

Architecture

ExaGear Desktop is not a classic emulator that provides a complete operating system environment – in particular, it lacks its own kernel. In principle, the software works in a similar way to Wine, which provides a Windows environment under Linux. The run-time environment intercepts x86 commands and translates them into corresponding ARM commands. For graphics output, ExaGear uses the host's X server; the Linux desktop's architecture helps the emulator here (see the "X Architecture on Linux" box).

X Architecture on Linux

On Linux, the operating system traditionally does not draw the graphical output, but instead relies on a separate program known as the X server. Applications that want to output a graphical user interface communicate with the X server and tell it what to draw. The X server then calls the kernel's low-level system driver interfaces. Communication between the X clients and the X server takes place via the network interfaces.

On workstations, the X server and its clients usually run on the same system. The X clients could also run on a computer at the other side of the world and send their graphics commands via the Internet to the home computer, which then displays the interface. Thanks to the standardized protocol, this also works across operating system boundaries. A Rasp Pi program's graphical output could therefore be easily displayed on an X server running Windows.

In relation to ExaGear Desktop, this means that the emulator does not have to take care of the graphical user interface. The x86 programs are ultimately equivalent to additional X clients. They send the output commands to the host's X server, which then displays the output. The server returns keyboard and mouse events to the X client in the emulator.

The advantage of the lean emulation layer is that it automatically supports multithreading; however, you still experience a loss of performance. Eltechs promises up to 80 percent of native performance, with the loss depending on the specific commands an application uses. In extreme cases, up to two-thirds of the Rasp Pi performance is lost.

On the Raspbian side, you should definitely take some precautions to ensure optimal conditions. This includes at least a newer generation RPi2 (the same processor as the RPi3) or higher. A fast hard disk (SSD) for the system also helps. You should also give the GPU enough memory, at least 256MB, which you can set with the parameter gpu_mem in the /boot/config.txt file.

Graphic-intensive applications also benefit from enabling hardware-supported graphics acceleration. You can do this in raspi-config, where you will find the setting GL Driver below Advanced Options. Select GL (Full KMS) OpenGL desktop driver with full KMS. Applications such as Skype (32-bit Linux version) have a problem with this. When Skype accesses the video camera, whether it's a Pi or USB camera, the X server crashes.

On the network side, emulation is less of a performance brake. Cloning a 260MB GitHub project took 140 seconds natively and 231 seconds in the emulator. The download rate in the emulator was only seven percent lower, the rest of the loss was attributable to the CPU for encryption and processing the Git metadata. With NFS or Samba transfers, on the other hand, the loss is in the range of measurement uncertainty.

First Tests

With ExaGear Desktop, all (32-bit) programs running under Debian 8 can be run on the Rasp Pi. Eltechs has a collection of instructions for popular programs on its website, such as Skype for Linux or Wine as the basis for Windows programs. Often a video also shows the necessary steps. Anyone who has already installed programs under Raspbian will usually be able to do without these instructions.

The first candidate for the emulator was the open source Visual Studio Code (VSC) editor, which was developed by Microsoft and has since found a large community on GitHub. In addition, VSC runs on many platforms and has what it takes to send even my own XEmacs editor into retirement.

There are no precompiled binaries for Raspbian for the editor, and building your own binaries is tricky because of the many dependencies. Fortunately, the installation under ExaGear with the standard installation instructions from the VSC page [3] worked with virtually no problems. I had to install two dependencies manually, but this was not due to ExaGear.

However, the result of this first attempt was disappointing. VSC started via ExaGear could not be used under Raspbian. Launching the program consumed so many resources that the system seemed to hang. A little research on the Internet shows, however, that even a native ARM build under Raspbian can be very slow.

The lesson: Don't expect miracles from ExaGear (or Raspbian itself). Even though many programs run smoothly on a RPi3/RPi3B+, there are limits, and an additional emulation layer doesn't make things any better.

Saving Old Treasures

Much more important than modern and accordingly resource-hungry applications are old treasures, which you want to launch on Raspbian every now and then. This above all includes Windows programs from the last and penultimate generation.

For this you install the already mentioned Windows run-time environment Wine (Listing 4) under ExaGear. Eltechs provides a custom version whose package name contains the string "eltechs". The Windows Explorer celebrates its resurrection under Raspbian (Figure 3).

Listing 4

Installing Wine

$ sudo apt update
$ sudo full-upgrade
$ sudo apt install wine
$ wine --version
wine-2.0-eltechs
Figure 3: Windows Explorer in action on Raspbian.

This additional emulation layer costs surprisingly little power. This is because only Windows system calls have to be translated to the analog kernel commands, but not the x86 to the ARM command set. After the Wine installation, supported Windows programs (32-bit) can be installed in this environment. This does not always work without complications, but is well documented for a large number of programs [4] and independent of the Raspbian and ExaGear substructure.

Wine typically supports older Windows programs, as the Windows command set has expanded over time and the Wine developers have to program for it. The advantage: Older programs were developed for weaker PC generations, so that a Rasp Pi's computing power including the emulator is usually sufficient. The freeware mp3DirectCut [5] for lossless editing of MP3 files, for example, runs smoothly and without problems (Figure 4).

Figure 4: You can run older Windows programs like mp3DirectCut on the Raspberry Pi using Wine plus ExaGear.

Even old games may run smoothly with the combination of Wine plus ExaGear, if you believe the reports on the Internet. Due to my lack of experience in this field, however, this was not tested.

Conclusions

ExaGear's license terms are not very customer-friendly, especially in the basic version with the binding to a single Raspberry Pi board. One should therefore consider the choice of license carefully. However, if you don't want to do without an important program under Raspbian, you can pay the required amount after a performance test.

The Author

Bernhard Bablok is an SAP-HR developer at Allianz Technology SE. When he's not listening to music, riding his bike, or walking, he focuses on topics relating to Linux and object orientation.