Linux® 程式庫並未預設安裝,而且 Linux® 二進位檔相容性並未啟用。 Linux® 程式庫可以手動安裝或是從 FreeBSD Ports 安裝。
編譯 port 前,要載入 Linux® 核心模組,否則編譯會失敗:
#
kldload linux
確認模組已載入:
%
kldstat
Id Refs Address Size Name 1 2 0xc0100000 16bdb8 kernel 7 1 0xc24db000 d000 linux.ko
在 FreeBSD 安裝基本的 Linux® 程式庫和二進位檔最簡單的方式是安裝 emulators/linux_base-c6 套件或是 port 。安裝 port:
#
printf "compat.linux.osrelease=2.6.18\n" >> /etc/sysctl.conf
#
sysctl compat.linux.osrelease=2.6.18
#
pkg install emulators/linux_base-c6
要讓 Linux® 相容性在開機時就啟用,可以加入這行到 /etc/rc.conf
:
linux_enable="YES"
想要靜態連結 Linux® 二進位檔相容性到自訂核心的使用者應該增加 options COMPAT_LINUX
到他們自訂核心設定檔。
編譯和安裝新核心的方法,如 章 8, 設定 FreeBSD Kernel所述。
如果一個 Linux® 應用程式在設定 Linux®二進位檔相容性後表示缺少共享程式庫, 看看這個Linux® 二進位檔需要哪個共享程式庫,手動安裝他。
Linux® 系統中, ldd
可以用來決定應用程式需要哪個。
例如,檢查 linuxdoom
需要哪個共享程式庫,從安裝 Doom的 Linux® 系統中執行這個指令:
%
ldd linuxdoom
libXt.so.3 (DLL Jump 3.1) => /usr/X11/lib/libXt.so.3.1.0 libX11.so.3 (DLL Jump 3.1) => /usr/X11/lib/libX11.so.3.1.0 libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29
然後,複製所有 Linux® 系統輸出最後一欄的檔案到 FreeBSD系統的 /compat/linux
。
複製完後,建立符號連結到剛剛輸出第一欄的名字。這個例子會在 FreeBSD 系統產生以下檔案:
/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
If a Linux® shared library already exists with a
matching major revision number to the first column of the
ldd
output, it does not need to be copied
to the file named in the last column, as the existing library
should work. It is advisable to copy the shared library if it
is a newer version, though. The old one can be removed, as
long as the symbolic link points to the new one.
For example, these libraries already exist on the FreeBSD system:
/compat/linux/lib/libc.so.4.6.27 /compat/linux/lib/libc.so.4 -> libc.so.4.6.27
and ldd
indicates that a binary
requires a later version:
libc.so.4 (DLL Jump 4.5pl26) -> libc.so.4.6.29
Since the existing library is only one or two versions out
of date in the last digit, the program should still work with
the slightly older version. However, it is safe to replace
the existing libc.so
with the newer
version:
/compat/linux/lib/libc.so.4.6.29 /compat/linux/lib/libc.so.4 -> libc.so.4.6.29
Generally, one will need to look for the shared libraries that Linux® binaries depend on only the first few times that a Linux® program is installed on FreeBSD. After a while, there will be a sufficient set of Linux® shared libraries on the system to be able to run newly installed Linux® binaries without any extra work.
ELF 二進位等有時候需要額外的步驟。當執行未標記的 ELF 二進位檔,會產生錯誤訊息:
%
./my-linux-elf-binary
ELF binary type not known Abort
為了幫 FreeBSD 核心辨識 FreeBSD ELF 二進位檔和 Linux® 二進位檔,使用 brandelf(1):
%
brandelf -t Linux my-linux-elf-binary
因為GNU工具鏈會自動放置適當的標記資訊進 ELF 二進位檔,通常就不需要這個步驟。
要安裝 Linux® RPM 基礎的應用程式,先安裝 archivers/rpm 套件或 port。
安裝後, root
可以使用這個指令來安裝.rpm
檔:
#
cd /compat/linux
#
rpm2cpio < /path/to/linux.archive.rpm | cpio -id
如果需要, brandelf
已安裝的 ELF二進位檔。注意,這將會無法乾淨地解除安裝。
如果 DNS 有問題或是出現這個錯誤:
resolv+: "bind" is an invalid keyword resolv+: "hosts" is an invalid keyword
將 /compat/linux/etc/host.conf
設定如下:
order hosts, bind multi on
這指定先搜尋 /etc/hosts
, DNS 次之。
當 /compat/linux/etc/host.conf
不存在, Linux® 應用程式會使用 /etc/host.conf
並會抱怨不相容的 FreeBSD 語法。
如果名稱伺服器未設定使用/etc/resolv.conf
的話,移除 bind
。
本文及其他文件,可由此下載: ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。
若有 FreeBSD 方面疑問,請先閱讀
FreeBSD 相關文件,如不能解決的話,再洽詢
<questions@FreeBSD.org>。
關於本文件的問題,請洽詢
<doc@FreeBSD.org>。