mirror of
https://github.com/bin456789/reinstall.git
synced 2025-07-08 20:19:51 +00:00
Compare commits
No commits in common. "90ebc1b1231f495029e0070ad27941e033db2492" and "0f147ed656a1cb8c0c36e43006f2336e57525a95" have entirely different histories.
90ebc1b123
...
0f147ed656
@ -15,8 +15,8 @@ One-Click Script to Reinstall System [中文](README.md)
|
|||||||
|
|
||||||
## Highlights
|
## Highlights
|
||||||
|
|
||||||
- One-click Linux installation: Supports 19 common distributions.
|
- One-click Linux installation: Supports 18 common distributions.
|
||||||
- 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`.
|
- One-click Windows installation: Uses the official ISO for installation instead of custom images. The script automatically retrieves the ISO link and installs `Virtio` and other drivers.
|
||||||
- Supports installation in any direction, i.e., `Linux to Linux`, `Linux to Windows`, `Windows to Windows`, `Windows to Linux`
|
- Supports installation in any direction, i.e., `Linux to Linux`, `Linux to Windows`, `Windows to Windows`, `Windows to Linux`
|
||||||
- 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
|
- 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
|
||||||
- Specially optimized for low-spec servers, requires less memory than the official netboot
|
- Specially optimized for low-spec servers, requires less memory than the official netboot
|
||||||
@ -47,8 +47,7 @@ The system requirements for the target system are as follows:
|
|||||||
| <img width="16" height="16" src="https://github.com/user-attachments/assets/99a542b6-6482-4086-addf-f192c06fef73" /> NixOS | 24.11 | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://github.com/user-attachments/assets/99a542b6-6482-4086-addf-f192c06fef73" /> NixOS | 24.11 | 512 MB | 5 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://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://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | Rolling | 512 MB | 5 GB |
|
||||||
| <img width="16" height="16" src="https://aosc.io/assets/aosc.svg" /> AOSC | Rolling | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> 飞牛 fnOS | Beta | 512 MB | 12 GB |
|
||||||
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> fnOS | Beta | 512 MB | 12 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 | Depends on image |
|
| <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 | Depends on 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) | 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 - 2025) | 1 GB | 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 - 2025) | 1 GB | 25 GB |
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
## 亮点
|
## 亮点
|
||||||
|
|
||||||
- 一键安装 Linux,支持 19 种常见发行版
|
- 一键安装 Linux,支持 18 种常见发行版
|
||||||
- 一键安装 Windows,使用官方 ISO 安装而非自制镜像,~~脚本会自动获取 ISO 链接~~、自动安装 Virtio 等常见驱动
|
- 一键安装 Windows,使用官方 ISO 安装而非自制镜像,脚本会自动获取 ISO 链接、自动安装 Virtio 等驱动
|
||||||
- 支持任意方向重装,即 `Linux to Linux`、`Linux to Windows`、`Windows to Windows`、`Windows to Linux`
|
- 支持任意方向重装,即 `Linux to Linux`、`Linux to Windows`、`Windows to Windows`、`Windows to Linux`
|
||||||
- 无需填写 IP 参数,自动识别动静态,支持 `/32`、`/128`、`网关不在子网范围内`、`纯 IPv6`、`双网卡` 等特殊网络
|
- 无需填写 IP 参数,自动识别动静态,支持 `/32`、`/128`、`网关不在子网范围内`、`纯 IPv6`、`双网卡` 等特殊网络
|
||||||
- 专门适配低配小鸡,比官方 netboot 需要更少的内存
|
- 专门适配低配小鸡,比官方 netboot 需要更少的内存
|
||||||
@ -47,8 +47,7 @@
|
|||||||
| <img width="16" height="16" src="https://github.com/user-attachments/assets/99a542b6-6482-4086-addf-f192c06fef73" /> NixOS | 24.11 | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://github.com/user-attachments/assets/99a542b6-6482-4086-addf-f192c06fef73" /> NixOS | 24.11 | 512 MB | 5 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://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://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB |
|
||||||
| <img width="16" height="16" src="https://aosc.io/assets/aosc.svg" /> 安同 AOSC | 滚动 | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> 飞牛 fnOS | 公测版 | 512 MB | 12 GB |
|
||||||
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> 飞牛 fnOS | 公测 | 512 MB | 12 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 (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) | 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 - 2025) | 1 GB | 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 - 2025) | 1 GB | 25 GB |
|
||||||
@ -144,7 +143,6 @@ bash reinstall.sh anolis 7|8|23
|
|||||||
kali
|
kali
|
||||||
arch
|
arch
|
||||||
gentoo
|
gentoo
|
||||||
aosc
|
|
||||||
fnos
|
fnos
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ ExecStart=/usr/bin/env bash /fix-eth-name.sh
|
|||||||
ExecStart=/usr/bin/env rm -f /fix-eth-name.sh
|
ExecStart=/usr/bin/env rm -f /fix-eth-name.sh
|
||||||
ExecStart=/usr/bin/env rm -f /etc/systemd/system/fix-eth-name.service
|
ExecStart=/usr/bin/env rm -f /etc/systemd/system/fix-eth-name.service
|
||||||
ExecStart=/usr/bin/env rm -f /etc/systemd/system/multi-user.target.wants/fix-eth-name.service
|
ExecStart=/usr/bin/env rm -f /etc/systemd/system/multi-user.target.wants/fix-eth-name.service
|
||||||
ExecStart=/usr/bin/env rm -f /usr/lib/systemd/system-preset/01-fix-eth-name.preset
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
@ -6,8 +6,8 @@ set confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
|
|||||||
set confhome_cn=https://gitlab.com/bin456789/reinstall/-/raw/main
|
set confhome_cn=https://gitlab.com/bin456789/reinstall/-/raw/main
|
||||||
rem set confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main
|
rem set confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main
|
||||||
|
|
||||||
set pkgs=curl,cpio,p7zip,dos2unix,jq,xz,gzip,zstd,openssl,bind-utils,libiconv,binutils
|
set pkgs=curl,cpio,p7zip,ipcalc,dos2unix,jq,xz,gzip,zstd,openssl,bind-utils,libiconv,binutils
|
||||||
set cmds=curl,cpio,p7zip,dos2unix,jq,xz,gzip,zstd,openssl,nslookup,iconv,ar
|
set cmds=curl,cpio,p7zip,ipcalc,dos2unix,jq,xz,gzip,zstd,openssl,nslookup,iconv,ar
|
||||||
|
|
||||||
rem 65001 代码页会乱码
|
rem 65001 代码页会乱码
|
||||||
|
|
||||||
@ -202,6 +202,7 @@ exit /b 1
|
|||||||
set "cmds_space=%cmds:,= %"
|
set "cmds_space=%cmds:,= %"
|
||||||
for %%c in (%cmds_space%) do (
|
for %%c in (%cmds_space%) do (
|
||||||
if not exist "%SystemDrive%\cygwin\bin\%%c" if not exist "%SystemDrive%\cygwin\bin\%%c.exe" (
|
if not exist "%SystemDrive%\cygwin\bin\%%c" if not exist "%SystemDrive%\cygwin\bin\%%c.exe" (
|
||||||
|
echo %%c not found.
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
41
reinstall.sh
41
reinstall.sh
@ -62,7 +62,6 @@ Usage: $reinstall_____ anolis 7|8|23
|
|||||||
kali
|
kali
|
||||||
arch
|
arch
|
||||||
gentoo
|
gentoo
|
||||||
aosc
|
|
||||||
fnos
|
fnos
|
||||||
dd --img="http://xxx.com/yyy.zzz" (raw image stores in raw/vhd/tar/gz/xz/zst)
|
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" --lang=xx-yy
|
||||||
@ -126,24 +125,11 @@ curl() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
mask2cidr() {
|
|
||||||
local x=${1##*255.}
|
|
||||||
set -- 0^^^128^192^224^240^248^252^254^ $(((${#1} - ${#x}) * 2)) ${x%%.*}
|
|
||||||
x=${1%%"$3"*}
|
|
||||||
echo $(($2 + (${#x} / 4)))
|
|
||||||
}
|
|
||||||
|
|
||||||
is_in_china() {
|
is_in_china() {
|
||||||
[ "$force_cn" = 1 ] && return 0
|
[ "$force_cn" = 1 ] && return 0
|
||||||
|
|
||||||
if [ -z "$_loc" ]; then
|
if [ -z "$_loc" ]; then
|
||||||
# www.cloudflare.com/dash.cloudflare.com 国内访问的是美国服务器,而且部分地区被墙
|
# www.cloudflare.com/dash.cloudflare.com 国内访问的是美国服务器,而且部分地区被墙
|
||||||
# 备用 www.bose.cn
|
|
||||||
# 备用 www.qualcomm.cn
|
|
||||||
# 备用 www.prologis.cn
|
|
||||||
# 备用 www.garmin.com.cn
|
|
||||||
# 备用 www.autodesk.com.cn
|
|
||||||
# 备用 www.keysight.com.cn
|
|
||||||
_loc=$(curl -L http://www.visa.cn/cdn-cgi/trace | grep '^loc=' | cut -d= -f2)
|
_loc=$(curl -L http://www.visa.cn/cdn-cgi/trace | grep '^loc=' | cut -d= -f2)
|
||||||
if [ -z "$_loc" ]; then
|
if [ -z "$_loc" ]; then
|
||||||
error_and_exit "Can not get location."
|
error_and_exit "Can not get location."
|
||||||
@ -1488,27 +1474,11 @@ Continue with DD?
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
iso=$(curl -L https://fnnas.com/ | grep -o 'https://[^"]*\.iso' | head -1)
|
iso=$(curl -L https://fnnas.com | grep -o 'https://[^"]*\.iso' | head -1)
|
||||||
test_url "$iso" 'iso'
|
test_url "$iso" 'iso'
|
||||||
eval "${step}_iso='$iso'"
|
eval "${step}_iso='$iso'"
|
||||||
}
|
}
|
||||||
|
|
||||||
setos_aosc() {
|
|
||||||
if is_in_china; then
|
|
||||||
mirror=https://mirror.nju.edu.cn/anthon/aosc-os
|
|
||||||
else
|
|
||||||
# 服务器在香港
|
|
||||||
mirror=https://releases.aosc.io
|
|
||||||
fi
|
|
||||||
|
|
||||||
dir=os-$basearch_alt/base
|
|
||||||
file=$(curl -L $mirror/$dir/ | grep -oP 'aosc-os_base_.*?\.tar.xz' |
|
|
||||||
sort -uV | tail -1 | grep .)
|
|
||||||
img=$mirror/$dir/$file
|
|
||||||
test_url $img 'tar.xz'
|
|
||||||
eval ${step}_img=$img
|
|
||||||
}
|
|
||||||
|
|
||||||
setos_centos_almalinux_rocky_fedora() {
|
setos_centos_almalinux_rocky_fedora() {
|
||||||
# el 10 需要 x86-64-v3
|
# el 10 需要 x86-64-v3
|
||||||
if [ "$basearch" = x86_64 ] &&
|
if [ "$basearch" = x86_64 ] &&
|
||||||
@ -1749,7 +1719,6 @@ verify_os_name() {
|
|||||||
'kali' \
|
'kali' \
|
||||||
'arch' \
|
'arch' \
|
||||||
'gentoo' \
|
'gentoo' \
|
||||||
'aosc' \
|
|
||||||
'fnos' \
|
'fnos' \
|
||||||
'windows' \
|
'windows' \
|
||||||
'dd' \
|
'dd' \
|
||||||
@ -2007,7 +1976,7 @@ check_ram() {
|
|||||||
case "$distro" in
|
case "$distro" in
|
||||||
netboot.xyz) echo 0 ;;
|
netboot.xyz) echo 0 ;;
|
||||||
alpine | debian | kali | dd) echo 256 ;;
|
alpine | debian | kali | dd) echo 256 ;;
|
||||||
arch | gentoo | aosc | nixos | windows) echo 512 ;;
|
arch | gentoo | nixos | windows) echo 512 ;;
|
||||||
redhat | centos | almalinux | rocky | fedora | oracle | ubuntu | anolis | opencloudos | openeuler) echo 1024 ;;
|
redhat | centos | almalinux | rocky | fedora | oracle | ubuntu | anolis | opencloudos | openeuler) echo 1024 ;;
|
||||||
opensuse | fnos) echo -1 ;; # 没有安装模式
|
opensuse | fnos) echo -1 ;; # 没有安装模式
|
||||||
esac
|
esac
|
||||||
@ -2393,9 +2362,7 @@ collect_netconf() {
|
|||||||
ip=${ips[i]}
|
ip=${ips[i]}
|
||||||
subnet=${subnets[i]}
|
subnet=${subnets[i]}
|
||||||
if [[ "$ip" = *.* ]]; then
|
if [[ "$ip" = *.* ]]; then
|
||||||
# ipcalc 依赖 perl,会使 cygwin 增加 ~50M
|
cidr=$(ipcalc -b "$ip/$subnet" | grep Netmask: | awk '{print $NF}')
|
||||||
# cidr=$(ipcalc -b "$ip/$subnet" | grep Netmask: | awk '{print $NF}')
|
|
||||||
cidr=$(mask2cidr "$subnet")
|
|
||||||
ipv4_addr="$ip/$cidr"
|
ipv4_addr="$ip/$cidr"
|
||||||
ipv4_gateway="$gateway"
|
ipv4_gateway="$gateway"
|
||||||
ipv4_mac="$mac_addr"
|
ipv4_mac="$mac_addr"
|
||||||
@ -3782,7 +3749,7 @@ mkdir_clear "$tmp"
|
|||||||
# 强制忽略/强制添加 --ci 参数
|
# 强制忽略/强制添加 --ci 参数
|
||||||
# debian 不强制忽略 ci 留作测试
|
# debian 不强制忽略 ci 留作测试
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
dd | windows | netboot.xyz | kali | alpine | arch | gentoo | aosc | nixos | fnos)
|
dd | windows | netboot.xyz | kali | alpine | arch | gentoo | nixos)
|
||||||
if is_use_cloud_image; then
|
if is_use_cloud_image; then
|
||||||
echo "ignored --ci"
|
echo "ignored --ci"
|
||||||
unset cloud_image
|
unset cloud_image
|
||||||
|
116
trans.sh
116
trans.sh
@ -758,12 +758,6 @@ del_empty_lines() {
|
|||||||
sed '/^[[:space:]]*$/d'
|
sed '/^[[:space:]]*$/d'
|
||||||
}
|
}
|
||||||
|
|
||||||
del_head_empty_lines_inplace() {
|
|
||||||
# 从第一行直到找到 ^[:space:]
|
|
||||||
# 这个区间内删除所有空行
|
|
||||||
sed -i '1,/[^[:space:]]/ { /^[[:space:]]*$/d }' "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
get_part_num_by_part() {
|
get_part_num_by_part() {
|
||||||
dev_part=$1
|
dev_part=$1
|
||||||
echo "$dev_part" | grep -o '[0-9]*' | tail -1
|
echo "$dev_part" | grep -o '[0-9]*' | tail -1
|
||||||
@ -1657,12 +1651,6 @@ add_fix_eth_name_systemd_service() {
|
|||||||
download "$confhome/fix-eth-name.sh" "$os_dir/fix-eth-name.sh"
|
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"
|
download "$confhome/fix-eth-name.service" "$os_dir/etc/systemd/system/fix-eth-name.service"
|
||||||
chroot "$os_dir" systemctl enable fix-eth-name
|
chroot "$os_dir" systemctl enable fix-eth-name
|
||||||
|
|
||||||
# aosc 首次开机会执行 preset-all
|
|
||||||
# 因此需要设置 fix-eth-name 的 preset 状态
|
|
||||||
# 不然首次开机 /etc/systemd/system/multi-user.target.wants/fix-eth-name.service 会被删除
|
|
||||||
# 通常 /etc/systemd/system-preset/ 文件夹要新建,因此不放在这里
|
|
||||||
echo 'enable fix-eth-name.service' >"$os_dir/usr/lib/systemd/system-preset/01-fix-eth-name.preset"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_init() {
|
basic_init() {
|
||||||
@ -1718,16 +1706,9 @@ basic_init() {
|
|||||||
add_fix_eth_name_systemd_service $os_dir
|
add_fix_eth_name_systemd_service $os_dir
|
||||||
}
|
}
|
||||||
|
|
||||||
install_arch_gentoo_aosc() {
|
install_arch_gentoo() {
|
||||||
info "install $distro"
|
info "install $distro"
|
||||||
|
|
||||||
network_app=$(
|
|
||||||
case "$distro" in
|
|
||||||
arch | gentoo) echo systemd-networkd ;;
|
|
||||||
aosc) echo network-manager ;;
|
|
||||||
esac
|
|
||||||
)
|
|
||||||
|
|
||||||
set_locale() {
|
set_locale() {
|
||||||
echo "C.UTF-8 UTF-8" >>$os_dir/etc/locale.gen
|
echo "C.UTF-8 UTF-8" >>$os_dir/etc/locale.gen
|
||||||
chroot $os_dir locale-gen
|
chroot $os_dir locale-gen
|
||||||
@ -1810,13 +1791,13 @@ EOF
|
|||||||
create_swap_if_ram_less_than 2048 $os_dir/swapfile
|
create_swap_if_ram_less_than 2048 $os_dir/swapfile
|
||||||
|
|
||||||
# 解压系统
|
# 解压系统
|
||||||
apk add tar xz pv
|
apk add tar xz
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
download "$img" $os_dir/gentoo.tar.xz
|
download "$img" $os_dir/gentoo.tar.xz
|
||||||
echo "Uncompressing Gentoo..."
|
echo "Uncompressing Gentoo..."
|
||||||
pv -f $os_dir/gentoo.tar.xz | tar xpJ --numeric-owner --xattrs-include='*.*' -C $os_dir
|
tar xpf $os_dir/gentoo.tar.xz -C $os_dir --xattrs-include='*.*' --numeric-owner
|
||||||
rm $os_dir/gentoo.tar.xz
|
rm $os_dir/gentoo.tar.xz
|
||||||
apk del tar xz pv
|
apk del tar xz
|
||||||
|
|
||||||
# dns
|
# dns
|
||||||
cp_resolv_conf $os_dir
|
cp_resolv_conf $os_dir
|
||||||
@ -1925,22 +1906,6 @@ EOF
|
|||||||
chroot $os_dir emerge sys-kernel/gentoo-kernel-bin
|
chroot $os_dir emerge sys-kernel/gentoo-kernel-bin
|
||||||
}
|
}
|
||||||
|
|
||||||
install_aosc() {
|
|
||||||
# 解压系统
|
|
||||||
apk add wget tar xz
|
|
||||||
wget "$img" -O- | tar xpJ --numeric-owner --xattrs-include='*.*' -C $os_dir
|
|
||||||
apk del wget tar xz
|
|
||||||
|
|
||||||
# 添加 swap
|
|
||||||
create_swap_if_ram_less_than 1024 $os_dir/swapfile
|
|
||||||
|
|
||||||
# 挂载伪文件系统
|
|
||||||
mount_pseudo_fs $os_dir
|
|
||||||
|
|
||||||
# 生成 initramfs
|
|
||||||
chroot $os_dir update-initramfs
|
|
||||||
}
|
|
||||||
|
|
||||||
os_dir=/os
|
os_dir=/os
|
||||||
|
|
||||||
# 挂载分区
|
# 挂载分区
|
||||||
@ -1962,13 +1927,18 @@ EOF
|
|||||||
chroot $os_dir systemd-firstboot --force --timezone=Asia/Shanghai
|
chroot $os_dir systemd-firstboot --force --timezone=Asia/Shanghai
|
||||||
# gentoo 不会自动创建 machine-id
|
# gentoo 不会自动创建 machine-id
|
||||||
clear_machine_id $os_dir
|
clear_machine_id $os_dir
|
||||||
|
|
||||||
# 网络配置
|
|
||||||
case "$network_app" in
|
|
||||||
systemd-networkd)
|
|
||||||
chroot $os_dir systemctl enable systemd-networkd
|
chroot $os_dir systemctl enable systemd-networkd
|
||||||
chroot $os_dir systemctl enable systemd-resolved
|
chroot $os_dir systemctl enable systemd-resolved
|
||||||
|
chroot $os_dir systemctl enable sshd
|
||||||
|
allow_root_password_login $os_dir
|
||||||
|
if is_need_change_ssh_port; then
|
||||||
|
change_ssh_port $os_dir $ssh_port
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 修改密码
|
||||||
|
change_root_password $os_dir
|
||||||
|
|
||||||
|
# 网络配置
|
||||||
apk add cloud-init
|
apk add cloud-init
|
||||||
# 第二次运行会报错
|
# 第二次运行会报错
|
||||||
useradd systemd-network || true
|
useradd systemd-network || true
|
||||||
@ -1978,30 +1948,12 @@ EOF
|
|||||||
cloud-init devel net-convert -p net.cfg -k yaml -d out -D alpine -O networkd
|
cloud-init devel net-convert -p net.cfg -k yaml -d out -D alpine -O networkd
|
||||||
cp out/etc/systemd/network/10-cloud-init-eth*.network $os_dir/etc/systemd/network/
|
cp out/etc/systemd/network/10-cloud-init-eth*.network $os_dir/etc/systemd/network/
|
||||||
|
|
||||||
# 删除网卡名匹配
|
|
||||||
sed -i '/^Name=/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
|
||||||
|
|
||||||
# 删除 Generated by cloud-init. Changes will be lost.
|
|
||||||
# 并删除头部的空行
|
|
||||||
sed -i '/^# Generated by cloud-init/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
|
||||||
del_head_empty_lines_inplace $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
|
||||||
|
|
||||||
# 清理
|
# 清理
|
||||||
rm -rf net.cfg out
|
rm -rf net.cfg out
|
||||||
apk del cloud-init
|
apk del cloud-init
|
||||||
|
|
||||||
# 显示网络配置
|
# 删除网卡名匹配
|
||||||
cat -n $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
sed -i '/^Name=/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
||||||
;;
|
|
||||||
network-manager)
|
|
||||||
chroot $os_dir systemctl enable NetworkManager
|
|
||||||
|
|
||||||
# 可以直接用 alpine 的 cloud-init 生成 Network Manager 配置
|
|
||||||
create_cloud_init_network_config /net.cfg
|
|
||||||
create_network_manager_config /net.cfg "$os_dir"
|
|
||||||
rm /net.cfg
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# 修正网卡名
|
# 修正网卡名
|
||||||
add_fix_eth_name_systemd_service $os_dir
|
add_fix_eth_name_systemd_service $os_dir
|
||||||
@ -2009,16 +1961,6 @@ EOF
|
|||||||
# arch gentoo 网络配置是用 alpine cloud-init 生成的
|
# arch gentoo 网络配置是用 alpine cloud-init 生成的
|
||||||
# cloud-init 版本够新,因此无需修复 onlink 网关
|
# cloud-init 版本够新,因此无需修复 onlink 网关
|
||||||
|
|
||||||
# ssh
|
|
||||||
chroot $os_dir systemctl enable sshd
|
|
||||||
allow_root_password_login $os_dir
|
|
||||||
if is_need_change_ssh_port; then
|
|
||||||
change_ssh_port $os_dir $ssh_port
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 修改密码
|
|
||||||
change_root_password $os_dir
|
|
||||||
|
|
||||||
# ntp 用 systemd 自带的
|
# ntp 用 systemd 自带的
|
||||||
# TODO: vm agent + 随机数生成器
|
# TODO: vm agent + 随机数生成器
|
||||||
|
|
||||||
@ -2043,9 +1985,8 @@ EOF
|
|||||||
|
|
||||||
# fstab
|
# fstab
|
||||||
# fstab 可不写 efi 条目, systemd automount 会自动挂载
|
# fstab 可不写 efi 条目, systemd automount 会自动挂载
|
||||||
# fstab 头部有使用说明,因此用 >>
|
|
||||||
apk add arch-install-scripts
|
apk add arch-install-scripts
|
||||||
genfstab -U $os_dir | sed '/swap/d' >>$os_dir/etc/fstab
|
genfstab -U $os_dir | sed '/swap/d' >$os_dir/etc/fstab
|
||||||
apk del arch-install-scripts
|
apk del arch-install-scripts
|
||||||
|
|
||||||
# 删除 resolv.conf,不然 systemd-resolved 无法创建软链接
|
# 删除 resolv.conf,不然 systemd-resolved 无法创建软链接
|
||||||
@ -2366,8 +2307,7 @@ create_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 ]; then
|
||||||
[ "$distro" = nixos ] || [ "$distro" = aosc ]; then
|
|
||||||
# alpine 本身关闭了 64bit ext4
|
# alpine 本身关闭了 64bit ext4
|
||||||
# https://gitlab.alpinelinux.org/alpine/alpine-conf/-/blob/3.18.1/setup-disk.in?ref_type=tags#L908
|
# https://gitlab.alpinelinux.org/alpine/alpine-conf/-/blob/3.18.1/setup-disk.in?ref_type=tags#L908
|
||||||
# 而且 alpine 的 extlinux 不兼容 64bit ext4
|
# 而且 alpine 的 extlinux 不兼容 64bit ext4
|
||||||
@ -2478,7 +2418,7 @@ create_part() {
|
|||||||
umount_pseudo_fs() {
|
umount_pseudo_fs() {
|
||||||
os_dir=$(realpath "$1")
|
os_dir=$(realpath "$1")
|
||||||
|
|
||||||
dirs="/proc /sys /dev /run"
|
dirs="/proc /sys /dev /run /sys/firmware/efi/efivars"
|
||||||
regex=$(echo "$dirs" | sed 's, ,|,g')
|
regex=$(echo "$dirs" | sed 's, ,|,g')
|
||||||
if mounts=$(mount | grep -Ew "on $os_dir($regex)" | awk '{print $3}' | tac); then
|
if mounts=$(mount | grep -Ew "on $os_dir($regex)" | awk '{print $3}' | tac); then
|
||||||
for mount in $mounts; do
|
for mount in $mounts; do
|
||||||
@ -2981,17 +2921,7 @@ create_network_manager_config() {
|
|||||||
sed -i -e '/^may-fail=/d' -e 's/^method=dhcp/method=auto/' \
|
sed -i -e '/^may-fail=/d' -e 's/^method=dhcp/method=auto/' \
|
||||||
/out/etc/NetworkManager/system-connections/cloud-init-eth*.nmconnection
|
/out/etc/NetworkManager/system-connections/cloud-init-eth*.nmconnection
|
||||||
|
|
||||||
# 删除 # Generated by cloud-init. Changes will be lost.
|
cp /out/etc/NetworkManager/system-connections/cloud-init-eth*.nmconnection $os_dir/etc/NetworkManager/system-connections/
|
||||||
# 删除 org.freedesktop.NetworkManager.origin=cloud-init
|
|
||||||
# 并删除头部的空行
|
|
||||||
sed -i \
|
|
||||||
-e '/^# Generated by cloud-init/d' \
|
|
||||||
-e '/^org\.freedesktop\.NetworkManager\.origin=cloud-init/d' \
|
|
||||||
/out/etc/NetworkManager/system-connections/cloud-init-eth*.nmconnection
|
|
||||||
del_head_empty_lines_inplace /out/etc/NetworkManager/system-connections/cloud-init-eth*.nmconnection
|
|
||||||
|
|
||||||
cp /out/etc/NetworkManager/system-connections/cloud-init-eth*.nmconnection \
|
|
||||||
$os_dir/etc/NetworkManager/system-connections/
|
|
||||||
|
|
||||||
# 清理
|
# 清理
|
||||||
rm -rf /out
|
rm -rf /out
|
||||||
@ -3876,7 +3806,7 @@ install_fnos() {
|
|||||||
# 复制系统
|
# 复制系统
|
||||||
info "Extract fnos"
|
info "Extract fnos"
|
||||||
apk add tar gzip pv
|
apk add tar gzip pv
|
||||||
pv -f /iso/trimfs.tgz | tar zxp --numeric-owner --xattrs-include='*.*' -C /os
|
pv -f /iso/trimfs.tgz | tar zx -C /os --numeric-owner
|
||||||
apk del tar gzip pv
|
apk del tar gzip pv
|
||||||
|
|
||||||
# 挂载 /os/boot/efi
|
# 挂载 /os/boot/efi
|
||||||
@ -5596,7 +5526,7 @@ install_windows() {
|
|||||||
|
|
||||||
mkdir -p $drv/gce/$name
|
mkdir -p $drv/gce/$name
|
||||||
link=$(grep -o "/pool/.*-google-compute-engine-driver-$name.*\.goo" /tmp/gce.json)
|
link=$(grep -o "/pool/.*-google-compute-engine-driver-$name.*\.goo" /tmp/gce.json)
|
||||||
wget $gce_repo$link -O- | tar xz -C $drv/gce/$name
|
wget $gce_repo$link -O- | tar -xzf- -C $drv/gce/$name
|
||||||
|
|
||||||
# 没有 win6.0 文件夹
|
# 没有 win6.0 文件夹
|
||||||
# 但 inf 没限制
|
# 但 inf 没限制
|
||||||
@ -6157,9 +6087,9 @@ trans() {
|
|||||||
alpine)
|
alpine)
|
||||||
install_alpine
|
install_alpine
|
||||||
;;
|
;;
|
||||||
arch | gentoo | aosc)
|
arch | gentoo)
|
||||||
create_part
|
create_part
|
||||||
install_arch_gentoo_aosc
|
install_arch_gentoo
|
||||||
;;
|
;;
|
||||||
nixos)
|
nixos)
|
||||||
create_part
|
create_part
|
||||||
|
Loading…
x
Reference in New Issue
Block a user