File:  [NetBSD Developer Wiki] / wikisrc / guide / linux.mdwn
Revision 1.4: download - view: text, annotated - select for diffs
Fri Jun 19 19:18:31 2015 UTC (6 years, 5 months ago) by plunky
Branches: MAIN
CVS tags: HEAD
replace direct links to manpages on with templates

    1: **Contents**
    3: [[!toc levels=3]]
    5: # Linux emulation
    7: The NetBSD port for i386, amd64, mac68k, macppc, and many others can execute a
    8: great number of native Linux programs, using the Linux emulation layer.
    9: Generally, when you think about emulation you imagine something slow and
   10: inefficient because, often, emulations must reproduce hardware instructions and
   11: even architectures (usually from old machines) in software. In the case of the
   12: Linux emulation, this is radically different: it is only a thin software layer,
   13: mostly for system calls which are already very similar between the two systems.
   14: The application code itself is processed at the full speed of your CPU, so you
   15: don't get a degraded performance with the Linux emulation and the feeling is
   16: exactly the same as for native NetBSD applications.
   18: This chapter explains how to configure the Linux emulation with an example: the
   19: installation of the well known Acrobat Reader version 7 program.
   21: ## Emulation setup
   23: The installation of the Linux emulation is described in the
   24: [[!template id=man name="compat\_linux" section="8"]]
   25: man page; using the package system, only two steps are needed.
   27:  1. Configuring the kernel.
   28:  2. Installing the Linux libraries.
   29:  3. Installing Linux applications like Acrobat Reader
   31: ### Configuring the kernel
   33: If you use a GENERIC kernel you don't need to do anything because Linux
   34: compatibility is already enabled.
   36: If you use a customized kernel, check that the following options are enabled:
   38:     option COMPAT_LINUX
   39:     option EXEC_ELF32
   41: or the following options if you are going to use 64-bit ELF binaries:
   43:     option COMPAT_LINUX
   44:     option EXEC_ELF64
   46: When you have compiled a kernel with the previous options, you can start
   47: installing the necessary software.
   49: ### Installing the Linux libraries
   51: Usually, applications are linked against shared libraries, and for Linux
   52: applications, Linux shared libraries are needed. You can get the shared
   53: libraries from any Linux distribution, provided it's not too old, but the
   54: suggested method is to use the package system and install the libraries
   55: automatically (which uses SUSE libraries). When you install the libraries, the
   56: following happens:
   58:  * A *secondary root directory* is created which will be used for Linux
   59:    programs. This directory is `/emul/linux`. The Linux programs in emulation
   60:    mode will use this directory as their root directory and use files there. If
   61:    a required file is not found, it will be searched with `/` as root directory.
   63:    For example, if a Linux application opens `/etc/`, it will first be
   64:    searched in `/emul/linux/etc/`, and if not found there, in
   65:    `/etc/`.
   67:  * The shared libraries for Linux are installed. Most applications are linked
   68:    dynamically and expect to find the necessary libraries on the system. For
   69:    example, for Acrobat Reader, if you go to the `/usr/pkgsrc/print/acroread7`
   70:    and give the `make depends` command, pkgsrc will fetch and install all
   71:    dependencies for Acrobat Reader.
   73: Both operations will be handled automatically by the package system, without the
   74: need of manual intervention from the user (we suppose that, by now, you have
   75: already begun to love the package system...). Note that this section describes
   76: manual installation of the Linux libraries.
   78: To install the libraries, a program must be installed that handles the RPM
   79: format: it is `rpm`, which will be used to extract the SUSE libraries. Execute
   80: `make` and `make install` in the `/usr/pkgsrc/misc/rpm/` directory to build
   81: and install `rpm`.
   83: Next the `suse121_base` package must be installed. The SUSE RPM files can be
   84: downloaded by the package system or, if you have a SUSE CD, you can copy them in
   85: the `/usr/pkgsrc/distfiles/suse121` directory and then run `make` and
   86: `make install` after going to the `/usr/pkgsrc/emulators/suse121_base`
   87: directory.
   89: With the same method install `suse121_compat` and `suse121_x11`. The final
   90: configuration is:
   92:     # pkg_info -a | grep suse
   93: 	suse_base-12.1nb3   Linux compatibility package
   94: 	suse_compat-12.1    Linux compatibility package with old shared libraries
   95: 	suse_x11-12.1       Linux compatibility package for X11
   97: *Note*: Of course you can also install the packages binary. To do this, you
   98: would either set the proper `PKG_PATH` and then
  100:     # pkg_add rpm
  101:     # pkg_add suse_base
  102:     # pkg_add suse_compat
  103:     # pkg_add suse_x11
  105: Or, using `pkgin`:
  107:     # pkgin install rpm suse_base suse_compat suse_x11
  109: *Note*: You can also skip this step when you are installing a package from
  110: pkgsrc which requires Linux emulation! A good example for this is the package
  111: `www/opera`, which will automatically install the packages needed for emulating
  112: the Linux version of the Opera browser.
  114: ### Installing Acrobat Reader
  116: Now everything is ready for the installation of the Acrobat Reader program (or
  117: other Linux programs). Change to `/usr/pkgsrc/print/acroread7` and give the
  118: usual commands.
  120:     # make
  121:     # make install
  123: ### Note
  125: To download and install Acrobat Reader you need to add the line
  126: `ACCEPTABLE_LICENSES+=adobe-acrobat-license` to `/etc/mk.conf` to accept the
  127: Acrobat Reader license, simply follow the instructions given after `make`.
  129: ## Directory structure
  131: If we examine the outcome of the installation of the Linux libraries and
  132: programs we find that `/emul/linux` is a symbolic link pointing to
  133: `/usr/pkg/emul/linux`, where the following directories have been created:
  135:  * `bin/`
  136:  * `dev/`
  137:  * `etc/`
  138:  * `lib/`
  139:  * `opt/`
  140:  * `proc/`
  141:  * `root/`
  142:  * `sbin/`
  143:  * `usr/`
  144:  * `var/`
  146: *Note*: Please always refer to `/emul/linux` and not to `/usr/pkg/emul/linux`.
  147: The latter is an implementation detail and may change in the future.
  149: How much space is required for the Linux emulation software? On one system we
  150: got the following figure:
  152:     # cd /usr/pkg/emul
  153:     # du -k /emul/linux/
  154:     ...
  155:     127804  /emul/linux/
  157: Acrobat Reader, the program, has been installed in the usual directory for
  158: package binaries: `/usr/pkg/bin`. It can be run just as any other program:
  160:     $ acroread netbsd.pdf
  162: ## Emulating /proc
  164: Some Linux programs rely on a Linux-like `/proc` filesystem. The NetBSD procfs
  165: filesystem can emulate a `/proc` filesystem that contains Linux-specific
  166: pseudo-files. To accomplish this you can mount the procfs with the
  167: `linux`-option:
  169:     # mount_procfs -o linux procfs /emul/linux/proc
  171: In this example a Linux-like proc filesystem will be mounted to the
  172: `/emul/linux/proc` directory. You can also let NetBSD mount it automatically
  173: during the booting process of NetBSD, by adding the following line to
  174: `/etc/fstab`:
  176:     procfs /emul/linux/proc procfs ro,linux
  178: ## Using Linux browser plugins
  180: Linux plugins for Mozilla-based browsers can be used on native NetBSD Firefox
  181: builds through nspluginwrapper, a wrapper that translates between the native
  182: browser and a foreign plugin. At the moment, nspluginwrapper only works reliably
  183: on Mozilla-based browsers that link against GTK2+ (GTK1+ is not supported).
  184: nspluginwrapper can be installed through pkgsrc:
  186:     # cd /usr/pkgsrc/www/nspluginwrapper
  187:     # make install
  189: Plugins can then be installed in two steps: first, the plugin has to be
  190: installed on the system (e.g. through pkgsrc). After that the plugin should be
  191: registered with the `nspluginwrapper` by the users who want to use that
  192: plugin.
  194: In this short example we will have a look at installing the Macromedia Flash
  195: plugin. We can fullfill the first step by installing the Flash plugin through
  196: pkgsrc:
  198:     # cd /usr/pkgsrc/multimedia/ns-flash
  199:     # make install
  201: After that an unprivileged user can register the Flash plugin:
  203:     $ nspluginwrapper -i /usr/pkg/lib/netscape/plugins/
  205: The plugin should then be registered correctly. You can check this by using the
  206: `-l` option of `nspluginwrapper` (`nspluginwrapper -l`). If the plugin is
  207: listed, you can restart Firefox, and verify that the plugin was installed by
  208: entering `about:plugins` in the location bar.
  210: ## Further reading
  212: The following articles may be of interest for further understanding Linux (and other) emulation:
  214:  * *[Implementing Linux emulation on NetBSD](*. Peter Seebach. May 2004.
  215:  * *[Linux compatibility on BSD for the PPC platform, part 1](*. Emmanuel Dreyfus. May 2001.
  216:  * *[Linux compatibility on BSD for the PPC platform, part 2](*. Emmanuel Dreyfus. May 2001.
  217:  * *[Linux compatibility on BSD for the PPC platform, part 3](*. Emmanuel Dreyfus. Jun 2001.
  218:  * *[Linux compatibility on BSD for the PPC platform, part 4](*. Emmanuel Dreyfus. Jun 2001.
  219:  * *[Linux compatibility on BSD for the PPC platform, part 5](*. Emmanuel Dreyfus. Aug 2002.
  220:  * *[Irix binary compatibility, part 1](*. Emmanuel Dreyfus. Aug 2002.
  221:  * *[Irix binary compatibility, part 2](*. Emmanuel Dreyfus. Aug 2002.
  222:  * *[Irix binary compatibility, part 3](*. Emmanuel Dreyfus. Sep 2002.
  223:  * *[Irix binary compatibility, part 4](*. Emmanuel Dreyfus. Oct 2002.
  224:  * *[Irix binary compatibility, part 5](*. Emmanuel Dreyfus. Dec 2002.
  225:  * *[Irix binary compatibility, part 6](*. Emmanuel Dreyfus. Apr 2003.

CVSweb for NetBSD wikisrc <> software: FreeBSD-CVSweb