Linux 软件的运行不仅需要 ABI,还需要安装一个 Linux 用户空间环境。
复制 # pkg install linux-sublime-text4
12.3.1. 来自 FreeBSD 软件包的 Rocky Linux 基本系统
要安装 Rocky Linux 9 用户空间,可执行以下命令:
复制 # pkg install linux_base-rl9
会将源自 Rocky Linux 9 的基本系统放置在 /compat/linux
目录中。
安装该软件包后,可通过以下命令确认 Rocky Linux 用户空间是否已安装到 /compat/linux
:
输出应类似于:
复制 total 36
drwxr-xr-x 2 root wheel 512 Oct 9 17:28 afs
lrwxr-xr-x 1 root wheel 7 May 16 2022 bin -> usr/bin
drwxr-xr-x 3 root wheel 512 Oct 9 17:28 dev
drwxr-xr-x 24 root wheel 1536 Oct 9 17:28 etc
lrwxr-xr-x 1 root wheel 7 May 16 2022 lib -> usr/lib
lrwxr-xr-x 1 root wheel 9 May 16 2022 lib64 -> usr/lib64
drwxr-xr-x 2 root wheel 512 Oct 9 17:28 opt
drwxr-xr-x 2 root wheel 512 Oct 9 17:28 proc
lrwxr-xr-x 1 root wheel 8 Oct 1 03:11 run -> /var/run
lrwxr-xr-x 1 root wheel 8 May 16 2022 sbin -> usr/sbin
drwxr-xr-x 2 root wheel 512 Oct 9 17:28 srv
drwxr-xr-x 2 root wheel 512 Oct 9 17:28 sys
drwxr-xr-x 8 root wheel 512 Oct 9 17:28 usr
drwxr-xr-x 16 root wheel 512 Oct 9 17:28 var
12.3.2. 来自 FreeBSD 软件包的 CentOS 基本系统
警告
要安装 CentOS 用户空间,可执行以下命令:
复制 # pkg install linux_base-c7
安装完成后,可通过以下命令验证 CentOS 用户空间是否已安装:
输出应类似于:
复制 total 30
lrwxr-xr-x 1 root wheel 7 Apr 11 2018 bin -> usr/bin
drwxr-xr-x 13 root wheel 512 Apr 11 21:10 dev
drwxr-xr-x 25 root wheel 64 Apr 11 21:10 etc
lrwxr-xr-x 1 root wheel 7 Apr 11 2018 lib -> usr/lib
lrwxr-xr-x 1 root wheel 9 Apr 11 2018 lib64 -> usr/lib64
drwxr-xr-x 2 root wheel 2 Apr 11 21:10 opt
dr-xr-xr-x 1 root wheel 0 Apr 11 21:25 proc
lrwxr-xr-x 1 root wheel 8 Feb 18 02:10 run -> /var/run
lrwxr-xr-x 1 root wheel 8 Apr 11 2018 sbin -> usr/sbin
drwxr-xr-x 2 root wheel 2 Apr 11 21:10 srv
dr-xr-xr-x 1 root wheel 0 Apr 11 21:25 sys
drwxr-xr-x 8 root wheel 9 Apr 11 21:10 usr
drwxr-xr-x 16 root wheel 17 Apr 11 21:10 var
12.3.3. 使用 debootstrap 的 Debian / Ubuntu 基本系统
安装 debootstrap 的命令如下:
复制 # pkg install debootstrap
复制 # debootstrap focal /compat/ubuntu
注意
虽然技术上可以安装到 /compat/linux
,但由于可能与基于 CentOS 的软件包发生冲突,不建议这么做。应使用基于发行版或版本名的路径,例如 /compat/ubuntu
。
输出应类似于:
复制 I: Retrieving InRelease
I: Checking Release signature
I: Valid Release signature (key id F6ECB3762474EDA9D21B7022871920D1991BC93C)
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Checking component main on http://archive.ubuntu.com/ubuntu...
[...]
I: Configuring console-setup...
I: Configuring kbd...
I: Configuring ubuntu-minimal...
I: Configuring libc-bin...
I: Configuring ca-certificates...
I: Base system installed successfully.
然后在 /etc/fstab
中设置挂载点。
技巧
如果希望共享 home 目录的内容并运行 X11 应用程序,应使用 nullfs(5) 进行回环挂载,将 /home 和 /tmp 挂载到 Linux 兼容区中。
可以将以下示例添加到 /etc/fstab:
复制 # Device Mountpoint FStype Options Dump Pass#
devfs /compat/ubuntu/dev devfs rw,late 0 0
tmpfs /compat/ubuntu/dev/shm tmpfs rw,late,size=1g,mode=1777 0 0
fdescfs /compat/ubuntu/dev/fd fdescfs rw,late,linrdlnk 0 0
linprocfs /compat/ubuntu/proc linprocfs rw,late 0 0
linsysfs /compat/ubuntu/sys linsysfs rw,late 0 0
/tmp /compat/ubuntu/tmp nullfs rw,late 0 0
/home /compat/ubuntu/home nullfs rw,late 0 0
复制 # chroot /compat/ubuntu /bin/bash
输出应类似于:
技巧
要添加默认缺失的软件包仓库,请编辑文件 /compat/ubuntu/etc/apt/sources.list
。
对于 amd64,可以使用以下示例:
复制 deb http://archive.ubuntu.com/ubuntu focal main universe restricted multiverse
deb http://security.ubuntu.com/ubuntu/ focal-security universe multiverse restricted main
deb http://archive.ubuntu.com/ubuntu focal-backports universe multiverse restricted main
deb http://archive.ubuntu.com/ubuntu focal-updates universe multiverse restricted main
arm64 可使用以下例子:
复制 deb http://ports.ubuntu.com/ubuntu-ports bionic main universe restricted multiverse