不重要的优化

This commit is contained in:
bin456789 2024-05-22 22:32:43 +08:00
parent a83cd16145
commit d4f6ac2e56
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
7 changed files with 416 additions and 298 deletions

View File

@ -1,71 +1,115 @@
<!-- markdownlint-disable MD028 MD033 MD045 -->
# reinstall # reinstall
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/dc679a17751448628fe6d8ac35e26eed)](https://app.codacy.com/gh/bin456789/reinstall/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Codacy](https://img.shields.io/codacy/grade/dc679a17751448628fe6d8ac35e26eed?logo=Codacy&label=Codacy)](https://app.codacy.com/gh/bin456789/reinstall/dashboard)
[![CodeFactor](https://www.codefactor.io/repository/github/bin456789/reinstall/badge)](https://www.codefactor.io/repository/github/bin456789/reinstall) [![CodeFactor](https://img.shields.io/codefactor/grade/github/bin456789/reinstall?logo=CodeFactor&logoColor=white&label=CodeFactor)](https://www.codefactor.io/repository/github/bin456789/reinstall)
[![Lines of Code](https://tokei.rs/b1/github/bin456789/reinstall?category=code&style=flat)](https://github.com/XAMPPRocky/tokei_rs) [![Lines of Code](https://tokei.rs/b1/github/bin456789/reinstall?category=code&style=flat&label=Lines%20of%20Code)](https://github.com/XAMPPRocky/tokei_rs)
One-click reinstallation script Reinstall server with one-click [中文](README.md)
[中文](README.md) | English
## Highlights ## Highlights
- Support arbitrary conversion between the following systems (including Windows to Linux). - Support installation of 12 common Linux distributions.
- Compatible low-spec servers and automatically select the appropriate official slimmed-down kernel. - Support for installing Windows using the official original ISO. The script can automatically search for the ISO and drivers.
- Supports installing Windows using the official ISO. - Support reinstallation in any direction, meaning `Linux to Linux`, `Linux to Win`, `Win to Win`, `Win to Linux`.
- Automatically detect dynamic/static IPv4/IPv6, eliminating the need to fill in IP/mask/gateway (even for DD/ISO installation of Windows). - Specifically tailored for low-spec machines, addressing insufficient memory that prevents network installation.
- Supports BIOS, EFI, ARM. The original system partition supports LVM, Btrfs. - Automatically detect dynamic and static IPv4 / IPv6, eliminating the need to fill in IP / subnet mask / gateway.
- Progress of DD and cloud image installation can be viewed through SSH, HTTP port 80, serial console, and vendor backend VNC. - Support ARM, BIOS, EFI boot, with original system supporting LVM, BTRFS.
- The script does not include third-party homemade packages; all resources are obtained in real-time from the source site. - No third-party custom packages included, all resources obtained in real-time from source sites.
- Includes many comments. - Includes many comments.
## System Requirements ## System Requirements
| Target System | Memory | Disk | | Target System | Version | Memory | Disk |
| -------------------------------------------------------- | --------- | ---------------------- | | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | --------- | ---------------------- |
| Alpine | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.17, 3.18, 3.19, 3.20 | 256 MB | 1 GB |
| Debian / Kali | 256 MB | 1~1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ |
| Ubuntu | 512 MB \* | 2 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 ^ |
| CentOS / Alma / Rocky / Oracle | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://assets.ubuntu.com/v1/49a1a858-favicon-32x32.png" /> Ubuntu | 20.04, 22.04, 24.04 | 512 MB \* | 2 GB |
| Fedora | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.centos.org/assets/img/favicon.png" /> CentOS | 7, 8, 9 | 512 MB \* | 5 GB |
| openSUSE | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 7, 8, 9 | 512 MB \* | 5 GB |
| Arch | 512 MB | 5 GB | | <img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> Alma | 8, 9 | 512 MB \* | 5 GB |
| Gentoo | 512 MB | 5 GB | | <img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky | 8, 9 | 512 MB \* | 5 GB |
| DD | 512 MB | Depending on the image | | <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 39, 40 | 512 MB \* | 5 GB |
| Windows 8.1 (Server 2012 R2) or below (ISO installation) | 512 MB | 20~25 GB | | <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | 15.5, Tumbleweed (Rolling) | 512 MB \* | 5 GB |
| Windows 10 (Server 2016) or above (ISO installation) | 1G | 20~25 GB | | <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | Rolling | 512 MB | 5 GB |
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | Rolling | 512 MB | 5 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (DD) | Any | 512 MB | Depending on the image |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | Vista, 7, 8.x (Server 2008 ~ 2012 R2) | 512 MB | 25 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | 10, 11 (Server 2016 ~ 2022) | 1 GB | 25 GB |
(\*) Indicates installation using cloud images (\*) Indicates installation using cloud images, not traditional network installation.
(^) indicates requiring either 256 MB memory + 1.5 GB disk, or 512 MB memory + 1 GB disk (^) indicates requiring either 256 MB memory + 1.5 GB disk, or 512 MB memory + 1 GB disk
## Download (Current system is Linux) > [!WARNING]
> ❌ This script does not support OpenVZ or LXC virtual machines.
>
> Please use <https://github.com/LloydAsp/OsMutation> instead.
For users outside China: ## System Accounts
| System | Username | Password |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------- |
| <img width="16" height="16" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux | root | 123@@@ |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | administrator | 123@@@ |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (DD) | Image username | Image password |
> [!TIP]
> If remote login to Windows fails, try using the username `.\administrator`.
## Download (Current system is <img width="20" height="20" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux)
For server outside China:
```bash ```bash
curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh
``` ```
For users in China: For server inside China:
```bash ```bash
curl -O https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh curl -O https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh
``` ```
## Download (Current system is Windows) ## Download (Current system is <img width="20" height="20" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows)
[Unable to download?](#if-the-script-cannot-be-downloaded-under-windows) > [!IMPORTANT]
> Before proceeding, please disable the 'Real-time protection' feature in `Windows Defender`. This feature may prevent `certutil` from downloading any files.
Before proceeding, please disable the 'Real-time protection' feature in `Windows Defender`. This feature may prevent `certutil` from downloading any files. <details>
For users outside China: <summary>😢Still unable to download?</summary>
### Try the following methods
1. For Windows 7, install this patch to enable TLS 1.2.
<https://aka.ms/easyfix51044>
2. Update SSL root certificates.
```batch
certutil -generateSSTFromWU root.sst
certutil -addstore Root root.sst
```
3. Download manually by copying these two files through `Remote Desktop Connection`.
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat>
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh>
</details>
For server outside China:
```batch ```batch
certutil -urlcache -f -split https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat certutil -urlcache -f -split https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat
``` ```
For users in China: For server inside China:
```batch ```batch
certutil -urlcache -f -split https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat certutil -urlcache -f -split https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat
@ -73,26 +117,34 @@ certutil -urlcache -f -split https://mirror.ghproxy.com/https://raw.githubuserco
## Usage ## Usage
All features can be used on both Linux and Windows. > [!TIP]
> All features can be used on both Linux and Windows.
>
> on Linux, execute `bash reinstall.sh`
>
> on Windows, execute `reinstall.bat`
- on Linux, execute `bash reinstall.sh` ### Feature 1: Install <img width="16" height="16" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux
- on Windows, execute `reinstall.bat`
### Feature 1: Install Linux
- If no version number is entered, the latest version will be installed. - If no version number is entered, the latest version will be installed.
- When installing on a virtual machine, it will automatically select a slimmed-down kernel. - Does not include a boot partition (except for Fedora), nor a swap partition, maximizing disk space utilization.
- When installing on a virtual machine, it will automatically select a official limmed-down kernel.
> [!TIP]
> When installing Debian / Kali, x86 architectures can monitor the installation progress through VNC in the background, while ARM architectures can use the serial console.
>
> When installing other systems, can monitor the progress through various methods (SSH, HTTP 80 port, VNC in the background, serial console).
```bash ```bash
bash reinstall.sh centos 7|8|9 (8|9 for the stream version) bash reinstall.sh centos 7|8|9 (8|9 for the stream version)
oracle 7|8|9 oracle 7|8|9
alma 8|9 alma 8|9
rocky 8|9 rocky 8|9
fedora 38|39|40 fedora 39|40
debian 10|11|12 debian 10|11|12
opensuse 15.5|tumbleweed opensuse 15.5|tumbleweed
ubuntu 20.04|22.04|24.04 ubuntu 20.04|22.04|24.04
alpine 3.16|3.17|3.18|3.19 alpine 3.17|3.18|3.19|3.20
kali kali
arch arch
gentoo gentoo
@ -103,11 +155,14 @@ bash reinstall.sh centos 7|8|9 (8|9 for the stream version)
- Supports gzip, xz formats. - Supports gzip, xz formats.
- For machines with static IP, DD Windows, and the script will automatically configure the IP. - For machines with static IP, DD Windows, and the script will automatically configure the IP.
> [!TIP]
> Can monitor the progress through various methods (SSH, HTTP 80 port, VNC in the background, serial console).
```bash ```bash
bash reinstall.sh dd --img https://example.com/xxx.xz bash reinstall.sh dd --img https://example.com/xxx.xz
``` ```
### Feature 3: Reboot to Alpine Rescue System (Live OS) ### Feature 3: Reboot to <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine Rescue System (Live OS)
- Can be connected via SSH to perform manual DD, modify partitions, manually install Arch / Gentoo, etc. - Can be connected via SSH to perform manual DD, modify partitions, manually install Arch / Gentoo, etc.
- If the disk content is not modified, rebooting again will return to the original system. - If the disk content is not modified, rebooting again will return to the original system.
@ -116,7 +171,7 @@ bash reinstall.sh dd --img https://example.com/xxx.xz
bash reinstall.sh alpine --hold=1 bash reinstall.sh alpine --hold=1
``` ```
### Feature 4: Reboot to netboot.xyz ### Feature 4: Reboot to <img width="16" height="16" src="https://netboot.xyz/img/favicon.ico" /> netboot.xyz
- Can install [more systems](https://github.com/netbootxyz/netboot.xyz?tab=readme-ov-file#what-operating-systems-are-currently-available-on-netbootxyz) using vendor backend VNC. - Can install [more systems](https://github.com/netbootxyz/netboot.xyz?tab=readme-ov-file#what-operating-systems-are-currently-available-on-netbootxyz) using vendor backend VNC.
- If the disk content is not modified, rebooting again will return to the original system. - If the disk content is not modified, rebooting again will return to the original system.
@ -127,10 +182,17 @@ bash reinstall.sh netboot.xyz
![netboot.xyz](https://netboot.xyz/images/netboot.xyz.gif) ![netboot.xyz](https://netboot.xyz/images/netboot.xyz.gif)
### Feature 5: Install Windows ISO ### Feature 5: Install <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows ISO
- Pay attention to the quotation marks around the parameters - Can automatically searching for most iso links. Need to set the language using `--lang`, default is `en-us`.
- Supports automatically searching for some ISO links. Need to set the language using `--lang`, default is `en-us`. - Machines with static IP addresses will have their IPs automatically configured after installation.
- Can bypass Windows 11 installation restrictions.
> [!TIP]
> The script uses <https://massgrave.dev/genuine-installation-media.html> as the ISO source. All ISOs provided are official originals.
> [!IMPORTANT]
> Note that parameters should be enclosed in quotation marks.
```bash ```bash
bash reinstall.sh windows \ bash reinstall.sh windows \
@ -146,9 +208,28 @@ bash reinstall.sh windows \
--iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso' --iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso'
``` ```
<details>
<summary>The following website provides iso links.</summary>
- Massgrave
- <https://massgrave.dev/genuine-installation-media.html> (Recommended, iso sourced from official channels, updated monthly, includes the latest patches)
- Microsoft
- <https://www.microsoft.com/software-download/indows8>
- <https://www.microsoft.com/software-download/indows10> (Need to open it with a mobile User-Agent)
- <https://www.microsoft.com/software-download/indows11>
- <https://www.microsoft.com/evalcenter/ownload-windows-10-enterprise>
- <https://www.microsoft.com/evalcenter/ownload-windows-11-enterprise>
- <https://www.microsoft.com/evalcenter/ownload-windows-server-2012-r2>
- <https://www.microsoft.com/evalcenter/ownload-windows-server-2016>
- <https://www.microsoft.com/evalcenter/ownload-windows-server-2019>
- <https://www.microsoft.com/evalcenter/download-windows-server-2022>
</details>
![Installing Windows](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7) ![Installing Windows](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7)
Parameters Description: #### Parameters Description
`--image-name` Specify the image to install, case-insensitive, Commonly used images include: `--image-name` Specify the image to install, case-insensitive, Commonly used images include:
@ -163,78 +244,36 @@ Use `Dism++` File menu > Open Image File, select the iso to be installed to get
![image-name](https://github.com/bin456789/reinstall/assets/7548515/5aae0a9b-61e2-4f66-bb98-d470a6beaac2) ![image-name](https://github.com/bin456789/reinstall/assets/7548515/5aae0a9b-61e2-4f66-bb98-d470a6beaac2)
1. Supported systems: #### Supported systems
- Windows Vista to 11
- Windows Server 2008 to 2022, including the following variants
- Windows Server Essentials
- Windows Server Annual Channel
- Hyper-V Server
- Azure Stack HCI
2. The script will install the following drivers as needed:
- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN](https://xenproject.org/windows-pv-drivers/), [Citrix](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade), [AWS](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA Network Adapter](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html), [NVMe Storage Controller](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC Network Adapter](https://cloud.google.com/compute/docs/networking/using-gvnic), [GGA Graphics](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA Network Adapter](https://learn.microsoft.com/azure/virtual-network/accelerated-networking-mana-windows))
3. Vista (Server 2008) and 32-bit systems may lack drivers.
4. For EFI machines without CSM enabled, Windows 7 (Server 2008 R2) cannot be installed.
5. If the machine has a static IP, the IP will be automatically set after installation.
6. Can bypass Windows 11 hardware restrictions.
7. Supports Windows 11 on ARM, exclusively for Hyper-V (Azure), not compatible with KVM (Oracle Cloud).
8. The process `wsappx` will occupy CPU for a long time after installing the image `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso`.
This is an issue with the image, and the solution is to install the `VCLibs` library. - Windows (Vista ~ 11)
- Windows Server (2008 ~ 2022)
- Windows Server Essentials
- Windows Server (Semi) Annual Channel
- Hyper-V Server
- Azure Stack HCI
<https://www.google.com/search?q=ltsc+wsappx> #### The script will install the following drivers as needed
9. The following website provides iso links. - KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN](https://xenproject.org/windows-pv-drivers/), [Citrix](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade), [AWS](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA Network Adapter](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html), [NVMe Storage Controller](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC Network Adapter](https://cloud.google.com/compute/docs/networking/using-gvnic), [GGA Graphics](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA Network Adapter](https://learn.microsoft.com/azure/virtual-network/accelerated-networking-mana-windows))
<https://massgrave.dev/genuine-installation-media.html> (Recommended, iso sourced from official channels, updated monthly, includes the latest patches) > [!WARNING]
> Vista (Server 2008) and 32-bit systems may lack drivers.
<https://www.microsoft.com/software-download/windows8> > [!WARNING]
> For EFI machines without CSM enabled, Windows 7 (Server 2008 R2) cannot be installed.
<https://www.microsoft.com/software-download/windows10> (Need to open it with a mobile User-Agent) > [!WARNING]
> Supports installation of Windows 11 on ARM machines, limited to Hyper-V (Azure) only, not supported on KVM (Oracle Cloud).
<https://www.microsoft.com/software-download/windows11> > [!WARNING]
> In the Chinese version of Windows 10 LTSC 2021 ISO `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso`, the `wsappx` process may indefinitely consume CPU resources.
## Virtualization Requirements >
> The solution is to update the system patches or manually install the `VCLibs` library <https://www.google.com/search?q=ltsc+wsappx>.
Not supported on OpenVZ, LXC virtual machines.
Please use <https://github.com/LloydAsp/OsMutation>.
## Default Passwords
| System | Username | Password |
| ------------- | -------------- | -------------- |
| Linux | root | 123@@@ |
| Windows (iso) | administrator | 123@@@ |
| Windows (dd) | Image username | Image password |
If encountering a password error during remote login to Windows, try using the username .\administrator.
## If the script cannot be downloaded under Windows
You can try the following methods:
1. Disable Windows Defender Real-time Protection.
2. For Windows 7, install this patch to enable TLS 1.2.
<https://aka.ms/easyfix51044>
3. Update SSL root certificates.
```batch
certutil -generateSSTFromWU root.sst
certutil -addstore Root root.sst
```
4. Download manually by copying these two files through `Remote Desktop Connection`.
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat>
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh>
## Thanks ## Thanks

266
README.md
View File

@ -1,71 +1,115 @@
<!-- markdownlint-disable MD028 MD033 MD045 -->
# reinstall # reinstall
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/dc679a17751448628fe6d8ac35e26eed)](https://app.codacy.com/gh/bin456789/reinstall/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Codacy](https://img.shields.io/codacy/grade/dc679a17751448628fe6d8ac35e26eed?logo=Codacy&label=Codacy)](https://app.codacy.com/gh/bin456789/reinstall/dashboard)
[![CodeFactor](https://www.codefactor.io/repository/github/bin456789/reinstall/badge)](https://www.codefactor.io/repository/github/bin456789/reinstall) [![CodeFactor](https://img.shields.io/codefactor/grade/github/bin456789/reinstall?logo=CodeFactor&logoColor=white&label=CodeFactor)](https://www.codefactor.io/repository/github/bin456789/reinstall)
[![Lines of Code](https://tokei.rs/b1/github/bin456789/reinstall?category=code&style=flat)](https://github.com/XAMPPRocky/tokei_rs) [![Lines of Code](https://tokei.rs/b1/github/bin456789/reinstall?category=code&style=flat&label=Lines%20of%20Code)](https://github.com/XAMPPRocky/tokei_rs)
一键重装脚本 一键重装脚本 [English](README.en.md)
中文 | [English](README.en.md)
## 亮点 ## 亮点
- 支持以下系统任意转换(包括 Windows 转 Linux - 支持安装 12 种常见 Linux 发行版
- 适配低配小鸡,并自动选择合适的官方精简内核 - 支持用官方原版 iso 安装 Windows并且脚本会自动查找 iso 和驱动
- 支持用官方 iso 安装 Windows - 支持任意方向重装,也就是支持 `Linux to Linux``Linux to Win``Win to Win``Win to Linux`
- 自动判断动静态 IPv4 / IPv6无需填写 IP / 掩码 / 网关(即使是 DD / ISO 安装 Windows - 专门适配低配小鸡,解决内存过少导致无法进行网络安装
- 支持 BIOS、EFI、ARM原系统分区支持 lvm、btrfs - 自动判断动静态 IPv4 / IPv6无需填写 IP / 掩码 / 网关
- 可通过 SSH、HTTP 80 端口、串行控制台、商家后台 VNC 查看 DD、云镜像安装进度 - 支持 ARM支持 BIOS、EFI 引导,原系统支持 LVM、BTRFS
- 不含第三方自制包,所有资源均实时从源站点获得 - 不含第三方自制包,所有资源均实时从源站点获得
- 有很多注释 - 有很多注释
## 配置要求 ## 配置要求
| 目标系统 | 内存 | 硬盘 | | 目标系统 | 版本 | 内存 | 硬盘 |
| ---------------------------------------------- | --------- | ---------- | | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | --------- | ------------ |
| Alpine | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.17, 3.18, 3.19, 3.20 | 256 MB | 1 GB |
| Debian / Kali | 256 MB | 1~1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ |
| Ubuntu | 512 MB \* | 2 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 ^ |
| CentOS / Alma / Rocky / Oracle | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://assets.ubuntu.com/v1/49a1a858-favicon-32x32.png" /> Ubuntu | 20.04, 22.04, 24.04 | 512 MB \* | 2 GB |
| Fedora | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.centos.org/assets/img/favicon.png" /> CentOS | 7, 8, 9 | 512 MB \* | 5 GB |
| openSUSE | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 7, 8, 9 | 512 MB \* | 5 GB |
| Arch | 512 MB | 5 GB | | <img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> Alma | 8, 9 | 512 MB \* | 5 GB |
| Gentoo | 512 MB | 5 GB | | <img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky | 8, 9 | 512 MB \* | 5 GB |
| DD | 512 MB | 取决于镜像 | | <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 39, 40 | 512 MB \* | 5 GB |
| Windows 8.1 (Server 2012 R2) 或以下 (ISO 安装) | 512 MB | 20~25 GB | | <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | 15.5, Tumbleweed (滚动) | 512 MB \* | 5 GB |
| Windows 10 (Server 2016) 或以上 (ISO 安装) | 1024 MB | 20~25 GB | | <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | 滚动 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (DD) | 任何 | 512 MB | 取决于镜像 |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | Vista, 7, 8.x (Server 2008 ~ 2012 R2) | 512 MB | 25 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | 10, 11 (Server 2016 ~ 2022) | 1 GB | 25 GB |
(\*) 表示使用云镜像安装 (\*) 表示使用云镜像安装,非传统网络安装
(^) 需要 256 MB 内存 + 1.5 GB 硬盘,或 512 MB 内存 + 1 GB 硬盘 (^) 需要 256 MB 内存 + 1.5 GB 硬盘,或 512 MB 内存 + 1 GB 硬盘
## 下载(当前系统是 Linux > [!WARNING]
> ❌ 本脚本不支持 OpenVZ、LXC 虚拟机
>
> 请改用 <https://github.com/LloydAsp/OsMutation>
国外: ## 系统账号
| 系统 | 用户名 | 密码 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -------- |
| <img width="16" height="16" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux | root | 123@@@ |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | administrator | 123@@@ |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (DD) | 镜像用户名 | 镜像密码 |
> [!TIP]
> 如果远程登录 Windows 失败,尝试使用用户名 `.\administrator`
## 下载(当前系统是 <img width="20" height="20" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux
国外服务器:
```bash ```bash
curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh
``` ```
国内: 国内服务器
```bash ```bash
curl -O https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh curl -O https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh
``` ```
## 下载(当前系统是 Windows ## 下载(当前系统是 <img width="20" height="20" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows
[无法下载?](#如果-windows-下无法下载脚本) > [!IMPORTANT]
> 请先关闭 `Windows Defender``实时保护` 功能。该功能会阻止 `certutil` 下载任何文件。
请先关闭 `Windows Defender``实时保护` 功能。该功能会阻止 `certutil` 下载任何文件 <details>
国外: <summary>😢还是无法下载?</summary>
### 可尝试以下几种方法
1. Windows 7 安装此补丁启用 TLS 1.2
<https://aka.ms/easyfix51044>
2. 更新 SSL 根证书
```batch
certutil -generateSSTFromWU root.sst
certutil -addstore Root root.sst
```
3. 手动下载,通过 `远程桌面` 复制这两个文件
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat>
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh>
</details>
国外服务器:
```batch ```batch
certutil -urlcache -f -split https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat certutil -urlcache -f -split https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat
``` ```
国内: 国内服务器
```batch ```batch
certutil -urlcache -f -split https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat certutil -urlcache -f -split https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat
@ -73,26 +117,35 @@ certutil -urlcache -f -split https://mirror.ghproxy.com/https://raw.githubuserco
## 使用 ## 使用
所有功能均可在 Linux / Windows 下使用 > [!TIP]
>
> 所有功能均可在 Linux / Windows 下使用。
>
> Linux 下运行 `bash reinstall.sh`
>
> Windows 下运行 `reinstall.bat`
- Linux 下运行 `bash reinstall.sh` ### 功能 1: 安装 <img width="16" height="16" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux
- Windows 下运行 `reinstall.bat`
### 功能 1: 安装 Linux
- 不输入版本号,则安装最新版 - 不输入版本号,则安装最新版
- 在虚拟机上,会自动安装精简内核 - 不含 boot 分区Fedora 例外),不含 swap 分区,最大化利用磁盘空间
- 在虚拟机上,会自动安装官方精简内核
> [!TIP]
> 安装 Debian / Kali 时x86 可通过后台 VNC 查看安装进度ARM 可通过串行控制台查看安装进度。
>
> 安装其它系统时可通过多种方式SSH、HTTP 80 端口、后台 VNC、串行控制台查看安装进度。
```bash ```bash
bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本) bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本)
oracle 7|8|9 oracle 7|8|9
alma 8|9 alma 8|9
rocky 8|9 rocky 8|9
fedora 38|39|40 fedora 39|40
debian 10|11|12 debian 10|11|12
opensuse 15.5|tumbleweed opensuse 15.5|tumbleweed
ubuntu 20.04|22.04|24.04 ubuntu 20.04|22.04|24.04
alpine 3.16|3.17|3.18|3.19 alpine 3.17|3.18|3.19|3.20
kali kali
arch arch
gentoo gentoo
@ -103,11 +156,14 @@ bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本)
- 支持 gzip、xz 格式 - 支持 gzip、xz 格式
- 静态 IP 的机器 DD Windows会自动配置好 IP - 静态 IP 的机器 DD Windows会自动配置好 IP
> [!TIP]
> 可通过多种方式SSH、HTTP 80 端口、后台 VNC、串行控制台查看安装进度。
```bash ```bash
bash reinstall.sh dd --img https://example.com/xxx.xz bash reinstall.sh dd --img https://example.com/xxx.xz
``` ```
### 功能 3: 重启到 Alpine 救援系统 (Live OS) ### 功能 3: 重启到 <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine 救援系统 (Live OS)
- 可用 ssh 连接,进行手动 DD、修改分区、手动安装 Arch / Gentoo 等操作 - 可用 ssh 连接,进行手动 DD、修改分区、手动安装 Arch / Gentoo 等操作
- 如果没有修改硬盘内容,再次重启将回到原系统 - 如果没有修改硬盘内容,再次重启将回到原系统
@ -116,7 +172,7 @@ bash reinstall.sh dd --img https://example.com/xxx.xz
bash reinstall.sh alpine --hold=1 bash reinstall.sh alpine --hold=1
``` ```
### 功能 4: 重启到 netboot.xyz ### 功能 4: 重启到 <img width="16" height="16" src="https://netboot.xyz/img/favicon.ico" /> netboot.xyz
- 可使用商家后台 VNC 安装 [更多系统](https://github.com/netbootxyz/netboot.xyz?tab=readme-ov-file#what-operating-systems-are-currently-available-on-netbootxyz) - 可使用商家后台 VNC 安装 [更多系统](https://github.com/netbootxyz/netboot.xyz?tab=readme-ov-file#what-operating-systems-are-currently-available-on-netbootxyz)
- 如果没有修改硬盘内容,再次重启将回到原系统 - 如果没有修改硬盘内容,再次重启将回到原系统
@ -127,10 +183,17 @@ bash reinstall.sh netboot.xyz
![netboot.xyz](https://netboot.xyz/images/netboot.xyz.gif) ![netboot.xyz](https://netboot.xyz/images/netboot.xyz.gif)
### 功能 5: 安装 Windows ISO ### 功能 5: 安装 <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows ISO
- 注意参数两边的引号 - 支持自动查找大部分 iso 链接,需指定语言 `--lang`,默认 `en-us`
- 支持自动查找部分 iso 链接,需设置语言 `--lang`,默认 `en-us` - 静态 IP 的机器,安装后会自动配置好 IP
- 能够绕过 Windows 11 安装限制
> [!TIP]
> 脚本以 <https://massgrave.dev/genuine-installation-media.html> 作为 iso 镜像查找源。所有 iso 都是官方原版。
> [!IMPORTANT]
> 注意参数两边有引号。
```bash ```bash
bash reinstall.sh windows \ bash reinstall.sh windows \
@ -146,9 +209,28 @@ bash reinstall.sh windows \
--iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso' --iso 'https://drive.massgrave.dev/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso'
``` ```
<details>
<summary>以下网站可找到 iso 链接</summary>
- Massgrave
- <https://massgrave.dev/genuine-installation-media.html> (推荐iso 来自官方,每月更新,包含最新补丁)
- 微软
- <https://www.microsoft.com/software-download/windows8>
- <https://www.microsoft.com/software-download/windows10> (需用手机 User-Agent 打开)
- <https://www.microsoft.com/software-download/windows11>
- <https://www.microsoft.com/evalcenter/download-windows-10-enterprise>
- <https://www.microsoft.com/evalcenter/download-windows-11-enterprise>
- <https://www.microsoft.com/evalcenter/download-windows-server-2012-r2>
- <https://www.microsoft.com/evalcenter/download-windows-server-2016>
- <https://www.microsoft.com/evalcenter/download-windows-server-2019>
- <https://www.microsoft.com/evalcenter/download-windows-server-2022>
</details>
![Installing Windows](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7) ![Installing Windows](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7)
参数说明: #### 参数说明
`--image-name` 指定要安装的映像,不区分大小写,常用映像有: `--image-name` 指定要安装的映像,不区分大小写,常用映像有:
@ -163,78 +245,36 @@ Windows Server 2022 SERVERDATACENTER
![image-name](https://github.com/bin456789/reinstall/assets/7548515/5aae0a9b-61e2-4f66-bb98-d470a6beaac2) ![image-name](https://github.com/bin456789/reinstall/assets/7548515/5aae0a9b-61e2-4f66-bb98-d470a6beaac2)
1. 支持的系统: #### 支持的系统
- Windows Vista 到 11
- Windows Server 2008 到 2022包括以下衍生版
- Windows Server Essentials
- Windows Server Annual Channel
- Hyper-V Server
- Azure Stack HCI
2. 脚本会按需安装以下驱动:
- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN](https://xenproject.org/windows-pv-drivers/)、[Citrix](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade)、[AWS](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA 网卡](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html)、[NVME 存储控制器](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC 网卡](https://cloud.google.com/compute/docs/networking/using-gvnic)、[GGA 显卡](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA 网卡](https://learn.microsoft.com/azure/virtual-network/accelerated-networking-mana-windows))
3. Vista (Server 2008) 和 32 位系统可能会缺少驱动
4. 未开启 CSM 的 EFI 机器,无法安装 Windows 7 (Server 2008 R2)
5. 静态 IP 的机器,安装后会自动配置好 IP
6. 可绕过 Windows 11 硬件限制
7. 支持 Windows 11 on ARM仅限 Hyper-V (Azure) ,不支持 KVM (甲骨文云)
8. `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso` 此镜像安装后 `wsappx` 进程会长期占用 CPU
这是镜像的问题,解决方法是安装 `VCLibs` - Windows (Vista ~ 11)
- Windows Server (2008 ~ 2022)
- Windows Server Essentials
- Windows Server (Semi) Annual Channel
- Hyper-V Server
- Azure Stack HCI
<https://www.google.com/search?q=ltsc+wsappx> #### 脚本会按需安装以下驱动
9. 以下网站可找到 iso 链接 - KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/))
- XEN ([XEN](https://xenproject.org/windows-pv-drivers/)、[Citrix](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade)、[AWS](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/xen-drivers-overview.html))
- AWS ([ENA 网卡](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/enhanced-networking-ena.html)、[NVME 存储控制器](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/aws-nvme-drivers.html))
- GCP ([gVNIC 网卡](https://cloud.google.com/compute/docs/networking/using-gvnic)、[GGA 显卡](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display))
- Azure ([MANA 网卡](https://learn.microsoft.com/azure/virtual-network/accelerated-networking-mana-windows))
<https://massgrave.dev/genuine-installation-media.html> (推荐iso 来自官方,每月更新,包含最新补丁) > [!WARNING]
> Vista (Server 2008) 和 32 位系统可能会缺少驱动
<https://www.microsoft.com/software-download/windows8> > [!WARNING]
> 未开启 CSM 的 EFI 机器,无法安装 Windows 7 (Server 2008 R2)
<https://www.microsoft.com/software-download/windows10> (需用手机 User-Agent 打开) > [!WARNING]
> 支持 ARM 机器安装 Windows 11仅限于 Hyper-V (Azure) ,不支持 KVM (甲骨文云)
<https://www.microsoft.com/software-download/windows11> > [!WARNING]
> Windows 10 LTSC 2021 中文版镜像 `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso``wsappx` 进程会长期占用 CPU
## 虚拟化要求 >
> 解决方法是更新系统补丁,或者手动安装 `VCLibs`<https://www.google.com/search?q=ltsc+wsappx>
不支持 OpenVZ、LXC 虚拟机
请使用 <https://github.com/LloydAsp/OsMutation>
## 默认密码
| 系统 | 用户名 | 密码 |
| ------------- | ------------- | -------- |
| Linux | root | 123@@@ |
| Windows (iso) | administrator | 123@@@ |
| Windows (dd) | 镜像用户名 | 镜像密码 |
如果远程登录 Windows 提示密码错误,尝试用户名 `.\administrator`
## 如果 Windows 下无法下载脚本
可尝试以下几种方法
1. 关闭 Windows Defender 实时保护
2. Windows 7 安装此补丁启用 TLS 1.2
<https://aka.ms/easyfix51044>
3. 更新 SSL 根证书
```batch
certutil -generateSSTFromWU root.sst
certutil -addstore Root root.sst
```
4. 手动下载,通过 `远程桌面` 复制这两个文件
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.bat>
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh>
## 感谢 ## 感谢

View File

@ -190,10 +190,12 @@ fix_wicked_conf() {
} }
# debian 10/11/12: netplan + networkd/resolved # debian 10/11/12: netplan + networkd/resolved
# 23.1.1 修复
fix_netplan_conf fix_netplan_conf
# arch: networkd/resolved # arch: networkd/resolved
# gentoo: networkd/resolved # gentoo: networkd/resolved
# 24.2 修复
fix_networkd_conf fix_networkd_conf
# opensuse 15.5: ifcfg + netconfig (dns) + wicked # opensuse 15.5: ifcfg + netconfig (dns) + wicked

View File

@ -1,4 +1,5 @@
# shellcheck disable=SC2148,SC2154 #_preseed_V1
# shellcheck disable=SC1091,SC2148
# https://www.debian.org/releases/stable/amd64/apbs04.zh-cn.html # https://www.debian.org/releases/stable/amd64/apbs04.zh-cn.html
# https://www.debian.org/releases/stable/example-preseed.txt # https://www.debian.org/releases/stable/example-preseed.txt
# https://preseed.debian.net/debian-preseed/bookworm/amd64-main-full.txt # https://preseed.debian.net/debian-preseed/bookworm/amd64-main-full.txt
@ -109,6 +110,8 @@ d-i finish-install/reboot_in_progress note
# B.5.1. 安装过程中运行用户命令 # B.5.1. 安装过程中运行用户命令
# 注意所有命令都会合并成一行命令 # 注意所有命令都会合并成一行命令
# 最后的 true; \ 没什么用,只是让 vscode 代码高亮不报错误
# 有 /cdrom/simple-cdd 才安装 simple-cdd-profiles # 有 /cdrom/simple-cdd 才安装 simple-cdd-profiles
# 不然安装时 control 脚本会报错: # 不然安装时 control 脚本会报错:
# Loading simple-cdd-profiles failed for unknown reasons # Loading simple-cdd-profiles failed for unknown reasons
@ -118,16 +121,19 @@ d-i preseed/early_command string true; \
# debian 11 initrd 没有 xargs awk # debian 11 initrd 没有 xargs awk
# debian 12 initrd 没有 xargs # debian 12 initrd 没有 xargs
# efi 分区大小未改变时,不会被格式化,因此需要手动删除旧系统的 efi 文件 # efi 分区大小未改变时,不会被格式化,因此需要手动删除旧系统的 efi 文件
# os-prober 卡太久,因此跳过
d-i partman/early_command string true; \
confhome="$(grep -o 'extra\.confhome=[^ ]*' /proc/cmdline | cut -d= -f2)"; \ confhome="$(grep -o 'extra\.confhome=[^ ]*' /proc/cmdline | cut -d= -f2)"; \
swapfile=/target/swapfile; \
postinst=/var/lib/dpkg/info/bootstrap-base.postinst; \ postinst=/var/lib/dpkg/info/bootstrap-base.postinst; \
cp $postinst $postinst.orig; \ cp $postinst $postinst.orig; \
true >$postinst; \
mem=$(grep ^MemTotal: /proc/meminfo | { read x y z; echo $y; }); \ swapfile=/target/swapfile; \
mem=$(grep ^MemTotal: /proc/meminfo | { read -r _ y _; echo "$y"; }); \
mem=$((mem / 1024)); \ mem=$((mem / 1024)); \
swap_size=$((512 - mem)); \ swap_size=$((512 - mem)); \
[ $swap_size -gt 0 ] && echo "fallocate -l ${swap_size}M $swapfile; mkswap $swapfile; swapon $swapfile; $postinst.orig" >$postinst; \ [ $swap_size -gt 0 ] && echo "fallocate -l ${swap_size}M $swapfile; mkswap $swapfile; swapon $swapfile" >>$postinst; \
echo "swapoff -a; rm -f $swapfile" >/usr/lib/finish-install.d/95swapoff; \ echo "swapoff -a; rm -f $swapfile" >/usr/lib/finish-install.d/95swapoff; \
chmod a+x /usr/lib/finish-install.d/95swapoff; \ chmod a+x /usr/lib/finish-install.d/95swapoff; \
@ -139,7 +145,7 @@ d-i preseed/early_command string true; \
debconf-set grub-installer/bootdev "/dev/$xda"; \ debconf-set grub-installer/bootdev "/dev/$xda"; \
rm -rf /usr/sbin/fdisk /usr/sbin/sfdisk; \ rm -rf /usr/sbin/fdisk /usr/sbin/sfdisk; \
ttys=$(wget --tries=5 $confhome/ttys.sh -O- | sh -s console=); \ ttys=$(wget --tries=5 "$confhome/ttys.sh" -O- | sh -s console=); \
debconf-set debian-installer/add-kernel-opts "$ttys"; \ debconf-set debian-installer/add-kernel-opts "$ttys"; \
sh /can_use_cloud_kernel.sh "$xda" || debconf-set base-installer/kernel/image "$(debconf-get base-installer/kernel/image | sed 's/-cloud//')"; \ sh /can_use_cloud_kernel.sh "$xda" || debconf-set base-installer/kernel/image "$(debconf-get base-installer/kernel/image | sed 's/-cloud//')"; \
@ -149,11 +155,9 @@ d-i preseed/early_command string true; \
true >/bin/os-prober true >/bin/os-prober
# os-prober 卡太久,因此跳过
# debian 10 没有 /target/etc/ssh/sshd_config.d/ 文件夹 # debian 10 没有 /target/etc/ssh/sshd_config.d/ 文件夹
# kali ssh 默认关闭 # kali ssh 默认关闭
d-i preseed/late_command string \ d-i preseed/late_command string true; \
in-target systemctl enable ssh; \ in-target systemctl enable ssh; \
echo "PermitRootLogin yes" >/target/etc/ssh/sshd_config.d/01-permitrootlogin.conf || \ echo "PermitRootLogin yes" >/target/etc/ssh/sshd_config.d/01-permitrootlogin.conf || \
echo "PermitRootLogin yes" >>/target/etc/ssh/sshd_config echo "PermitRootLogin yes" >>/target/etc/ssh/sshd_config

View File

@ -48,6 +48,7 @@ if not errorlevel 1 (
) )
) )
) else ( ) else (
rem 服务器在美国 equinix 机房,不是 cdn
set mirror=http://mirrors.kernel.org set mirror=http://mirrors.kernel.org
) )

View File

@ -30,11 +30,11 @@ Usage: $reinstall____ centos 7|8|9
oracle 7|8|9 oracle 7|8|9
alma 8|9 alma 8|9
rocky 8|9 rocky 8|9
fedora 38|39|40 fedora 39|40
debian 10|11|12 debian 10|11|12
ubuntu 20.04|22.04|24.04
alpine 3.16|3.17|3.18|3.19
opensuse 15.5|tumbleweed opensuse 15.5|tumbleweed
ubuntu 20.04|22.04|24.04
alpine 3.17|3.18|3.19|3.20
kali kali
arch arch
gentoo gentoo
@ -472,15 +472,16 @@ is_have_arm_version() {
case "$version" in case "$version" in
10) 10)
case "$edition" in case "$edition" in
pro | 'pro for workstations' | education | 'pro education' | enterprise) return ;; pro | education | enterprise | 'pro education' | 'pro for workstations') return ;;
'iot enterprise') return ;; 'iot enterprise') return ;;
'iot enterprise ltsc 2021' | 'enterprise ltsc 2021') return ;; 'enterprise ltsc 2021' | 'iot enterprise ltsc 2021') return ;;
esac esac
;; ;;
11) 11)
case "$edition" in case "$edition" in
pro | 'pro for workstations' | education | 'pro education' | enterprise) return ;; pro | education | enterprise | 'pro education' | 'pro for workstations') return ;;
'iot enterprise') return ;; 'iot enterprise') return ;;
'enterprise ltsc 2024' | 'iot enterprise ltsc 2024' | 'iot enterprise ltsc 2024 subscription') return ;;
esac esac
;; ;;
esac esac
@ -567,7 +568,7 @@ get_windows_iso_links() {
10) 10)
case "$edition" in case "$edition" in
home | 'home single language') echo consumer ;; home | 'home single language') echo consumer ;;
pro | 'pro for workstations' | education | 'pro education' | enterprise) echo business ;; pro | education | enterprise | 'pro education' | 'pro for workstations') echo business ;;
'iot enterprise') echo 'iot enterprise' ;; 'iot enterprise') echo 'iot enterprise' ;;
'enterprise 2015 ltsb' | 'enterprise 2016 ltsb' | 'enterprise ltsc 2019') echo "$edition" ;; 'enterprise 2015 ltsb' | 'enterprise 2016 ltsb' | 'enterprise ltsc 2019') echo "$edition" ;;
'enterprise ltsc 2021') 'enterprise ltsc 2021')
@ -583,8 +584,10 @@ get_windows_iso_links() {
11) 11)
case "$edition" in case "$edition" in
home | 'home single language') echo consumer ;; home | 'home single language') echo consumer ;;
pro | 'pro for workstations' | education | 'pro education' | enterprise) echo business ;; pro | education | enterprise | 'pro education' | 'pro for workstations') echo business ;;
'iot enterprise') echo 'iot enterprise' ;; 'iot enterprise') echo 'iot enterprise' ;;
'enterprise ltsc 2024') echo 'enterprise ltsc 2024' ;;
'iot enterprise ltsc 2024' | 'iot enterprise ltsc 2024 subscription') echo 'iot enterprise ltsc 2024' ;;
esac esac
;; ;;
esac esac
@ -595,7 +598,7 @@ get_windows_iso_links() {
case "$version" in case "$version" in
10 | 11) 10 | 11)
case "$edition" in case "$edition" in
pro | 'pro for workstations' | education | 'pro education' | enterprise) echo pro ;; pro | education | enterprise | 'pro education' | 'pro for workstations') echo pro ;;
esac esac
;; ;;
esac esac
@ -640,7 +643,7 @@ get_windows_iso_links() {
error_and_exit "Not support find this iso. Check --image-name or set --iso manually." error_and_exit "Not support find this iso. Check --image-name or set --iso manually."
fi fi
curl -L "$page_url" | grep -ioP 'https://.*?.iso' | awk -F/ '{print $NF}' >$tmp/win.list curl -L "$page_url" | grep -ioP 'https://.*?.iso' >$tmp/win.list
# 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的 # 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的
# 例如查找 windows 10 iot enterprise会得到 # 例如查找 windows 10 iot enterprise会得到
@ -689,9 +692,8 @@ get_windows_iso_link() {
for regex in "${regexs[@]}"; do for regex in "${regexs[@]}"; do
regex=${regex// /_} regex=${regex// /_}
echo "finding: $regex" >&2 echo "looking for: $regex" >&2
if file=$(grep -Eix "$regex" "$tmp/win.list" | get_shortest_line | grep .); then if iso=$(grep -Ei "/$regex" "$tmp/win.list" | get_shortest_line | grep .); then
iso="https://drive.massgrave.dev/$file"
return return
fi fi
done done
@ -759,22 +761,25 @@ setos() {
if is_in_china; then if is_in_china; then
cdimage_mirror=https://mirrors.ustc.edu.cn/debian-cdimage cdimage_mirror=https://mirrors.ustc.edu.cn/debian-cdimage
else else
cdimage_mirror=https://cdimage.debian.org/images cdimage_mirror=https://cdimage.debian.org/images # 在瑞典,不是 cdn
# cloud.debian.org 同样在瑞典,不是 cdn
fi fi
if is_use_cloud_image; then if is_use_cloud_image; then
# cloud image # cloud image
is_virt && ci_type=genericcloud || ci_type=generic is_virt && ci_type=genericcloud || ci_type=generic
# 甲骨文 debian 10 amd64 genericcloud vnc 没有显示 # 甲骨文 debian 10 amd64 genericcloud vnc 没有显示
[ "$releasever" -eq 10 ] && [ "$basearch_alt" = amd64 ] && ci_type=generic # 甲骨文 debian 10 arm64 没有 genericcloud 镜像
[ "$releasever" -eq 10 ] && ci_type=generic
eval ${step}_img=$cdimage_mirror/cloud/$codename/latest/debian-$releasever-$ci_type-$basearch_alt.qcow2 eval ${step}_img=$cdimage_mirror/cloud/$codename/latest/debian-$releasever-$ci_type-$basearch_alt.qcow2
else else
# 传统安装 # 传统安装
if is_in_china; then if is_in_china; then
# 部分国内机无法访问 ftp.cn.debian.org # ftp.cn.debian.org 不在国内还严重丢包
# https://www.itdog.cn/ping/ftp.cn.debian.org
deb_hostname=mirrors.tuna.tsinghua.edu.cn deb_hostname=mirrors.tuna.tsinghua.edu.cn
else else
deb_hostname=deb.debian.org deb_hostname=deb.debian.org # fastly
fi fi
mirror=http://$deb_hostname/debian/dists/$codename/main/installer-$basearch_alt/current/images/netboot/debian-installer/$basearch_alt mirror=http://$deb_hostname/debian/dists/$codename/main/installer-$basearch_alt/current/images/netboot/debian-installer/$basearch_alt
@ -800,7 +805,8 @@ setos() {
if is_in_china; then if is_in_china; then
deb_hostname=mirrors.tuna.tsinghua.edu.cn deb_hostname=mirrors.tuna.tsinghua.edu.cn
else else
deb_hostname=kali.download # http.kali.org (geoip 重定向) 到 kali.download (cf)
deb_hostname=http.kali.org
fi fi
codename=kali-rolling codename=kali-rolling
mirror=http://$deb_hostname/kali/dists/$codename/main/installer-$basearch_alt/current/images/netboot/debian-installer/$basearch_alt mirror=http://$deb_hostname/kali/dists/$codename/main/installer-$basearch_alt/current/images/netboot/debian-installer/$basearch_alt
@ -827,6 +833,12 @@ setos() {
if is_use_cloud_image; then if is_use_cloud_image; then
# cloud image # cloud image
if is_in_china; then if is_in_china; then
# 有的源没有 releases 镜像
# https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/releases/
# https://unicom.mirrors.ustc.edu.cn/ubuntu-cloud-images/releases/
# https://mirror.nju.edu.cn/ubuntu-cloud-images/releases/
# mirrors.cloud.tencent.com
ci_mirror=https://mirror.nju.edu.cn/ubuntu-cloud-images ci_mirror=https://mirror.nju.edu.cn/ubuntu-cloud-images
else else
ci_mirror=https://cloud-images.ubuntu.com ci_mirror=https://cloud-images.ubuntu.com
@ -869,14 +881,14 @@ setos() {
if is_in_china; then if is_in_china; then
mirror=https://mirrors.tuna.tsinghua.edu.cn/archlinux mirror=https://mirrors.tuna.tsinghua.edu.cn/archlinux
else else
mirror=https://geo.mirror.pkgbuild.com mirror=https://geo.mirror.pkgbuild.com # geoip
fi fi
else else
if is_in_china; then if is_in_china; then
mirror=https://mirrors.tuna.tsinghua.edu.cn/archlinuxarm mirror=https://mirrors.tuna.tsinghua.edu.cn/archlinuxarm
else else
# https 证书有问题 # https 证书有问题
mirror=http://mirror.archlinuxarm.org mirror=http://mirror.archlinuxarm.org # geoip
fi fi
fi fi
@ -898,8 +910,7 @@ setos() {
if is_in_china; then if is_in_china; then
mirror=https://mirrors.tuna.tsinghua.edu.cn/gentoo mirror=https://mirrors.tuna.tsinghua.edu.cn/gentoo
else else
# mirror=https://mirror.leaseweb.com/gentoo # 不支持 ipv6 mirror=https://distfiles.gentoo.org # cdn77
mirror=https://distfiles.gentoo.org
fi fi
if is_use_cloud_image; then if is_use_cloud_image; then
@ -995,13 +1006,7 @@ setos() {
"8" | "9") ci_image=$ci_mirror/$releasever-stream/$basearch/images/CentOS-Stream-GenericCloud-$releasever-latest.$basearch.qcow2 ;; "8" | "9") ci_image=$ci_mirror/$releasever-stream/$basearch/images/CentOS-Stream-GenericCloud-$releasever-latest.$basearch.qcow2 ;;
esac esac
;; ;;
"alma") "alma") ci_image=$ci_mirror/AlmaLinux-$releasever-GenericCloud-latest.$basearch.qcow2 ;;
# alma8 x86_64 有独立的uefi镜像
if [ "$releasever" = 8 ] && is_efi && [ "$basearch" = x86_64 ]; then
alma_efi=-UEFI
fi
ci_image=$ci_mirror/AlmaLinux-$releasever-GenericCloud$alma_efi-latest.$basearch.qcow2
;;
"rocky") ci_image=$ci_mirror/Rocky-$releasever-GenericCloud-Base.latest.$basearch.qcow2 ;; "rocky") ci_image=$ci_mirror/Rocky-$releasever-GenericCloud-Base.latest.$basearch.qcow2 ;;
"fedora") "fedora")
# Fedora-Cloud-Base-39-1.5.x86_64.qcow2 # Fedora-Cloud-Base-39-1.5.x86_64.qcow2
@ -1128,11 +1133,11 @@ verify_os_name() {
'oracle 7|8|9' \ 'oracle 7|8|9' \
'alma 8|9' \ 'alma 8|9' \
'rocky 8|9' \ 'rocky 8|9' \
'fedora 38|39|40' \ 'fedora 39|40' \
'debian 10|11|12' \ 'debian 10|11|12' \
'ubuntu 20.04|22.04|24.04' \
'alpine 3.16|3.17|3.18|3.19' \
'opensuse 15.5|tumbleweed' \ 'opensuse 15.5|tumbleweed' \
'ubuntu 20.04|22.04|24.04' \
'alpine 3.17|3.18|3.19|3.20' \
'kali' \ 'kali' \
'arch' \ 'arch' \
'gentoo' \ 'gentoo' \
@ -1690,7 +1695,7 @@ add_efi_entry_in_linux() {
install_pkg efibootmgr install_pkg efibootmgr
for efi_part in $(get_maybe_efi_dirs_in_linux); do for efi_part in $(get_maybe_efi_dirs_in_linux); do
if find $efi_part -name "*.efi" >/dev/null; then if find $efi_part -iname "*.efi" >/dev/null; then
dist_dir=$efi_part/EFI/reinstall dist_dir=$efi_part/EFI/reinstall
basename=$(basename $source) basename=$(basename $source)
mkdir -p $dist_dir mkdir -p $dist_dir
@ -1740,9 +1745,10 @@ install_grub_linux_efi() {
# 不要用 download.opensuse.org 和 download.fedoraproject.org # 不要用 download.opensuse.org 和 download.fedoraproject.org
# 因为 ipv6 访问有时跳转到 ipv4 地址,造成 ipv6 only 机器无法下载 # 因为 ipv6 访问有时跳转到 ipv4 地址,造成 ipv6 only 机器无法下载
# 日韩机器有时得到国内链接,且连不上 # 日韩机器有时得到国内镜像源,但镜像源屏蔽了国外 IP 导致连不上
# https://mirrors.bfsu.edu.cn/opensuse/ports/aarch64/tumbleweed/repo/oss/EFI/BOOT/grub.efi
if [ "$efi_distro" = fedora ]; then if [ "$efi_distro" = fedora ]; then
fedora_ver=39 fedora_ver=40
if is_in_china; then if is_in_china; then
mirror=https://mirrors.tuna.tsinghua.edu.cn/fedora mirror=https://mirrors.tuna.tsinghua.edu.cn/fedora
@ -1770,6 +1776,8 @@ install_grub_win() {
# 下载 grub # 下载 grub
info download grub info download grub
grub_ver=2.06 grub_ver=2.06
# ftpmirror.gnu.org 是 geoip 重定向,不是 cdn
# 有可能重定义到一个拉黑了部分 IP 的服务器
is_in_china && grub_url=https://mirrors.tuna.tsinghua.edu.cn/gnu/grub/grub-$grub_ver-for-windows.zip || is_in_china && grub_url=https://mirrors.tuna.tsinghua.edu.cn/gnu/grub/grub-$grub_ver-for-windows.zip ||
grub_url=https://ftpmirror.gnu.org/gnu/grub/grub-$grub_ver-for-windows.zip grub_url=https://ftpmirror.gnu.org/gnu/grub/grub-$grub_ver-for-windows.zip
curl -Lo $tmp/grub.zip $grub_url curl -Lo $tmp/grub.zip $grub_url
@ -1796,6 +1804,7 @@ install_grub_win() {
# efi # efi
info install grub for efi info install grub for efi
if [ "$basearch" = aarch64 ]; then if [ "$basearch" = aarch64 ]; then
# 3.20 是 grub 2.12,可能会有问题
alpine_ver=3.19 alpine_ver=3.19
is_in_china && mirror=http://mirrors.tuna.tsinghua.edu.cn/alpine || mirror=https://dl-cdn.alpinelinux.org/alpine is_in_china && mirror=http://mirrors.tuna.tsinghua.edu.cn/alpine || mirror=https://dl-cdn.alpinelinux.org/alpine
grub_efi_apk=$(curl -L $mirror/v$alpine_ver/main/aarch64/ | grep -oP 'grub-efi-.*?apk' | head -1) grub_efi_apk=$(curl -L $mirror/v$alpine_ver/main/aarch64/ | grep -oP 'grub-efi-.*?apk' | head -1)
@ -2436,7 +2445,7 @@ mod_initrd() {
# 解压 # 解压
# 先删除临时文件,避免之前运行中断有残留文件 # 先删除临时文件,避免之前运行中断有残留文件
tmp_dir=$tmp/reinstall tmp_dir=$tmp/initrd
mkdir_clear $tmp_dir mkdir_clear $tmp_dir
cd $tmp_dir cd $tmp_dir
@ -2562,7 +2571,7 @@ else
fi fi
# 整理参数 # 整理参数
if ! opts=$(getopt -n $0 -o "" --long ci,debug,hold:,sleep:,iso:,image-name:,img:,lang: -- "$@"); then if ! opts=$(getopt -n $0 -o "" --long ci,debug,hold:,sleep:,iso:,image-name:,img:,lang,commit: -- "$@"); then
usage_and_exit usage_and_exit
fi fi
@ -2570,6 +2579,10 @@ eval set -- "$opts"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
while true; do while true; do
case "$1" in case "$1" in
--commit)
commit=$2
shift 2
;;
--debug) --debug)
set -x set -x
shift shift
@ -2681,9 +2694,24 @@ esac
# gitee 不支持ipv6 # gitee 不支持ipv6
# jsdelivr 有12小时缓存 # jsdelivr 有12小时缓存
# https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L31 # https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L31
if [ -n "$github_proxy" ] && [[ "$confhome" = http*://raw.githubusercontent.com/* ]] && is_in_china; then if [ -n "$github_proxy" ] && [[ "$confhome" = http*://raw.githubusercontent.com/* ]]; then
confhome=${confhome/http:\/\//https:\/\/} # 未测试
confhome=${confhome/https:\/\/raw.githubusercontent.com/$github_proxy} if false; then
repo=$(echo $confhome | cut -d/ -f4,5)
branch=$(echo $confhome | cut -d/ -f6)
# 避免脚本更新时,文件不同步造成错误
if [ -z "$commit" ]; then
commit=$(curl -L https://api.github.com/repos/$repo/git/refs/heads/$branch |
grep '"sha"' | grep -Eo '[0-9a-f]{40}')
fi
# shellcheck disable=SC2001
confhome=$(echo "$confhome" | sed "s/main$/$commit/")
fi
if is_in_china; then
confhome=${confhome/http:\/\//https:\/\/}
confhome=${confhome/https:\/\/raw.githubusercontent.com/$github_proxy}
fi
fi fi
# 以下目标系统不需要两步安装 # 以下目标系统不需要两步安装

View File

@ -112,7 +112,7 @@ download() {
apk add coreutils apk add coreutils
fi fi
# 阿里云源检测 user-agent 禁止 axel/aria2 下载 # 阿里云源限速,而且检测 user-agent 禁止 axel/aria2 下载
# aria2 默认 --max-tries 5 # aria2 默认 --max-tries 5
# 默认 --max-tries=5但以下情况服务器出错aria2不会重试而是直接返回错误 # 默认 --max-tries=5但以下情况服务器出错aria2不会重试而是直接返回错误
@ -395,10 +395,10 @@ get_netconf_to() {
# shellcheck disable=SC2154 # shellcheck disable=SC2154
# debian initrd 没有 xargs # debian initrd 没有 xargs
case "$1" in case "$1" in
slaac) echo "$ra" | grep 'Autonomous address conf' | grep Yes && res=1 || res=0 ;; slaac) echo "$ra" | grep 'Autonomous address conf' | grep -q Yes && res=1 || res=0 ;;
dhcpv6) echo "$ra" | grep 'Stateful address conf' | grep Yes && res=1 || res=0 ;; dhcpv6) echo "$ra" | grep 'Stateful address conf' | grep -q Yes && res=1 || res=0 ;;
rdnss) res=$(echo "$ra" | grep 'Recursive DNS server' | cut -d: -f2-) ;; rdnss) res=$(echo "$ra" | grep 'Recursive DNS server' | cut -d: -f2-) ;;
other) echo "$ra" | grep 'Stateful other conf' | grep Yes && res=1 || res=0 ;; other) echo "$ra" | grep 'Stateful other conf' | grep -q Yes && res=1 || res=0 ;;
*) res=$(cat /dev/$1) ;; *) res=$(cat /dev/$1) ;;
esac esac
@ -936,7 +936,7 @@ EOF
pacstrap -K $os_dir $pkgs pacstrap -K $os_dir $pkgs
# dns # dns
cp -f /etc/resolv.conf $os_dir/etc/resolv.conf cp_resolv_conf $os_dir
# 挂载伪文件系统 # 挂载伪文件系统
mount_pseudo_fs $os_dir mount_pseudo_fs $os_dir
@ -982,7 +982,7 @@ EOF
apk del tar xz apk del tar xz
# dns # dns
cp -f /etc/resolv.conf $os_dir/etc/resolv.conf cp_resolv_conf $os_dir
# 挂载伪文件系统 # 挂载伪文件系统
mount_pseudo_fs $os_dir mount_pseudo_fs $os_dir
@ -1187,7 +1187,7 @@ EOF
apk del arch-install-scripts apk del arch-install-scripts
# 删除 resolv.conf不然 systemd-resolved 无法创建软链接 # 删除 resolv.conf不然 systemd-resolved 无法创建软链接
rm -f $os_dir/etc/resolv.conf rm_resolv_conf $os_dir
# 删除 swap # 删除 swap
swapoff -a swapoff -a
@ -1587,7 +1587,7 @@ download_cloud_init_config() {
if ! grep -w swap $os_dir/etc/fstab; then if ! grep -w swap $os_dir/etc/fstab; then
# btrfs # btrfs
# 目前只有 arch 和 fedora 镜像使用 btrfs # 目前只有 arch 和 fedora 镜像使用 btrfs
# 等 fedora 38 cloud-init 升级到 v23.3 后删除 # 等 fedora 39 cloud-init 升级到 v23.3 后删除
if mount | grep 'on /os type btrfs'; then if mount | grep 'on /os type btrfs'; then
insert_into_file $ci_file after '^runcmd:' <<EOF insert_into_file $ci_file after '^runcmd:' <<EOF
- btrfs filesystem mkswapfile --size 1G /swapfile - btrfs filesystem mkswapfile --size 1G /swapfile
@ -1711,12 +1711,16 @@ get_axx64() {
esac esac
} }
cp_resolv_conf() { is_file_or_link() {
os_dir=$1
# -e / -f 坏软连接,返回 false # -e / -f 坏软连接,返回 false
# -L 坏软连接,返回 true # -L 坏软连接,返回 true
if { [ -e $os_dir/etc/resolv.conf ] || [ -L $os_dir/etc/resolv.conf ]; } && [ -f $1 ] || [ -L $1 ]
! { [ -e $os_dir/etc/resolv.conf.orig ] || [ -L $os_dir/etc/resolv.conf.orig ]; }; then }
cp_resolv_conf() {
os_dir=$1
if is_file_or_link $os_dir/etc/resolv.conf &&
! is_file_or_link $os_dir/etc/resolv.conf.orig; then
mv $os_dir/etc/resolv.conf $os_dir/etc/resolv.conf.orig mv $os_dir/etc/resolv.conf $os_dir/etc/resolv.conf.orig
fi fi
cp -f /etc/resolv.conf $os_dir/etc/resolv.conf cp -f /etc/resolv.conf $os_dir/etc/resolv.conf
@ -1729,7 +1733,7 @@ rm_resolv_conf() {
restore_resolv_conf() { restore_resolv_conf() {
os_dir=$1 os_dir=$1
if [ -f $os_dir/etc/resolv.conf.orig ]; then if is_file_or_link $os_dir/etc/resolv.conf.orig; then
mv -f $os_dir/etc/resolv.conf.orig $os_dir/etc/resolv.conf mv -f $os_dir/etc/resolv.conf.orig $os_dir/etc/resolv.conf
fi fi
} }
@ -1770,7 +1774,7 @@ EOF
# 修复 fedora 38 或以下用静态 ipv6 会掉线 # 修复 fedora 38 或以下用静态 ipv6 会掉线
# el 全系也用 NetworkManager但他们的配置文件是 sysconfig因此不受影响 # el 全系也用 NetworkManager但他们的配置文件是 sysconfig因此不受影响
# https://github.com/canonical/cloud-init/commit/5d440856cb6d2b4c908015fe4eb7227615c17c8b # https://github.com/canonical/cloud-init/commit/5d440856cb6d2b4c908015fe4eb7227615c17c8b
if grep -E 'fedora:38' $os_dir/etc/os-release; then if false && grep -E 'fedora:38' $os_dir/etc/os-release; then
network_manager_py=$os_dir/usr/lib/python3.11/site-packages/cloudinit/net/network_manager.py network_manager_py=$os_dir/usr/lib/python3.11/site-packages/cloudinit/net/network_manager.py
if ! grep '"static6": "manual",' $network_manager_py; then if ! grep '"static6": "manual",' $network_manager_py; then
echo '"static6": "manual",' | insert_into_file $network_manager_py after '"static": "manual",' echo '"static6": "manual",' | insert_into_file $network_manager_py after '"static": "manual",'
@ -1850,19 +1854,18 @@ EOF
add_onlink_script_if_need add_onlink_script_if_need
# 同步证书 # 同步证书
rm $os_dir/etc/resolv.conf cp_resolv_conf $os_dir
cp /etc/resolv.conf $os_dir/etc/resolv.conf
mount_pseudo_fs $os_dir mount_pseudo_fs $os_dir
chroot $os_dir pacman-key --init chroot $os_dir pacman-key --init
chroot $os_dir pacman-key --populate chroot $os_dir pacman-key --populate
rm $os_dir/etc/resolv.conf rm_resolv_conf $os_dir
fi fi
# gentoo # gentoo
if [ -f $os_dir/etc/gentoo-release ]; then if [ -f $os_dir/etc/gentoo-release ]; then
# 挂载伪文件系统 # 挂载伪文件系统
mount_pseudo_fs $os_dir mount_pseudo_fs $os_dir
cp -f /etc/resolv.conf $os_dir/etc/resolv.conf cp_resolv_conf $os_dir
# 在这里修改密码而不是用cloud-init因为我们的默认密码太弱 # 在这里修改密码而不是用cloud-init因为我们的默认密码太弱
sed -i 's/enforce=everyone/enforce=none/' $os_dir/etc/security/passwdqc.conf sed -i 's/enforce=everyone/enforce=none/' $os_dir/etc/security/passwdqc.conf
@ -1876,7 +1879,7 @@ EOF
chroot $os_dir eselect profile set $profile chroot $os_dir eselect profile set $profile
# 删除 resolv.conf不然 systemd-resolved 无法创建软链接 # 删除 resolv.conf不然 systemd-resolved 无法创建软链接
rm -f $os_dir/etc/resolv.conf rm_resolv_conf $os_dir
# 启用网络服务 # 启用网络服务
chroot $os_dir systemctl enable systemd-networkd chroot $os_dir systemctl enable systemd-networkd
@ -2201,7 +2204,7 @@ install_qcow_by_copy() {
modify_el_ol() { modify_el_ol() {
# resolv.conf # resolv.conf
cp /etc/resolv.conf /os/etc/resolv.conf cp_resolv_conf /os
# selinux kdump # selinux kdump
disable_selinux_kdump /os disable_selinux_kdump /os
@ -2219,6 +2222,7 @@ install_qcow_by_copy() {
# 删除云镜像自带的 dhcp 配置,防止歧义 # 删除云镜像自带的 dhcp 配置,防止歧义
# clout-init 网络配置在 /etc/sysconfig/network-scripts/ # clout-init 网络配置在 /etc/sysconfig/network-scripts/
rm -rf /os/etc/NetworkManager/system-connections/*.nmconnection rm -rf /os/etc/NetworkManager/system-connections/*.nmconnection
rm -rf /os/etc/sysconfig/network-scripts/ifcfg-*
# 为 centos 7 ci 安装 NetworkManager # 为 centos 7 ci 安装 NetworkManager
# 1. 能够自动配置 onlink 网关 # 1. 能够自动配置 onlink 网关
@ -2332,14 +2336,13 @@ EOF
fi fi
# 不删除可能网络管理器不会写入dns # 不删除可能网络管理器不会写入dns
rm -f /os/etc/resolv.conf rm_resolv_conf /os
} }
modify_ubuntu() { modify_ubuntu() {
os_dir=/os os_dir=/os
mv $os_dir/etc/resolv.conf $os_dir/etc/resolv.conf.orig cp_resolv_conf $os_dir
cp /etc/resolv.conf $os_dir/etc/resolv.conf
# 关闭 os prober因为 os prober 有时很慢 # 关闭 os prober因为 os prober 有时很慢
cp $os_dir/etc/default/grub $os_dir/etc/default/grub.orig cp $os_dir/etc/default/grub $os_dir/etc/default/grub.orig
@ -3375,6 +3378,7 @@ if [ "$hold" = 2 ]; then
exit exit
fi fi
cd /
# 让 web 输出全部内容 # 让 web 输出全部内容
sleep 5 sleep 5
reboot reboot