mirror of
https://github.com/bin456789/reinstall.git
synced 2026-03-22 04:24:17 +08:00
Compare commits
5 Commits
f2cfe672d1
...
99b99cc7ac
| Author | SHA1 | Date | |
|---|---|---|---|
| 99b99cc7ac | |||
| 81081873df | |||
| 4cf8e81fc7 | |||
| ff4b6de258 | |||
| fc7bdc5711 |
19
README.en.md
19
README.en.md
@ -248,9 +248,28 @@ bash reinstall.sh dd --img "https://example.com/xxx.xz"
|
||||
- `--ssh-port PORT` Change SSH port (for log observation during installation)
|
||||
- `--web-port PORT` Change Web port (for log observation during installation)
|
||||
- `--frpc-toml PATH` Add frpc for intranet tunneling (DD Windows only). Parameter can be local filepath or HTTP URL
|
||||
- `--cloud-data PATH_OR_URL` Inject cloud-init NoCloud configuration into the DD'd Linux image (DD Linux only)
|
||||
- `--hold 1` Reboot only into install environment, without running installer, only for SSH connect to test network connection.
|
||||
- `--hold 2` Prevent reboot after the DD process finishes. For SSH login to modify system content. The Windows system will be mounted at `/os`, but Linux systems will **NOT** be automatically mounted.
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> `--cloud-data` accepts a local directory path or an HTTP base URL. The directory must contain a `user-data` file; `meta-data` and `network-config` are optional:
|
||||
>
|
||||
> ```
|
||||
> seed/
|
||||
> ├── user-data # required
|
||||
> ├── meta-data # optional
|
||||
> └── network-config # optional
|
||||
> ```
|
||||
>
|
||||
> ```bash
|
||||
> # Local directory
|
||||
> bash reinstall.sh dd --img "https://example.com/xxx.xz" --cloud-data /path/to/seed/
|
||||
> # HTTP directory
|
||||
> bash reinstall.sh dd --img "https://example.com/xxx.xz" --cloud-data "https://example.com/seed/"
|
||||
> ```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> Can monitor the progress through various methods (SSH, HTTP 80 port, VNC from server provider, serial console).
|
||||
|
||||
19
README.md
19
README.md
@ -248,9 +248,28 @@ bash reinstall.sh dd --img "https://example.com/xxx.xz"
|
||||
- `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志用)
|
||||
- `--web-port PORT` 修改 Web 端口(安装期间观察日志用)
|
||||
- `--frpc-toml PATH` 添加 frpc 内网穿透(仅限 DD Windows),参数填本地路径或 HTTP 链接
|
||||
- `--cloud-data PATH_OR_URL` 为 DD Linux 镜像注入 cloud-init NoCloud 配置(仅限 DD Linux)
|
||||
- `--hold 1` 仅重启到安装环境,不运行安装,用于 SSH 登录验证网络连通性
|
||||
- `--hold 2` DD 结束后不重启,用于 SSH 登录修改系统内容,Windows 系统会挂载在 `/os`,Linux 系统**不会**自动挂载
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> `--cloud-data` 参数为本地目录或 HTTP 基础 URL,目录须包含 `user-data` 文件,`meta-data`、`network-config` 可选:
|
||||
>
|
||||
> ```
|
||||
> seed/
|
||||
> ├── user-data # 必须
|
||||
> ├── meta-data # 可选
|
||||
> └── network-config # 可选
|
||||
> ```
|
||||
>
|
||||
> ```bash
|
||||
> # 使用本地目录
|
||||
> bash reinstall.sh dd --img "https://example.com/xxx.xz" --cloud-data /path/to/seed/
|
||||
> # 使用 HTTP 目录
|
||||
> bash reinstall.sh dd --img "https://example.com/xxx.xz" --cloud-data "https://example.com/seed/"
|
||||
> ```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> 可通过多种方式(SSH、HTTP 80 端口、商家后台 VNC、串行控制台)查看安装进度。
|
||||
|
||||
70
reinstall.sh
70
reinstall.sh
@ -305,6 +305,10 @@ get_host_by_url() {
|
||||
cut -d/ -f3 <<<$1
|
||||
}
|
||||
|
||||
get_scheme_and_host_by_url() {
|
||||
cut -d/ -f1-3 <<<$1
|
||||
}
|
||||
|
||||
get_function() {
|
||||
declare -f "$1"
|
||||
}
|
||||
@ -882,8 +886,14 @@ find_windows_iso() {
|
||||
full_lang=$(english)
|
||||
|
||||
case "$basearch" in
|
||||
x86_64) arch_win=x64 ;;
|
||||
aarch64) arch_win=arm64 ;;
|
||||
x86_64)
|
||||
arch_win=x64
|
||||
arch_win_vlsc=64bit
|
||||
;;
|
||||
aarch64)
|
||||
arch_win=arm64
|
||||
arch_win_vlsc=arm64
|
||||
;;
|
||||
esac
|
||||
|
||||
get_windows_iso_link
|
||||
@ -1009,6 +1019,9 @@ get_windows_iso_link() {
|
||||
pro | education | enterprise | 'pro education' | 'pro for workstations') echo pro ;;
|
||||
esac
|
||||
;;
|
||||
2025)
|
||||
echo SrvSTDCORE
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@ -1086,10 +1099,17 @@ get_windows_iso_link() {
|
||||
if [ -n "$label_msdl" ]; then
|
||||
iso=$(curl -L "$page_url" | grep -ioP 'https://[^ ]+?#[0-9]+' | head -1 | grep .)
|
||||
else
|
||||
http_to_host=$(get_scheme_and_host_by_url "$page_url")
|
||||
http_to_current_dir=$(dirname "$page_url")
|
||||
curl -L "$page_url" |
|
||||
tr -d '\n' | sed -e 's,<a ,\n<a ,g' -e 's,</a>,</a>\n,g' | # 使每个 <a></a> 占一行
|
||||
grep -Ei '\.(iso|img)</a>$' | # 找出是 iso 或 img 的行
|
||||
sed -E 's,<a href="?([^" ]+)"?.+>(.+)</a>,\2 \1,' >$tmp/win.list # 提取文件名和链接
|
||||
# 提取文件名和链接
|
||||
# 如果链接是 / 开头,则补全域名
|
||||
# 如果链接非 https:// 开头,则补全域名和目录
|
||||
sed -E -e 's,<a href="?([^" ]+)"?.+>(.+)</a>,\2 \1,' \
|
||||
-e "s, (/), $http_to_host\1," |
|
||||
awk '{if ($2 !~ /^https?:\/\//) $2 = "'$http_to_current_dir/'" $2; print}' >$tmp/win.list
|
||||
|
||||
# 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的
|
||||
# 例如查找 windows 10 iot enterprise,会得到
|
||||
@ -1136,8 +1156,11 @@ get_windows_iso_link_inner() {
|
||||
fi
|
||||
|
||||
# vlsc
|
||||
# SW_DVD5_Win_10_IOT_Enterprise_2015_LTSB_64Bit_EMB_English_OEM_X20-20063.IMG
|
||||
# SW_DVD9_Win_Pro_10_22H2.15_Arm64_English_Pro_Ent_EDU_N_MLF_X23-67223.ISO
|
||||
# SWDVD9_WinSrvSTDCORE2025_24H2.16_64Bit_English_DC_STD_MLF_RTMUpdJan26_X24-26760.iso
|
||||
if [ -n "$label_vlsc" ]; then
|
||||
regex="sw_dvd[59]_win_${label_vlsc}_${version}.*${arch_win}_${full_lang}.*.(iso|img)"
|
||||
regex="sw_?dvd[59]_win_?${label_vlsc}_?${version}.*${arch_win_vlsc}_${full_lang}.*.(iso|img)"
|
||||
regexs+=("$regex")
|
||||
fi
|
||||
|
||||
@ -1654,15 +1677,9 @@ Continue with DD?
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$basearch" = aarch64 ]; then
|
||||
if [ -z "$iso" ]; then
|
||||
IFS= read -r -p "ISO Link: " iso
|
||||
if [ -z "$iso" ]; then
|
||||
error_and_exit "ISO Link is empty."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
iso=$(curl -L https://fnnas.com/ | grep -o -m1 'https://[^"]*\.iso')
|
||||
# 对于同一行有多个成功匹配,grep -m1 无效
|
||||
iso=$(curl -L "https://fnnas.com/download$([ "$basearch" = aarch64 ] && echo -arm)" |
|
||||
grep -o 'https://[^"]*\.iso' | head -1 | grep .)
|
||||
|
||||
# curl 7.82.0+
|
||||
# curl -L --json '{"url":"'$iso'"}' https://www.fnnas.com/api/download-sign
|
||||
@ -1672,7 +1689,6 @@ Continue with DD?
|
||||
-H 'Content-Type: application/json' \
|
||||
https://www.fnnas.com/api/download-sign |
|
||||
grep -o 'https://[^"]*')
|
||||
fi
|
||||
|
||||
test_url "$iso" iso
|
||||
eval "${step}_iso='$iso'"
|
||||
@ -3746,6 +3762,23 @@ 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"
|
||||
cloud_data_files=$(ls $initrd_dir/configs/cloud-data/ | tr '\n' ' ')
|
||||
fi
|
||||
|
||||
if is_distro_like_debian $nextos_distro; then
|
||||
mod_initrd_debian_kali
|
||||
else
|
||||
@ -3912,6 +3945,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 +4181,10 @@ EOF
|
||||
img=$2
|
||||
shift 2
|
||||
;;
|
||||
--cloud-data)
|
||||
cloud_data=$2
|
||||
shift 2
|
||||
;;
|
||||
--iso)
|
||||
iso=$2
|
||||
shift 2
|
||||
@ -4655,6 +4693,10 @@ if is_netboot_xyz; then
|
||||
elif is_alpine_live; then
|
||||
echo 'Reboot to start Alpine Live OS.'
|
||||
elif is_use_dd; then
|
||||
if [ -n "$cloud_data" ]; then
|
||||
echo "Cloud Data: $cloud_data"
|
||||
echo "Cloud Data Files: $cloud_data_files"
|
||||
fi
|
||||
show_dd_password_tips
|
||||
echo 'Reboot to start DD.'
|
||||
elif [ "$distro" = fnos ]; then
|
||||
|
||||
40
trans.sh
40
trans.sh
@ -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
|
||||
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
|
||||
if [ -d /configs/cloud-data ]; then
|
||||
modify_os_on_disk nocloud
|
||||
else
|
||||
modify_os_on_disk windows
|
||||
fi
|
||||
;;
|
||||
qemu) # dd qemu 不可能到这里,因为上面已处理
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user