Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions reinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: \
Expand Down Expand Up @@ -4147,6 +4164,10 @@ EOF
img=$2
shift 2
;;
--cloud-data)
cloud_data=$2
shift 2
;;
--iso)
iso=$2
shift 2
Expand Down
44 changes: 39 additions & 5 deletions trans.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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 不可能到这里,因为上面已处理
;;
Expand Down