Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| zh:docs:guide-user:additional-software:imagebuilder [2018/08/08 07:48] – ↷ Page moved from zh:docs:user-guide:imagebuilder to zh:docs:guide-user:additional-software:imagebuilder tmomas | zh:docs:guide-user:additional-software:imagebuilder [2024/11/30 14:58] – [详细帮助] starsfall | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== 使用镜像生成工具 (Image Builder) ====== | + | ====== 使用Image Builder ====== |
| - | 镜像生成工具是一个适合创建自定义镜像(且无需从源码编译)的预编译环境。\\ | + | 另请参阅: |
| - | 它负责下载预编译的包,并将软件包整合在一个可擦写镜像文件中。\\ | + | [[docs: |
| + | [[docs: | ||
| + | [[docs: | ||
| - | 以下情形适合你: | + | Image Builder (以前称为 Image Generator) 是一个预编译环境, |
| - | * 你希望在有限存储介质中放入更多软件包 | + | 它下载预编译的软件包并将它们集成到单个可闪存映像中. |
| - | * 你希望跟踪开发版的快照 | + | |
| - | * 你的设备只有32MB或更低的内存,以至于OPKG无法正常工作 | + | 在以下情况下, 这样做很有用: |
| - | * 你有许多大容量存储的设备,并且需要特殊定制的固件 | + | * 您想在较小的闪存中容纳更多的封装 |
| + | * 你想关注开发快照 | ||
| + | * 您的设备具有 32MB 或更少的 RAM 并且 opkg 无法正常工作 | ||
| + | * 你想批量刷新几十个设备,你需要一个特定的映像设置 | ||
| + | |||
| + | <WRAP important> | ||
| + | Image Builder 映像与官方映像不同, | ||
| + | 在进行 recent/ | ||
| + | </ | ||
| ===== 先决条件 ===== | ===== 先决条件 ===== | ||
| - | :!: 镜像生成工具仅可运行在64位LINUX环境下。你可以在32位WINDOWS上通过虚拟机环境安装64位LINUX (例如 virtualbox) | + | <WRAP important> |
| - | :!: 镜像生成工具工作环境的先决条件 [[docs: | + | * Image Builder 仅在 64 位 Linux 中运行. 但您可以在 PC 或 VM(例如 VirtualBox)中运行 64 位 Linux, 甚至可以从 32 位 Windows 运行. |
| + | * Image Builder 具有与 [[docs:guide-developer:toolchain: | ||
| + | </ | ||
| + | |||
| + | 最常见发行版中的示例依赖项: | ||
| + | |||
| + | ==== Arch ==== | ||
| + | <code bash> | ||
| + | sudo pacman -S --needed base-devel ncurses zlib gawk git gettext \ | ||
| + | openssl libxslt wget unzip python python-distutils-extra | ||
| + | </ | ||
| + | |||
| + | ==== Fedora ==== | ||
| + | <code bash> | ||
| + | sudo dnf install git gawk gettext ncurses-devel zlib-devel \ | ||
| + | openssl-devel libxslt wget which @c-development @development-tools \ | ||
| + | @development-libs zlib-static which python3 perl | ||
| + | </ | ||
| + | |||
| + | ==== Debian / Ubuntu / Mint ==== | ||
| + | <code bash> | ||
| + | sudo apt install build-essential libncurses-dev zlib1g-dev gawk git \ | ||
| + | gettext libssl-dev xsltproc rsync wget unzip python3 python3-distutils | ||
| + | </ | ||
| + | |||
| + | ==== WSL ==== | ||
| + | 此方法未得到官方支持。 | ||
| + | |||
| + | 但它有效。 [[docs: | ||
| + | |||
| + | 建议使用 VirtualBox 配合 Debian 或 DietPi(Debian) 使用,以减少资源和配置。 | ||
| + | |||
| + | ===== 获取 Image Builder ===== | ||
| + | 您可以下载包含 **Image Builder** 的存档, 它通常位于您找到设备固件映像的同一下载页面中. | ||
| + | |||
| + | 例如, 这是您可以下载 **ath79/ | ||
| + | [[https:// | ||
| + | 您会找到一个 **openwrt-imagebuilder-ath79-generic.Linux-x86_64.tar.xz** 包含映像生成器的存档. | ||
| + | 此外, 它始终由构建系统创建, | ||
| + | 如果启用了 " | ||
| + | |||
| + | ===== 用法 ===== | ||
| + | <WRAP important> | ||
| + | 所有操作都应使用非 root 用户帐户执行. | ||
| + | </ | ||
| + | |||
| + | 解压存档并更改工作目录: | ||
| + | |||
| + | <code bash> | ||
| + | tar -J -x -f openwrt-imagebuilder-*.tar.xz | ||
| + | cd openwrt-imagebuilder-*/ | ||
| + | </ | ||
| + | |||
| + | 可以使用以下变量自定义映像构建: | ||
| + | |||
| + | ^ 变量 ^ 描述 ^ | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | 运行 | ||
| + | |||
| + | ==== 选择配置文件 ==== | ||
| + | 该 '' | ||
| + | |||
| + | <code bash> | ||
| + | PROFILE=" | ||
| + | </ | ||
| + | |||
| + | 运行 '' | ||
| + | |||
| + | ==== 选择插件 ==== | ||
| + | 该 '' | ||
| + | 默认情况下( PACKAGES 变量值为空), | ||
| + | |||
| + | <code bash> | ||
| + | PACKAGES=" | ||
| + | </ | ||
| + | |||
| + | 上面的例子将安装 pkg1, pkg2, pkg3 插件, 并删除 pkg4, pkg5, pkg6 插件, 特别注意要删除插件前的 " | ||
| + | |||
| + | 您无需在此列表中列出您需要的插件的所有依赖项,Image Builder 使用 '' | ||
| + | |||
| + | 可以使用以下命令获取设备上当前安装的插件列表: | ||
| + | |||
| + | <code bash> | ||
| + | echo $(opkg list-installed | sed -e " | ||
| + | </ | ||
| + | |||
| + | <WRAP important> | ||
| + | 许多设备的存储容量有限,并且不能保证构建系统会检测到何时添加了过多的软件包以至于超出设备存储空间。如果安装过多软件包,可能会导致设备无法启动。如果有疑问,不要过度添加。以设备上安装成功的内容为指导,或者先创建一个最小的镜像,安装到设备上并首先测试要添加的内容。考虑删除不必要的软件包以 [[docs: | ||
| + | </ | ||
| + | |||
| + | 此外,诸如 '' | ||
| + | 当这些作为插件提供时, | ||
| + | 为避免出现问题, | ||
| + | 该 '' | ||
| + | |||
| + | ==== 添加额外插件 ==== | ||
| + | |||
| + | 如果有你喜欢使用的插件或 '' | ||
| + | |||
| + | ==== 自定义文件夹 ==== | ||
| + | 该 '' | ||
| + | 如果您需要在刷机前更改默认网络配置, | ||
| + | |||
| + | <code bash> | ||
| + | FILES=" | ||
| + | </ | ||
| + | |||
| + | 该 '' | ||
| + | |||
| + | 强烈建议使用 [[docs:guide-developer:uci-defaults|uci-defaults]] 仅增量集成所需的自定义. | ||
| + | 这有助于最大限度地减少与自动生成的设置的冲突, | ||
| + | |||
| + | 参考: [[: | ||
| + | |||
| + | ==== Building image ==== | ||
| + | 选择适当的配置文件, | ||
| + | |||
| + | <code bash> | ||
| + | make image \ | ||
| + | PROFILE=" | ||
| + | PACKAGES=" | ||
| + | FILES=" | ||
| + | DISABLED_SERVICES=" | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | 构建的固件将在子目录下找到 '' | ||
| + | |||
| + | ==== 清理编译 ==== | ||
| + | 要清理临时构建文件和生成的固件,请使用该 '' | ||
| + | |||
| + | ==== 例子 ==== | ||
| + | 以下示例显示: | ||
| + | * 为配置文件创建目录. | ||
| + | * 使用 '' | ||
| + | * 使用自定义插件和 '' | ||
| + | |||
| + | <code bash> | ||
| + | mkdir -p files/ | ||
| + | scp root@192.168.1.1:/ | ||
| + | scp root@192.168.1.1:/ | ||
| + | scp root@192.168.1.1:/ | ||
| + | make image PROFILE=" | ||
| + | </ | ||
| + | |||
| + | ===== 故障排除 ===== | ||
| + | - 您是否以非 root 用户身份运行所有内容? | ||
| + | - 检查日志输出, | ||
| + | - 检查日志输出, | ||
| + | - 每天等待几个小时上游 packages 可能处于不一致状态, | ||
| + | - 验证您拥有受支持的操作系统, | ||
| + | |||
| + | ===== 附加功能 ===== | ||
| + | T以下主题不仅限于简单的使用,而且面向开发人员和高级用户. | ||
| + | |||
| + | ==== 详细帮助 ==== | ||
| + | 另请参阅 [[https:// | ||
| + | |||
| + | 获取详细帮助: | ||
| + | |||
| + | < | ||
| + | # make help | ||
| + | |||
| + | 可用命令参数: | ||
| + | help: | ||
| + | info: | ||
| + | clean: | ||
| + | image: | ||
| + | |||
| + | 构建镜像: | ||
| + | 默认情况下 'make image' 将使用默认的目标配置文件和包集创建一个镜像. | ||
| + | 您可以使用以下参数进行更改: | ||
| + | |||
| + | make image PROFILE="< | ||
| + | make image PACKAGES="< | ||
| + | make image FILES="< | ||
| + | make image BIN_DIR="< | ||
| + | make image EXTRA_IMAGE_NAME="< | ||
| + | make image DISABLED_SERVICES="< | ||
| + | make image ADD_LOCAL_KEY=1 # 在构建的映像中存储本地生成的签名密钥 | ||
| + | make image ROOTFS_PARTSIZE="< | ||
| + | |||
| + | 打印清单: | ||
| + | 列出安装到固件映像中的 " | ||
| + | 您可以使用以下参数: | ||
| + | |||
| + | make manifest PROFILE="< | ||
| + | make manifest PACKAGES="< | ||
| + | make manifest STRIP_ABI=1 # 从打印的插件名中删除 ABI 版本 | ||
| + | </ | ||
| + | |||
| + | <color # | ||
| + | ==== 可用配置文件 ==== | ||
| + | 列出可用的配置文件: | ||
| + | |||
| + | < | ||
| + | # make info | ||
| + | |||
| + | Available Profiles: | ||
| + | |||
| + | Default: | ||
| + | Default Profile | ||
| + | Packages: kmod-usb-core kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport | ||
| + | ai-br100: | ||
| + | Aigale Ai-BR100 | ||
| + | Packages: kmod-usb2 kmod-usb-ohci | ||
| + | rp-n53: | ||
| + | Asus RP-N53 | ||
| + | Packages: | ||
| + | rt-n14u: | ||
| + | Asus RT-N14u | ||
| + | Packages: | ||
| + | whr-1166d: | ||
| + | Buffalo WHR-1166D | ||
| + | Packages: | ||
| + | whr-300hp2: | ||
| + | Buffalo WHR-300HP2 | ||
| + | Packages: | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | ==== 构建包含所有插件的 Image Builder ==== | ||
| + | 可以使用 buildroot 来创建您自己的 Image Builder 并将所有插件集成到其中, | ||
| + | |||
| + | 在图形配置中, | ||
| + | 如果遇到无法编译的未维护插件, | ||
| + | |||
| + | 不要在路径中调用 '' | ||
| + | |||
| + | ==== Adding package repositories ==== | ||
| + | The Image Builder you download from the OpenWrt pages is already configured to download any non-default packages from official repositories. | ||
| + | The package sources are configured in the '' | ||
| + | Sources are specified in //opkg// native config format. | ||
| + | This can be either the official package repositories or custom generated repositories. | ||
| + | |||
| + | An example of the contents of the '' | ||
| + | |||
| + | <code bash> | ||
| + | ## Place your custom repositories here, they must match the architecture and version. | ||
| + | # src/gz %n http:// | ||
| + | # src custom file:/// | ||
| + | |||
| + | ## Remote package repositories | ||
| + | src/gz openwrt_core http:// | ||
| + | src/gz openwrt_base http:// | ||
| + | src/gz openwrt_luci http:// | ||
| + | src/gz openwrt_packages http:// | ||
| + | src/gz openwrt_routing http:// | ||
| + | src/gz openwrt_telephony http:// | ||
| + | |||
| + | ## This is the local package repository, do not remove! | ||
| + | src imagebuilder file: | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| + | |||
| + | If you want to add a custom local repository, copy the '' | ||
| + | If you have problems with using you local repository because the " | ||
| + | |||
| + | If you have custom repositories online, copy and modify the '' | ||
| + | |||
| + | NOTE: if you want to override packages coming from an existing feed, you must write your custom feed ABOVE the line of the package feed containing the packages you want to override, as shown in the examples above. | ||
| + | |||
| + | ==== Restricting root access ==== | ||
| + | Create a non-privileged admin user and lock root password. | ||
| + | Configure privilege elevation with sudo. | ||
| + | Set up key-based authentication and disable password authentication for Dropbear. | ||
| + | |||
| + | <code bash> | ||
| + | mkdir -p files/ | ||
| + | cat << " | ||
| + | USER_NAME=" | ||
| + | USER_GROUP=" | ||
| + | USER_SSHPUB=" | ||
| + | USER_SHELL="/ | ||
| + | SUDO_USER=" | ||
| + | SUDO_GROUP=" | ||
| + | SUDO_GID=" | ||
| + | uci set dropbear.@dropbear[0].PasswordAuth=" | ||
| + | uci set dropbear.@dropbear[0].RootPasswordAuth=" | ||
| + | uci commit dropbear | ||
| + | / | ||
| + | passwd -l " | ||
| + | groupadd -r -g " | ||
| + | touch / | ||
| + | cat << EOI > / | ||
| + | %${SUDO_GROUP} ALL=(ALL) ALL | ||
| + | EOI | ||
| + | groupadd " | ||
| + | useradd -m -g " | ||
| + | -s " | ||
| + | passwd -d " | ||
| + | USER_HOME=" | ||
| + | mkdir -p " | ||
| + | cat << EOI > " | ||
| + | ${USER_SSHPUB} | ||
| + | EOI | ||
| + | chown -R " | ||
| + | chmod -R go= " | ||
| + | EOF | ||
| + | make image FILES=" | ||
| + | </ | ||
| + | |||
| + | ==== Adding/ | ||
| + | |||
| + | <WRAP important> | ||
| + | Examples below may contain version dependent / legacy information and are for informational purposes. They are very low level so expect to have a good level of skill and familiarity with the ImageBuilder / OpenWrt in general. | ||
| + | </ | ||
| + | |||
| + | The image building is tied to the profile names. | ||
| + | If you add a new profile without also adding an appropriate macro to the image-generation Makefile, no suitable firmware file will get generated when using the custom profile. | ||
| + | Remove the ''/ | ||
| + | |||
| + | The location of the profiles for the pre-compiled package for // | ||
| + | |||
| + | Remarkably, all that needs to be done to add a new profile, is to add a new file to the // | ||
| + | //While this may have been the case in earlier releases, for 17.01, it appears that manual editing of '' | ||
| + | |||
| + | Here is what the // | ||
| + | |||
| + | <code bash> | ||
| + | define Profile/ | ||
| + | NAME: | ||
| + | PACKAGES: | ||
| + | endef | ||
| + | |||
| + | define Profile/ | ||
| + | Package set compatible with hardware using Broadcom BCM43xx cards | ||
| + | endef | ||
| + | $(eval $(call Profile, | ||
| + | </ | ||
| + | |||
| + | Alternately edit the hidden .profile.mk file at the top level directory of the image builder and manually add the names of the desired packages to be added to the output image. | ||
| + | An "ls -a" will reveal the files hidden in the various directories. | ||
| + | |||
| + | ==== Removing useless files from firmware ==== | ||
| + | <WRAP important> | ||
| + | This is not a standard feature of the Image Builder. | ||
| + | |||
| + | It is highly recommended that you test file removal prior to incorporating such changes at the image builder level or that you have low level means to recover a device before attempting this type of mod, as bricking / non booting may result. | ||
| + | |||
| + | Note that it requires patching of the '' | ||
| - | 常见发行版的解决依赖性范例: | + | It is based on older Chaos Calmer era code... and not applicable to modern ImageBuilders but useful as a reference... |
| - | < | + | </ |
| - | < | + | Create file '' |
| - | yum group install " | + | |
| + | <code bash> | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | </ | ||
| - | ===== 获取镜像生成工具 ===== | + | Patch Makefile: |
| - | 你可以在你的路由设备固件所属下载页面找到**镜像生成工具** 压缩包。\\ | + | |
| - | 以下是下载 **ar71xx/ | + | |
| - | https:// | + | |
| - | 点击该链接,你可以找到一个名为 **lede-imagebuilder-ar71xx-generic.Linux-x86_64.tar.xz** 的压缩包, **镜像生成工具** 就包含在里面。 | + | |
| - | 除此以外,当你从源码编译固件且勾选 | + | <code diff> |
| + | ifneq ($(USER_FILES), | ||
| + | | ||
| + | | ||
| + | + | ||
| + | +ifneq ($(FILES_REMOVE), | ||
| + | + @echo | ||
| + | + @echo Remove useless files | ||
| + | + | ||
| + | + while read filename; do \ | ||
| + | + rm -rfv "$(TARGET_DIR)$$filename"; \ | ||
| + | + done < $(FILES_REMOVE); | ||
| + | +endif | ||
| + | + | ||
| + | | ||
| + | | ||
| + | </ | ||
| - | ---- | + | Rebuild firmware: |
| + | <code bash> | ||
| + | make image \ | ||
| + | PROFILE=" | ||
| + | PACKAGES=" | ||
| + | FILES_REMOVE=" | ||
| + | </ | ||