📄 linuxemu-lbc-install.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Installation</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Linux Binary Compatibility" href="linuxemu.html" /><link rel="PREVIOUS" title="Linux Binary Compatibility" href="linuxemu.html" /><link rel="NEXT" title="Installing Mathematica" href="linuxemu-mathematica.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="linuxemu.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 10 Linux Binary Compatibility</td><td width="10%" align="right" valign="bottom"><a href="linuxemu-mathematica.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="LINUXEMU-LBC-INSTALL" name="LINUXEMU-LBC-INSTALL">10.2Installation</a></h1><p>Linux binary compatibility is not turned on by default. The easiest way to enable thisfunctionality is to load the <var class="LITERAL">linux</var> KLD object (``KernelLoaDable object''). You can load this module by simply typing <ttclass="COMMAND">linux</tt> at the command prompt.</p><p>If you would like Linux compatibility to always be enabled, then you should add thefollowing line to <tt class="FILENAME">/etc/rc.conf</tt>:</p><pre class="PROGRAMLISTING">linux_enable="YES"</pre><p>The <a href="http://www.FreeBSD.org/cgi/man.cgi?query=kldstat&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">kldstat</span>(8)</span></a> command canbe used to verify that the KLD is loaded:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">kldstat</kbd>Id Refs Address Size Name 1 2 0xc0100000 16bdb8 kernel 7 1 0xc24db000 d000 linux.ko</pre><p>If for some reason you do not want to or cannot load the KLD, then you may staticallylink Linux binary compatibility into the kernel by adding <var class="LITERAL">optionsCOMPAT_LINUX</var> to your kernel configuration file. Then install your new kernel asdescribed in <a href="kernelconfig.html">Chapter 8</a>.</p><div class="SECT2"><h2 class="SECT2"><a id="AEN13107" name="AEN13107">10.2.1 Installing Linux RuntimeLibraries</a></h2><p>This can be done one of two ways, either by using the <ahref="linuxemu-lbc-install.html#LINUXEMU-LIBS-PORT">linux_base</a> port, or by installingthem <a href="linuxemu-lbc-install.html#LINUXEMU-LIBS-MANUALLY">manually</a>.</p><div class="SECT3"><h3 class="SECT3"><a id="LINUXEMU-LIBS-PORT" name="LINUXEMU-LIBS-PORT">10.2.1.1Installing Using the linux_base Port</a></h3><p>This is by far the easiest method to use when installing the runtime libraries. It isjust like installing any other port from the <a href="file://localhost/usr/ports/"target="_top">ports collection</a>. Simply do the following:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">cd /usr/ports/emulators/linux_base</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make install distclean</kbd></pre><p>You should now have working Linux binary compatibility. Some programs may complainabout incorrect minor versions of the system libraries. In general, however, this doesnot seem to be a problem.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> There may be multiple versions of the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/emulators/linux_base/pkg-descr"><ttclass="FILENAME">emulators/linux_base</tt></a> port available, corresponding to differentversions of various Linux distributions. You should install the port most closelyresembling the requirements of the Linux applications you would like to install.</p></blockquote></div></div><div class="SECT3"><h3 class="SECT3"><a id="LINUXEMU-LIBS-MANUALLY" name="LINUXEMU-LIBS-MANUALLY">10.2.1.2Installing Libraries Manually</a></h3><p>If you do not have the ``ports'' collection installed, you can install the librariesby hand instead. You will need the Linux shared libraries that the program depends on andthe runtime linker. Also, you will need to create a ``shadow root'' directory, <ttclass="FILENAME">/compat/linux</tt>, for Linux libraries on your FreeBSD system. Anyshared libraries opened by Linux programs run under FreeBSD will look in this tree first.So, if a Linux program loads, for example, <tt class="FILENAME">/lib/libc.so</tt>,FreeBSD will first try to open <tt class="FILENAME">/compat/linux/lib/libc.so</tt>, andif that does not exist, it will then try <tt class="FILENAME">/lib/libc.so</tt>. Sharedlibraries should be installed in the shadow tree <ttclass="FILENAME">/compat/linux/lib</tt> rather than the paths that the Linux <ttclass="COMMAND">ld.so</tt> reports.</p><p>Generally, you will need to look for the shared libraries that Linux binaries dependon only the first few times that you install a Linux program on your FreeBSD system.After a while, you will have a sufficient set of Linux shared libraries on your system tobe able to run newly imported Linux binaries without any extra work.</p></div><div class="SECT3"><h3 class="SECT3"><a id="AEN13142" name="AEN13142">10.2.1.3 How to Install AdditionalShared Libraries</a></h3><p>What if you install the <tt class="FILENAME">linux_base</tt> port and your applicationstill complains about missing shared libraries? How do you know which shared librariesLinux binaries need, and where to get them? Basically, there are 2 possibilities (whenfollowing these instructions you will need to be <tt class="USERNAME">root</tt> on yourFreeBSD system).</p><p>If you have access to a Linux system, see what shared libraries the application needs,and copy them to your FreeBSD system. Look at the following example:</p><div class="INFORMALEXAMPLE"><a id="AEN13150" name="AEN13150"></a><p>Let us assume you used FTP to get the Linux binary of <b class="APPLICATION">Doom</b>,and put it on a Linux system you have access to. You then can check which sharedlibraries it needs by running <tt class="COMMAND">ldd linuxdoom</tt>, like so:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">ldd linuxdoom</kbd>libXt.so.3 (DLL Jump 3.1) => /usr/X11/lib/libXt.so.3.1.0libX11.so.3 (DLL Jump 3.1) => /usr/X11/lib/libX11.so.3.1.0libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29</pre><p>You would need to get all the files from the last column, and put them under <ttclass="FILENAME">/compat/linux</tt>, with the names in the first column as symbolic linkspointing to them. This means you eventually have these files on your FreeBSD system:</p><pre class="SCREEN">/compat/linux/usr/X11/lib/libXt.so.3.1.0/compat/linux/usr/X11/lib/libXt.so.3 -> libXt.so.3.1.0/compat/linux/usr/X11/lib/libX11.so.3.1.0/compat/linux/usr/X11/lib/libX11.so.3 -> libX11.so.3.1.0/compat/linux/lib/libc.so.4.6.29/compat/linux/lib/libc.so.4 -> libc.so.4.6.29</pre><a id="AEN13162" name="AEN13162"></a><blockquote class="BLOCKQUOTE"><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> Note that if you already have a Linux shared library with a matchingmajor revision number to the first column of the <tt class="COMMAND">ldd</tt> output, youwill not need to copy the file named in the last column to your system, the one youalready have should work. It is advisable to copy the shared library anyway if it is anewer version, though. You can remove the old one, as long as you make the symbolic linkpoint to the new one. So, if you have these libraries on your system:</p><pre class="SCREEN">/compat/linux/lib/libc.so.4.6.27/compat/linux/lib/libc.so.4 -> libc.so.4.6.27</pre><p>and you find a new binary that claims to require a later version according to theoutput of <tt class="COMMAND">ldd</tt>:</p><pre class="SCREEN">libc.so.4 (DLL Jump 4.5pl26) -> libc.so.4.6.29</pre><p>If it is only one or two versions out of date in the in the trailing digit then do notworry about copying <tt class="FILENAME">/lib/libc.so.4.6.29</tt> too, because theprogram should work fine with the slightly older version. However, if you like, you candecide to replace the <tt class="FILENAME">libc.so</tt> anyway, and that should leave youwith:</p><pre class="SCREEN">/compat/linux/lib/libc.so.4.6.29/compat/linux/lib/libc.so.4 -> libc.so.4.6.29</pre></blockquote></div></blockquote><a id="AEN13174" name="AEN13174"></a><blockquote class="BLOCKQUOTE"><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> The symbolic link mechanism is <span class="emphasis"><iclass="EMPHASIS">only</i></span> needed for Linux binaries. The FreeBSD runtime linkertakes care of looking for matching major revision numbers itself and you do not need toworry about it.</p></blockquote></div></blockquote></div></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN13178" name="AEN13178">10.2.2 Installing Linux ELFBinaries</a></h2><p>ELF binaries sometimes require an extra step of ``branding''. If you attempt to run anunbranded ELF binary, you will get an error message like the following:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">./my-linux-elf-binary</kbd>ELF binary type not knownAbort</pre><p>To help the FreeBSD kernel distinguish between a FreeBSD ELF binary from a Linuxbinary, use the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=brandelf&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">brandelf</span>(1)</span></a>utility.</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">brandelf -t Linux my-linux-elf-binary</kbd></pre><p>The GNU toolchain now places the appropriate branding information into ELF binariesautomatically, so this step should become increasingly unnecessary in the future.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN13198" name="AEN13198">10.2.3 Configuring the HostnameResolver</a></h2><p>If DNS does not work or you get this message:</p><pre class="SCREEN">resolv+: "bind" is an invalid keyword resolv+:"hosts" is an invalid keyword</pre><p>You will need to configure a <tt class="FILENAME">/compat/linux/etc/host.conf</tt>file containing:</p><pre class="PROGRAMLISTING">order hosts, bindmulti on</pre><p>The order here specifies that <tt class="FILENAME">/etc/hosts</tt> is searched firstand DNS is searched second. When <tt class="FILENAME">/compat/linux/etc/host.conf</tt> isnot installed, Linux applications find FreeBSD's <tt class="FILENAME">/etc/host.conf</tt>and complain about the incompatible FreeBSD syntax. You should remove <varclass="LITERAL">bind</var> if you have not configured a name server using the <ttclass="FILENAME">/etc/resolv.conf</tt> file.</p></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="linuxemu.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="linuxemu-mathematica.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Linux Binary Compatibility</td><td width="34%" align="center" valign="top"><a href="linuxemu.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Installing <spanclass="TRADEMARK">Mathematica</span>®</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting <<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>>.<br />For questions about this documentation, e-mail <<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>>.</small></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -