Chapter 10. Linux emulation

Table of Contents

10.1. Emulation setup
10.1.1. Configuring the kernel
10.1.2. Installing the Linux libraries
10.1.3. Installing LibreOffice
10.2. Directory structure
10.3. Emulating /proc
10.4. Using Linux browser plugins
10.5. Further reading

The NetBSD port for amd64, i386, alpha, mac68k, macppc, and many others can execute a great number of native Linux programs, using the Linux emulation layer. Generally, when you think about emulation you imagine something slow and inefficient because, often, emulations must reproduce hardware instructions and even architectures (usually from old machines) in software. In the case of the Linux emulation this is radically different: it is only a thin software layer, mostly for system calls which are already very similar between the two systems. The application code itself is processed at the full speed of your CPU, so you don't get a degraded performance with the Linux emulation and the feeling is exactly the same as for native NetBSD applications.

This chapter explains how to configure the Linux emulation with an example: the installation of LibreOffice Linux RPM.

10.1. Emulation setup

The installation of the Linux emulation is described in the compat_linux(8) man page; using the package system only two steps are needed.

  1. Configuring the kernel.

  2. Installing the Linux libraries.

  3. Installing Linux applications like LibreOffice

10.1.1. Configuring the kernel

If you use a GENERIC kernel you don't need to do anything because Linux compatibility is already enabled.

If you use a customized kernel, check that the following options are enabled:

option EXEC_ELF32

or the following options if you are going to use 64-bit ELF binaries:

option EXEC_ELF64

when you have compiled a kernel with the previous options you can start installing the necessary software.

10.1.2. Installing the Linux libraries

Usually, applications are linked against shared libraries, and for Linux applications, Linux shared libraries are needed. You can get the shared libraries from any Linux distribution, provided it's not too old, but the suggested method is to use the package system and install the libraries automatically (which uses SUSE libraries). When you install the libraries, the following happens:

  • A secondary root directory is created which will be used for Linux programs. This directory is /emul/linux. The Linux programs in emulation mode will use this directory as their root directory and use files there. If a required file is not found, it will be searched with / as root directory.

    For example, if a Linux application opens /etc/, it will first be searched in /emul/linux/etc/, and if not found there in /etc/

  • The shared libraries for Linux are installed. Most applications are linked dynamically and expect to find the necessary libraries on the system. For example, for LibreOffice, if you go to the /usr/pkgsrc/misc/libreoffice6-bin and give the make depends command, pkgsrc will fetch and install all dependencies for LibreOffice.

Both operations will be handled automatically by the package system, without the need of manual intervention from the user (we suppose that, by now, you have already begun to love the package system...). Note that this section describes manual installation of the Linux libraries.

To install the libraries, a program must be installed that handles the RPM format: it is rpm, which will be used to extract the SUSE libraries. Execute make and make install in the /usr/pkgsrc/misc/rpm/ directory to build and install rpm.

Next the suse131_base package must be installed. The SUSE RPM files can be downloaded by the package system or, if you have a SUSE CD, you can copy them in the /usr/pkgsrc/distfiles/suse131 directory and then run make and make install after going to the /usr/pkgsrc/emulators/suse131_base directory.

With the same method install suse131_compat and suse131_x11. The final configuration is:

# pkg_info -a | grep suse
suse_base-13.1nb3   Linux compatibility package
suse_compat-13.1    Linux compatibility package with old shared libraries
suse_x11-13.1nb7    Linux compatibility package for X11 binaries

10.1.3. Installing LibreOffice

Now everything is ready for the installation of the LibreOffice program (or other Linux programs). Change to /usr/pkgsrc/misc/libreoffice6-bin and give the usual commands.

# make
# make install

10.2. Directory structure

If we examine the outcome of the installation of the Linux libraries and programs we find that /emul/linux is a symbolic link pointing to /usr/pkg/emul/linux, where the following directories have been created:



Please always refer to /emul/linux and not to /usr/pkg/emul/linux. The latter is an implementation detail and may change in the future.

How much space is required for the Linux emulation software? On one system we got the following figure:

# cd /usr/pkg/emul
# du -k /emul/linux/
399658  /emul/linux/

LibreOffice, the program, has been installed in the usual directory for package binaries: /usr/pkg/bin. It can be run just as any other program:

$ soffice 

10.3. Emulating /proc

Some Linux programs rely on a Linux-like /proc filesystem. The NetBSD procfs filesystem can emulate a /proc filesystem that contains Linux-specific pseudo-files. To accomplish this you can mount the procfs with the linux-option:

# mount_procfs -o linux procfs /emul/linux/proc

In this example a Linux-like proc filesystem will be mounted to the /emul/linux/proc directory. You can also let NetBSD mount it automatically during the booting process of NetBSD, by adding the following line to /etc/fstab:

procfs /emul/linux/proc procfs ro,linux

10.4. Using Linux browser plugins

Linux plugins for Mozilla-based browsers can be used on native NetBSD Firefox builds through nspluginwrapper, a wrapper that translates between the native browser and a foreign plugin. At the moment, nspluginwrapper only works reliably on Mozilla-based browsers that link against GTK2+ (GTK1+ is not supported). nspluginwrapper can be installed through pkgsrc:

# cd /usr/pkgsrc/www/nspluginwrapper
# make install

Plugins can then be installed in two steps: first, the plugin has to be installed on the system (e.g. through pkgsrc). After that the plugin should be registered with the nspluginwrapper by the users who want to use that plugin.

In this short example we will have a look at installing the Macromedia Flash plugin. We can fullfill the first step by installing the Flash plugin through pkgsrc:

# cd /usr/pkgsrc/multimedia/ns-flash
# make install

After that an unprivileged user can register the Flash plugin:

$ nspluginwrapper -i /usr/pkg/lib/netscape/plugins/

The plugin should then be registered correctly. You can check this by using the -l option of nspluginwrapper (nspluginwrapper -l). If the plugin is listed, you can restart Firefox, and verify that the plugin was installed by entering about:plugins in the location bar.

10.5. Further reading

The following articles may be of interest for further understanding Linux (and other) emulation:


[chap-linux-further-implementing-linux-emul-on-netbsd] Implementing Linux emulation on NetBSD . Peter Seebach. May 2004.