Annotation of wikisrc/guide/linux.mdwn, revision 1.4
1.3 jdf 1: **Contents**
3: [[!toc levels=3]]
1.1 jdf 5: # Linux emulation
1.2 jdf 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
1.1 jdf 16: exactly the same as for native NetBSD applications.
1.2 jdf 18: This chapter explains how to configure the Linux emulation with an example: the
1.1 jdf 19: installation of the well known Acrobat Reader version 7 program.
21: ## Emulation setup
1.2 jdf 23: The installation of the Linux emulation is described in the
1.4 ! plunky 24: [[!template id=man name="compat\_linux" section="8"]]
1.1 jdf 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
1.2 jdf 33: If you use a GENERIC kernel you don't need to do anything because Linux
1.1 jdf 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
1.2 jdf 46: When you have compiled a kernel with the previous options, you can start
1.1 jdf 47: installing the necessary software.
49: ### Installing the Linux libraries
1.2 jdf 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
1.1 jdf 56: following happens:
1.2 jdf 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
1.1 jdf 61: a required file is not found, it will be searched with `/` as root directory.
1.2 jdf 63: For example, if a Linux application opens `/etc/ld.so.conf`, it will first be
64: searched in `/emul/linux/etc/ld.so.conf`, and if not found there, in
1.1 jdf 65: `/etc/ld.so.conf`.
1.2 jdf 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
1.1 jdf 71: dependencies for Acrobat Reader.
1.2 jdf 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
1.1 jdf 76: manual installation of the Linux libraries.
1.2 jdf 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
1.1 jdf 81: and install `rpm`.
1.2 jdf 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
1.1 jdf 85: the `/usr/pkgsrc/distfiles/suse121` directory and then run `make` and
1.2 jdf 86: `make install` after going to the `/usr/pkgsrc/emulators/suse121_base`
1.1 jdf 87: directory.
1.2 jdf 89: With the same method install `suse121_compat` and `suse121_x11`. The final
1.1 jdf 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
1.2 jdf 97: *Note*: Of course you can also install the packages binary. To do this, you
1.1 jdf 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
1.2 jdf 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
1.1 jdf 112: the Linux version of the Opera browser.
114: ### Installing Acrobat Reader
1.2 jdf 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
1.1 jdf 118: usual commands.
120: # make
121: # make install
123: ### Note
1.2 jdf 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
1.1 jdf 127: Acrobat Reader license, simply follow the instructions given after `make`.
129: ## Directory structure
1.2 jdf 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
1.1 jdf 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/`
1.2 jdf 146: *Note*: Please always refer to `/emul/linux` and not to `/usr/pkg/emul/linux`.
1.1 jdf 147: The latter is an implementation detail and may change in the future.
1.2 jdf 149: How much space is required for the Linux emulation software? On one system we
1.1 jdf 150: got the following figure:
152: # cd /usr/pkg/emul
153: # du -k /emul/linux/
155: 127804 /emul/linux/
1.2 jdf 157: Acrobat Reader, the program, has been installed in the usual directory for
1.1 jdf 158: package binaries: `/usr/pkg/bin`. It can be run just as any other program:
1.2 jdf 160: $ acroread netbsd.pdf
1.1 jdf 161:
162: ## Emulating /proc
1.2 jdf 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
1.1 jdf 167: `linux`-option:
169: # mount_procfs -o linux procfs /emul/linux/proc
1.2 jdf 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
1.1 jdf 174: `/etc/fstab`:
176: procfs /emul/linux/proc procfs ro,linux
178: ## Using Linux browser plugins
1.2 jdf 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).
1.1 jdf 184: nspluginwrapper can be installed through pkgsrc:
186: # cd /usr/pkgsrc/www/nspluginwrapper
187: # make install
1.2 jdf 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
1.1 jdf 192: plugin.
1.2 jdf 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
1.1 jdf 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/libflashplayer.so
1.2 jdf 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
1.1 jdf 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](http://www.linux.com/articles/35998)*. Peter Seebach. May 2004.
215: * *[Linux compatibility on BSD for the PPC platform, part 1](http://www.onlamp.com/pub/a/onlamp/2001/05/10/linux_bsd.html)*. Emmanuel Dreyfus. May 2001.
216: * *[Linux compatibility on BSD for the PPC platform, part 2](http://www.onlamp.com/pub/a/onlamp/2001/05/17/linux_bsd.html)*. Emmanuel Dreyfus. May 2001.
217: * *[Linux compatibility on BSD for the PPC platform, part 3](http://www.onlamp.com/pub/a/onlamp/2001/06/07/linux_bsd.html)*. Emmanuel Dreyfus. Jun 2001.
218: * *[Linux compatibility on BSD for the PPC platform, part 4](http://www.onlamp.com/pub/a/onlamp/2001/06/21/linux_bsd.html)*. Emmanuel Dreyfus. Jun 2001.
219: * *[Linux compatibility on BSD for the PPC platform, part 5](http://www.onlamp.com/pub/a/onlamp/2001/08/09/linux_bsd.html)*. Emmanuel Dreyfus. Aug 2002.
220: * *[Irix binary compatibility, part 1](http://www.onlamp.com/pub/a/bsd/2002/08/08/irix.html)*. Emmanuel Dreyfus. Aug 2002.
221: * *[Irix binary compatibility, part 2](http://www.onlamp.com/pub/a/bsd/2002/08/29/irix.html)*. Emmanuel Dreyfus. Aug 2002.
222: * *[Irix binary compatibility, part 3](http://www.onlamp.com/pub/a/bsd/2002/09/12/irix.html)*. Emmanuel Dreyfus. Sep 2002.
223: * *[Irix binary compatibility, part 4](http://www.onlamp.com/pub/a/bsd/2002/10/10/irix.html)*. Emmanuel Dreyfus. Oct 2002.
224: * *[Irix binary compatibility, part 5](http://www.onlamp.com/pub/a/bsd/2002/12/19/irix.html)*. Emmanuel Dreyfus. Dec 2002.
225: * *[Irix binary compatibility, part 6](http://www.onlamp.com/pub/a/bsd/2003/04/03/irix.html)*. Emmanuel Dreyfus. Apr 2003.
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb