Compare commits

..

2 Commits

Author SHA1 Message Date
bin456789
57542c4cbf core: 添加 reset 模式取消重装 2026-03-09 01:11:58 +08:00
bin456789
9a264250f1 core: 不重要的更改 2026-03-09 00:02:34 +08:00
5 changed files with 279 additions and 259 deletions

View File

@@ -51,7 +51,7 @@ The system requirements for the target system are as follows:
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.20, 3.21, 3.22, 3.23 | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.20, 3.21, 3.22, 3.23 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | Rolling | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | Rolling | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 18.04 LTS - 26.04 LTS | 512 MB \* | 2 GB | | <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.10 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB |
@@ -168,7 +168,7 @@ bash reinstall.sh anolis 7|8|23
alpine 3.20|3.21|3.22|3.23 alpine 3.20|3.21|3.22|3.23
opensuse 15.6|16.0|tumbleweed opensuse 15.6|16.0|tumbleweed
openeuler 20.03|22.03|24.03|25.09 openeuler 20.03|22.03|24.03|25.09
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal] ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
kali kali
arch arch
gentoo gentoo
@@ -337,15 +337,15 @@ bash reinstall.sh netboot.xyz
- Windows (Vista ~ 11) - Windows (Vista ~ 11)
- Windows Server (2008 ~ 2025) - Windows Server (2008 ~ 2025)
- Windows Server Essentials - Windows Server Essentials \*
- Windows Server (Semi) Annual Channel - Windows Server (Semi) Annual Channel \*
- Hyper-V Server - Hyper-V Server \*
- Azure Local (Azure Stack HCI) - Azure Local (Azure Stack HCI) \*
#### Method 1: Let the Script Automatically Search for ISO #### Method 1: Let the Script Automatically Search for ISO
- The script will search for ISOs from <https://massgrave.dev/genuine-installation-media>, a site that collects official ISOs. - The script will search for ISOs from <https://massgrave.dev/genuine-installation-media>, a site that collects official ISOs.
- Only supports ISOs searching for Windows 10, 11, Server 2019, 2022, 2025. - Systems marked with \* do not support automatic ISO searching.
```bash ```bash
bash reinstall.sh windows \ bash reinstall.sh windows \

View File

@@ -51,7 +51,7 @@
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.20, 3.21, 3.22, 3.23 | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.20, 3.21, 3.22, 3.23 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | 滚动 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | 滚动 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 18.04 LTS - 26.04 LTS | 512 MB \* | 2 GB | | <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.10 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB |
@@ -168,7 +168,7 @@ bash reinstall.sh anolis 7|8|23
alpine 3.20|3.21|3.22|3.23 alpine 3.20|3.21|3.22|3.23
opensuse 15.6|16.0|tumbleweed opensuse 15.6|16.0|tumbleweed
openeuler 20.03|22.03|24.03|25.09 openeuler 20.03|22.03|24.03|25.09
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal] ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
kali kali
arch arch
gentoo gentoo
@@ -337,15 +337,15 @@ bash reinstall.sh netboot.xyz
- Windows (Vista ~ 11) - Windows (Vista ~ 11)
- Windows Server (2008 ~ 2025) - Windows Server (2008 ~ 2025)
- Windows Server Essentials - Windows Server Essentials \*
- Windows Server (Semi) Annual Channel - Windows Server (Semi) Annual Channel \*
- Hyper-V Server - Hyper-V Server \*
- Azure Local (Azure Stack HCI) - Azure Local (Azure Stack HCI) \*
#### 方法 1: 让脚本自动查找 ISO #### 方法 1: 让脚本自动查找 ISO
- 脚本会从 <https://massgrave.dev/genuine-installation-media> 查找 ISO该网站专门提供官方 ISO 下载 - 脚本会从 <https://massgrave.dev/genuine-installation-media> 查找 ISO该网站专门提供官方 ISO 下载
- 只支持查找 Windows 10, 11, Server 2019, 2022, 2025 的 ISO - 上面带 \* 的系统不支持自动查找 ISO
```bash ```bash
bash reinstall.sh windows \ bash reinstall.sh windows \

View File

@@ -33,9 +33,7 @@ export LC_ALL=C
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
# 如果不是 bash 的话,继续执行会有语法错误,因此在这里判断是否 bash # 如果不是 bash 的话,继续执行会有语法错误,因此在这里判断是否 bash
if [ -z "$BASH" ] || if [ -z "$BASH" ]; then
# el 的 sh 是 bash 运行在 posix 模式,依然有 $BASH 和 $BASH_VERSION
{ [ -n "$BASH" ] && [ -n "$POSIXLY_CORRECT" ]; }; then
if ! command -v bash >/dev/null; then if ! command -v bash >/dev/null; then
if [ -f /etc/alpine-release ]; then if [ -f /etc/alpine-release ]; then
if ! apk add bash; then if ! apk add bash; then
@@ -89,7 +87,7 @@ Usage: $reinstall_____ anolis 7|8|23
alpine 3.20|3.21|3.22|3.23 alpine 3.20|3.21|3.22|3.23
opensuse 15.6|16.0|tumbleweed opensuse 15.6|16.0|tumbleweed
openeuler 20.03|22.03|24.03|25.09 openeuler 20.03|22.03|24.03|25.09
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal] ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
kali kali
arch arch
gentoo gentoo
@@ -488,11 +486,10 @@ fix_file_type() {
-e 's/[,;#]//g' \ -e 's/[,;#]//g' \
-e 's/^[[:space:]]*//' \ -e 's/^[[:space:]]*//' \
-e 's/(POSIX|Unicode|UTF-8|ASCII)//gi' \ -e 's/(POSIX|Unicode|UTF-8|ASCII)//gi' \
-e 's/^DOS\/MBR boot sector/raw/i' \ -e 's/DOS\/MBR boot sector/raw/i' \
-e 's/^x86 boot sector/raw/i' \ -e 's/x86 boot sector/raw/i' \
-e 's/^Zstandard/zstd/i' \ -e 's/Zstandard/zstd/i' \
-e 's/^UDF/iso/i' \ -e 's/Windows imaging \(WIM\) image/wim/i' |
-e 's/^Windows imaging \(WIM\) image/wim/i' |
awk '{print $1}' | to_lower awk '{print $1}' | to_lower
} }
@@ -912,7 +909,17 @@ get_windows_iso_link() {
get_label_msdn() { get_label_msdn() {
if [ -n "$server" ]; then if [ -n "$server" ]; then
case "$version" in case "$version" in
2019 | 2022 | 2025) 2008 | '2008 r2')
case "$edition" in
serverweb | serverwebcore) echo _ ;;
serverstandard | serverstandardcore) echo _ ;;
serverenterprise | serverenterprisecore) echo _ ;;
serverdatacenter | serverdatacentercore) echo _ ;;
esac
;;
# massgrave 不提供 2012 下载
'2012 r2' | \
2016 | 2019 | 2022 | 2025)
case "$edition" in case "$edition" in
serverstandard | serverstandardcore) echo _ ;; serverstandard | serverstandardcore) echo _ ;;
serverdatacenter | serverdatacentercore) echo _ ;; serverdatacenter | serverdatacentercore) echo _ ;;
@@ -921,6 +928,39 @@ get_windows_iso_link() {
esac esac
else else
case "$version" in case "$version" in
vista)
case "$edition" in
starter)
case "$arch_win" in
x86) echo _ ;;
esac
;;
homebasic | homepremium | ultimate) echo _ ;;
business | enterprise) echo "$edition" ;;
esac
;;
7)
case "$edition" in
starter)
case "$arch_win" in
x86) echo starter ;;
esac
;;
homebasic)
case "$arch_win" in
x86) echo "home basic" ;;
esac
;;
homepremium) echo "home premium" ;;
professional | enterprise | ultimate) echo "$edition" ;;
esac
;;
8 | 8.1)
case "$edition" in
'') echo _ ;; # windows 8.x core
pro | enterprise) echo "$edition" ;;
esac
;;
10) 10)
case "$edition" in case "$edition" in
home | 'home single language') echo consumer ;; home | 'home single language') echo consumer ;;
@@ -934,8 +974,9 @@ get_windows_iso_link() {
# iot # iot
'iot enterprise') echo 'iot enterprise' ;; 'iot enterprise') echo 'iot enterprise' ;;
# iot ltsc # iot ltsc
'iot enterprise ltsc 2021') echo "$edition" ;; 'iot enterprise ltsc 2019' | 'iot enterprise ltsc 2021') echo "$edition" ;;
# ltsc # ltsc
'enterprise 2015 ltsb' | 'enterprise 2016 ltsb' | 'enterprise ltsc 2019') echo "$edition" ;;
'enterprise ltsc 2021') 'enterprise ltsc 2021')
# arm64 的 enterprise ltsc 2021 要下载 iot enterprise ltsc 2021 iso # arm64 的 enterprise ltsc 2021 要下载 iot enterprise ltsc 2021 iso
case "$arch_win" in case "$arch_win" in
@@ -996,7 +1037,13 @@ get_windows_iso_link() {
# win10 22h2 arm 有每月发布的 iso因此不从 msdl 下载 # win10 22h2 arm 有每月发布的 iso因此不从 msdl 下载
# win10/11 ltsc 没有每月发布的 iso但是 msdl 没有 ltsc 版本 # win10/11 ltsc 没有每月发布的 iso但是 msdl 没有 ltsc 版本
get_label_msdl() { get_label_msdl() {
: case "$version" in
8.1)
case "$edition" in
'' | pro) echo _ ;;
esac
;;
esac
} }
get_page() { get_page() {
@@ -1008,7 +1055,7 @@ get_windows_iso_link() {
echo server echo server
else else
case "$version" in case "$version" in
10 | 11) vista | 7 | 8 | 8.1 | 10 | 11)
echo "$version" echo "$version"
;; ;;
esac esac
@@ -1025,7 +1072,9 @@ get_windows_iso_link() {
label_vlsc=$(get_label_vlsc) label_vlsc=$(get_label_vlsc)
page=$(get_page) page=$(get_page)
if [ "$page" = server ]; then if [ "$page" = vista ]; then
page_url=https://massgrave.dev/windows_vista__links
elif [ "$page" = server ]; then
page_url=https://massgrave.dev/windows-server-links page_url=https://massgrave.dev/windows-server-links
else else
page_url=https://massgrave.dev/windows_${page}_links page_url=https://massgrave.dev/windows_${page}_links
@@ -1309,11 +1358,12 @@ Continue?
setos_ubuntu() { setos_ubuntu() {
case "$releasever" in case "$releasever" in
16.04) codename=xenial ;;
18.04) codename=bionic ;; 18.04) codename=bionic ;;
20.04) codename=focal ;; 20.04) codename=focal ;;
22.04) codename=jammy ;; 22.04) codename=jammy ;;
24.04) codename=noble ;; 24.04) codename=noble ;;
26.04) codename=resolute ;; 25.10) codename=questing ;; # non-lts
esac esac
if is_use_cloud_image; then if is_use_cloud_image; then
@@ -1337,19 +1387,24 @@ Continue?
[ "$basearch_alt" = amd64 ] || [ "${releasever%.*}" -ge 24 ] [ "$basearch_alt" = amd64 ] || [ "${releasever%.*}" -ge 24 ]
} }
basearch_img=$basearch_alt get_suffix() {
if [ "$basearch_alt" = amd64 ] && [ "${releasever%.*}" -ge 26 ] && is_cpu_supports_x86_64_v3; then if [ "$releasever" = 16.04 ]; then
basearch_img=amd64v3 if is_efi; then
fi echo -uefi1
else
echo -disk1
fi
fi
}
if [ "$minimal" = 1 ]; then if [ "$minimal" = 1 ]; then
if ! is_have_minimal_image; then if ! is_have_minimal_image; then
error_and_exit "Minimal cloud image is not available for $releasever $basearch_alt." error_and_exit "Minimal cloud image is not available for $releasever $basearch_alt."
fi fi
eval ${step}_img="$ci_mirror/minimal/releases/$codename/release/ubuntu-$releasever-minimal-cloudimg-$basearch_img.img" eval ${step}_img="$ci_mirror/minimal/releases/$codename/release/ubuntu-$releasever-minimal-cloudimg-$basearch_alt$(get_suffix).img"
else else
# 用 codename 而不是 releasever可减少一次跳转 # 用 codename 而不是 releasever可减少一次跳转
eval ${step}_img="$ci_mirror/releases/$codename/release/ubuntu-$releasever-server-cloudimg-$basearch_img.img" eval ${step}_img="$ci_mirror/releases/$codename/release/ubuntu-$releasever-server-cloudimg-$basearch_alt$(get_suffix).img"
fi fi
else else
# 传统安装 # 传统安装
@@ -1631,20 +1686,18 @@ Continue with DD?
fi fi
done done
if [ -z "$iso" ]; then # 对于同一行有多个成功匹配grep -m1 无效
# 对于同一行有多个成功匹配grep -m1 无效 iso=$(curl -L "https://fnnas.com/download$([ "$basearch" = aarch64 ] && echo -arm)" |
iso=$(curl -L "https://fnnas.com/download$([ "$basearch" = aarch64 ] && echo -arm)" | grep -o 'https://[^"]*\.iso' | head -1 | grep .)
grep -o 'https://[^"]*\.iso' | head -1 | grep .)
# curl 7.82.0+ # curl 7.82.0+
# curl -L --json '{"url":"'$iso'"}' https://www.fnnas.com/api/download-sign # curl -L --json '{"url":"'$iso'"}' https://www.fnnas.com/api/download-sign
iso=$(curl -L \ iso=$(curl -L \
-d '{"url":"'$iso'"}' \ -d '{"url":"'$iso'"}' \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
https://www.fnnas.com/api/download-sign | https://www.fnnas.com/api/download-sign |
grep -o 'https://[^"]*') grep -o 'https://[^"]*')
fi
test_url "$iso" iso test_url "$iso" iso
eval "${step}_iso='$iso'" eval "${step}_iso='$iso'"
@@ -1920,7 +1973,7 @@ verify_os_name() {
'opensuse 15.6|16.0|tumbleweed' \ 'opensuse 15.6|16.0|tumbleweed' \
'alpine 3.20|3.21|3.22|3.23' \ 'alpine 3.20|3.21|3.22|3.23' \
'openeuler 20.03|22.03|24.03|25.09' \ 'openeuler 20.03|22.03|24.03|25.09' \
'ubuntu 18.04|20.04|22.04|24.04|26.04' \ 'ubuntu 16.04|18.04|20.04|22.04|24.04|25.10' \
'redhat' \ 'redhat' \
'kali' \ 'kali' \
'arch' \ 'arch' \
@@ -2265,7 +2318,7 @@ check_ram() {
is_efi() { is_efi() {
if is_in_windows; then if is_in_windows; then
# bcdedit | grep -qi '^path.*\.efi' # bcdedit | grep -qi '^path.*\.efi'
mountvol | grep -q -a 'EFI' mountvol | grep -q --text 'EFI'
else else
[ -d /sys/firmware/efi ] [ -d /sys/firmware/efi ]
fi fi
@@ -2316,7 +2369,7 @@ is_use_local_extlinux() {
is_mbr_using_grub() { is_mbr_using_grub() {
find_main_disk find_main_disk
# 各发行版不一定自带 strings hexdump xxd od 命令 # 各发行版不一定自带 strings hexdump xxd od 命令
head -c 440 /dev/$xda | grep -a -iq 'GRUB' head -c 440 /dev/$xda | grep --text -iq 'GRUB'
} }
to_upper() { to_upper() {
@@ -2910,7 +2963,7 @@ install_grub_linux_efi() {
info 'download grub efi' info 'download grub efi'
# fedora 39 的 efi 无法识别 opensuse tumbleweed 的 xfs # fedora 39 的 efi 无法识别 opensuse tumbleweed 的 xfs
efi_distro=fedora efi_distro=opensuse
grub_efi=$(get_grub_efi_filename) grub_efi=$(get_grub_efi_filename)
@@ -3060,7 +3113,7 @@ install_grub_win() {
# 添加引导 # 添加引导
# 脚本可能不是首次运行,所以先删除原来的 # 脚本可能不是首次运行,所以先删除原来的
id='{1c41f649-1637-52f1-aea8-f96bfebeecc8}' id='{1c41f649-1637-52f1-aea8-f96bfebeecc8}'
bcdedit /enum all | grep -a $id && bcdedit /delete $id bcdedit /enum all | grep --text $id && bcdedit /delete $id
bcdedit /create $id /d "$(get_entry_name)" /application bootsector bcdedit /create $id /d "$(get_entry_name)" /application bootsector
bcdedit /set $id device partition=$c: bcdedit /set $id device partition=$c:
bcdedit /set $id path \\g2ldr bcdedit /set $id path \\g2ldr
@@ -3480,15 +3533,8 @@ EOF
for driver in $(get_disk_drivers $xda); do for driver in $(get_disk_drivers $xda); do
echo "using driver: $driver" echo "using driver: $driver"
case $driver in case $driver in
nvme) nvme) extra_drivers+=" nvme nvme-core" ;;
extra_drivers+=" nvme nvme-core" # xen 的横杠特别不同
# debian 13+ / kali 有 nvme-auth 模块
# 添加后才能识别 nvme 硬盘
if grep -q nvme-auth lib/modules/$kver/modules.order; then
extra_drivers+=" nvme-auth"
fi
;;
# xen 的横杠特别不同
xen_blkfront) extra_drivers+=" xen-blkfront" ;; xen_blkfront) extra_drivers+=" xen-blkfront" ;;
xen_scsifront) extra_drivers+=" xen-scsifront" ;; xen_scsifront) extra_drivers+=" xen-scsifront" ;;
virtio_blk | virtio_scsi | hv_storvsc | vmw_pvscsi) extra_drivers+=" $driver" ;; virtio_blk | virtio_scsi | hv_storvsc | vmw_pvscsi) extra_drivers+=" $driver" ;;
@@ -3869,7 +3915,7 @@ This script is outdated, please download reinstall.sh again.
# -c Identical to "-H newc", use the new (SVR4) # -c Identical to "-H newc", use the new (SVR4)
# portable format.If you wish the old portable # portable format.If you wish the old portable
# (ASCII) archive format, use "-H odc" instead. # (ASCII) archive format, use "-H odc" instead.
find . | cpio --quiet -o -H newc -R 0:0 | gzip -1 >/reinstall-initrd find . | cpio --quiet -o -H newc | gzip -1 >/reinstall-initrd
cd - >/dev/null cd - >/dev/null
} }
@@ -3915,6 +3961,7 @@ remove_useless_initrd_files() {
net/wireless \ net/wireless \
net/bluetooth \ net/bluetooth \
drivers/hid \ drivers/hid \
drivers/mmc \
drivers/mtd \ drivers/mtd \
drivers/usb \ drivers/usb \
drivers/ssb \ drivers/ssb \
@@ -4150,12 +4197,12 @@ remove_exist_reinstall() {
remove_exist_reinstall_efi_dir remove_exist_reinstall_efi_dir
bcdedit /set '{fwbootmgr}' bootsequence '{bootmgr}' bcdedit /set '{fwbootmgr}' bootsequence '{bootmgr}'
bcdedit /enum bootmgr | grep -a -B3 'reinstall' | awk '{print $2}' | grep '{.*}' | bcdedit /enum bootmgr | grep --text -B3 'reinstall' | awk '{print $2}' | grep '{.*}' |
xargs -I {} cmd /c bcdedit /delete {} xargs -I {} cmd /c bcdedit /delete {}
else else
# bios # bios
id='{1c41f649-1637-52f1-aea8-f96bfebeecc8}' id='{1c41f649-1637-52f1-aea8-f96bfebeecc8}'
if bcdedit /enum all | grep -a "$id"; then if bcdedit /enum all | grep --text "$id"; then
bcdedit /delete "$id" bcdedit /delete "$id"
fi fi
fi fi
@@ -4179,7 +4226,7 @@ remove_exist_reinstall() {
# 删除 reinstall 条目 # 删除 reinstall 条目
if [ -f "$target_cfg" ]; then if [ -f "$target_cfg" ]; then
sed -i "/^$BOOT_ENTEY_START_MARK/,/^$BOOT_ENTEY_END_MARK/d" "$target_cfg" sed -i "/^$BOOT_ENTEY_START_MARK/,/^$BOOT_ENTEY_END_MARK/d}" "$target_cfg"
fi fi
# 清除 next entry # 清除 next entry

361
trans.sh
View File

@@ -1,6 +1,6 @@
#!/bin/ash #!/bin/ash
# shellcheck shell=dash # shellcheck shell=dash
# shellcheck disable=SC2086,SC3047,SC3036,SC3010,SC3001,SC3060,SC3015 # shellcheck disable=SC2086,SC3047,SC3036,SC3010,SC3001,SC3060
# alpine 默认使用 busybox ash # alpine 默认使用 busybox ash
# 注意 bash 和 ash 以下语句结果不同 # 注意 bash 和 ash 以下语句结果不同
# [[ a = '*a' ]] && echo 1 # [[ a = '*a' ]] && echo 1
@@ -1263,13 +1263,6 @@ networking = {
EOF EOF
for ethx in $(get_eths); do for ethx in $(get_eths); do
# ipv4 使用 DHCP 时显式开启 useDHCP
if is_dhcpv4; then
cat <<EOF >>$conf_file
interfaces.$ethx.useDHCP = true;
EOF
fi
# ipv4 # ipv4
if is_staticv4; then if is_staticv4; then
get_netconf_to ipv4_addr get_netconf_to ipv4_addr
@@ -2542,22 +2535,6 @@ is_xda_gt_2t() {
[ "$disk_size" -gt "$disk_2t" ] [ "$disk_size" -gt "$disk_2t" ]
} }
is_ends_with_digit() {
[[ "$1" =~ [0-9]$ ]]
}
xda() {
if [ -n "$1" ]; then
if is_ends_with_digit "$xda"; then
echo "${xda}p$1"
else
echo "${xda}$1"
fi
else
echo "$xda"
fi
}
create_part() { create_part() {
# 除了 dd 都会用到 # 除了 dd 都会用到
info "Create Part" info "Create Part"
@@ -2572,6 +2549,7 @@ create_part() {
# TODO: 先检测iso链接/各种链接 # TODO: 先检测iso链接/各种链接
# wipefs -a /dev/$xda # wipefs -a /dev/$xda
# xda*1 星号用于 nvme0n1p1 的字母 p
# shellcheck disable=SC2154 # shellcheck disable=SC2154
if [ "$distro" = windows ]; then if [ "$distro" = windows ]; then
if ! size_bytes=$(get_link_file_size "$iso"); then if ! size_bytes=$(get_link_file_size "$iso"); then
@@ -2604,10 +2582,10 @@ create_part() {
set 3 msftdata on set 3 msftdata on
update_part update_part
mkfs.fat -n efi "/dev/$(xda 1)" #1 efi mkfs.fat -n efi /dev/$xda*1 #1 efi
dd if=/dev/zero of="/dev/$(xda 2)" bs=1M count=16 #2 msr dd if=/dev/zero of="$(ls /dev/$xda*2)" bs=1M count=16 #2 msr
mkfs.ntfs -f -F -L os "/dev/$(xda 3)" #3 os mkfs.ntfs -f -F -L os /dev/$xda*3 #3 os
mkfs.ntfs -f -F -L installer "/dev/$(xda 4)" #4 installer mkfs.ntfs -f -F -L installer /dev/$xda*4 #4 installer
else else
# bios + mbr 启动盘最大可用 2t # bios + mbr 启动盘最大可用 2t
if is_xda_gt_2t; then if is_xda_gt_2t; then
@@ -2624,10 +2602,13 @@ create_part() {
set 1 boot on set 1 boot on
update_part update_part
mkfs.ntfs -f -F -L os "/dev/$(xda 1)" #1 os mkfs.ntfs -f -F -L os /dev/$xda*1 #1 os
mkfs.ntfs -f -F -L installer "/dev/$(xda 2)" #2 installer mkfs.ntfs -f -F -L installer /dev/$xda*2 #2 installer
fi fi
elif [ "$distro" = fnos ]; then elif [ "$distro" = fnos ]; then
# 先用 100% 分区安装后再缩小没意义,因为小硬盘用 100% 还是装不了
# 因此直接用用户输入的分区大小
# 1. 官方安装器对系统盘大小的定义包含引导分区大小 # 1. 官方安装器对系统盘大小的定义包含引导分区大小
# 2. 官方 efi 用的是 1MiB-100M但我们用 1MiB-101MiB # 2. 官方 efi 用的是 1MiB-100M但我们用 1MiB-101MiB
@@ -2659,53 +2640,47 @@ create_part() {
# The location 20480MiB is outside of the device /dev/vda. # The location 20480MiB is outside of the device /dev/vda.
# 但是 100% 分区后 end 就是 20480MiB # 但是 100% 分区后 end 就是 20480MiB
os_part_end=${expect_m}MiB
if [ "$expect_m" -ge "$max_can_use_m" ]; then if [ "$expect_m" -ge "$max_can_use_m" ]; then
warn "Expect size is equal/greater than max size. Uses max size." echo "Expect size is equal/greater than max size. Setting to 100%"
NEED_SHRINK_FNOS_OS_PART=false os_part_end=100%
FNOS_OS_PART_END_M=$max_can_use_m
else
NEED_SHRINK_FNOS_OS_PART=true
FNOS_OS_PART_END_M=$expect_m
fi fi
# fnos 的 grub 是 debian 11 的 # 需关闭这几个特性,否则 grub 无法识别
# 需关闭 metadata_csum_seed否则 grub 会进入 grub rescue 模式,但 efi 下一切正常
# orphan_file 不需要关,但是官方安装器安装的系统分区没有这个特性,因此我们也关闭它
ext4_opts="-O ^metadata_csum_seed,^orphan_file" ext4_opts="-O ^metadata_csum_seed,^orphan_file"
if is_efi; then if is_efi; then
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
mklabel gpt \ mklabel gpt \
mkpart BOOT fat32 1MiB 101MiB \ mkpart BOOT fat32 1MiB 101MiB \
mkpart SYSTEM ext4 101MiB 100% \ mkpart SYSTEM ext4 101MiB $os_part_end \
set 1 esp on set 1 esp on
update_part update_part
mkfs.fat "/dev/$(xda 1)" #1 efi mkfs.fat /dev/$xda*1 #1 efi
mkfs.ext4 -F $ext4_opts "/dev/$(xda 2)" #2 os + installer mkfs.ext4 -F $ext4_opts /dev/$xda*2 #2 os + installer
elif is_xda_gt_2t; then elif is_xda_gt_2t; then
# bios > 2t # bios > 2t
# 官方安装器是 mkpart BOOT 1M 100M无论 esp 或者 bios_grub 都用这个分区和大小 # 官方安装器是 mkpart BOOT 1M 100M无论 esp 或者 bios_grub 都用这个分区和大小
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
mklabel gpt \ mklabel gpt \
mkpart BOOT ext4 1MiB 101MiB \ mkpart BOOT ext4 1MiB 101MiB \
mkpart SYSTEM ext4 101MiB 100% \ mkpart SYSTEM ext4 101MiB $os_part_end \
set 1 bios_grub on set 1 bios_grub on
update_part update_part
echo #1 bios_boot echo #1 bios_boot
mkfs.ext4 -F $ext4_opts "/dev/$(xda 2)" #2 os + installer mkfs.ext4 -F $ext4_opts /dev/$xda*2 #2 os + installer
else else
# bios # bios
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
mklabel msdos \ mklabel msdos \
mkpart primary 1MiB 101MiB \ mkpart primary 1MiB 101MiB \
mkpart primary 101MiB 100% \ mkpart primary 101MiB $os_part_end \
set 2 boot on set 2 boot on
update_part update_part
echo #1 官方安装有这个分区 echo #1 官方安装有这个分区
mkfs.ext4 -F $ext4_opts "/dev/$(xda 2)" #2 os + installer mkfs.ext4 -F $ext4_opts /dev/$xda*2 #2 os + installer
fi fi
elif is_use_cloud_image; then elif is_use_cloud_image; then
installer_part_size="$(get_cloud_image_part_size)" installer_part_size="$(get_cloud_image_part_size)"
@@ -2725,9 +2700,9 @@ create_part() {
set 1 esp on set 1 esp on
update_part update_part
mkfs.fat -n efi "/dev/$(xda 1)" #1 efi mkfs.fat -n efi /dev/$xda*1 #1 efi
echo #2 os 用目标系统的格式化工具 echo #2 os 用目标系统的格式化工具
mkfs.ext4 -F -L installer "/dev/$(xda 3)" #3 installer mkfs.ext4 -F -L installer /dev/$xda*3 #3 installer
else else
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
mklabel gpt \ mklabel gpt \
@@ -2737,9 +2712,9 @@ create_part() {
set 1 bios_grub on set 1 bios_grub on
update_part update_part
echo #1 bios_boot echo #1 bios_boot
echo #2 os 用目标系统的格式化工具 echo #2 os 用目标系统的格式化工具
mkfs.ext4 -F -L installer "/dev/$(xda 3)" #3 installer mkfs.ext4 -F -L installer /dev/$xda*3 #3 installer
fi fi
else else
# 使用 dd qcow2 # 使用 dd qcow2
@@ -2750,8 +2725,8 @@ create_part() {
mkpart '" "' ext4 -$installer_part_size 100% mkpart '" "' ext4 -$installer_part_size 100%
update_part update_part
mkfs.ext4 -F -L os "/dev/$(xda 1)" #1 os mkfs.ext4 -F -L os /dev/$xda*1 #1 os
mkfs.ext4 -F -L installer "/dev/$(xda 2)" #2 installer mkfs.ext4 -F -L installer /dev/$xda*2 #2 installer
fi fi
elif [ "$distro" = alpine ] || [ "$distro" = arch ] || [ "$distro" = gentoo ] || elif [ "$distro" = alpine ] || [ "$distro" = arch ] || [ "$distro" = gentoo ] ||
[ "$distro" = nixos ] || [ "$distro" = aosc ]; then [ "$distro" = nixos ] || [ "$distro" = aosc ]; then
@@ -2768,8 +2743,8 @@ create_part() {
set 1 boot on set 1 boot on
update_part update_part
mkfs.fat "/dev/$(xda 1)" #1 efi mkfs.fat /dev/$xda*1 #1 efi
mkfs.ext4 -F $ext4_opts "/dev/$(xda 2)" #2 os mkfs.ext4 -F $ext4_opts /dev/$xda*2 #2 os
elif is_xda_gt_2t; then elif is_xda_gt_2t; then
# bios > 2t # bios > 2t
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
@@ -2779,8 +2754,8 @@ create_part() {
set 1 bios_grub on set 1 bios_grub on
update_part update_part
echo #1 bios_boot echo #1 bios_boot
mkfs.ext4 -F $ext4_opts "/dev/$(xda 2)" #2 os mkfs.ext4 -F $ext4_opts /dev/$xda*2 #2 os
else else
# bios # bios
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
@@ -2789,7 +2764,7 @@ create_part() {
set 1 boot on set 1 boot on
update_part update_part
mkfs.ext4 -F $ext4_opts "/dev/$(xda 1)" #1 os mkfs.ext4 -F $ext4_opts /dev/$xda*1 #1 os
fi fi
else else
# 安装红帽系或ubuntu # 安装红帽系或ubuntu
@@ -2822,9 +2797,9 @@ create_part() {
set 1 boot on set 1 boot on
update_part update_part
mkfs.fat -n efi "/dev/$(xda 1)" #1 efi mkfs.fat -n efi /dev/$xda*1 #1 efi
mkfs.ext4 -F -L os "/dev/$(xda 2)" #2 os mkfs.ext4 -F -L os /dev/$xda*2 #2 os
mkfs.ext4 -F -L installer $ext4_opts "/dev/$(xda 3)" #2 installer mkfs.ext4 -F -L installer $ext4_opts /dev/$xda*3 #2 installer
elif is_xda_gt_2t; then elif is_xda_gt_2t; then
# bios > 2t # bios > 2t
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
@@ -2835,9 +2810,9 @@ create_part() {
set 1 bios_grub on set 1 bios_grub on
update_part update_part
echo #1 bios_boot echo #1 bios_boot
mkfs.ext4 -F -L os "/dev/$(xda 2)" #2 os mkfs.ext4 -F -L os /dev/$xda*2 #2 os
mkfs.ext4 -F -L installer $ext4_opts "/dev/$(xda 3)" #3 installer mkfs.ext4 -F -L installer $ext4_opts /dev/$xda*3 #3 installer
else else
# bios # bios
parted /dev/$xda -s -- \ parted /dev/$xda -s -- \
@@ -2847,8 +2822,8 @@ create_part() {
set 1 boot on set 1 boot on
update_part update_part
mkfs.ext4 -F -L os "/dev/$(xda 1)" #1 os mkfs.ext4 -F -L os /dev/$xda*1 #1 os
mkfs.ext4 -F -L installer $ext4_opts "/dev/$(xda 2)" #2 installer mkfs.ext4 -F -L installer $ext4_opts /dev/$xda*2 #2 installer
fi fi
update_part update_part
fi fi
@@ -3943,9 +3918,7 @@ modify_os_on_disk() {
mkdir -p /os mkdir -p /os
# 按分区容量大到小,依次寻找系统分区 # 按分区容量大到小,依次寻找系统分区
# lsblk /dev/mmcblk0* 会列出 mmcblk0boot0 mmcblk0boot1 for part in $(lsblk /dev/$xda*[0-9] --sort SIZE -no NAME | tac); do
# lsblk /dev/mmcblk0 不会列出 mmcblk0boot0 mmcblk0boot1
for part in $(lsblk /dev/$xda --filter 'TYPE == "part"' --sort SIZE -no NAME | tac); do
# btrfs挂载的是默认子卷如果没有默认子卷挂载的是根目录 # btrfs挂载的是默认子卷如果没有默认子卷挂载的是根目录
# fedora 云镜像没有默认子卷且系统在root子卷中 # fedora 云镜像没有默认子卷且系统在root子卷中
if mount -o ro /dev/$part /os; then if mount -o ro /dev/$part /os; then
@@ -4402,19 +4375,23 @@ chroot_apt_autoremove() {
change_confs() { change_confs() {
action=$1 action=$1
file=$os_dir/etc/apt/apt.conf.d/01autoremove # 只有 16.04 有 01autoremove-kernels
case "$action" in # 16.04 结束支持后删除
change) for conf in 01autoremove 01autoremove-kernels; do
if [ -f $file ]; then file=$os_dir/etc/apt/apt.conf.d/$conf
sed -i.orig 's/VersionedKernelPackages/x/; s/NeverAutoRemove/x/' $file case "$action" in
fi change)
;; if [ -f $file ]; then
restore) sed -i.orig 's/VersionedKernelPackages/x/; s/NeverAutoRemove/x/' $file
if [ -f $file.orig ]; then fi
mv $file.orig $file ;;
fi restore)
;; if [ -f $file.orig ]; then
esac mv $file.orig $file
fi
;;
esac
done
} }
change_confs change change_confs change
@@ -4471,7 +4448,7 @@ install_fnos() {
# 挂载 /os # 挂载 /os
mkdir -p /os mkdir -p /os
mount "/dev/$(xda 2)" /os mount /dev/$xda*2 /os
# 下载并挂载 iso # 下载并挂载 iso
mkdir -p /os/installer /iso mkdir -p /os/installer /iso
@@ -4512,7 +4489,7 @@ install_fnos() {
# 挂载 /os/boot/efi # 挂载 /os/boot/efi
if is_efi; then if is_efi; then
mkdir -p /os/boot/efi mkdir -p /os/boot/efi
mount -o "$(echo "$fstab_line_efi" | awk '{print $4}')" "/dev/$(xda 1)" /os/boot/efi mount -o "$(echo "$fstab_line_efi" | awk '{print $4}')" /dev/$xda*1 /os/boot/efi
fi fi
# 复制系统 # 复制系统
@@ -4524,36 +4501,6 @@ install_fnos() {
# 删除 installer (trimfs.tgz) # 删除 installer (trimfs.tgz)
rm -rf /os/installer rm -rf /os/installer
# 缩小分区
if $NEED_SHRINK_FNOS_OS_PART; then
info "Shrink fnos os partition"
# 取消挂载
if is_efi; then
umount /os/boot/efi
fi
umount /os
# 101M 是 efi + bios_grub 分区,即使 bios 引导飞牛官方安装器也会生成一个 100M 预留分区
# 99M 是预留的文件系统和分区表的差值
# 一共 200M
apk add e2fsprogs-extra parted
e2fsck -p -f "/dev/$(xda 2)"
resize2fs "/dev/$(xda 2)" "$((FNOS_OS_PART_END_M - 200))M"
update_part
printf "yes" | parted /dev/$xda resizepart 2 "$((FNOS_OS_PART_END_M))MiB" ---pretend-input-tty
update_part
resize2fs "/dev/$(xda 2)"
update_part
apk del e2fsprogs-extra parted
# 重新挂载
mount "/dev/$(xda 2)" /os
if is_efi; then
mount -o "$(echo "$fstab_line_efi" | awk '{print $4}')" "/dev/$(xda 1)" /os/boot/efi
fi
fi
# 挂载 proc sys dev # 挂载 proc sys dev
mount_pseudo_fs /os mount_pseudo_fs /os
@@ -4573,7 +4520,7 @@ install_fnos() {
# fstab # fstab
{ {
# / # /
uuid=$(lsblk "/dev/$(xda 2)" -no UUID) uuid=$(lsblk /dev/$xda*2 -no UUID)
echo "$fstab_line_os" | sed "s/%s/$uuid/" echo "$fstab_line_os" | sed "s/%s/$uuid/"
# swapfile # swapfile
@@ -4582,7 +4529,7 @@ install_fnos() {
# /boot/efi # /boot/efi
if is_efi; then if is_efi; then
uuid=$(lsblk "/dev/$(xda 1)" -no UUID) uuid=$(lsblk /dev/$xda*1 -no UUID)
echo "$fstab_line_efi" | sed "s/%s/$uuid/" echo "$fstab_line_efi" | sed "s/%s/$uuid/"
fi fi
} >$os_dir/etc/fstab } >$os_dir/etc/fstab
@@ -4708,7 +4655,7 @@ install_qcow_by_copy() {
if is_efi; then if is_efi; then
# centos/oracle 要创建efi条目 # centos/oracle 要创建efi条目
if ! grep /boot/efi /os/etc/fstab; then if ! grep /boot/efi /os/etc/fstab; then
efi_part_uuid=$(lsblk "/dev/$(xda 1)" -no UUID) efi_part_uuid=$(lsblk /dev/$xda*1 -no UUID)
echo "UUID=$efi_part_uuid /boot/efi vfat $efi_mount_opts 0 0" >>/os/etc/fstab echo "UUID=$efi_part_uuid /boot/efi vfat $efi_mount_opts 0 0" >>/os/etc/fstab
fi fi
else else
@@ -4923,6 +4870,19 @@ EOF
done done
fi fi
# 16.04 arm64 镜像没有 grub 引导文件
if is_efi && ! [ -d $os_dir/boot/efi/EFI/ubuntu ]; then
chroot_apt_install $os_dir efibootmgr shim "grub-efi-$(get_axx64)"
# 创建 ubuntu 文件夹和 grubaa64.efi
DEBIAN_FRONTEND=noninteractive chroot $os_dir dpkg-reconfigure "grub-efi-$(get_axx64)"
cat <<EOF >"$os_dir/boot/efi/EFI/ubuntu/grub.cfg"
search.fs_uuid $os_part_uuid root
set prefix=(\$root)'/boot/grub'
configfile \$prefix/grub.cfg
EOF
fi
# 避免 do-release-upgrade 时自动执行 dpkg-reconfigure grub-xx 但是 efi/biosgrub 分区不存在而导致报错 # 避免 do-release-upgrade 时自动执行 dpkg-reconfigure grub-xx 但是 efi/biosgrub 分区不存在而导致报错
# shellcheck disable=SC2046 # shellcheck disable=SC2046
chroot_apt_remove $os_dir $(is_efi && echo 'grub-pc' || echo 'grub-efi*' 'shim*') chroot_apt_remove $os_dir $(is_efi && echo 'grub-pc' || echo 'grub-efi*' 'shim*')
@@ -4978,31 +4938,43 @@ EOF
# 网络配置 # 网络配置
# 18.04+ netplan # 18.04+ netplan
# 避免删除 cloud-init 后minimal 镜像的 netplan.io 被 autoremove if is_have_cmd_on_disk $os_dir netplan; then
chroot $os_dir apt-mark manual netplan.io # 避免删除 cloud-init 后minimal 镜像的 netplan.io 被 autoremove
chroot $os_dir apt-mark manual netplan.io
# 生成 cloud-init 网络配置 # 生成 cloud-init 网络配置
create_cloud_init_network_config $os_dir/net.cfg create_cloud_init_network_config $os_dir/net.cfg
# ubuntu 18.04 cloud-init 版本 23.1.2,因此不用处理 onlink # ubuntu 18.04 cloud-init 版本 23.1.2,因此不用处理 onlink
# 如果不是输出到 / 则不会生成 50-cloud-init.yaml # 如果不是输出到 / 则不会生成 50-cloud-init.yaml
# 注意比较多了什么东西 # 注意比较多了什么东西
if false; then if false; then
chroot $os_dir cloud-init devel net-convert \ chroot $os_dir cloud-init devel net-convert \
-p /net.cfg -k yaml -d /out -D ubuntu -O netplan -p /net.cfg -k yaml -d /out -D ubuntu -O netplan
sed -Ei "/^[[:space:]]+set-name:/d" $os_dir/out/etc/netplan/50-cloud-init.yaml sed -Ei "/^[[:space:]]+set-name:/d" $os_dir/out/etc/netplan/50-cloud-init.yaml
cp $os_dir/out/etc/netplan/50-cloud-init.yaml $os_dir/etc/netplan/ cp $os_dir/out/etc/netplan/50-cloud-init.yaml $os_dir/etc/netplan/
# 清理 # 清理
rm -rf $os_dir/net.cfg $os_dir/out rm -rf $os_dir/net.cfg $os_dir/out
else
chroot $os_dir cloud-init devel net-convert \
-p /net.cfg -k yaml -d / -D ubuntu -O netplan
sed -Ei "/^[[:space:]]+set-name:/d" $os_dir/etc/netplan/50-cloud-init.yaml
# 清理
rm -rf $os_dir/net.cfg
fi
else else
chroot $os_dir cloud-init devel net-convert \ # 避免删除 cloud-init 后 ifupdown 被 autoremove
-p /net.cfg -k yaml -d / -D ubuntu -O netplan chroot $os_dir apt-mark manual ifupdown
sed -Ei "/^[[:space:]]+set-name:/d" $os_dir/etc/netplan/50-cloud-init.yaml
# 清理 # 16.04 镜像用 ifupdown/networking 管理网络
rm -rf $os_dir/net.cfg # 要安装 resolveconf不然 /etc/resolv.conf 为空
chroot_apt_install $os_dir resolvconf
ln -sf /run/resolvconf/resolv.conf $os_dir/etc/resolv.conf.orig
create_ifupdown_config $os_dir/etc/network/interfaces
fi fi
# 自带的 60-cloudimg-settings.conf 禁止了 PasswordAuthentication # 自带的 60-cloudimg-settings.conf 禁止了 PasswordAuthentication
@@ -5018,7 +4990,7 @@ EOF
# 因为 24.04 fsuuid 对应 boot 分区 # 因为 24.04 fsuuid 对应 boot 分区
efi_grub_cfg=$os_dir/boot/efi/EFI/ubuntu/grub.cfg efi_grub_cfg=$os_dir/boot/efi/EFI/ubuntu/grub.cfg
if is_efi; then if is_efi; then
os_uuid=$(lsblk -rno UUID "/dev/$(xda 2)") os_uuid=$(lsblk -rno UUID /dev/$xda*2)
sed -Ei "s|[0-9a-f-]{36}|$os_uuid|i" $efi_grub_cfg sed -Ei "s|[0-9a-f-]{36}|$os_uuid|i" $efi_grub_cfg
# 24.04 移除 boot 分区后,需要添加 /boot 路径 # 24.04 移除 boot 分区后,需要添加 /boot 路径
@@ -5032,7 +5004,7 @@ EOF
if [ -e $force_partuuid_cfg ]; then if [ -e $force_partuuid_cfg ]; then
if is_virt; then if is_virt; then
# 更改写死的 partuuid # 更改写死的 partuuid
os_part_uuid=$(lsblk -rno PARTUUID "/dev/$(xda 2)") os_part_uuid=$(lsblk -rno PARTUUID /dev/$xda*2)
sed -i "s/^GRUB_FORCE_PARTUUID=.*/GRUB_FORCE_PARTUUID=$os_part_uuid/" $force_partuuid_cfg sed -i "s/^GRUB_FORCE_PARTUUID=.*/GRUB_FORCE_PARTUUID=$os_part_uuid/" $force_partuuid_cfg
else else
# 独服不应该使用 initrdless boot # 独服不应该使用 initrdless boot
@@ -5183,8 +5155,8 @@ EOF
mount_nouuid /dev/$os_part /nbd/ mount_nouuid /dev/$os_part /nbd/
mount_pseudo_fs /nbd/ mount_pseudo_fs /nbd/
case "$os_part_fstype" in case "$os_part_fstype" in
ext4) chroot /nbd mkfs.ext4 -F -L "$os_part_label" -U "$os_part_uuid" "/dev/$(xda 2)" ;; ext4) chroot /nbd mkfs.ext4 -F -L "$os_part_label" -U "$os_part_uuid" /dev/$xda*2 ;;
xfs) chroot /nbd mkfs.xfs -f -L "$os_part_label" -m uuid=$os_part_uuid "/dev/$(xda 2)" ;; xfs) chroot /nbd mkfs.xfs -f -L "$os_part_label" -m uuid=$os_part_uuid /dev/$xda*2 ;;
esac esac
umount -R /nbd/ umount -R /nbd/
@@ -5192,7 +5164,7 @@ EOF
# 创建并挂载 /os # 创建并挂载 /os
mkdir -p /os mkdir -p /os
mount -o noatime "/dev/$(xda 2)" /os/ mount -o noatime /dev/$xda*2 /os/
# 如果是 efi 则创建 /os/boot/efi # 如果是 efi 则创建 /os/boot/efi
# 如果镜像有 efi 分区也创建 /os/boot/efi用于复制 efi 分区的文件 # 如果镜像有 efi 分区也创建 /os/boot/efi用于复制 efi 分区的文件
@@ -5203,7 +5175,7 @@ EOF
# 预先挂载 /os/boot/efi 因为可能 boot 和 efi 在同一个分区openeuler 24.03 arm # 预先挂载 /os/boot/efi 因为可能 boot 和 efi 在同一个分区openeuler 24.03 arm
# 复制 boot 时可以会复制 efi 的文件 # 复制 boot 时可以会复制 efi 的文件
if is_efi; then if is_efi; then
mount -o $efi_mount_opts "/dev/$(xda 1)" /os/boot/efi/ mount -o $efi_mount_opts /dev/$xda*1 /os/boot/efi/
fi fi
fi fi
@@ -5254,7 +5226,7 @@ EOF
if is_efi && [ -n "$efi_part_uuid" ] && ! [ "$efi_part" = "$os_part" ]; then if is_efi && [ -n "$efi_part_uuid" ] && ! [ "$efi_part" = "$os_part" ]; then
info "Copy efi partition uuid" info "Copy efi partition uuid"
apk add mtools apk add mtools
mlabel -N "$(echo $efi_part_uuid | sed 's/-//')" -i "/dev/$(xda 1)" ::$efi_part_label mlabel -N "$(echo $efi_part_uuid | sed 's/-//')" -i /dev/$xda*1 ::$efi_part_label
apk del mtools apk del mtools
update_part update_part
fi fi
@@ -5268,9 +5240,9 @@ EOF
# 重新挂载 /os /boot/efi # 重新挂载 /os /boot/efi
info "Re-mount disk" info "Re-mount disk"
mount -o noatime "/dev/$(xda 2)" /os/ mount -o noatime /dev/$xda*2 /os/
if is_efi; then if is_efi; then
mount -o $efi_mount_opts "/dev/$(xda 1)" /os/boot/efi/ mount -o $efi_mount_opts /dev/$xda*1 /os/boot/efi/
fi fi
# 创建 swap # 创建 swap
@@ -5490,22 +5462,22 @@ resize_after_install_cloud_image() {
ext4) ext4)
# debian ci # debian ci
apk add e2fsprogs-extra apk add e2fsprogs-extra
e2fsck -p -f "/dev/$(xda $last_part_num)" e2fsck -p -f /dev/$xda*$last_part_num
resize2fs "/dev/$(xda $last_part_num)" resize2fs /dev/$xda*$last_part_num
apk del e2fsprogs-extra apk del e2fsprogs-extra
;; ;;
xfs) xfs)
# opensuse ci # opensuse ci
apk add xfsprogs-extra apk add xfsprogs-extra
mount "/dev/$(xda $last_part_num)" /os mount /dev/$xda*$last_part_num /os
xfs_growfs "/dev/$(xda $last_part_num)" xfs_growfs /dev/$xda*$last_part_num
umount /os umount /os
apk del xfsprogs-extra apk del xfsprogs-extra
;; ;;
btrfs) btrfs)
# fedora ci # fedora ci
apk add btrfs-progs apk add btrfs-progs
mount "/dev/$(xda $last_part_num)" /os mount /dev/$xda*$last_part_num /os
btrfs filesystem resize max /os btrfs filesystem resize max /os
umount /os umount /os
apk del btrfs-progs apk del btrfs-progs
@@ -5513,8 +5485,8 @@ resize_after_install_cloud_image() {
ntfs) ntfs)
# windows dd # windows dd
apk add ntfs-3g-progs apk add ntfs-3g-progs
echo y | ntfsresize "/dev/$(xda $last_part_num)" echo y | ntfsresize /dev/$xda*$last_part_num
ntfsfix -d "/dev/$(xda $last_part_num)" ntfsfix -d /dev/$xda*$last_part_num
apk del ntfs-3g-progs apk del ntfs-3g-progs
;; ;;
esac esac
@@ -5535,12 +5507,12 @@ mount_part_basic_layout() {
# 挂载系统分区 # 挂载系统分区
mkdir -p $os_dir mkdir -p $os_dir
mount -t ext4 "/dev/$(xda $os_part_num)" $os_dir mount -t ext4 /dev/${xda}*${os_part_num} $os_dir
# 挂载 efi 分区 # 挂载 efi 分区
if is_efi; then if is_efi; then
mkdir -p $efi_dir mkdir -p $efi_dir
mount -t vfat -o umask=077 "/dev/$(xda 1)" $efi_dir mount -t vfat -o umask=077 /dev/${xda}*1 $efi_dir
fi fi
} }
@@ -5880,7 +5852,7 @@ install_windows() {
while true; do while true; do
# 匹配成功 # 匹配成功
# 改成正确的大小写 # 改成正确的大小写
if matched_image_name=$(printf '%s\n' "$all_image_names" | grep -Fix "$image_name"); then if matched_image_name=$(echo "$all_image_names" | grep -ix "$image_name"); then
image_name=$matched_image_name image_name=$matched_image_name
image_index=$(wiminfo "$iso_install_wim" "$image_name" | grep 'Index:' | awk '{print $NF}') image_index=$(wiminfo "$iso_install_wim" "$image_name" | grep 'Index:' | awk '{print $NF}')
break break
@@ -6091,14 +6063,13 @@ install_windows() {
boot_dir=/os boot_dir=/os
fi fi
# 复制 iso 根目录 boot 开头的文件 # 复制启动相关的文件
# efi 额外复制efi目录
echo 'Copying boot files...' echo 'Copying boot files...'
find /iso -maxdepth 1 -iname 'boot*' -exec cp -r {} "$boot_dir" \; cp -r "$(get_path_in_correct_case /iso/boot)"* $boot_dir
# efi 额外复制 iso 根目录 efi 文件夹
if is_efi; then if is_efi; then
echo 'Copying efi files...' echo 'Copying efi files...'
find /iso -maxdepth 1 -type d -iname efi -exec cp -r {} "$boot_dir" \; cp -r "$(get_path_in_correct_case /iso/efi)" $boot_dir
fi fi
# 复制iso全部文件(除了boot.wim)到installer分区 # 复制iso全部文件(除了boot.wim)到installer分区
@@ -6506,9 +6477,9 @@ EOF
apk add msitools apk add msitools
# 8.4.3+ 的 xenbus 驱动挑创建实例时的初始系统 # 8.4.3 的 xenbus 挑创建实例时的初始系统
# 初始系统为 windows 的实例支持 8.4.3+ # 初始系统为 windows 的实例支持 8.4.3
# 初始系统为 linux 的实例不支持 8.4.3+ # 初始系统为 linux 的实例不支持 8.4.3
# 初始系统为 linux + 安装 8.4.3 # 初始系统为 linux + 安装 8.4.3
# 如果用 msi 安装,则不会启用 xenbus结果是能启动但无法上网 # 如果用 msi 安装,则不会启用 xenbus结果是能启动但无法上网
@@ -6523,16 +6494,11 @@ EOF
6.1) $support_sha256 && echo 8.3.5 || echo 8.3.2 ;; 6.1) $support_sha256 && echo 8.3.5 || echo 8.3.2 ;;
6.2 | 6.3) 6.2 | 6.3)
case "$hypervisor_vendor" in case "$hypervisor_vendor" in
Xen) echo 8.3.5 ;; # 实例初始系统为 Linux Microsoft) echo 8.4.3 ;; # 实例初始系统为 Windows能使用 8.4.3
Microsoft) echo 8.4.3 ;; # 实例初始系统为 Windows Xen) echo 8.3.5 ;; # 实例初始系统为 Linux不能使用 8.4.3
esac
;;
*)
case "$hypervisor_vendor" in
Xen) echo 8.3.5 ;; # 实例初始系统为 Linux
Microsoft) echo Latest ;; # 实例初始系统为 Windows
esac esac
;; ;;
*) echo Latest ;;
esac esac
) )
@@ -7219,12 +7185,12 @@ EOF
# 或者用 ms-sys # 或者用 ms-sys
apk add grub-bios apk add grub-bios
# efi 下,强制安装 mbr 引导,需要添加 --target i386-pc # efi 下,强制安装 mbr 引导,需要添加 --target i386-pc
grub-install --target i386-pc --boot-directory="$(get_path_in_correct_case /os/boot)" /dev/$xda grub-install --target i386-pc --boot-directory=/os/boot /dev/$xda
cat <<EOF >"$(get_path_in_correct_case /os/boot/grub/grub.cfg)" cat <<EOF >/os/boot/grub/grub.cfg
set timeout=5 set timeout=5
menuentry "reinstall" { menuentry "reinstall" {
search --no-floppy --label --set=root os search --no-floppy --label --set=root os
ntldr /$(cd /os && get_path_in_correct_case bootmgr) ntldr /bootmgr
} }
EOF EOF
fi fi
@@ -7308,25 +7274,32 @@ get_ubuntu_kernel_flavor() {
# https://github.com/systemd/systemd/blob/main/src/basic/virt.c # https://github.com/systemd/systemd/blob/main/src/basic/virt.c
# https://github.com/canonical/cloud-init/blob/main/tools/ds-identify # https://github.com/canonical/cloud-init/blob/main/tools/ds-identify
# http://git.annexia.org/?p=virt-what.git;a=blob;f=virt-what.in;hb=HEAD # http://git.annexia.org/?p=virt-what.git;a=blob;f=virt-what.in;hb=HEAD
if [ "$releasever" = 16.04 ]; then
# 这里有坑
# $(get_cloud_vendor) 调用了 cache_dmi_and_virt
# 但是 $(get_cloud_vendor) 运行在 subshell 里面
# subshell 运行结束后里面的变量就消失了
# 因此先运行 cache_dmi_and_virt
cache_dmi_and_virt
vendor="$(get_cloud_vendor)"
case "$vendor" in
aws | gcp | oracle | azure | ibm) echo $vendor ;;
*)
is_ubuntu_lts && suffix=-hwe-$releasever || suffix=
if is_virt; then if is_virt; then
echo virtual$suffix echo virtual-hwe-$releasever
else else
echo generic$suffix echo generic-hwe-$releasever
fi fi
;; else
esac # 这里有坑
# $(get_cloud_vendor) 调用了 cache_dmi_and_virt
# 但是 $(get_cloud_vendor) 运行在 subshell 里面
# subshell 运行结束后里面的变量就消失了
# 因此先运行 cache_dmi_and_virt
cache_dmi_and_virt
vendor="$(get_cloud_vendor)"
case "$vendor" in
aws | gcp | oracle | azure | ibm) echo $vendor ;;
*)
is_ubuntu_lts && suffix=-hwe-$releasever || suffix=
if is_virt; then
echo virtual$suffix
else
echo generic$suffix
fi
;;
esac
fi
} }
install_redhat_ubuntu() { install_redhat_ubuntu() {

Binary file not shown.