> 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-31-zhang-linux-jail/di-31.4-jie-antix-linux-jail.md).

# 31.4 antiX Linux Jail

antiX Linux 是基于 Debian 的轻量级发行版，不使用 systemd，而是提供多种初始化系统选择：antiX-23.2 提供 SysVinit 和 runit；antiX-26 默认使用 runit，同时提供 SysVinit、dinit、s6-rc、s6-66 等多种 init 可选。其中 SysVinit 基于运行级别（runlevels）和 init 脚本管理服务；而 runit、dinit 和 s6 系列（s6-rc、s6-66）则采用基于依赖关系或服务监督的服务管理模型，不依赖传统运行级别概念。这些初始化系统均不依赖 systemd，在 Jail 环境中兼容性更好。

## 准备基本系统

先安装 `squashfs-tools`，用来解压 antiX Linux 文件系统镜像。

使用 pkg 安装 squashfs-tools：

```sh
# pkg install squashfs-tools
```

antiX-23.2 提供四款镜像版本：full、base、core 和 net，本示例下载 core 版本：

```sh
# 下载 antiX 23.2 Core ISO 镜像
# fetch https://mirrors.tuna.tsinghua.edu.cn/mxlinux-isos/ANTIX/Final/antiX-23.2/antiX-23.2_x64-core.iso

# 将 ISO 文件作为内存设备挂载
# mdconfig -a -t vnode -f antiX-23.2_x64-core.iso

# 将内存设备挂载到 /mnt，类型为 cd9660
# mount -t cd9660 /dev/md0 /mnt

# 创建 antiX Jail 根目录
# mkdir -p /usr/jails/antix

# 解压 squashfs 文件系统到 Jail 根目录
# unsquashfs -d /usr/jails/antix /mnt/antiX/linuxfs

# 创建必要的设备节点
# touch /usr/jails/antix/dev/fd
# touch /usr/jails/antix/dev/shm

# 清理：卸载 ISO 挂载点并销毁 md 设备
# umount /mnt
# mdconfig -d -u 0
```

## 配置挂载文件

创建 **/etc/fstab.antix** 文件，内容如下：

```ini
devfs      /usr/jails/antix/dev      devfs       rw                      0  0
tmpfs      /usr/jails/antix/dev/shm  tmpfs       rw,size=1g,mode=1777    0  0
fdescfs    /usr/jails/antix/dev/fd   fdescfs     rw,linrdlnk             0  0
linprocfs  /usr/jails/antix/proc     linprocfs   rw                      0  0
linsysfs   /usr/jails/antix/sys      linsysfs    rw                      0  0
/tmp       /usr/jails/antix/tmp      nullfs      rw                      0  0
```

## 管理 Jail 配置文件

在 **/etc/jail.conf** 文件中写入（仅展示 antiX 相关部分）：

```ini
antix {                               # Jail 名称
  host.hostname = "antix";             # 设置 Jail 的主机名
  mount.fstab = "/etc/fstab.antix";    # Jail 使用的 fstab 文件
  path = "/usr/jails/antix";           # Jail 根目录路径
  devfs_ruleset = 4;                     # devfs 挂载规则集
  enforce_statfs = 1;                    # 设置挂载点可见性
  allow.mount;                          # 允许挂载文件系统
  allow.mount.devfs;                     # 允许挂载 devfs
  exec.start = "/etc/init.d/rc 3";       # 启动 Jail 时执行的命令（运行级别 3）
  exec.stop = "/etc/init.d/rc 0";        # 停止 Jail 时执行的命令（运行级别 0）
  persist;                               # 即使无进程也保持 Jail 存活
  allow.raw_sockets;                      # 允许使用 raw Socket
  interface = "lo1";                      # 指定网络接口
  ip4.addr = 192.168.5.3;                 # 分配 IPv4 地址
  ip6 = "disable";                        # 禁用 IPv6
}
```

此处将 `exec.start` 设置为 **/etc/init.d/rc 3**。

如前文所述，Debian 使用 systemd 作为初始化系统，在 Jail 中无法使用，因此其 Jail 配置使用 **/bin/true** 安全返回 `true` 而不执行任何操作。

antiX 不使用 systemd，而是提供多种初始化系统。此处 **/etc/init.d/rc 3** 是 SysVinit 风格的启动命令，指定 antiX Jail 在运行级别 3 启动。若使用其他初始化系统，启动命令有所不同：runit 使用 `sv` 管理服务；dinit 使用 `dinitctl`；s6-rc 使用 `s6-rc`；s6-66 使用 `66` 前端工具。本示例以 SysVinit 为例，由于 antiX 不依赖 systemd，Debian Jail 中由 systemd 受限引起的服务启动问题不会在此出现，可直接在 Jail 启动时运行服务（如 sshd）。

## 允许网络访问

在 pf 防火墙中允许网络访问，与前述方法相同：

```sh
# pfctl -t jails -T add 192.168.5.3	# 将 IP 地址 192.168.5.3 添加到 pf 防火墙的 jails 表中
```

## 更新 antiX Linux 系统

设置开机自启，随后启动：

```sh
# sysrc jail_list+=antix  # 将 antix Jail 添加到系统开机启动列表
# jail -c antix   # 或者使用 service jail start antix
```

现在进入 Jail：

```sh
# jexec antix /bin/bash     # 物理机（FreeBSD）中
root@antix:/# echo "nameserver 223.5.5.5" > /etc/resolv.conf    # Jail 中，留意提示符变化；先设置地址解析，此处使用阿里云公共 DNS
root@antix:/# echo 'APT::Cache-Start "90000000";' >> /etc/apt/apt.conf   # APT::Cache-Start 可设置 apt 缓存大小，默认约 20 MB 偏小，可按提示增大
root@antix:/# apt update         # 可先修改 /etc/apt/sources.list.d/ 中的文件以使用镜像站，请参考各镜像站中 Debian 的镜像站设置
root@antix:/# apt upgrade  # 更新系统和软件包
root@antix:/# mandb       # apt upgrade 时如果出现 mandb 权限错误，多次执行 mandb 命令可完成索引更新。
```

apt upgrade 过程中可能出现 mandb 权限相关提示，多次执行 `mandb` 命令可完成索引更新。


---

# 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-31-zhang-linux-jail/di-31.4-jie-antix-linux-jail.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.
