我们使用一些必要的Cookie来确保网站正常运行。

我们使用可选的 Cookie,具体详情请参阅我们的Cookie政策,用于记住您的设置并了解您如何使用我们的网站。

如何向 Imager 添加你自己的镜像

你是镜像供应商,或是希望通过 Raspberry Pi Imager 分发自己定制的 Raspberry Pi OS 镜像的爱好者吗?如果是,那么本指南就是为你准备的。在这篇文章中,我们将深入探讨 Raspberry Pi Imager 是如何发现并列出操作系统镜像的,以及 repository JSON 格式在底层是如何运作的。

随着Raspberry Pi Imager 2.0,用户界面、镜像写入流程以及内部配置处理都得到了多项改进(更多详情请参见 Raspberry Pi Imager 2.0公告文章)。其中一项较为有趣的变更,是用于定义可用操作系统镜像的 JSON schema 得到了更新。这项更新与cloud-init 支持在 Raspberry Pi OS 中的引入尤为相关,其中包括一个新的cc_raspberry_pi module that enables configuration features like enabling SPI automatically.

Imager 如何获知镜像信息

Raspberry Pi Imager 和 Raspberry Pi OS 的发布周期并不相同。在新版 Imager 发布之前,操作系统可能已经收到了多次更新。为每次操作系统更新都发布一个新的 Imager 构建版本效率低下——更不用说还会给用户带来不便。

为了解决这个问题,Raspberry Pi Imager 并不随附固定的操作系统镜像列表。相反,它会从一个远程 JSON 文件(称为“repository JSON”)动态获取这些信息。这使我们能够独立于 Imager 的发布来更新受支持设备和可用操作系统镜像的列表。用户无需重新安装或更新应用程序,即可自动获得最新选项。

该格式的当前版本——由 Imager 2.0 及后续版本使用——被正式编码为Repository JSON V4.

为什么要将 repository 独立出来?

将镜像元数据托管在外部带来了一些强大的可能性。例如,你可以维护多个仓库——一个用于官方稳定版本,另一个用于每日构建或测试镜像,甚至可以建立一个用于内部部署或课堂环境的私有仓库。

为了让这一功能更易使用,Imager 2.0 在应用设置中引入了一个新选项,允许你在官方仓库和自定义 JSON 文件之间切换,而自定义文件既可以从本地文件加载,也可以从 URL 加载。

当你更改此设置时,Imager 会重置当前会话,并使用所选 repository JSON 的内容重新加载界面。此功能面向高级用户和维护者——普通用户永远不需要更改它。

对于高级用户或自动化场景,经典方法依然存在:你可以使用--repo command-line option. This can point to either a URL or a local JSON file, making it ideal for scripted workflows or provisioning setups.

理解 repository JSON 结构

Raspberry Pi Imager 的 repository 文件遵循可预测的结构,并围绕四个主要配置元素构建:

  • 最新的 Imager 版本
  • 用户可下载更新的 URL
  • 受支持设备配置文件的列表
  • 可用操作系统条目列表

基本结构如下:

{
  "imager": {
    "latest_version": "2.0.0",
    "url": "https://www.raspberrypi.com/software/",
    "devices": [
      /* Device objects go here */
    ]
  },
  "os_list": [
    /* OS objects go here */
  ]
}

imager.latest_version and url

该latest_version field is used by Imager to determine whether a newer version is available. When a user launches the application, it compares its own version against this field. If the repository indicates a newer version, Imager displays an update prompt and links to the URL provided in the url field.

该devices list

该devices array contains a list of supported hardware profiles. These profiles allow Imager to filter OS entries based on the selected Raspberry Pi model. For example, an image may be restricted to Raspberry Pi 5 only, or marked as compatible with all boards.

你还会看到一个名为 ‘No filtering’ 的特殊条目。选择该选项时,将显示所有 OS 镜像,而不应用任何设备兼容性过滤器。此模式常用于测试或使用通用镜像的场景。它的行为类似于一个支持所有功能的虚拟设备配置文件。这意味着即使没有选择特定的 Raspberry Pi 型号,所有配置选项也都可用。

该os_list

真正发挥作用的地方就在这里。os_list contains all operating system entries that Imager displays to the user. Each entry can represent a full OS, a subgroup with multiple variants, or even reference nested JSON files for modular repositories.

如果你要构建自己的自定义仓库,通常只需要编辑这一部分。顶层的imager block — which includes device metadata and update information — is managed by Raspberry Pi and tightly integrated with how the official application works.

JSON device 对象 —— 定义硬件配置文件

在 Raspberry Pi Imager 能够决定为哪种设备显示哪些操作系统之前,它需要一种方式来了解每个 Raspberry Pi 型号的身份与能力。这就是 device 对象的作用所在。

其中的每个条目devices array represents a device profile — not necessarily a single board, but often a group of compatible models. For example, there may be a single profile representing ‘Raspberry Pi 4 / 400’, rather than separate entries for every board variant.

device 对象可以包含以下内容:

键类型说明
name字符串在 Imager 中显示的名称(例如 ‘Raspberry Pi 5’)
tagsstring[]一组标识符,OS 对象可引用它们来声明兼容性
defaultboolean(默认值:true)只应有一个设备设置此项;当未应用手动过滤器时,Imager 会自动选择它
iconstring (URL)在设备选择对话框中显示于名称旁边的小尺寸 PNG 图标
description字符串可选文本,用于列出支持的型号或提供额外说明
matching_type"inclusive" | "exclusive"定义未声明设备标签的 OS 条目应如何处理:
• inclusive → show them anyway
• exclusive → hide them, unless explicitly tagged for this device
capabilities (Imager 2.0 新增)string[](例如 “usb_otg“)充当功能标志 —— 用于根据所选设备是否支持相应功能来隐藏或启用 UI 选项

设备能力尤其有用,因为它使 Imager 只呈现有意义的配置选项。例如,只有当所选设备和所选 OS 都列出usb_otg in their capabilities. This avoids confusing users with options that won’t work on their hardware.

内部对象os_list: categories vs. operating systems

该os_list section can contain two different types of objects, each serving a different purpose:

1. 类别对象

类别是用于组织多个操作系统条目甚至子类别的容器。它无法被选中下载,也不包含url or image metadata.

类别对象仅支持以下键:

键类型说明
name字符串在 UI 中显示的类别标题
description字符串显示在名称下方的可选文本
iconstring (URL)显示在类别名称旁边的图标
randomboolean(可选)替换为您的实际地址:true, randomises the order of the entries inside subitems
subitems数组包含操作系统对象和/或嵌套的类别对象

可以把类别看作 UI 中的文件夹——点击它即可展开查看其中的内容。

2. 操作系统对象

操作系统对象定义了一个可选择的镜像。这些条目是有可安装的。它们不包含random or subitems.

操作系统条目支持的键有:

键类型说明
name字符串操作系统的显示名称
description字符串简短说明或变体信息
iconstring (URL)显示在条目旁边的图标
urlstring (URL)压缩镜像文件的直接链接(.img.xz, .img.zip, etc.)
extract_size整数未压缩的镜像大小(用于 UI 空间估算)
extract_sha256字符串解压后镜像的 SHA256 哈希值
image_download_size整数压缩下载文件的大小
image_download_sha256字符串压缩文件的 SHA256 哈希值
release_datestring(日期)用于标识版本/构建的显示日期
init_format"none" | "systemd" | "cloudinit" | "cloudinit-rpi"声明 Imager 可以提供哪种自定义功能;cloudinit-rpi enables the Raspberry Pi–specific cc_raspberry_pi module
devicesstring[]此操作系统支持的设备标签列表(来自设备对象)
capabilitiesstring[]指明此操作系统镜像支持哪些功能(例如usb_otg or rpi_connect)

提示:对于开发或内部测试,你可以省略 checksum 和 size 字段。但对于公共仓库,提供这些字段有助于 Imager 给出准确的进度信息,并支持校验和验证。

经验法则:

  • 如果它包含其他条目 → 它是一个分类对象
  • 如果它会下载内容 → 它是一个操作系统对象

Capabilities —— 功能匹配

下面对 capabilities 做一个更清晰的说明,它同时适用于设备对象和操作系统对象:

价值感适用于含义
usb_otg设备和操作系统仅当所选设备和操作系统都支持 USB gadget 功能时才显示(需要rpi-usb-gadget in the OS and OTG-capable hardware)
rpi_connect仅操作系统镜像在 UI 中标示支持 Raspberry Pi Connect 连接功能

镜像要求

如果你希望你的镜像在 Raspberry Pi Imager 中提供自定义选项,尤其是配合新的cloud-init 集成,那么你的镜像必须满足一些技术要求。

支持 cloud-init 自定义

要启用基于 cloud-init 的配置(例如在首次启动时设置主机名、Wi-Fi 凭据或 SSH 密钥),你的镜像必须:

  • 支持 cloud-init 的 Network Config Version 2 —— 通常通过 Netplan 并配合正确的 network renderer 来实现
  • 包含 cloud-init,并通过以下方式支持 NoCloud 数据源:bootfs partition (Imager writes configuration files into bootfs, and the OS must detect them on first boot)

cloudinit-rpi — advanced Raspberry Pi integration

如果你声明了init_format: "cloudinit-rpi" in your OS entry, Imager will also expose Raspberry Pi–specific options, such as enabling SPI or I2C automatically. To support this mode, your image must:

  • 具有cc_raspberry_pi cloud-init module enabled
  • 包含raspi-config-vendor package (modified for your distro), which provides integration hooks for the cloud-init module during first boot

更多详情,包括模板设置,可参见这里.

其他 init 模式

init_format valueImager 行为
"none"不向用户提供任何自定义选项 —— 简单的下载与刷写流程
"systemd"启用旧版bootfs-based firstrun.sh customisation mechanism
"cloud-init"启用标准 cloud-init(NoCloud)及通用选项
"cloud-init-rpi"通过以下内容启用扩展的 Raspberry Pi 专用选项cc_raspberry_pi

如果你的镜像不支持任何自定义机制,请使用init_format: "none" to explicitly disable the customisation step in the UI.

收录进官方 Raspberry Pi Imager 仓库

如果你维护着一个高质量的镜像,并希望它与官方镜像一起出现在 Raspberry Pi Imager 中(位于某个社区分类下),你可以填写以下表格提交审核申请表.

我们的团队会审核你提交的内容,验证其兼容性,并在需要调整时与你联系。一旦通过审核,你的镜像就可以通过我们的主仓库基础设施分发给全球数千名 Raspberry Pi Imager 用户。

12条评论

Anders avatar

我现在设想有一个由社区贡献镜像的仓库,有点像 Docker 的那个。

nafanz avatar

https://github.com/raspberrypi/rpi-imager/issues/1025

请问 DietPi 有可能出现在 Pi Imager 界面中吗?

Gordon Hollingworth avatar

这个你得去问 DietPi 那边的人……从来没有人要求我们把某个镜像加入列表

nafanz avatar

我给出了讨论该问题的 GitHub issue 链接。

据我了解,MichaIng 提供了所有要求的数据,之后就没有下文了。

这就是我决定在这里提一下的原因。

Mark Tomlin avatar

下载的 JSON 有大小限制吗?在由固件临时下载的 UEFI 版 Imager 中,是否可以设置自定义仓库?

imager 团队完成了这一切,做得非常出色。Imager 是一个非常好的项目,对我以及整个社区都有巨大的帮助。

AndrewS avatar

是的,参见https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#IMAGER_REPO_URL
(尽管“Embedded Imager”尚未更新到 Imager 2)

bsimmo avatar

你好,
能否把与你们镜像配套的那个文件也加到下载页面
https://www.raspberrypi.com/software/operating-systems/
这样我们就能方便地离线写入或重复写入,
因为它们与这个文件是配套使用的。这会帮上大忙。

既然这是很多人卡住的地方,而你们现在又不允许我们“自担风险使用这些设置”,尽管我们知道用下载版本是没问题的。

AndrewS avatar

请查看https://github.com/raspberrypi/rpi-imager/tree/main/doc/local_json这个文件的出现就是为了让离线写入更简单。

bsimmo avatar

那太麻烦了,而且还得完整安装一套 python。
我只是请求在发布 OS 下载时一并提供该文件,用于本地安装,这样 PiImager 就知道该怎么做。

beta-tester avatar

Raspberry Pi Imager 2 在使用 clear 选项时还会把 SD 卡弄坏吗?

jordana avatar

它不会把卡损坏到无法恢复的程度——请参见https://github.com/raspberrypi/rpi-imager/issues/1406

MechWarriorZero avatar

我不喜欢这个新版本,请退回到旧版本

评论已关闭