dd 引入cloud-data 提供 nocloud自动配置 (#551)
Some checks are pending
运行主程序 / 运行主程序 (./reinstall.bat --debug --password 123@@@, windows-latest) (push) Waiting to run
运行主程序 / 运行主程序 (sudo bash reinstall.sh --debug --password 123@@@, ubuntu-latest) (push) Waiting to run
同步到 CNB / 同步到 CNB (push) Waiting to run

This commit is contained in:
Heng lu 2026-02-12 22:14:04 +08:00 committed by GitHub
parent f2cfe672d1
commit fc7bdc5711
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 5 deletions

View File

@ -3746,6 +3746,22 @@ This script is outdated, please download reinstall.sh again.
cat "$frpc_config" >$initrd_dir/configs/frpc.toml
fi
# 收集 cloud-data 打包进 initrd
if [ -n "$cloud_data" ]; then
mkdir -p $initrd_dir/configs/cloud-data
if [ -d "$cloud_data" ]; then
# 本地目录:直接复制
cp "$cloud_data"/* $initrd_dir/configs/cloud-data/
else
# URL在 host 下载
for f in user-data meta-data network-config; do
curl -fsSL "$cloud_data/$f" -o "$initrd_dir/configs/cloud-data/$f" 2>/dev/null || true
done
fi
# 校验:至少要有 user-data
[ -f $initrd_dir/configs/cloud-data/user-data ] || error_and_exit "--cloud-data must contain user-data"
fi
if is_distro_like_debian $nextos_distro; then
mod_initrd_debian_kali
else
@ -3912,6 +3928,7 @@ for o in ci installer debug minimal allow-ping force-cn help \
image-name: \
boot-wim: \
img: \
cloud-data: \
lang: \
passwd: password: \
ssh-port: \
@ -4147,6 +4164,10 @@ EOF
img=$2
shift 2
;;
--cloud-data)
cloud_data=$2
shift 2
;;
--iso)
iso=$2
shift 2

View File

@ -3793,14 +3793,40 @@ EOF
rm -f $os_dir/swapfile
}
setup_nocloud() {
os_dir=$1
info "Setup NoCloud"
# 1. 配置 NoCloud-only datasource
mkdir -p "$os_dir/etc/cloud/cloud.cfg.d"
cat > "$os_dir/etc/cloud/cloud.cfg.d/99-datasource.cfg" << 'EOF'
datasource_list: [ NoCloud, None ]
datasource:
NoCloud:
seedfrom: /var/lib/cloud/seed/nocloud/
fs_label: null
EOF
# 2. 复制 seed 文件(已在 host 上准备好,打包在 initrd 中)
mkdir -p "$os_dir/var/lib/cloud/seed/nocloud"
cp /configs/cloud-data/* "$os_dir/var/lib/cloud/seed/nocloud/"
# 3. 确保 cloud-init 没有被禁用
rm -f "$os_dir/etc/cloud/cloud-init.disabled"
# 4. 清除 cloud-init 旧状态,确保首次启动重新执行
rm -rf "$os_dir/var/lib/cloud/instance"
rm -rf "$os_dir/var/lib/cloud/instances"
}
modify_os_on_disk() {
only_process=$1
info "Modify disk if is $only_process"
update_part
# dd linux 的时候不用修改硬盘内容
if [ "$distro" = "dd" ] && ! lsblk -f /dev/$xda | grep ntfs; then
# dd linux 的时候不用修改硬盘内容nocloud 模式除外)
if [ "$distro" = "dd" ] && [ "$only_process" != "nocloud" ] && ! lsblk -f /dev/$xda | grep ntfs; then
return
fi
@ -3810,12 +3836,16 @@ modify_os_on_disk() {
# btrfs挂载的是默认子卷如果没有默认子卷挂载的是根目录
# fedora 云镜像没有默认子卷且系统在root子卷中
if mount -o ro /dev/$part /os; then
if [ "$only_process" = linux ]; then
if [ "$only_process" = linux ] || [ "$only_process" = nocloud ]; then
if etc_dir=$({ ls -d /os/etc/ || ls -d /os/*/etc/; } 2>/dev/null); then
os_dir=$(dirname $etc_dir)
# 重新挂载为读写
mount -o remount,rw /os
modify_linux $os_dir
if [ "$only_process" = nocloud ]; then
setup_nocloud $os_dir
else
modify_linux $os_dir
fi
return
fi
elif [ "$only_process" = windows ]; then
@ -7229,7 +7259,11 @@ trans() {
# windows 扩容在 windows 下完成
resize_after_install_cloud_image
fi
modify_os_on_disk windows
if [ -d /configs/cloud-data ]; then
modify_os_on_disk nocloud
else
modify_os_on_disk windows
fi
;;
qemu) # dd qemu 不可能到这里,因为上面已处理
;;