owut: OpenWrt 升级工具
概述
有关整个过程的更详细描述, 请参阅 Attended Sysupgrade。
owut
是一个命令行升级工具,用于创建和安装 OpenWrt 的自定义版本,其中包含您当前安装的所有软件包并保留您的配置。
它的子命令和选项有以下功能
- 检查最新版本状态
- 列出升级服务器上所有可用的 OpenWrt 版本
- 仅下载固件
- 验证并安装您下载的固件
- 生成已安装软件包的列表, 便于配合 Firmware Selector 或者 源码构建使用
- 生成固件时,您可以做以下操作
- 在构建列表中增加或删除包
- 使用
uci-defaults
脚本 - 设置非标准根文件系统大小
- 在升级时更改文件系统类型
- 以及更多。
您可以在命令行上指定这些选项,也可以使用标准的 OpenWrt config系统来存储这些值,从而避免在每次升级时记住并重新设置。
安装和升级
owut
是一个标准的可选 OpenWrt 软件包, 可在 SNAPSHOT(测试版)或是 24.x 之后的稳定版支持的所有平台上使用。
opkg update && opkg install owut # 在 24.10 稳定版。 apk -U add owut # 在主线测试版。
如果您发现您需要的功能不在您当前版本的 owut
中,您可以按如下方式升级。
opkg update && opkg upgrade owut # 在 24.10 稳定版。 apk -U upgrade owut # 在主线测试版。
通常不需要专门升级 owut
, 因为一旦安装,只要您进行完整的固件升级,owut
就会与其他所有内容一起升级。
如果您对安装或配置有任何疑问, 请在论坛发帖。.
快速升级
如果您的目标只是升级路由器的当前固件,保持相同的版本(例如,24.10 或 SNAPSHOT),那么只需使用 upgrade 命令即可。 如果各种预构建检查发现了任何问题,或者在构建过程中检测到错误,则升级将中止,并显示一条指示问题的消息。
请牢记开始的第一步是
备份!
- 图形化备份:网页(Luci)转到 系统(System) → 备份与升级(Backup/Flash firmware)。 单击 生成备份(Generate archive)。
- 命令行备份: 复制粘贴后运行该命令
sysupgrade --create-backup /tmp/backup.tar.gz
然后使用scp
或其他工具将文件复制到安全位置(通常是另一台主机)。
不要问为什么,跟着做!
如果 owut
发现软件包降级, 或者自上次升级以来没有进行任何更改,它会告诉您并停止. 您可以使用 --force
选项重新运行该命令,该选项将继续构建和安装,保留所有配置。
请注意, owut
目前仅在主线 SNAPSHOT(测试版) 或 24.x 之后稳定版上可用。
$ opkg update && opkg install owut # 在 24.10 稳定版。 $ apk -U add owut # 在主线测试版。 $ owut upgrade owut - OpenWrt Upgrade Tool 2024.12.10~e38844ae-r1 (/usr/bin/owut) ASU-Server https://sysupgrade.openwrt.org Upstream https://downloads.openwrt.org Target x86/64 Profile generic Package-arch x86_64 Root-FS-type ext4 Sys-type combined-efi Version-from 24.10-SNAPSHOT r28242-1eff737906 (kernel 6.6.67) Version-to 24.10-SNAPSHOT r28304-6dacba30a7 (kernel 6.6.69) Build-FS-type ext4 Build-at 2025-01-04T21:35:37Z (~66 hours ago) Image-prefix openwrt-24.10-snapshot-r28304-6dacba30a7-x86-64-generic Image-URL https://downloads.openwrt.org/releases/24.10-SNAPSHOT/targets/x86/64 Image-file openwrt-24.10-snapshot-r28304-6dacba30a7-x86-64-generic-ext4-combined-efi.img.gz Installed 284 packages Top-level 83 packages Default 43 packages User-installed 51 packages (top-level only) Package version changes: kmod-amazon-ena 6.6.67-r1 6.6.69-r1 kmod-amd-xgbe 6.6.67-r1 6.6.69-r1 ... procd-ujail 2024.12.17~fd01fb85-r1 2024.12.22~42d39376-r1 ubus 2024.10.20~252a9b0c-r1 2025.01.02~afa57cce-r1 ubusd 2024.10.20~252a9b0c-r1 2025.01.02~afa57cce-r1 92 packages are out-of-date Default package analysis: Default Provided-by dnsmasq dnsmasq-full kmod-dwmac-intel not installed libustream-mbedtls not installed nftables nftables-json There are currently package build failures for 24.10-SNAPSHOT x86_64: Feed: telephony freeswitch Mon Jan 6 05:37:57 2025 - not installed freeswitch-mod-bcg729 Mon Jan 6 05:46:38 2025 - not installed freetdm Mon Jan 6 05:46:40 2025 - not installed Failures don't affect this device, details at https://downloads.openwrt.org/releases/faillogs-24.10/x86_64/ WARNING: There are 2 missing default packages, confirm this is expected before proceeding Request: Version 24.10-SNAPSHOT r28304-6dacba30a7 (kernel 6.6.69) Request hash: fc626783b488e9a7e5a5914495a7ebbbf9fb079cff7abbf2a2165a25d02c8eb6 -- Status: queued - 0 ahead of you Progress: 0s total = 0s in queue + 0s in build -- Status: init Progress: 1s total = 0s in queue + 1s in build -- Status: container_setup Progress: 17s total = 0s in queue + 17s in build -- Status: validate_manifest Progress: 101s total = 0s in queue + 101s in build -- Status: building_image Progress: 185s total = 0s in queue + 185s in build -- Status: done Progress: 187s total = 0s in queue + 187s in build Build succeeded in 187s total = 0s in queue + 187s to build: version_number = 24.10-SNAPSHOT version_code = r28304-6dacba30a7 (requested r28304-6dacba30a7) kernel_version = 6.6.69 rootfs_size_mb = default init-script = no-init-script Image source: http://asu-dev.brain.lan:8000/store/fc626783b488e9a7e5a5914495a7ebbbf9fb079cff7abbf2a2165a25d02c8eb6/openwrt-24.10-snapshot-r28304-6dacba30a7-8e0b0deb02c0-x86-64-generic-ext4-combined-efi.img.gz Image saved : /tmp/firmware.bin Manifest : /tmp/firmware-manifest.json Verifying : /tmp/firmware.bin (32751632 bytes) against /tmp/firmware.sha256sums Saved sha256 matches Tue Jan 7 07:54:20 PST 2025 upgrade: Image metadata not present Tue Jan 7 07:54:20 PST 2025 upgrade: Reading partition table from bootdisk... Tue Jan 7 07:54:20 PST 2025 upgrade: Extract boot sector from the image Tue Jan 7 07:54:21 PST 2025 upgrade: Reading partition table from image... Checks complete, image is valid. Installing /tmp/firmware.bin and rebooting... ... system reboots ...
用法
$ owut -h owut - OpenWrt Upgrade Tool 2025.01.06~e623a900-r1 (/usr/bin/owut) owut is an upgrade tool for OpenWrt. Usage: owut COMMAND [-V VERSION_TO] [-R REV_CODE] [-v] [-q] [-k] [--force] [-a ADD] [-r REMOVE] [--ignored-defaults IGNORED_DEFAULTS] [-I INIT_SCRIPT] [-F FSTYPE] [-S ROOTFS_SIZE] [-i IMAGE] [-f FORMAT] [-p PRE_INSTALL] [-T POLL_INTERVAL] -h/--help - Show this message and quit. --version - Show the program version and terminate. COMMAND - Sub-command to execute, must be one of: check - Collect all resources and report stats. list - Show all the packages installed by user. blob - Display the json blob for the ASU build request. download - Build, download and verify an image. verify - Verify the downloaded image. install - Install the specified local image. upgrade - Build, download, verify and install an image. versions - Show available versions. dump - Collect all resources and dump internal data structures. -V/--version-to VERSION_TO - Specify the target version, defaults to installed version. -R/--rev-code REV_CODE - Specify a 'version_code', literal 'none' allowed, defaults to latest build. -v/--verbose - Print various diagnostics. Repeat for even more output. -q/--quiet - Reduce verbosity. Repeat for total silence. -k/--keep - Save all downloaded working files. --force - Force a build even when there are downgrades or no changes. -a/--add ADD - New packages to add to build list. -r/--remove REMOVE - Installed packages to remove from build list. --ignored-defaults IGNORED_DEFAULTS - List of explicitly ignored default package names. -I/--init-script INIT_SCRIPT - Path to uci-defaults script to run on first boot ('-' use stdin). -F/--fstype FSTYPE - Desired root file system type (squashfs, ext4, ubifs, jffs2). -S/--rootfs-size ROOTFS_SIZE - DANGER: See wiki before using! Root file system size in MB (1-1024). -i/--image IMAGE - Image name for download, verify, install and upgrade. -f/--format FORMAT - Format for 'list' output (fs-user, fs-all, config). -p/--pre-install PRE_INSTALL - Script to exec just prior to launching final sysupgrade. -T/--poll-interval POLL_INTERVAL - Poll interval for build monitor, in milliseconds. Full documentation https://openwrt.org/docs/guide-user/installation/sysupgrade.owut Questions and discussion https://forum.openwrt.org/t/owut-openwrt-upgrade-tool/200035 Issues and bug reports https://github.com/efahl/owut/issues
子命令
子命令 | 描述 |
---|---|
check | Downloads all resource files, collects the metadata from the device and the resources, and displays a report on everything found. This includes available version upgrades on all packages, availability of installed packages, listing of all package build breakages, and so on. At the end of the report, you'll see an indication as to whether it is possible to upgrade or not. |
list | This sub-command allows you to generate the list of packages installed on your device. This list is tailored for use with either the OpenWrt Firmware Selector or for use with source builds. For more details, see the --format option description, below. |
blob | Display the json blob for the ASU build request. Mostly useful for debugging and satisfying your curiosity. |
download | Build, download and verify an image. Used to create an image that you may then archive off-system, before subsequently owut install ing it. |
verify | Verify the downloaded image. After you have download ed an image, verify can be used to make sure it corresponds to the downloaded checksums and is correct according to sysupgrade . |
install | Install the specified image. Does another verify , then runs sysupgrade to install the image, results in a reboot. |
upgrade | Build, download, verify and install an image. Short hand way to run all steps involved in upgrading the system, basically a download and install in one command. |
versions | Show available versions according to what the ASU server knows. This may not be a complete list with respect to what is available on the build servers (aka downloads.openwrt.org ), as the ASU server does not deal with archives and discourages use of out-of-date releases. |
dump | Collect all resources and dump internal data structures. Again, like the blob sub-command, this is for debugging and curious users. |
命令行选项
选项 | 默认值 | 描述 |
---|---|---|
-V/--version-to VERSION | newest version on current branch | Search for updates for this version or branch. Detailed description. |
-R/--rev-code REV_CODE | - | Optionally specify the build revision code. Rarely needed, if you think you need to use it, ask on the forum. |
-v/--verbose | - | Print various diagnostics and operational messages; repeat for even more output. |
-q/--quiet | - | Reduces verbosity and can be repeated for less output. |
-k/--keep | false | Save all downloaded working files, primarily for diagnostics and debugging. Look in /tmp/ after using this option; turn on -v to watch as they are saved. |
--force | false | Force download or upgrade when there are package downgrades, or when there are no changes detected. Detailed description. |
-a/--add ADD | none | List of new packages to add to build list. Detailed description. |
-r/--remove REMOVE | none | List of installed packages to remove from build list. Detailed description. |
--ignored-defaults IGNORED_DEFAULTS | none | List of explicitly ignored default package names. Detailed description. |
-I/--init-script INIT_SCRIPT | none | Path to uci-defaults script to run on first boot ('-' use stdin). Detailed description. |
-F/--fstype FSTYPE | current | Desired root file system type. May be one of squashfs , ext4 , ubifs or jffs2 depending on platform constraints. Detailed description. |
-S/--rootfs-size ROOTFS_SIZE | current | Root file system size in MB (1-1024). Detailed description. |
-i/--image IMAGE | /tmp/firmware.bin | The image name used for the download , verify , install and upgrade sub-commands. |
-f/--format FORMAT | fs-user | Format for list output. Valid formats are fs-user , fs-all and config . Detailed description. |
-p/--pre-install PRE_INSTALL | none | Path to a user-defined script that will be run after image verification and before the actual installation of the image. Detailed description. |
-T/--poll-interval POLL_INTERVAL | 2000 | Milliseconds to sleep between checks on build status when running the build. |
选择版本
当您不指定版本时
当您未明确指定 --version-to
值时, owut
会查找已安装分支的最新版本并将其设置为目标版本。
对于所有示例,假设 21.02
分支上的最新版本是 21.02.7
版本, 在 23.05
分支上是 23.05.4
版本。
Installed Version | Target |
---|---|
21.02.2 | 21.02.7 |
23.05.0-rc1 | 23.05.4 |
23.05.3 | 23.05.4 |
23.05.4 | 23.05.4 |
例外情况是,如果安装的版本是 SNAPSHOT
,在这种情况下,版本目标将保留为已安装的版本。
Installed Version | Target |
---|---|
22.03-SNAPSHOT | 22.03-SNAPSHOT |
23.05-SNAPSHOT | 23.05-SNAPSHOT |
SNAPSHOT | SNAPSHOT |
当您指定版本
当您指定 --version-to
时,它必须命名有效的版本或分支。如果您提供的值无效, owut
将显示所有可用版本(或者您可以使用 owut versions
手动选择)。
指定完整版本时,将根据可用版本检查输入,并保持原样:
User specifies | Target |
---|---|
--version-to 23.05.3 | 23.05.3 |
--version-to 23.05.0-rc2 | 23.05.0-rc2 |
--version-to 23.05-snapshot | 23.05-SNAPSHOT |
--version-to snapshot | SNAPSHOT |
如果您仅指定一个分支(即没有最终“点值”的版本号),则 version-to 目标将设置为该分支上的最新版本。
User specifies | Target |
---|---|
--version-to 21.02 | 21.02.7 |
--version-to 23.05 | 23.05.4 |
--version-to SNAPSHOT | SNAPSHOT |
请注意,字符大小写在命名版本时并不重要, owut
会在内部转换为升级服务器所需的内容。 你可以 snapshot
, SnapShot
或 SNAPSHOT
或 rc1
或 rC1
, owut
知道该怎么做。
强制构建
owut
的正常行为是在未找到更改时停止生成请求,从而避免执行不需要的工作。 --force
选项用于覆盖此权限并重新安装当前系统。 如果您无意中删除了软件包或类似内容,并且无法弄清楚如何恢复,这可能很有用。
当 owut
检测到 package 中的降级时,它会通过在 Package version changes:
列表中将新版本号着色为红色来表示这一点,并在列表底部报告降级次数。这也会导致 owut
止处理任何正在进行的 download
或 upgrade
, 除非您指定 --force
选项。
添加和删除包
--add
和 --remove
选项 允许您将包添加到 owut
构建服务器的构建列表中或从中删除包。这些选项在命令行中只能出现一次;如果您想添加或删除多个包,请用逗号分隔包名称或用引号将它们分组。
例如,如果您想升级并同时切换到 dnsmasq
和 tc
的完整版本,您可以:
$ owut upgrade -r dnsmasq,tc-tiny -a "dnsmasq-full tc-full" ...
从版本 2025.01.06 开始, --add
和 --remove
的命令行参数都可以用逗号或任意空格(包括换行符)分隔(在该版本之前,只允许使用逗号)。这样做的主要目的是允许您使用包名称的简单平面文件作为包列表的输入源,如本例所示。
$ cat additions nmap bind-dig tcpdump $ owut download --add "$(cat additions)" ...
关于添加包
- 如果您添加了一个已经安装的软件包,
owut
会静默地忽略它并继续。 - 如果您添加的包不存在、尚未移植到您的设备或当前不可用,则
owut
会报告错误并停止。
关于删除包
- 如果您尝试删除未安装的软件包,
owut
会报告错误并停止。 - 如果您删除了设备的默认软件包之一,
owut
将产生警告,该软件包将被删除,owut
将继续您的请求。 请注意,这可能会在构建期间或安装到您的设备上之后破坏一切,您有责任确保删除软件包是适当的。$ owut check -r kmod-igb WARNING: package 'kmod-igb' is a default package, removal may have unknown side effects ...
- 如果你试图删除一个有依赖项的包(即 “非顶级包” -- 作为另一个包的要求安装的东西),
owut
会警告你这一点,这个包将从构建列表中删除,owut
将继续。 请注意,这通常没有效果,因为该软件包将被最初安装它的同一顶级软件包拉回。$ owut check -r kernel WARNING: package 'kernel' has dependents and removal will have no effect on the build ...
关于忽略默认值
如果 Default package analysis:
显示已删除但希望忽略的默认包,只需将它们作为参数提供给 --ignored-defaults
选项,即可抑制有关缺少默认值的警告。
$ owut check ... Default package analysis: Default Provided-by dnsmasq dnsmasq-full kmod-drm-i915 not installed kmod-dwmac-intel not installed nftables nftables-json ... WARNING: There are 2 missing default packages, confirm this is expected before proceeding
请注意,这些包仍列在分析表中,确认您的选择,但不显示警告消息。
$ owut check --ignored-defaults kmod-drm-i915,kmod-dwmac-intel ... Default package analysis: Default Provided-by dnsmasq dnsmasq-full kmod-drm-i915 user ignored kmod-dwmac-intel user ignored nftables nftables-json
您可以将这些包添加到配置文件中,而无需每次都在命令行中键入它们。
$ cat /etc/config/attendedsysupgrade ... config owut 'owut' option verbosity 1 option poll_interval 2000 list ignored_defaults "kmod-drm-i915" list ignored_defaults "kmod-dwmac-intel"
使用 uci-defaults 脚本
不要将敏感信息放在 init-script
文件中。
您在 init-script
文件中提供的文本将作为构建配置的一部分发送到构建服务器。 这会在构建请求遍历 Internet 时将其暴露给潜在的泄露。 构建完成后,文件的内容将存储在生成映像中的生成服务器上,任何了解生成哈希值的人都可以下载和访问它。
如果您不熟悉 uci-defaults
(又名“首次启动脚本”), 您可以在此处阅读: UCI defaults。实现 owut
(以及 auc
和 LuCI 有人值守的系统升级和固件选择器)构建的底层机制是固件生成器,因此其描述也可能很有用: 固件生成器 - 自定义文件。
--init-script
选项允许您指定包含 uci-defaults
脚本的文件的名称,该脚本将在首次启动时执行。ASU 服务器获取你的 init-script 源,并将其放在 /etc/uci-defaults/99-asu-defaults
的镜像中(无法更改此名称)。在不可变文件系统(比如 squashfs
)上,这也会导致文件存储在 /rom/etc/uci-defaults/99-asu-defaults
中,这与 LuCI Attended Sysupgrade 有关。
以下是 owut
与其他升级工具如何实现此功能的比较。
auc
不实现此功能 (但是有 补丁)。- 固件选择器的行为与
owut
的行为相同,其Script to run on first boot (uci-defaults)
输入字段。 - LuCI Attended Sysupgrade 通过查找
/rom/etc/uci-defaults/99-asu-defaults
来实现这一点,然后隐式中继该文件的内容。 LuCI ASU 的缺点是它不允许您删除或更改已经存在的内容。owut
明确表示,如果您希望脚本包含在新固件中,则必须在请求构建时指定它。
以下两种场景(包括 7 个使用案例)中使用的术语是:
- “mutable system” - 使用读写文件系统作为其主存储的设备。 通常在 OpenWrt 中,这是一个 ext4 文件系统。
$ mount | grep '(ro' ... no output ...
- “immutable system” - 在
/rom
上安装了只读分区的设备,原始系统映像存储在其中。通常,但不总是,这是一个squashfs文件系统。$ mount | grep '(ro' /dev/root on /rom type squashfs (ro,relatime,errors=continue)
- “asu-defaults” - 文件
/rom/etc/uci-defaults/99-asu-defaults
,它仅存在于具有不可变文件系统且其映像已由ASU构建服务器构建的设备上。
在 immutable system ,有五种情况需要考虑:
- asu-defaults 文件不存在,您不需要或不想要:
owut upgrade
- asu-defaults 文件存在,您希望保持它不变:
owut upgrade --init-script /rom/etc/uci-defaults/99-asu-defaults
- 存在 asu-defaults 文件并且您想修改它:
cp /rom/etc/uci-defaults/99-asu-defaults my-modified-init-script.sh vi my-modified-init-script.sh # Change it. owut upgrade --init-script my-modified-init-script.sh
- asu-defaults 文件不存在,但您想添加一个:
vi my-new-init-script.sh owut upgrade --init-script my-new-init-script.sh
- 存在 asu-defaults 文件,您想从构建中删除它:
owut upgrade # Just ignore the warning.
在 mutable system, 由于没有 /rom/etc/uci-defaults
,您只有两个选择:
- 您不想在构建中创建 asu-defaults :
owut upgrade
- 您想创建一个:
owut upgrade --init-script my-init-script.sh
请注意,对于上述所有情况,如果您确实使用了asu-defaults,那么您必须保留备份。有关最佳实践,请参阅 持久默认值示例。
更改文件系统类型
在极少数情况下,可能需要更改安装的文件系统类型。通常这是在具有可扩展文件系统的设备上完成的, x86, RISC-V 和 ARM SBCs,这类存储设备不是固定容量的FLASH(事实上,如果您尝试在基于FLASH的一体化设备上更改文件系统类型,构建过程几乎总会失败)。
但是,举个例子,假设您有一台配备SSD的x86设备,并且想要从当前的 squashfs
文件系统切换到 ext4
。只需使用所需的文件系统进行升级,重启后即可运行目标文件系统。
$ owut upgrade --fstype ext4 ... Target x86/64 Profile generic Package-arch x86_64 Root-FS-type squashfs <<< Installed Version-from SNAPSHOT r26504-d4acd05218 (kernel 6.6.32) Version-to SNAPSHOT r26733-2b6772c82c (kernel 6.6.34) Build-FS-type ext4 <<< Requested ...
扩展根文件系统
更改根文件系统大小通常会导致 owut
的最终安装(由 sysupgrade
执行)丢失您的配置,因此请用备份进行恢复。请注意,如果您丢失了 /etc/config/network
,设备的LAN IP可能会发生变化,因此在继续之前请考虑如何连接到设备。
--rootfs-size
选项允许那些具有可扩展文件系统(通常是x86、RISC-V和ARM SBC)的设备指定根文件系统的大小。默认值因目标而异,但通常为104 MB,--rootfs-size
选项允许您将其增加到1024 MB,从而允许安装更多或更大的包。
您可以将此值放在配置中,并避免每次升级时在命令行上键入它。
$ uci set attendedsysupgrade.owut=owut $ uci set attendedsysupgrade.owut.rootfs_size=256 $ uci commit $ uci show attendedsysupgrade.owut attendedsysupgrade.owut=owut attendedsysupgrade.owut.rootfs_size='256'
列表格式
owut list命令使用 --format
选项,该选项采用以下值之一。
fs-user
- (默认值) 生成一个包列表供固件选择器使用,该列表仅包含顶级用户安装的包修改。您可以将此复制并粘贴到FS “已安装包” 字段中的默认列表之后。fs-all
- 为FS生成一个包含所有顶级包的包列表,您可以将粘贴到FS “已安装包” 字段中的值上。config
- 生成用户安装的顶级包的构建.config
片段,您可以在进行源构建时使用这些包。每个输出行看起来像CONFIG_PACKAGE_collectd-mod-thermal=y
。
The fs-*
options generate lists in the Image Builder syntax, where mentioning a package name adds it to the list, and prefixing a package name with a dash removes it.
例如,如果您安装了 dnsmasq-full 软件包,则必须移除默认的 dnsmasq 基础软件包。具体操作示例如下(为清晰起见已简化):
$ owut list
... dnsmasq-full ... -dnsmasq ...
默认值提供了几个包,它们使用通用包名命名,实际上是由不同名称的东西提供的, nftable
是一个突出的包(它由 nftables-json
或 nftables-nojson
提供,没有 nftables-nojson
包)。 owut
似乎正在删除它,但它实际上只是说,“使用默认值,不管是什么”。在下面的示例中,我们只看到删除了 -nftable
,但没有看到默认包 nftables-json
,因为它将被隐式添加。
$ opkg whatprovides nftables # Or 'apk list --providers nftables' What provides nftables nftables-json $ owut list ... -nftables ...
这可能发生在其他由于依赖关系而看起来“无处删除”的文件上。例如,如果您使用 luci-ssl-openssl
,则列表输出将包含 -libustream-mbedtls
,否则将由默认值添加,从而导致“不可能的包选择”错误。
在默认包分析结果中使用 check
时,您经常会看到这些映射的其他证据:
$ owut check ... Default package analysis: Default Provided-by dnsmasq dnsmasq-full kmod-dwmac-intel not installed nftables nftables-json ...
预安装脚本
提示
对于最新的示例,请参阅 github source 中预安装脚本的最新版本。
owut
在图像验证和图像安装之间有一个钩子,允许你在安装之前对系统进行自动备份、构建工件的存档或任何其他最终修改。使用命令行中的 --pre-install /path/to/script
选项。一旦你对你的脚本工作方式感到满意,最佳实践是将 option pre_install '/path/to/script
添加到配置文件的 owut
部分。
owut
的标准安装在 /etc/owut.d/pre-install.sh
中提供了几个示例。如果你想出其他有趣的用法,请分享它们。
请注意,目录 /etc/owut.d/
是标准系统升级备份的一部分,因此您存储在那里的任何文件都将成为系统备份的一部分,并在升级过程中持续存在(假设您“保留配置”)。
配置
请注意,虽然你可以将任何命令行选项存储在配置文件中,但对某些选项这样做可能会令人困惑。在设置默认值时请自行斟酌:例如,设置 option force true
可能不是一个好主意。
任何命令行选项都可以存储在 owut
部分的 /etc/config/attendedsysupgrade
中。例如,如果在每次升级时都在命令行上使用 --rootfs-size 256
,则可以编辑配置并按如下方式添加该选项:
config server 'server' option url 'https://sysupgrade.openwrt.org' config owut 'owut' option rootfs_size 256
请注意,命令行中 “long” 选项名称中的破折号在配置选项名称中变为下划线,但除此之外,语法几乎完全相同。
命名约定有一个例外,命令行 --verbose
和 --quiet
在配置文件中都映射到 verbosity
。 verbosity
的配置文件值是一个整数;命令行上每次提到 -v
都会使其递增, 而 -q
会使其递减: option verbosity 1
, 然后 owut check -v -v -q -v
会导致输出详细程度为 3 (即,比你想象的更多的输出)。
一种查看默认值以及验证对配置文件所做的任何更改是否正确的便捷方法是执行 owut dump
并检查输出的 options
部分。
$ owut dump | head -20 { "version": "owut/2025.01.06~e623a900-r1", "options": { "command": "dump", "version_to": null, "rev_code": null, "verbosity": 1, "keep": false, "force": false, "add": null, "remove": null, "init_script": null, "fstype": null, "rootfs_size": 256, "image": "/tmp/firmware.bin", "format": null, "pre_install": "/etc/owut.d/pre-install.sh", "poll_interval": 10000, "device": null },
配置示例
停留在给定的版本上
你可以通过在配置中设置此选项来强制设置 --version-to
的默认值。请注意,这与 owut
的默认行为是多余的 (请参阅上文 选择版本 的详细信息)。
config owut 'owut' option version_to '24.10'
设置根文件系统大小
设置此项之前,请先阅读上文的 扩展根文件系统, 因为这可能不适用于你的设备。
对于具有可扩展存储的设备,通常是 x86、RISC-V 和 ARM 单板计算机,你可能会发现扩展根文件系统大小很有用,这样可以轻松安装更多软件包或存储更多持久数据。
config owut 'owut' option rootfs_size 512
持久 uci-defaults
如果您使用过自定义 uci-defaults
, 您可能会意识到脚本在第一次启动时从 /etc/uci-defaults/
中删除。对于不可变安装,通常使用 squashfs
文件系统,您可以从 /rom/etc/uci-defaults/
查看和恢复自定义脚本,但在 ext4
文件系统上,没有 rom
分区,文件永远消失了。
owut
通过允许您将脚本放置在持久位置,然后设置配置文件使其成为已安装固件的一部分来解决此问题。
- 在持久位置创建您的init-script。
$ mkdir /etc/owut.d/ $ echo "# My first boot script." > /etc/owut.d/custom-init.sh
- 确保它在所有的
sysupgrade
备份中进行。# The /etc/owut.d/ directory is part of standard backups, lets make sure... $ sysupgrade -l | grep custom /etc/owut.d/custom-init.sh
- 配置
owut
以将脚本包含到您的构建中。$ uci set attendedsysupgrade.owut=owut $ uci set attendedsysupgrade.owut.init_script=/etc/owut.d/custom-init.sh $ uci commit $ uci show attendedsysupgrade.owut attendedsysupgrade.owut=owut attendedsysupgrade.owut.init_script='/etc/owut.d/custom-init.sh'
- 验证一切都设置正确。您的脚本应作为
defaults
条目出现在json中。$ owut blob { "client": "owut/%%VERSION%%", "target": "x86/64", "profile": "generic", "version": "SNAPSHOT", "version_code": "r26773-85d9fd6f0e", "filesystem": "ext4", "diff_packages": true, "packages": [ "base-files", "btop", "busybox", ... a bunch more packages ... "ucode-mod-uloop", "urandom-seed", "urngd" ], "defaults": "# My first boot script.\n" }
* - 自2024年6月起,您还可以通过使用 OpenWrt 固件选择器 创建映像来完成后一部分,手动将脚本粘贴到其 Script to run on first boot (uci-defaults)
字段。
FAQ
Q: owut
中没有在不保留配置的情况下升级的选项。我可以用 auc -n
来做,为什么 owut
不可以?
A: 这是(或应该是)一件罕见的事情,所以使用 owut
故意让它变得困难。解决方案是简单地使用 owut
来创建映像,然后运行 sysupgrade
表明您想要丢弃配置。因此,这样可以确保您真的打算这样做,因为这是极具破坏性的。
$ owut download ... $ sysupgrade -n /tmp/firmware.bin
Q: 我有一台大型 miniPC 作为我的路由器。为什么我不能使用 --rootfs-size 120000
创建一个固件并使用我的整个 128GB 硬盘?
A: 出于实际原因,ASU 服务器规定上限为 1024MB。在某些设备上创建分区的方式要求先创建全尺寸图像,然后进行压缩,这需要大量的内存、磁盘空间和时间。
作过一个测试,我进行了几次图像构建器运行,根文件系统分区从 x86 的默认值(104MB)到 20000MB 不等,以查看它们需要多长时间。
ROOTFS_PARTSIZE= | real | user | img size |
---|---|---|---|
104 | 26s | 18s | 12M |
512 | 48s | 25s | 13M |
1024 | 74s | 33s | 13M |
10000 | 11m47s | 4m36s | 32M |
20000 | 28m15s | 13m9s | 32M |
这最后两行应该非常清楚地说明了为什么增加上限是不可行的,除非对构建过程进行重新设计以减少创建更大图像所需的时间。
注意:上述测试均在 AMD R9 7950x 5.8GHz CPU、64GB CL6000 RAM 和 PCIe 4 SSD 上运行,其速度通常是 ASU 服务器硬件的 3 倍,因此这些数字远低于在使用 ASU 服务器时看到的数字。
参考文献
- ASU server - github source, API documentation
- LuCI Attended Sysupgrade - wiki page, github source
- Firmware Selector - github source, build site
- Docker container builds - github source
- OpenWrt buildbots - github source
- Downloads site - OpenWrt build artifacts and release archive
- Dashboards - OpenWrt buildbot dashboards
ucode
- Reference Manualucode-mod-uclient
- github source