# nestos-installer **Repository Path**: src-nest-os/nestos-installer ## Basic Information - **Project Name**: nestos-installer - **Description**: 管理nestos安装软件包 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2021-11-16 - **Last Updated**: 2022-05-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # nestos-installer nestos-installer is a program to assist with installing nestos-installer for NestOS. It can do the following: \* Install the operating system to a target disk, optionally customizing it with an Ignition config or first-boot kernel parameters \* Download and verify an operating system image for various cloud, virtualization, or bare metal platforms \* List nestos-installer images available for download \* Embed an Ignition config in a live ISO image to customize the running system that boots from it \* Wrap an Ignition config in an initrd image that can be appended to the live PXE initramfs to customize the running system that boots from it ## cmd命令行键入命令: ### 下载image nestos-installer download -** ``` | **--stream**, **-s** *name* | NestOS stream [default: stable] | | **--architecture** *name* | Target CPU architecture [default: x86_64] | | **--platform**, **-p** *name* | NestOS platform name [default: metal] | | **--format**, **-f** *name* | Image format [default: raw.xz] | | **--image-url**, **-u** *URL* | Manually specify the image URL | | **--directory**, **-C** *path* | Destination directory [default: .] | | **--decompress**, **-d** | Decompress image and don't save signature | | **--insecure** | Skip signature verification | | **--stream-base-url** *URL* | Base URL for NestOS stream metadata | | **--fetch-retries** *N* | Fetch retries, or string "infinite" | ``` ### 配置安装 nestos-install install -** device ``` | **--stream**, **-s** *name* | NestOS stream | | **--image-url**, **-u** *URL* | Manually specify the image URL | | **--image-file**, **-f** *path* | Manually specify a local image file | | **--ignition-file**, **-i** *path* | Embed an Ignition config from a file | | **--ignition-url**, **-I** *URL* | Embed an Ignition config from a URL | | **--ignition-hash** *digest* | Digest (type-value) of the Ignition config | | **--platform**, **-p** *name* | Override the Ignition platform ID | | **--append-karg** *arg1,arg2,...* | Append default kernel arg | | **--delete-karg** *arg1,arg2,...* | Delete default kernel arg | | **--copy-network**, **-n** | Copy network config from install environment | | **--network-dir** *path* | For use with **-n** [default: /etc/NetworkManager/system-connections/] | | **--save-partlabel** *lx,...* | Save partitions with this label glob | | **--save-partindex** *id,...* | Save partitions with this number or range | | **--offline** | Force offline installation | | **--insecure** | Skip signature verification | | **--insecure-ignition** | Allow Ignition URL without HTTPS or hash | | **--stream-base-url** *URL* | Base URL for Fedora CoreOS stream metadata | | **--architecture** *name* | Target CPU architecture [default: x86_64] | | **--preserve-on-error** | Don't clear partition table on error | | **--fetch-retries** *N* | Fetch retries, or string "infinite" | ``` ### 点火文件配置 ### 在image文件中嵌入点火文件 nestos-installer iso ignition embed -** ISO ``` | **--force**, **-f** | Overwrite an existing Ignition config | | **--ignition-file**, **-i** *path* | Ignition config to embed [default: stdin] | | **--output**, **-o** *path* | Write ISO to a new output file | ``` ### 显示image文件嵌入的点火文件 nestos-installer iso ignition show ISO ### 移除image文件中嵌入的点火配置文件 nestos-installer iso ignition remove -** ISO ``` | **--output**, **-o** *path* | Copy to a new file, instead of modifying in place | ``` ### 修改ISOimage内的内核参数 nestos-installer iso kargs modify -** ISO ``` | **--append**, **-a** *KARG...* | Kernel argument to append | | **--delete**, **-d** *KARG...* | Kernel argument to delete | | **--replace**, **-r** *KARG=OLDVAL=NEWVAL...* | Kernel argument to replace | | **--output**, **-o** *path* | Write ISO to a new output file | ``` ### 将ISOimage内的内核参数重置为默认值 nestos-installer iso kargs reset -** ISO ``` | **--output**, **-o** *path* | Write ISO to a new output file | ``` ### 显示ISOimage中的内核参数 nestos-installer iso kargs show -** ISO ``` | **--default**, **-d** | Show default kernel args | ``` ### 列出NestOS stream中可用的image nestos-nstaller list-stream -** ``` | **--stream**, **-s** *name* | NestOS stream [default: stable] | | **--stream-base-url** *URL* | Base URL for NestOS stream metadata | ``` ## 自定义安装 当使用内核命令行参数从nestos live映像(ISO或PXE)运行nestos安装程序时,可以在安装程序之前或之后运行其他自定义代码。为此,请为运行安装程序的live boot指定点火配置。此配置独立于控制已安装系统的点火配置。 ## 为开发测试并安装installer install”子命令直接写入块设备(磁盘)并占用整个设备。指定给安装程序的设备必须可用且当前未使用。不能将当前装入的磁盘作为目标。 ## 开始安装 ### 1.nestos-installer在NestOS中 nestos-installer被包含在NestOS中时,可以在命令行中使用'nestos-installer'进行运行。NestOS提供的ISOimage从RAM中开始运行,使用这些image去运行nestos-installer将NestOS安装到磁盘。 ### 2.nestos-installer运行于容器内 您可以从容器中运行coreos安装程序。如果要访问主机中的文件,需要绑定/dev`和`/run/udev,以及数据目录。 ### 3.nestos-installer通过RPM安装 事实上,也可以在`podman run--privileged`类型的容器中执行此操作,该容器的配置与上面针对“预构建容器”的配置类似路径,不一定是主机的根文件系统。 ### 4.nestos-installer使用Cargo安装 可以使用nestos-installer的二进制文件,使用Rust语言的Cargo命令安装。 ### 5.nestos-installer从源代码树构建和安装 将二进制和systemd单元安装到目标rootfs ### 6.nestos-installer使用内核命令行选项从实时映像运行 如果需要完全自动安装,可以配置NestOS live CD或netboot映像以运行NestOS安装程序,然后重新启动系统。您可以通过在内核命令上传递'nestos.inst.参数来实现这一点 ### 7.作为服务运行的nestos安装程序的内核命令行选项 \* `coreos.inst.install_dev` - The block device on the system to install to, such as `/dev/sda`. Mandatory. \* `coreos.inst.stream` - Download and install the current release of NestOS from the specified stream. Optional; defaults to installing from local media if run from NestOS live ISO or PXE media, and to `stable` on other systems. \* `coreos.inst.image_url` - Download and install the specified NestOS image, overriding `coreos.inst.stream`. Optional. \* `coreos.inst.ignition_url` - The URL of the Ignition config. Optional. If missing, no Ignition config will be embedded, which is probably not what you want. \* `coreos.inst.platform_id` - The Ignition platform ID of the platform the NestOS image is being installed on. Optional; defaults to `metal`. Normally this should be specified only if installing inside a virtual machine. \* `coreos.inst.save_partlabel` - Comma-separated labels of partitions to preserve during the install. Glob-style wildcards are permitted. The specified partitions need not exist. Optional. \* `coreos.inst.save_partindex` - Comma-separated indexes of partitions to preserve during the install. Ranges (`m-n`) are permitted, and either `m` or `n` can be omitted. The specified partitions need not exist. Optional. \* `coreos.inst.insecure` - Permit the OS image to be unsigned. Optional. \* `coreos.inst.skip_reboot` - Don't reboot after installing. Optional. ### 8.使用ISOimage安装nestos ISO映像可以在传统引导(BIOS)模式或UEFI模式下安装,可以在任何一种模式下启动它,不用管安装后操作系统将从哪种模式启动。在磁盘点火image并启动或通过LOM接口使用ISO重定向,或者可以直接使用'qemu'。创建一个磁盘映像以用作安装目标。到达启动菜单后,按``(isolinux)或`'e`(grub)编辑内核命令行。将参数添加到内核命令行。 \- `coreos.inst.install_dev=/dev/sda` \- `coreos.inst.ignition_url=http://example.com/config.ign` 现在按“”(isolinux)或“”(grub)开始安装。 ## ISO嵌入点火配置 NestOS ISO映像通常用于非云平台的只读存储设备(如CD-ROM或USB记忆棒)实时引导机器。在这样的环境中,通过点火进行首次引导是困难的,因为没有定义良好的元数据端点,可能没有任何管理程序后台通道或可写磁盘,并且在内核命令行上手动输入点火URL效率很低。 由于这些原因,“nestos installer”支持ISO映像的特殊模式,其中可以将点火配置文件作为用户自定义嵌入原始映像中。然后,生成的映像可用于引导使用给定点火配置配置的实时系统。 ## Osmet CoreOS系统支持引导到实时PXE和ISO环境。这些工作使用“rootfs initrd”,其中包含要引导到的实际rootfs的压缩。与任何基于OSTree的系统一样,这个rootfs包含一个系统OSTree repo,从中硬链接对象以填充根文件系统树。 在实践中,这些环境的主要使用情形是简单地将NestOS安装到磁盘并重新引导到已安装的系统中。在过去,安装意味着从远程位置获取裸金属image并将其写入磁盘。但是,这是低效的,因为该image上的大多数数据来自相同的OSTree对象,这些对象已经存在于压缩中。 osmet功能现在允许nestos安装程序重新使用这些对象安装到磁盘上,同时仍然与裸金属image逐位匹配(“osmet”是“OSTree”和“metal”的组合) #### osmet工作机理 在合成时(即创建裸金属image时),osmet从裸金属image装载分区,并使用[FIEMAP]ioctl构建一个“OSTree对象校验和->磁盘偏移”表。 然后,它通过遍历原始image“打包”原始image,但跳过与映射的OSTree对象对应的所有块。生成的压缩image实际上只包含分区表、BIOS引导分区、inode元数据等数据。 此压缩映像通过xz过滤器传递,然后与序列化的OSTree对象表捆绑在一起,形成一个“osmet”文件。coreos assembler运行打包两次:一次用于(常规)512b扇区原始金属图像,另一次用于4k扇区图像。因此,我们最终得到两个osmet文件。然后,这些文件作为rootfs initrd的一部分包含在liveiso和PXE环境中,与squashfs一起(而不是在squashfs内部)。 在安装时(即用户启动实时环境时),nestos安装程序会检测到存在的osmet文件,并根据目标磁盘的扇区大小使用适当的文件来重新创建要写入磁盘的金属映像。解包过程与打包过程相反:它通过xz解压,然后使用反序列化的查找表,使用挂载的squashf中的OSTree对象来填充打包对象跳过的间隙。同时,它验证写入图像的校验和,以确保它与原始图像完全匹配。 ------ Osmet/filemap.rs 返回filemap文件的偏移量 Osmet/file 读取Osmet的文件内信息 Osmet/io_helpers 检查测试 Osmet/unpacker 通过casa进行打包操作 Osmet: 结构体Osmet:已注册的image分区;最终的校验和;最终image的大小; osmet打包:首先,挂载想要从:/and/boot中提取数据的两个主要分区;对启动分区进行第一次扫描,并获取超过一定大小的文件;生成主OSTree对象<-->磁盘块image,并尝试将引导文件与OSTree对象匹配;创建第一个临时文件以存储压缩image;验证重新打包将产生预期的校验和;创建要序列化的最终Osmet对象; osmet写入磁盘image:其中包含已跳过映射的扩展数据块;理想情况下,这将使用O_TMPFILE,但由于tempfile*需要*创建一个命名的tempfile,所以给它一个描述性的名称和扩展名;健全性检查写入+打包的字节数是否与块设备大小匹配; osmet需要按物理偏移量排序映射,然后按长度排序(最长优先) 代码主体结构 download:下载图像的所有工件并验证其签名 ​ 1.建立image源 ​ 2.去除压缩包后缀名(gz,xz) ​ 3.检查现有image和签名;不重新下载如果确定上次解压缩,调用将失败,因为无法检查旧签名。如果上次没有解压缩,但这次正在解压缩,那么我们就没有足够 的智能来解压缩现有文件。 ​ 4.检查现有image和签名的有效性。下载后无法解压缩image。如果由于任何原因无效,则返回错误 ​ 5.将image和签名复制到磁盘;打开output文件,下载验证image,如果相关添加签名 cmdline: 包含所有用户态输入信息,对输入信息进行模式匹配 blockdev: 1.通过标签安装分区:获取分区列表;找到具有匹配标签的分区,将其安装 ​ 2.获取分区:在输出中遍历每个设备 ​ 3.以独占方式访问设备,则返回空列表,或者返回阻止我们以独占方式访问的分区列表。尝试重新读取分区表。这是最完整的检查,但它仅适用于可分区的设备。 ​ 4.遍历分区,记录报告正在使用的分区,并返回列表(如果有) ​ 5.为设备的各个分区获取设备节点集的句柄;设备的单个分区的一组设备节点的句柄。只要需要设备节点,就必须保持;它们可能会在掉落时被移除。 install: 1.建立image源,仅支持从单个artifact安装 ​ 2.开放式输出;确保它是块设备,并且我们具有独占访问权限 ​ 3.保留计划保存的分区 ​ 4.获取对分区表的引用。对于kpartx分区,当删除时,将有条件地调用kpartx-d ​ 5.复制和后处理磁盘image,出现故障时,清除并重新读取分区表,以防止磁盘被意外使用;将image源复制到目标磁盘并执行所有后处理。如果此函数失败,调用方应擦除分区表,以确保用户不会从部分写入的磁盘启动 io: 这类似于'std::io:copy()`,但限制了复制的字节数。“Read”特性具有“take()”,但这将获得读取器的所有权;使用buf来避免每次重新初始化一个块 (std::io::copy()通过使用maybeunit来解决这个问题,但这需要使用不安全的函数) source:存入本地image源,本地osmet源,远程image源 util:1.运行提供的命令。第一个宏参数是可执行文件,将参数传递给命令。 ​ 2.运行提供的命令,捕获其stdout。 verify:验证模块;使用限制模式创建GPG主目录;导入公钥;列出刚刚导入的公钥;将密钥ID累积到信任参数中;在trustdb中标记受信任的密钥,将此操作作为一个单独的过程来执行,以将生成的日志行保留在verify输出之外;将签名写入文件;开始验证;从底层读取器读取并丢弃所有字节,并验证签名; ​