<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter1. Ìinux emulation</title>
<link rel="stylesheet" type="text/css" href="/global.css">
<meta name="generator" content="DocBook XSL Stylesheets VX.X.X">
<link rel="home" href="index.html" title="The NetBSD Guide">
<link rel="up" href="part-virt.html" title="Part Ö. Öirtualization and emulation">
<link rel="prev" href="chap-virt.html" title="Chapter0. Õsing virtualization: QEMU and NVMM">
<link rel="next" href="part-compile.html" title="Part ÖI. Âuilding the system">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter1. Ìinux emulation</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="chap-virt.html">Prev</a>/td>
<th width="60%" align="center">Part Ö. Öirtualization and emulation</th>
<td width="20%" align="right">a accesskey="n" href="part-compile.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="chap-linux"></a>Chapter1. Ìinux emulation</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl class="toc">
<dt><span class="sect1"><a href="chap-linux.html#chap-linux-setup">31.1. Emulation setup</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="chap-linux.html#chap-linux-setup-configure-kernel">31.1.1. Configuring the kernel</a></span></dt>
<dt><span class="sect2"><a href="chap-linux.html#chap-linux-setup-install-linux-lib">31.1.2. Installing the Linux libraries</a></span></dt>
<dt><span class="sect2"><a href="chap-linux.html#chap-linux-setup-run-linux-bin">31.1.3. Running Linux programs</a></span></dt>
</dl></dd>
<dt><span class="sect1"><a href="chap-linux.html#chap-linux-directory-structure">31.2. Directory structure</a></span></dt>
<dt><span class="sect1"><a href="chap-linux.html#chap-linux-browser-plugins">31.3. Using Linux browser plugins</a></span></dt>
<dt><span class="sect1"><a href="chap-linux.html#chap-linux-further-reading">31.4. Further reading</a></span></dt>
</dl>
</div>
<p>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.</p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-linux-setup"></a>31.1. Åmulation setup</h2></div></div></div>
<p>The installation of the Linux emulation is described in the
<a class="citerefentry" href="//man.NetBSD.org/NetBSD-9.2/i386/compat_linux.8"><span class="citerefentry"><span class="refentrytitle">compat_linux</span>(8)</span></a> man page; using the package system only two steps
are needed.</p>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-linux-setup-configure-kernel"></a>31.1.1. Ãonfiguring the kernel</h3></div></div></div>
<p>If you use a GENERIC kernel you don't need to do anything because
Linux compatibility is already enabled.</p>
<p>If you use a customized kernel, check that the following options
are enabled:</p>
<pre class="programlisting">option COMPAT_LINUX
option EXEC_ELF32</pre>
<p>
or the following options if you are going to use 64-bit ELF
binaries:
</p>
<pre class="programlisting">option COMPAT_LINUX
option EXEC_ELF64</pre>
<p>when you have compiled a kernel with the previous options you can
start installing the necessary software.</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-linux-setup-install-linux-lib"></a>31.1.2. Énstalling the Linux libraries</h3></div></div></div>
<p>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 to install the provided libraries from openSUSE.</p>
<p>All Linux binaries exist entirely within the separate root
directories inside <code class="filename">/emul/linux</code> and
<code class="filename">/emul/linux32</code>.
The kernel will always search these paths first when looking
for shared objects required by Linux programs.</p>
<p>A number of useful Linux shared object binaries is provided by
pkgsrc, for running both 64-bit and 32-bit applications. The absolute
minimum required to run dynamically linked Linux applications are
are provided by the <code class="filename">suse131_base</code> and
<code class="filename">suse131_32_base</code> packages (or, if using binary
packages <code class="filename">suse_base-13</code> and
<code class="filename">suse32_base-13</code>). Many other libraries are also
provided as separate packages.</p>
<p>Some packages in pkgsrc are provided as Linux binaries and
will also install all the required SUSE dependencies when installed.
However, this is uncommon. One such package is
<code class="filename">adoptopenjdk11-bin</code>.</p>
<p>It is possible to examine which libraries are required by
a Linux program with <a class="citerefentry" href="//man.NetBSD.org/NetBSD-9.2/i386/readelf.1"><span class="citerefentry"><span class="refentrytitle">readelf</span>(1)</span></a>:</p>
<pre class="screen"><code class="prompt">$</code> <strong class="userinput"><code>readelf -d ./runner</code></strong>
Dynamic section at offset 0x3a2e94 contains 40 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
0x00000001 (NEEDED) Shared library: [libz.so.1]
0x00000001 (NEEDED) Shared library: [libXxf86vm.so.1]
0x00000001 (NEEDED) Shared library: [libGL.so.1]
0x00000001 (NEEDED) Shared library: [libopenal.so.1]
0x00000001 (NEEDED) Shared library: [libm.so.6]
0x00000001 (NEEDED) Shared library: [librt.so.1]
0x00000001 (NEEDED) Shared library: [libpthread.so.0]
0x00000001 (NEEDED) Shared library: [libdl.so.2]
0x00000001 (NEEDED) Shared library: [libcrypto.so.1.0.0]
0x00000001 (NEEDED) Shared library: [libXext.so.6]
0x00000001 (NEEDED) Shared library: [libX11.so.6]
0x00000001 (NEEDED) Shared library: [libXrandr.so.2]
0x00000001 (NEEDED) Shared library: [libGLU.so.1]
0x00000001 (NEEDED) Shared library: [libssl.so.1.0.0]
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]</pre>
<p>For example, an application which requires
<code class="filename">libcrypto.so.1.0.0</code>,
<code class="filename">libXext.so.6</code>, and
<code class="filename">libGL.so.1</code>
will require <code class="filename">openssl</code>,
<code class="filename">x11</code>, and <code class="filename">glx</code>,
in addition to the <code class="filename">base</code> SUSE package.</p>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-linux-setup-run-linux-bin"></a>31.1.3. Òunning Linux programs</h3></div></div></div>
<p>Once the correct libraries are installed, no special steps
are required to run a Linux program - simply type the command
(if you acquired it as a non-pkgsrc download, include the full path
on the filesystem). The kernel will detect it is a Linux executable
and run it in the correct translation mode.</p>
</div>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-linux-directory-structure"></a>31.2. Äirectory structure</h2></div></div></div>
<p>If we examine the outcome of the installation of the Linux
libraries and programs we find that
<code class="filename">/emul/linux</code> is a symbolic link pointing to
<code class="filename">/usr/pkg/emul/linux</code>, where the following
directories have been created:</p>
<div class="literallayout"><p>bin/<br>
dev/<br>
etc/<br>
lib/<br>
lib64/<br>
proc/<br>
sbin/<br>
usr/<br>
var/</p></div>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>Please always refer to <code class="filename">/emul/linux</code> and not
to <code class="filename">/usr/pkg/emul/linux</code>.
The latter is an implementation detail and may change in the
future.</p>
</div>
<p>How much space is required for the Linux emulation software?
On one system we got the following figure:</p>
<pre class="screen"><code class="prompt">#</code> <strong class="userinput"><code>cd /usr/pkg/emul</code></strong>
<code class="prompt">#</code> <strong class="userinput"><code>du -k /emul/linux/</code></strong>
...
399658 /emul/linux/</pre>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-linux-browser-plugins"></a>31.3. Õsing Linux browser plugins</h2></div></div></div>
<p>
Linux plugins for Mozilla-based browsers can be used on native
NetBSD Firefox builds through
<span class="application">nspluginwrapper</span>, 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:
</p>
<pre class="screen">
<code class="prompt">#</code> cd /usr/pkgsrc/www/nspluginwrapper
<code class="prompt">#</code> make install
</pre>
<p>
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
<span class="command"><strong>nspluginwrapper</strong></span> by the users who want to
use that plugin.
</p>
<p>
In this short example we will have a look at installing the
<span class="application">Macromedia Flash</span> plugin. We can
fullfill the first step by installing the Flash plugin through
pkgsrc:
</p>
<pre class="screen">
<code class="prompt">#</code> cd /usr/pkgsrc/multimedia/ns-flash
<code class="prompt">#</code> make install
</pre>
<p>
After that an unprivileged user can register the Flash plugin:
</p>
<pre class="screen">
<code class="prompt">$</code> nspluginwrapper -i /usr/pkg/lib/netscape/plugins/libflashplayer.so
</pre>
<p>
The plugin should then be registered correctly. You can check this
by using the <em class="parameter"><code>-l</code></em> option of
<span class="command"><strong>nspluginwrapper</strong></span>
(<span class="command"><strong>nspluginwrapper -l</strong></span>). If the plugin is listed,
you can restart Firefox, and verify that the plugin was installed
by entering <span class="emphasis"><em>about:plugins</em></span> in the location
bar.
</p>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="chap-linux-further-reading"></a>31.4. Æurther reading</h2></div></div></div>
<p>
The following articles may be of interest for further
understanding Linux (and other) emulation:
</p>
<div class="bibliography">
<div class="titlepage"><div><div><h3 class="title">
<a name="chap-linux-further"></a>Bibliography</h3></div></div></div>
<div class="biblioentry">
<a name="chap-linux-further-implementing-linux-emul-on-netbsd"></a><p>[chap-linux-further-implementing-linux-emul-on-netbsd] <span class="title"><i>
<a class="ulink" href="https://www.linux.com/news/implementing-linux-emulation-netbsd/" target="_top">
Implementing Linux emulation on NetBSD</a>
</i>. </span><span class="author"><span class="firstname">Peter</span> <span class="surname">Seebach</span>. </span><span class="date">May 2004. </span></p>
</div>
</div>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="chap-virt.html">Prev</a>/td>
<td width="20%" align="center"><a accesskey="u" href="part-virt.html">Up</a></td>
<td width="40%" align="right">a accesskey="n" href="part-compile.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter0. Õsing virtualization: QEMU and NVMM/td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Ðart ÖI. Âuilding the system</td>
</tr>
</table>
</div>
</body>
</html>