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