Skip to content

Commit a12718e

Browse files
committed
windows: 从 inf 获取驱动文件列表
1 parent 0be857b commit a12718e

6 files changed

+435
-70
lines changed

README.en.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@
1111

1212
One-Click Script to Reinstall System [中文](README.md)
1313

14-
![Sponsors](https://raw.githubusercontent.com/bin456789/sponsors/refs/heads/master/sponsors.svg)
14+
[![Sponsors](https://raw.githubusercontent.com/bin456789/sponsors/refs/heads/master/sponsors.svg)](https://github.com/sponsors/bin456789)
1515

1616
## Highlights
1717

1818
- One-click Linux installation: Supports 19 common distributions.
1919
- One-click Windows installation: Uses the official ISO for installation instead of custom images. The script can automatically ~~retrieves the ISO link~~ and installs common drivers like `Virtio`.
2020
- Supports installation in any direction, i.e., `Linux to Linux`, `Linux to Windows`, `Windows to Windows`, `Windows to Linux`
21-
- No need to input IP parameters; automatically recognizes dynamic and static IPs, supports `/32`, `/128`, `gateway outside subnet`, `IPv6 only`, `dual NIC` and other special network configurations
21+
- No need to input IP parameters; automatically recognizes dynamic and static IPs, supports `/32`, `/128`, `gateway outside subnet`, `IPv6 only`, `dual NIC`
2222
- Specially optimized for low-spec servers, requires less memory than the official netboot
2323
- Uses partition table ID to identify hard drives throughout the process, ensuring no wrong disk is written
2424
- Supports BIOS and EFI boot, and ARM Server
2525
- No homemades image included, all resources are obtained in real-time from mirror sites
26-
- Includes many comments.
2726

2827
## System Requirements
2928

@@ -32,7 +31,7 @@ The original system can be any system listed in the table.
3231
The system requirements for the target system are as follows:
3332

3433
| System | Version | Memory | Disk |
35-
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | --------- | -----------------|
34+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | --------- | ---------------- |
3635
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.18, 3.19, 3.20, 3.21 | 256 MB | 1 GB |
3736
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ |
3837
| <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 ^ |
@@ -144,6 +143,7 @@ bash reinstall.sh anolis 7|8|23
144143
kali
145144
arch
146145
gentoo
146+
aosc
147147
fnos
148148
```
149149

@@ -329,13 +329,23 @@ bash reinstall.sh windows \
329329
--iso "https://go.microsoft.com/fwlink/?linkid=2289029"
330330
```
331331

332+
or Magnet Link
333+
334+
```bash
335+
bash reinstall.sh windows \
336+
--image-name "Windows 11 Enterprise LTSC 2024" \
337+
--iso "magnet:?xt=urn:btih:7352bd2db48c3381dffa783763dc75aa4a6f1cff"
338+
```
339+
332340
<details>
333341

334342
<summary>The following website provides ISO links.</summary>
335343

336344
- General
337345
- <https://msdl.gravesoft.dev>
338346
- <https://massgrave.dev/genuine-installation-media>
347+
- <https://next.itellyou.cn>
348+
- <https://www.xitongku.com>
339349
- <https://www.microsoft.com/software-download/windows10> (Need to open it with a non-Windows User-Agent)
340350
- <https://www.microsoft.com/software-download/windows11>
341351
- <https://www.microsoft.com/software-download/windows11arm64>
@@ -349,8 +359,8 @@ bash reinstall.sh windows \
349359
- <https://www.microsoft.com/evalcenter/download-windows-server-2022>
350360
- <https://www.microsoft.com/evalcenter/download-windows-server-2025>
351361
- Insider Preview
352-
- <https://www.microsoft.com/software-download/windowsinsiderpreviewiso>
353-
- <https://www.microsoft.com/software-download/windowsinsiderpreviewserver>
362+
- <https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewiso>
363+
- <https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewserver>
354364

355365
</details>
356366

@@ -361,10 +371,9 @@ bash reinstall.sh windows \
361371
- `--rdp-port PORT` Change RDP port
362372
- `--ssh-port PORT` Change SSH port (for log observation during installation)
363373
- `--web-port PORT` Change Web port (for log observation during installation)
364-
- `--add-driver-dir DIR` Adds additional driver, specifying the folder where the .inf file is located.
374+
- `--add-driver INF_OR_DIR` Add additional driver, specifying .inf path, or the folder contains .inf file.
365375
- The driver must be downloaded locally first.
366-
- This parameter can be set multiple times to add different driver folders.
367-
- The script will copy the entire folder, so no other files should be placed inside the folder.
376+
- This parameter can be set multiple times to add different driver.
368377
- `--hold 2` Allow SSH connections for modifying the disk content before rebooting into the official Windows installation program, with the disk mounted at `/os`.
369378

370379
#### The following drivers will automatic download and install as needed, without the need for manual addition

README.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@
1111

1212
一键重装脚本 [English](README.en.md)
1313

14-
![捐赠者](https://raw.githubusercontent.com/bin456789/sponsors/refs/heads/master/sponsors.svg)
14+
[![Sponsors](https://raw.githubusercontent.com/bin456789/sponsors/refs/heads/master/sponsors.svg)](https://github.com/sponsors/bin456789)
1515

1616
## 亮点
1717

1818
- 一键安装 Linux,支持 19 种常见发行版
1919
- 一键安装 Windows,使用官方 ISO 安装而非自制镜像,~~脚本会自动获取 ISO 链接~~、自动安装 Virtio 等常见驱动
2020
- 支持任意方向重装,即 `Linux to Linux``Linux to Windows``Windows to Windows``Windows to Linux`
21-
- 无需填写 IP 参数,自动识别动静态,支持 `/32``/128``网关不在子网范围内``纯 IPv6``双网卡` 等特殊网络
21+
- 无需填写 IP 参数,自动识别动静态,支持 `/32``/128``网关不在子网范围内``纯 IPv6``双网卡`
2222
- 专门适配低配小鸡,比官方 netboot 需要更少的内存
2323
- 全程用分区表 ID 识别硬盘,确保不会写错硬盘
2424
- 支持 BIOS、EFI 引导,支持 ARM 服务器
2525
- 不含自制包,所有资源均实时从镜像源获得
26-
- 有很多注释
2726

2827
## 系统要求
2928

@@ -47,7 +46,7 @@
4746
| <img width="16" height="16" src="https://github.com/user-attachments/assets/99a542b6-6482-4086-addf-f192c06fef73" /> NixOS | 24.11 | 512 MB | 5 GB |
4847
| <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | 滚动 | 512 MB | 5 GB |
4948
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB |
50-
| <img width="16" height="16" src="https://aosc.io/assets/distros/aosc-os.svg" /> 安同 OS | 滚动 | 512 MB | 5 GB |
49+
| <img width="16" height="16" src="https://aosc.io/assets/distros/aosc-os.svg" /> 安同 OS | 滚动 | 512 MB | 5 GB |
5150
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> 飞牛 fnOS | 公测 | 512 MB | 12 GB |
5251
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (DD) | 任何 | 512 MB | 取决于镜像 |
5352
| <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 |
@@ -330,13 +329,23 @@ bash reinstall.sh windows \
330329
--iso "https://go.microsoft.com/fwlink/?linkid=2289029"
331330
```
332331

332+
或者磁力链接
333+
334+
```bash
335+
bash reinstall.sh windows \
336+
--image-name "Windows 11 Enterprise LTSC 2024" \
337+
--iso "magnet:?xt=urn:btih:7352bd2db48c3381dffa783763dc75aa4a6f1cff"
338+
```
339+
333340
<details>
334341

335342
<summary>以下网站可找到 ISO 链接</summary>
336343

337344
- 正式版
338345
- <https://msdl.gravesoft.dev>
339346
- <https://massgrave.dev/genuine-installation-media>
347+
- <https://next.itellyou.cn>
348+
- <https://www.xitongku.com>
340349
- <https://www.microsoft.com/software-download/windows10> (需用非 Windows User-Agent 打开)
341350
- <https://www.microsoft.com/software-download/windows11>
342351
- <https://www.microsoft.com/software-download/windows11arm64>
@@ -350,8 +359,8 @@ bash reinstall.sh windows \
350359
- <https://www.microsoft.com/evalcenter/download-windows-server-2022>
351360
- <https://www.microsoft.com/evalcenter/download-windows-server-2025>
352361
- Insider 预览版
353-
- <https://www.microsoft.com/software-download/windowsinsiderpreviewiso>
354-
- <https://www.microsoft.com/software-download/windowsinsiderpreviewserver>
362+
- <https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewiso>
363+
- <https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewserver>
355364

356365
</details>
357366

@@ -362,10 +371,9 @@ bash reinstall.sh windows \
362371
- `--rdp-port PORT` 更改 RDP 端口
363372
- `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志用)
364373
- `--web-port PORT` 修改 Web 端口(安装期间观察日志用)
365-
- `--add-driver-dir DIR` 添加额外驱动,填写 .inf 所在的文件夹
374+
- `--add-driver INF_OR_DIR` 添加额外驱动,填写 .inf 路径,或者 .inf 所在的文件夹
366375
- 需先下载驱动到本地
367-
- 可多次设置该参数以添加不同的驱动文件夹
368-
- 脚本将复制整个文件夹,因此文件夹内不要放置其他文件
376+
- 可多次设置该参数以添加不同的驱动
369377
- `--hold 2` 在进入 Windows 官方安装程序之前,可以 SSH 登录修改硬盘内容,硬盘挂载在 `/os`
370378

371379
#### 以下驱动会自动按需下载安装,无需手动添加

reinstall.sh

+61-27
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,15 @@ EOF
8181
}
8282

8383
info() {
84-
upper=$(to_upper <<<"$@")
85-
echo_color_text '\e[32m' "***** $upper *****" >&2
84+
local msg
85+
if [ "$1" = false ]; then
86+
shift
87+
msg=$*
88+
else
89+
msg=$(to_upper <<<"$@")
90+
fi
91+
92+
echo_color_text '\e[32m' "***** $msg *****" >&2
8693
}
8794

8895
warn() {
@@ -91,7 +98,7 @@ warn() {
9198

9299
error() {
93100
echo_color_text '\e[31m' "***** ERROR *****" >&2
94-
echo_color_text '\e[31m' "Error: $*" >&2
101+
echo_color_text '\e[31m' "$*" >&2
95102
}
96103

97104
echo_color_text() {
@@ -609,6 +616,12 @@ is_virt() {
609616
$_is_virt
610617
}
611618

619+
is_absolute_path() {
620+
# 检查路径是否以/开头
621+
# 注意语法和 ash 不同
622+
[[ "$1" = /* ]]
623+
}
624+
612625
assert_cpu_supports_x86_64_v3() {
613626
# 用 ld.so/cpuid/coreinfo.exe 更准确
614627
# centos 7 /usr/lib64/ld-linux-x86-64.so.2 没有 --help
@@ -2150,7 +2163,13 @@ del_empty_lines() {
21502163
sed '/^[[:space:]]*$/d'
21512164
}
21522165

2166+
trim() {
2167+
# sed -E -e 's/^[[:space:]]+//' -e 's/[[:space:]]+$//'
2168+
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
2169+
}
2170+
21532171
prompt_password() {
2172+
info "prompt password"
21542173
while true; do
21552174
IFS= read -r -p "Password [$DEFAULT_PASSWORD]: " password
21562175
IFS= read -r -p "Retype password [$DEFAULT_PASSWORD]: " password_confirm
@@ -3459,16 +3478,12 @@ This script is outdated, please download reinstall.sh again.
34593478
fi
34603479

34613480
# 添加自定义 windows 驱动
3462-
if [ "$distro" = windows ]; then
3463-
mkdir -p $initrd_dir/custom_drivers
3464-
i=0
3465-
while IFS= read -r dir; do
3466-
if [ -d "$dir" ]; then
3467-
((i += 1))
3468-
info "add custom driver: $dir"
3469-
cp -r "$dir" "$initrd_dir/custom_drivers/$i"
3470-
fi
3471-
done < <(echo "$custom_driver_dirs")
3481+
if [ "$distro" = windows ] && [ -n "$custom_infs" ]; then
3482+
# shellcheck disable=SC1090
3483+
. <(curl -L $confhome/windows-driver-utils.sh)
3484+
echo "$custom_infs" | while read -r inf; do
3485+
parse_inf_and_cp_driever "$inf" "$initrd_dir/custom_drivers" "$basearch_alt" true
3486+
done
34723487
fi
34733488

34743489
# alpine live 不精简 initrd
@@ -3594,7 +3609,7 @@ fi
35943609

35953610
long_opts=
35963611
for o in ci installer debug minimal allow-ping force-cn \
3597-
add-driver-dir: \
3612+
add-driver: \
35983613
hold: sleep: \
35993614
iso: \
36003615
image-name: \
@@ -3687,26 +3702,45 @@ while true; do
36873702
web_port=$2
36883703
shift 2
36893704
;;
3690-
--add-driver-dir)
3691-
# 指定 dir 而不是指定 inf
3692-
# 防止用户将 inf 放在 / 而复制整个 /
3693-
3705+
--add-driver)
36943706
# 路径转换
36953707
if is_in_windows; then
36963708
# 输入的路径是 / 开头也没问题
3697-
dir="$(cygpath -u "$2")"
3709+
inf_or_dir="$(cygpath -u "$2")"
36983710
else
3699-
dir=$2
3711+
inf_or_dir=$2
37003712
fi
37013713

3702-
# 防止重复添加
3703-
if ! grep -Fqx "$dir" <<<"$custom_driver_dirs"; then
3704-
# shellcheck disable=SC2010
3705-
{ [ -d "$dir" ] && ls "$dir" | grep -Eiq '\.inf$'; } || error_and_exit "Invalid Driver Directory: $2"
3706-
# 一行一个驱动文件夹
3707-
custom_driver_dirs+="$dir
3708-
"
3714+
# alpine busybox 不支持 readlink -m
3715+
# readlink -m /asfsafasfsaf/fasf
3716+
# 因此需要先判断路径是否存在
3717+
3718+
if ! [ -d "$inf_or_dir" ] &&
3719+
! { [ -f "$inf_or_dir" ] && [[ "$inf_or_dir" =~ \.[iI][nN][fF]$ ]]; }; then
3720+
error_and_exit "Not a inf or dir: $2"
3721+
fi
3722+
3723+
# 转为绝对路径
3724+
inf_or_dir=$(readlink -f "$inf_or_dir")
3725+
3726+
info "finding inf in $inf_or_dir"
3727+
# find /tmp -type f -iname '*.inf' 只要 /tmp 存在就会返回 0
3728+
if infs=$(find "$inf_or_dir" -type f -iname '*.inf' | grep .); then
3729+
while IFS= read -r inf; do
3730+
# 防止重复添加
3731+
if ! grep -Fqx "$inf" <<<"$custom_infs"; then
3732+
echo "inf found: $inf"
3733+
# 一行一个 inf
3734+
if [ -n "$custom_infs" ]; then
3735+
custom_infs+=$'\n'
3736+
fi
3737+
custom_infs+=$inf
3738+
fi
3739+
done <<<"$infs"
3740+
else
3741+
error_and_exit "Can't find inf files in $2"
37093742
fi
3743+
37103744
shift 2
37113745
;;
37123746
--force-old-windows-setup)

0 commit comments

Comments
 (0)