> 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.5-jie-slackware-linux-jian-rong-ceng.md).

# 20.5 Slackware Linux 兼容层

Slackware Linux 未提供预构建的基本系统镜像，需通过脚本自行生成。社区维护着一个构建 Slackware Linux 基本系统的脚本，位于 <https://github.com/ykla/slackware-WSL/releases>。

![Slackware Linux 兼容层](/files/mZrVq47BtoK93RAYbFfU)

兼容层脚本内容如下：

```sh
#!/bin/sh

ROOT_DIR=/compat/slackware
DIST_FULLNAME="Slackware Linux"
LinuxKernel=7.0.11
SUBDIR=""
BASE_URL="https://github.com/ykla/slackware-WSL/releases/download/auto-28"
UPDATE_CMD="DIALOG=off BATCH=on slackpkg update"
UPDATE=1
INSTALL=1

# ==========================================
# 版本选择菜单
# ==========================================
echo "请选择要安装的 ${DIST_FULLNAME} 版本："
echo "1) Slackware64 15.0"
echo "2) Slackware64 Current"
echo "3) Slackware AArch64 Current"
echo -n "请输入选项 [1-3] (默认 1): "
read VERSION_CHOICE

case $VERSION_CHOICE in
    2)
        VER="current"
        FILE="slackware64-current.tar.gz"
        ;;
    3)
        VER="current"
        FILE="slackwareaarch64-current.tar.gz"
        ;;
    1|*)
        VER="15.0"
        FILE="slackware64-15.0.tar.gz"
        ;;
esac

URL="${BASE_URL}/${FILE}"

echo "Starting ${DIST_FULLNAME} ($FILE) installation"
sleep 0.5

# ==========================================
# 检查 Linux 模块
# ==========================================
echo "Checking required modules"
if [ "$(sysrc -n linux_enable)" != "YES" ]; then
    echo "Linux service is not enabled. Enable it now? (Y|n)"
    read ANSWER
    case $ANSWER in
        [Nn][Oo]|[Nn])
            echo "Warning: You must start the Linux service with \"service linux start\" after each FreeBSD reboot."
            echo "Are you sure you want to continue without enabling the Linux service? (y|N)"
            read ANSWER
            case $ANSWER in
                [Yy][Ee][Ss]|[Yy])
                    echo "WARNING: Linux module not enabled"
                    ;;
                [Nn][Oo]|[Nn]|"")
                    echo "Enabling Linux module"
                    service linux enable
                    ;;
                *)
                    echo "Aborting."
                    exit 4
                    ;;
            esac
            ;;
        [Yy][Ee][Ss]|[Yy]|"")
            echo "Enabling Linux module"
            service linux enable
            ;;
        *)
            echo "Aborting."
            exit 4
            ;;
    esac
fi

echo "Starting Linux service"
service linux start

# ==========================================
# 检查 dbus
# ==========================================
if ! which -s dbus-daemon; then
    echo "dbus-daemon not found. Install D-Bus now? (Y|n)"
    read ANSWER
    case $ANSWER in
        [Nn][Oo]|[Nn])
            echo "Aborting. D-Bus not installed"
            exit 2
            ;;
        [Yy][Ee][Ss]|[Yy]|"")
            echo "Installing D-Bus"
            pkg install -y dbus
            ;;
        *)
            echo "Aborting."
            exit 4
            ;;
    esac
fi

if [ "$(sysrc -n dbus_enable)" != "YES" ]; then
    echo "D-Bus is not enabled. Enable it now? (Y|n)"
    read ANSWER
    case $ANSWER in
        [Nn][Oo]|[Nn])
            echo "WARNING: You must start D-Bus with \"service dbus start\" after each FreeBSD reboot."
            echo "Are you sure you want to continue without enabling D-Bus? (y|N)"
            read ANSWER
            case $ANSWER in
                [Yy][Ee][Ss]|[Yy])
                    echo "Warning: D-Bus not enabled"
                    ;;
                [Nn][Oo]|[Nn]|"")
                    echo "Enabling D-Bus service"
                    service dbus enable
                    ;;
                *)
                    echo "Aborting."
                    exit 4
                    ;;
            esac
            ;;
        [Yy][Ee][Ss]|[Yy]|"")
            echo "Enabling D-Bus service"
            service dbus enable
            ;;
        *)
            echo "Aborting."
            exit 4
            ;;
    esac
fi

if [ -z "$(ps aux | grep dbus | grep -v grep)" ]; then
    echo "Starting D-Bus service"
    service dbus start
fi

echo "compat.linux.osrelease=${LinuxKernel}"
sysctl compat.linux.osrelease=${LinuxKernel}

if ! grep -q '^compat.linux.osrelease=' /etc/sysctl.conf 2>/dev/null; then
    echo "compat.linux.osrelease=${LinuxKernel}" >> /etc/sysctl.conf
else
    sed -i '' "s|^compat.linux.osrelease=.*|compat.linux.osrelease=${LinuxKernel}|" /etc/sysctl.conf
fi

# ==========================================
# 下载和解压基本系统
# ==========================================
echo "${DIST_FULLNAME} will be installed in $ROOT_DIR"
echo "Downloading basic system from ${URL}"
fetch "${URL}"

echo "Extracting basic system"
sleep 0.5
mkdir -p "${ROOT_DIR}"
tar xvpf "${FILE}" ${SUBDIR:-} -C "${ROOT_DIR}" --numeric-owner 2>&1 | grep -v "Error exit delayed from previous errors"

# emulation path
sysctl compat.linux.emul_path="${ROOT_DIR}"

if ! grep -q '^compat.linux.emul_path=' /etc/sysctl.conf 2>/dev/null; then
    echo "compat.linux.emul_path=${ROOT_DIR}" >> /etc/sysctl.conf
else
    sed -i '' "s|^compat.linux.emul_path=.*|compat.linux.emul_path=${ROOT_DIR}|" /etc/sysctl.conf
fi

echo "compat.linux.emul_path=$(sysctl -n compat.linux.emul_path)"

service linux restart

# ==========================================
# 配置 DNS
# ==========================================
echo "Should ${DIST_FULLNAME} use Alibaba DNS or local resolv.conf? ((A)li | (L)ocal | (C)ancel)"
read ANSWER
case $ANSWER in
    [Aa][Ll][Ii]|[Aa]|"")
        echo "Setting Alibaba DNS"
        grep -q "nameserver 223.5.5.5" "${ROOT_DIR}/etc/resolv.conf" 2>/dev/null || \
            echo "nameserver 223.5.5.5" >> "${ROOT_DIR}/etc/resolv.conf"

        grep -q "nameserver 223.6.6.6" "${ROOT_DIR}/etc/resolv.conf" 2>/dev/null || \
            echo "nameserver 223.6.6.6" >> "${ROOT_DIR}/etc/resolv.conf"
        ;;
    [Ll][Oo][Cc][Aa][Ll]|[Ll])
        echo "Using local resolv.conf"
        cp /etc/resolv.conf "${ROOT_DIR}/etc/resolv.conf"
        ;;
    *)
        echo "Canceled."
        echo "You must manually edit $ROOT_DIR/etc/resolv.conf!"
        ;;
esac

# ==========================================
# 更新软件源
# ==========================================
if ping -c 1 -W 3000 223.5.5.5 > /dev/null 2>&1; then
    echo "Network reachable, starting operations..."
    [ $UPDATE = 1 ] && { echo "Updating package list"; chroot "${ROOT_DIR}" /bin/bash -c "${UPDATE_CMD}"; }
else
    echo "Network unreachable, skipping update and installation."
fi

echo "Setting up Bash configuration"
cp "${ROOT_DIR}/etc/profile" "${ROOT_DIR}/root/.bashrc"

# ==========================================
# 清理
# ==========================================
echo "Cleaning up"
rm "${FILE}"
service linux restart
echo "${DIST_FULLNAME} Base System is ready."
echo "chroot ${ROOT_DIR} /bin/bash"
```

## 故障排除

### 依赖缺失

Slackware Linux 的大多数包管理器均不解决依赖问题，因此任何软件的安装都将面临大量依赖缺失。

如需任何依赖，可前往 <https://packages.slackware.com/> 查询：键入关键词，如“libgc.so.1”，Release 选择正确的版本，Mode 调整为“content”，即可得到搜索结果：“gc-8.0.6-x86\_64-1.txz”，通常使用命令 `slackpkg install gc` 即可。


---

# 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.5-jie-slackware-linux-jian-rong-ceng.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.
