mirror of
https://github.com/bin456789/reinstall.git
synced 2025-03-13 23:24:43 +08:00
core: 不重要的优化
This commit is contained in:
parent
c63889f32d
commit
0f147ed656
19
README.en.md
19
README.en.md
@ -112,8 +112,9 @@ certutil -urlcache -f -split https://gitlab.com/bin456789/reinstall/-/raw/main/r
|
||||
|
||||
**All features** can be used on both Linux and Windows.
|
||||
|
||||
- on Linux, execute `bash reinstall.sh`
|
||||
- on Windows, execute `.\reinstall.bat`
|
||||
- on Linux, run `bash reinstall.sh ...`
|
||||
- on Windows, first run `cmd`, then run `.\reinstall.bat ...`
|
||||
- If the link in the parameter contains special characters, it should be enclosed in `""`, not `''`.
|
||||
|
||||
### Feature 1: Install <img width="16" height="16" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux
|
||||
|
||||
@ -128,7 +129,7 @@ certutil -urlcache -f -split https://gitlab.com/bin456789/reinstall/-/raw/main/r
|
||||
bash reinstall.sh anolis 7|8|23
|
||||
opencloudos 8|9|23
|
||||
rocky 8|9
|
||||
redhat 8|9 --img='http://xxx.com/xxx.qcow2'
|
||||
redhat 8|9 --img="http://xxx.com/xxx.qcow2"
|
||||
oracle 8|9
|
||||
almalinux 8|9
|
||||
centos 9|10
|
||||
@ -197,7 +198,7 @@ bash reinstall.sh ubuntu --installer
|
||||
- When deploy a Linux image, will **NOT** modify any contents of the image.
|
||||
|
||||
```bash
|
||||
bash reinstall.sh dd --img https://example.com/xxx.xz
|
||||
bash reinstall.sh dd --img "https://example.com/xxx.xz"
|
||||
```
|
||||
|
||||
#### Optional parameters
|
||||
@ -266,7 +267,7 @@ bash reinstall.sh netboot.xyz
|
||||
|
||||
```bash
|
||||
bash reinstall.sh windows \
|
||||
--image-name 'Windows 11 Enterprise LTSC 2024' \
|
||||
--image-name "Windows 11 Enterprise LTSC 2024" \
|
||||
--lang zh-cn
|
||||
```
|
||||
|
||||
@ -323,8 +324,8 @@ zh-tw
|
||||
|
||||
```bash
|
||||
bash reinstall.sh windows \
|
||||
--image-name 'Windows 11 Enterprise LTSC 2024' \
|
||||
--iso 'https://go.microsoft.com/fwlink/?linkid=2289029'
|
||||
--image-name "Windows 11 Enterprise LTSC 2024" \
|
||||
--iso "https://go.microsoft.com/fwlink/?linkid=2289029"
|
||||
```
|
||||
|
||||
<details>
|
||||
@ -359,13 +360,13 @@ bash reinstall.sh windows \
|
||||
- `--rdp-port PORT` Change RDP port
|
||||
- `--ssh-port PORT` Change SSH port (for log observation during installation)
|
||||
- `--web-port PORT` Change Web port (for log observation during installation)
|
||||
- `--add-driver-dir DIR` Adds an additional driver folder, specifying the folder where the .inf file is located.
|
||||
- `--add-driver-dir DIR` Adds additional driver, specifying the folder where the .inf file is located.
|
||||
- The driver must be downloaded locally first.
|
||||
- This parameter can be set multiple times to add different driver folders.
|
||||
- The script will copy the entire folder, so no other files should be placed inside the folder.
|
||||
- `--hold 2` Allow SSH connections for modifying the disk content before rebooting into the official Windows installation program, with the disk mounted at `/os`.
|
||||
|
||||
#### The script will automatic download and install the following drivers as needed, without the need for manual addition
|
||||
#### The following drivers will automatic download and install as needed, without the need for manual addition
|
||||
|
||||
- Virtio ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/), [Alibaba Cloud](https://www.alibabacloud.com/help/ecs/user-guide/update-red-hat-virtio-drivers-of-windows-instances))
|
||||
- XEN ([XEN](https://xenproject.org/resources/downloads/), [Citrix](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade), [AWS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/xen-drivers-overview.html))
|
||||
|
19
README.md
19
README.md
@ -112,8 +112,9 @@ certutil -urlcache -f -split https://gitlab.com/bin456789/reinstall/-/raw/main/r
|
||||
|
||||
**所有功能** 都可在 Linux / Windows 下运行
|
||||
|
||||
- Linux 下运行 `bash reinstall.sh`
|
||||
- Windows 下运行 `.\reinstall.bat`
|
||||
- Linux 下运行 `bash reinstall.sh ...`
|
||||
- Windows 下先运行 `cmd`,再运行 `reinstall.bat ...`
|
||||
- 如果参数中的链接包含特殊字符,要用 `""` 将链接包起来,不能用 `''`
|
||||
|
||||
### 功能 1: 安装 <img width="16" height="16" src="https://www.kernel.org/theme/images/logos/favicon.png" /> Linux
|
||||
|
||||
@ -128,7 +129,7 @@ certutil -urlcache -f -split https://gitlab.com/bin456789/reinstall/-/raw/main/r
|
||||
bash reinstall.sh anolis 7|8|23
|
||||
opencloudos 8|9|23
|
||||
rocky 8|9
|
||||
redhat 8|9 --img='http://xxx.com/xxx.qcow2'
|
||||
redhat 8|9 --img="http://xxx.com/xxx.qcow2"
|
||||
oracle 8|9
|
||||
almalinux 8|9
|
||||
centos 9|10
|
||||
@ -197,7 +198,7 @@ bash reinstall.sh ubuntu --installer
|
||||
- DD Linux 镜像时,**不会**修改镜像的任何内容
|
||||
|
||||
```bash
|
||||
bash reinstall.sh dd --img https://example.com/xxx.xz
|
||||
bash reinstall.sh dd --img "https://example.com/xxx.xz"
|
||||
```
|
||||
|
||||
#### 可选参数
|
||||
@ -266,7 +267,7 @@ bash reinstall.sh netboot.xyz
|
||||
|
||||
```bash
|
||||
bash reinstall.sh windows \
|
||||
--image-name 'Windows 11 Enterprise LTSC 2024' \
|
||||
--image-name "Windows 11 Enterprise LTSC 2024" \
|
||||
--lang zh-cn
|
||||
```
|
||||
|
||||
@ -323,8 +324,8 @@ zh-tw
|
||||
|
||||
```bash
|
||||
bash reinstall.sh windows \
|
||||
--image-name 'Windows 11 Enterprise LTSC 2024' \
|
||||
--iso 'https://go.microsoft.com/fwlink/?linkid=2289029'
|
||||
--image-name "Windows 11 Enterprise LTSC 2024" \
|
||||
--iso "https://go.microsoft.com/fwlink/?linkid=2289029"
|
||||
```
|
||||
|
||||
<details>
|
||||
@ -359,13 +360,13 @@ bash reinstall.sh windows \
|
||||
- `--rdp-port PORT` 更改 RDP 端口
|
||||
- `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志用)
|
||||
- `--web-port PORT` 修改 Web 端口(安装期间观察日志用)
|
||||
- `--add-driver-dir DIR` 添加额外驱动文件夹,填写 .inf 所在的文件夹
|
||||
- `--add-driver-dir DIR` 添加额外驱动,填写 .inf 所在的文件夹
|
||||
- 需先下载驱动到本地
|
||||
- 可多次设置该参数以添加不同的驱动文件夹
|
||||
- 脚本将复制整个文件夹,因此文件夹内不要放置其他文件
|
||||
- `--hold 2` 在进入 Windows 官方安装程序之前,可以 SSH 登录修改硬盘内容,硬盘挂载在 `/os`
|
||||
|
||||
#### 脚本会自动按需下载安装以下驱动,无需手动添加
|
||||
#### 以下驱动会自动按需下载安装,无需手动添加
|
||||
|
||||
- Virtio ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/)、[阿里云](https://www.alibabacloud.com/help/ecs/user-guide/update-red-hat-virtio-drivers-of-windows-instances))
|
||||
- XEN ([XEN](https://xenproject.org/resources/downloads/)、[Citrix](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade)、[AWS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/xen-drivers-overview.html))
|
||||
|
@ -204,13 +204,14 @@ test_by_wget() {
|
||||
fi
|
||||
|
||||
# tcp 443 通了就算成功,不管 http 是不是 404
|
||||
# grep -m1 快速返回
|
||||
wget -T "$TEST_TIMEOUT" \
|
||||
--bind-address="$src" \
|
||||
--no-check-certificate \
|
||||
--max-redirect 0 \
|
||||
--tries 1 \
|
||||
-O /dev/null \
|
||||
"$url" 2>&1 | grep -iq connected
|
||||
"$url" 2>&1 | grep -iq -m1 connected
|
||||
}
|
||||
|
||||
test_by_nc() {
|
||||
|
@ -48,7 +48,7 @@ usage_and_exit() {
|
||||
Usage: $reinstall_____ anolis 7|8|23
|
||||
opencloudos 8|9|23
|
||||
rocky 8|9
|
||||
redhat 8|9 --img='http://xxx.com/xxx.qcow2'
|
||||
redhat 8|9 --img="http://xxx.com/xxx.qcow2"
|
||||
oracle 8|9
|
||||
almalinux 8|9
|
||||
centos 9|10
|
||||
@ -63,9 +63,9 @@ Usage: $reinstall_____ anolis 7|8|23
|
||||
arch
|
||||
gentoo
|
||||
fnos
|
||||
dd --img='http://xxx.com/yyy.zzz' (raw image stores in raw/vhd/tar/gz/xz/zst)
|
||||
windows --image-name='windows xxx yyy' --lang=xx-yy
|
||||
windows --image-name='windows xxx yyy' --iso='http://xxx.com/xxx.iso'
|
||||
dd --img="http://xxx.com/yyy.zzz" (raw image stores in raw/vhd/tar/gz/xz/zst)
|
||||
windows --image-name="windows xxx yyy" --lang=xx-yy
|
||||
windows --image-name="windows xxx yyy" --iso="http://xxx.com/xxx.iso"
|
||||
netboot.xyz
|
||||
|
||||
Options: [--ssh-port PORT]
|
||||
|
45
trans.sh
45
trans.sh
@ -198,8 +198,9 @@ update_part() {
|
||||
sync
|
||||
|
||||
# partprobe
|
||||
# 有分区挂载中会报 Resource busy 错误
|
||||
if is_have_cmd partprobe; then
|
||||
partprobe /dev/$xda 2>/dev/null
|
||||
partprobe /dev/$xda 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# partx
|
||||
@ -422,7 +423,7 @@ EOF
|
||||
umount_all() {
|
||||
dirs="/mnt /os /iso /wim /installer /nbd /nbd-boot /nbd-efi /root /nix"
|
||||
regex=$(echo "$dirs" | sed 's, ,|,g')
|
||||
if mounts=$(mount | grep -Ew "$regex" | awk '{print $3}' | tac); then
|
||||
if mounts=$(mount | grep -Ew "on $regex" | awk '{print $3}' | tac); then
|
||||
for mount in $mounts; do
|
||||
echo "umount $mount"
|
||||
umount $mount
|
||||
@ -1642,6 +1643,16 @@ EOF
|
||||
show_nixos_config
|
||||
}
|
||||
|
||||
add_fix_eth_name_systemd_service() {
|
||||
os_dir=$1
|
||||
|
||||
# 无需执行 systemctl daemon-reload
|
||||
# 因为 chroot 下执行会提示 Running in chroot, ignoring command 'daemon-reload'
|
||||
download "$confhome/fix-eth-name.sh" "$os_dir/fix-eth-name.sh"
|
||||
download "$confhome/fix-eth-name.service" "$os_dir/etc/systemd/system/fix-eth-name.service"
|
||||
chroot "$os_dir" systemctl enable fix-eth-name
|
||||
}
|
||||
|
||||
basic_init() {
|
||||
os_dir=$1
|
||||
|
||||
@ -1691,13 +1702,8 @@ basic_init() {
|
||||
|
||||
# 下载 fix-eth-name.service
|
||||
# 即使开了 net.ifnames=0 也需要
|
||||
# 因为 alpine 和目标系统的网卡顺序可能不同
|
||||
|
||||
# 无需执行 systemctl daemon-reload
|
||||
# 因为 chroot 下执行会提示 Running in chroot, ignoring command 'daemon-reload'
|
||||
download "$confhome/fix-eth-name.sh" "$os_dir/fix-eth-name.sh"
|
||||
download "$confhome/fix-eth-name.service" "$os_dir/etc/systemd/system/fix-eth-name.service"
|
||||
chroot "$os_dir" systemctl enable fix-eth-name
|
||||
# 因为 alpine live 和目标系统的网卡顺序可能不同
|
||||
add_fix_eth_name_systemd_service $os_dir
|
||||
}
|
||||
|
||||
install_arch_gentoo() {
|
||||
@ -1949,12 +1955,8 @@ EOF
|
||||
# 删除网卡名匹配
|
||||
sed -i '/^Name=/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
||||
|
||||
# 下载 fix-eth-name.service
|
||||
# chroot 下执行 systemctl daemon-reload
|
||||
# 会提示 Running in chroot, ignoring command 'daemon-reload'
|
||||
download "$confhome/fix-eth-name.sh" "$os_dir/fix-eth-name.sh"
|
||||
download "$confhome/fix-eth-name.service" "$os_dir/etc/systemd/system/fix-eth-name.service"
|
||||
chroot "$os_dir" systemctl enable fix-eth-name
|
||||
# 修正网卡名
|
||||
add_fix_eth_name_systemd_service $os_dir
|
||||
|
||||
# arch gentoo 网络配置是用 alpine cloud-init 生成的
|
||||
# cloud-init 版本够新,因此无需修复 onlink 网关
|
||||
@ -1973,12 +1975,12 @@ EOF
|
||||
|
||||
# cmdline + 生成 grub.cfg
|
||||
if [ -d $os_dir/etc/default/grub.d ]; then
|
||||
file=$os_dir/etc/default/grub.d/cmdline.conf
|
||||
file=$os_dir/etc/default/grub.d/tty.cfg
|
||||
else
|
||||
file=$os_dir/etc/default/grub
|
||||
fi
|
||||
ttys_cmdline=$(get_ttys console=)
|
||||
echo GRUB_CMDLINE_LINUX=\"$ttys_cmdline\" >>$file
|
||||
echo GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX $ttys_cmdline\" >>$file
|
||||
chroot $os_dir grub-mkconfig -o /boot/grub/grub.cfg
|
||||
|
||||
# fstab
|
||||
@ -3359,8 +3361,11 @@ modify_os_on_disk() {
|
||||
if ls -d /os/*/ | grep -i '/windows/' 2>/dev/null; then
|
||||
# 重新挂载为读写、忽略大小写
|
||||
umount /os
|
||||
apk add ntfs-3g
|
||||
mount.lowntfs-3g /dev/$part /os -o ignore_case
|
||||
mount -t ntfs3 -o nocase /dev/$part /os
|
||||
# 有休眠文件时无法挂载成读写,提醒用户并退出脚本
|
||||
if mount | grep ' /os ' | grep -wq ro; then
|
||||
error_and_exit "Can't mount windows partition /dev/$part as rw."
|
||||
fi
|
||||
modify_windows /os
|
||||
return
|
||||
fi
|
||||
@ -4724,7 +4729,7 @@ mount_part_for_iso_installer() {
|
||||
info "Mount part for iso installer"
|
||||
|
||||
if [ "$distro" = windows ]; then
|
||||
mount_args="-t ntfs3"
|
||||
mount_args="-t ntfs3 -o nocase"
|
||||
else
|
||||
mount_args=
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user