> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/di-20-zhang-linux-jian-rong-ceng/di-20.10-jie-gu-zhang-pai-chu-yu-wei-jing-shi-yi.md).

# 20.10 故障排除与未竟事宜

本节汇总 Linux 兼容层常见问题及解决方法。

## Linux 兼容层的声音

chroot 进入的 Linux 兼容层内部如无声音输出，通常须在 FreeBSD 中直接运行 Linux 程序，而非使用 chroot。

Ubuntu 兼容层：

编辑 **/compat/ubuntu/etc/asound.conf** 文件，写入以下两行，请注意区分英文感叹号 `!` 与数字 `1`。

```sh
pcm.!sysdefault pcm.plug:oss
pcm.!default pcm.sysdefault
```

## 在 FreeBSD 的命令行运行软件（基于 Ubuntu 兼容层）

直接从 FreeBSD 命令行运行软件而无需 chroot 的方法：

方式一

```sh
# sysctl compat.linux.emul_path=/compat/ubuntu # 立即生效
# echo compat.linux.emul_path=/compat/ubuntu >> /etc/sysctl.conf # 持久化
```

方式二

> **警告**
>
> 此操作将移动并替换 `ld-linux-x86-64.so.2`，可能导致 Ubuntu 兼容层无法正常启动或运行。执行前请确保已备份相关文件，并充分了解该操作的影响。**该操作不可逆，请谨慎操作。**

```sh
# mv /compat/ubuntu/lib64/ld-linux-x86-64.so.2  /compat/ubuntu/lib64/ld-linux-x86-64.so.2.back
# ln -s /compat/ubuntu/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /compat/ubuntu/lib64/ld-linux-x86-64.so.2
```

无需 chroot，可直接在终端运行 Linux 程序（仅部分程序），需指定绝对路径。

**Arch 和 openSUSE 兼容层仅需方式一，无需方式二。**

### 参考文献

* Micski D K. FREEBSD, SYSTEM ADMINISTRATION Install Ubuntu base system into FreeBSD’s Linux Binary Compatibility\[EB/OL]. (2021-12-21)\[2026-03-25]. <https://www.micski.dk/2021/12/21/install-ubuntu-base-system-into-freebsds-linux-binary-compatibility/>. 该文章详细介绍在 FreeBSD 上构建 Ubuntu 兼容层的完整技术流程，为本章节实践提供重要参考。

## 以普通用户权限运行 QQ

兼容层的用户与 FreeBSD 用户存在 UID 映射关系。

假设在 FreeBSD 的普通用户名是 ykla，UID 是 1001（正常情况下默认为 1001）：

```sh
# useradd --uid 1001 --gid 0 -m ykla # 此步骤在兼容层内执行
```

> **警告**
>
> 在 Arch 中创建用户 ykla 后，此用户无法用于 yay 安装软件，仍然需要使用 Shell 脚本默认创建的 test 用户。

## 从图标启动程序

* 编辑 `QQ.desktop` 文件，写入以下内容（以 Ubuntu 兼容层为例）：

```ini
[Desktop Entry]
Name=QQ
Exec=/compat/ubuntu/opt/QQ/qq --no-sandbox --in-process-gpu %U
Terminal=false
Type=Application
Icon=/compat/ubuntu/usr/share/icons/hicolor/512x512/apps/qq.png
StartupWMClass=QQ
Categories=Network;
Comment=QQ
MimeType=x-scheme-handler/tencent;
```

* 编辑 `Chrome.desktop` 文件，写入以下内容（以 Ubuntu 兼容层为例）：

```ini
[Desktop Entry]
Version=1.0
Type=Application
Name=Chrome
Comment=
Exec=/compat/ubuntu/opt/google/chrome/chrome --no-sandbox --in-process-gpu
Icon=/compat/ubuntu/opt/google/chrome/product_logo_256.png
Path=
Terminal=false
StartupNotify=false
```

授予上述文件可执行权限后，文件将显示为正常的图标样式，点击即可启动对应软件。

## 运行 Chrome（以 Ubuntu 兼容层为例）

下载 Chrome：

```sh
# wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb # 可直接下载，无需代理。此时已位于 Ubuntu 兼容层
```

安装 Chrome：

```bash
# apt install ./google-chrome-stable_current_amd64.deb # 此时已位于 Ubuntu 兼容层
```

启动 Chrome：

```sh
# /usr/bin/google-chrome-stable --no-sandbox --no-zygote --in-process-gpu  # 此时已位于 Ubuntu 兼容层
```

## Linux 兼容层网络（Linux QQ 无网络）

本机同时有以太网卡 em0 和无线网卡 wlan0，但实际使用 wlan0 时，Linux 兼容层可能无法正常联网。FreeBSD 的 em0 对应兼容层的 eth0，wlan0 对应 eth1，依此类推。Linux 兼容层无法自动检测哪个接口有网络，且默认使用 eth0。

使用 wlan0 而未使用 em0 时，需要为 em0 分配一个未使用的 IP：

* 临时设置（重启失效）：`# ifconfig em0 192.168.11.1`
* 永久性设置：即在 FreeBSD **/etc/rc.conf** 文件中加入（不影响该网卡正常运行）：

```sh
# ifconfig_em0_alias0="inet 192.168.11.1 netmask 255.255.255.0"
```

以上 **192.168.11.1** 为未使用的 IP，可自行设置为其他值。

## 中文输入法

将 **/home** 路径下的 `.profile` 文件放置于兼容层的 **/** 目录下：

```sh
export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8

export XMODIFIERS='@im=fcitx'
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
```

如果遇到类似“sh: warning: setlocale: LC\_ALL: cannot change locale (zh\_CN.UTF-8)”的错误，应安装缺失的语言包，退出兼容层后重新进入即可。其他系统可搜索相似的包，例如 Rocky Linux 兼容层，应该安装 `glibc-locale-source`、`glibc-langpack-zh`。

## sysctl 变量

```sh
# sysctl -a -d  | grep -E "linux|compat.linux"
```

可以列出常用变量。

## 使用命令行下载软件时提示 `403 Forbidden`

国内某些镜像站可能出于流量限制等原因，只允许通过指定包管理器获取软件包。使用其他方式拉取时将提示“403 Forbidden”（禁止访问）。

这通常通过限制包管理器的 UA（User-Agent）实现。此时，最简便的方法是更换无限制的镜像站，如 TUNA/USTC Mirror。

## systemd 与 Wine

systemd 不可用，但可使用 `service xxx start` 命令替代。

此外，曾尝试使用 <https://github.com/zq1997/deepin-wine> 源以安装 deepin-qq、deepin-wechat 等软件，但均提示“段错误”。所有 Wine 程序均无法正常运行。如果读者能解决这个问题，请提出 issue 或者 PR。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-20-zhang-linux-jian-rong-ceng/di-20.10-jie-gu-zhang-pai-chu-yu-wei-jing-shi-yi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
