Portal:MicroOS/Combustion

跳转到:导航搜索

Combustion - 首次启动时配置 MicroOS

Combustion 是 dracut 的一个最小模块,它在系统的首次启动时运行用户提供的脚本。

您可以使用它来创建其他文件、安装软件包、设置设备,甚至重新分区硬盘。配置可以作为 shell 脚本提供,从外部存储介质加载,并在新的系统快照期间启动时运行。成功后,系统将直接启动到该新的快照中,因此无需重启。

可以使用 Ignition & Combustion Config Generator 创建 Ignition 和 Combustion 脚本。

视频演示 https://youtu.be/BHaPdJc8_zQ?t=190


您需要的东西

设置一个专用的 USB 驱动器,并带有标记为“combustion”(与 MicroOS 安装介质分开)的分区。

在该分区内,您将文件夹命名为“combustion”。

最后,在该文件夹内,您将一个文件命名为“script”,它将包含您的 bash 脚本。请注意,该文件不必是 .sh 文件。

然后,配置文件将从带有 LABEL “combustion” 的文件系统复制。

注意:为了与 Ignition 兼容并可共存,LABEL “ignition” 用作回退。

MicroOS 期望在文件系统的根目录下有一个名为“combustion”的目录,并在其中有一个名为“script”的文件,该文件将在事务更新 shell 中执行。

<root directory>
├── combustion
│   ├── script
│   └── ... other files
└── ignition (optional)
    └── config.ign

您可以从该脚本中执行所有必要的初始系统配置,包括添加 ssh 密钥、安装软件包、管理用户,甚至进行分区更改。

简单的 USB 驱动器格式化和添加配置示例

以下是格式化 USB 驱动器和添加配置的示例,它将安装“vim-small”软件包并启用 sshd

mkfs.ext4 /dev/sdX
e2label /dev/sdX ignition
mount /dev/sdX /mnt
mkdir -p /mnt/combustion/
cat >/mnt/combustion/script <<EOF


现在您已经设置了分区和文件夹,可以使用下面的示例“script”文件,并添加您想要的任何其他内容。

#!/bin/sh
# combustion: network
systemctl enable sshd.service
zypper --non-interactive install vim-small
EOF
echo "Hello User!" >/mnt/combustion/welcome
umount /mnt

“# combustion: network”注释会在运行脚本之前触发网络初始化。这相当于在内核命令行中传递“rd.neednet=1”,因此网络配置参数(man dracut.cmdline)也适用于此处。如果未指定这些参数,则默认情况下每个可用接口都使用“ip=dhcp”。

更复杂的配置示例

此脚本还提供启动期间可见的反馈,设置密码并复制公共 ssh 密钥(必须在“combustion”文件夹中)。

#!/bin/bash
# combustion: network
# Redirect output to the console
exec > >(exec tee -a /dev/tty0) 2>&1
# Set a password for root, generate the hash with "openssl passwd -6"
echo 'root:$5$.wn2BZHlEJ5R3B1C$TAHEchlU.h2tvfOpOki54NaHpGYKwdNhjaBuSpDotD7' | chpasswd -e
# Add a public ssh key and enable sshd
mkdir -pm700 /root/.ssh/
cat id_rsa_new.pub >> /root/.ssh/authorized_keys
systemctl enable sshd.service
# Install vim-small
zypper --non-interactive install vim-small
# Leave a marker
echo "Configured with combustion" > /etc/issue.d/combustion
# Close outputs and wait for tee to finish.
exec 1>&- 2>&-; wait;

关于 QEMU 的特别说明

如果找到名为“opt/org.opensuse.combustion/script”的 QEMU fw_cfg blob,则优先使用该内容作为脚本。QEMU 参数示例

-fw_cfg name=opt/org.opensuse.combustion/script,file=/var/combustion-script

在 libvirt 中使用 fw_cfg qemu 功能

如果您使用 libvirt 和 qemu/kvm 运行虚拟机,可以通过编辑为创建的 VM 的 libvirt XML 使 combustion 文件可用。您可以使用 virt-manager UI 或 virsh edit

<domain> 部分下,插入以下 XML 部分:

 <sysinfo type="fwcfg">
   <entry name="opt/org.opensuse.combustion/script" file="/location/for/your/file/script"/>
 </sysinfo>

您也可以在创建 VM 时使用 virt-install--sysinfo 选项来使用它:

 --sysinfo type=fwcfg,entry0.name="opt/org.opensuse.combustion/script",entry0.file="/location/for/your/file/script" \

链接

https://github.com/openSUSE/combustion?tab=readme-ov-file https://build.opensuse.org/package/show/devel:kubic:ignition/combustion

更多 combustion 脚本示例:https://code.opensuse.org/adathor/combustion-dotconf