arch: 支持常规安装方法
This commit is contained in:
parent
8ed23a8be1
commit
f2e1cb8b89
@ -75,9 +75,9 @@ bash reinstall.sh centos 7|8|9 (8|9 for the stream version)
|
||||
fedora 38|39
|
||||
debian 10|11|12
|
||||
ubuntu 20.04|22.04
|
||||
alpine 3.16|3.17|3.18|3.19
|
||||
opensuse 15.5|tumbleweed
|
||||
arch (not supports ARM)
|
||||
alpine 3.16|3.17|3.18|3.19
|
||||
arch
|
||||
gentoo
|
||||
|
||||
If no version number is entered, the latest version will be installed.
|
||||
@ -189,7 +189,7 @@ Use `Dism++` File menu > Open Image File, select the iso to be installed to get
|
||||
| CentOS / Alma / Rocky / Fedora | 1G | 512M |
|
||||
| Alpine | 256M | - |
|
||||
| openSUSE | - | 512M |
|
||||
| Arch | - | 512M |
|
||||
| Arch | 512M | - |
|
||||
| Gentoo | 512M | - |
|
||||
| Windows 8.1 (Server 2012 R2) or below | 512M | - |
|
||||
| Windows 10 (Server 2016) or above | 1G | - |
|
||||
|
@ -74,9 +74,9 @@ bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本)
|
||||
fedora 38|39
|
||||
debian 10|11|12
|
||||
ubuntu 20.04|22.04
|
||||
alpine 3.16|3.17|3.18|3.19
|
||||
opensuse 15.5|tumbleweed
|
||||
arch (暂不支持 ARM)
|
||||
alpine 3.16|3.17|3.18|3.19
|
||||
arch
|
||||
gentoo
|
||||
|
||||
不输入版本号,则安装最新版
|
||||
@ -188,7 +188,7 @@ Windows Server 2022 SERVERDATACENTER
|
||||
| CentOS / Alma / Rocky / Fedora | 1G | 512M |
|
||||
| Alpine | 256M | - |
|
||||
| openSUSE | - | 512M |
|
||||
| Arch | - | 512M |
|
||||
| Arch | 512M | - |
|
||||
| Gentoo | 512M | - |
|
||||
| Windows 8.1 (Server 2012 R2) 或以下 | 512M | - |
|
||||
| Windows 10 (Server 2016) 或以上 | 1G | - |
|
||||
|
41
reinstall.sh
41
reinstall.sh
@ -458,14 +458,33 @@ setos() {
|
||||
}
|
||||
|
||||
setos_arch() {
|
||||
# cloud image
|
||||
if [ "$basearch" = "x86_64" ]; then
|
||||
if is_in_china; then
|
||||
ci_mirror=https://mirrors.tuna.tsinghua.edu.cn/archlinux
|
||||
mirror=https://mirrors.tuna.tsinghua.edu.cn/archlinux
|
||||
else
|
||||
ci_mirror=https://geo.mirror.pkgbuild.com
|
||||
mirror=https://geo.mirror.pkgbuild.com
|
||||
fi
|
||||
else
|
||||
if is_in_china; then
|
||||
mirror=https://mirrors.tuna.tsinghua.edu.cn/archlinuxarm
|
||||
else
|
||||
# https 证书有问题
|
||||
mirror=http://mirror.archlinuxarm.org
|
||||
fi
|
||||
fi
|
||||
|
||||
if is_use_cloud_image; then
|
||||
# cloud image
|
||||
eval ${step}_img=$mirror/images/latest/Arch-Linux-x86_64-cloudimg.qcow2
|
||||
else
|
||||
# 传统安装
|
||||
case "$basearch" in
|
||||
x86_64) dir="core/os/$basearch" ;;
|
||||
aarch64) dir="$basearch/core" ;;
|
||||
esac
|
||||
test_url $mirror/$dir/core.db gzip
|
||||
eval ${step}_mirror=$mirror
|
||||
fi
|
||||
# eval ${step}_img=$ci_mirror/images/latest/Arch-Linux-x86_64-basic.qcow2
|
||||
eval ${step}_img=$ci_mirror/images/latest/Arch-Linux-x86_64-cloudimg.qcow2
|
||||
}
|
||||
|
||||
setos_gentoo() {
|
||||
@ -818,9 +837,9 @@ check_ram() {
|
||||
netboot.xyz) echo 0 ;;
|
||||
alpine | dd) echo 256 ;; # 192 无法启动 netboot
|
||||
debian) echo 384 ;;
|
||||
gentoo | windows) echo 512 ;;
|
||||
arch | gentoo | windows) echo 512 ;;
|
||||
centos | alma | rocky | fedora | ubuntu) echo 1024 ;;
|
||||
arch | opensuse) echo max ;; # 没有安装模式
|
||||
opensuse) echo max ;; # 没有安装模式
|
||||
esac
|
||||
)
|
||||
|
||||
@ -833,8 +852,8 @@ check_ram() {
|
||||
|
||||
has_cloud_image=$(
|
||||
case "$distro" in
|
||||
centos | alma | rocky | fedora | debian | ubuntu | opensuse | arch) echo true ;;
|
||||
netboot.xyz | alpine | dd | gentoo | windows) echo false ;;
|
||||
centos | alma | rocky | fedora | debian | ubuntu | opensuse) echo true ;;
|
||||
netboot.xyz | alpine | dd | arch | gentoo | windows) echo false ;;
|
||||
esac
|
||||
)
|
||||
|
||||
@ -1745,13 +1764,13 @@ install_pkg curl grep
|
||||
|
||||
# 强制忽略/强制添加 --ci 参数
|
||||
case "$distro" in
|
||||
dd | windows | netboot.xyz | alpine | gentoo)
|
||||
dd | windows | netboot.xyz | alpine | arch | gentoo)
|
||||
if is_use_cloud_image; then
|
||||
echo "ignored --ci"
|
||||
cloud_image=0
|
||||
fi
|
||||
;;
|
||||
opensuse | arch)
|
||||
opensuse)
|
||||
cloud_image=1
|
||||
;;
|
||||
esac
|
||||
|
238
trans.sh
238
trans.sh
@ -48,8 +48,8 @@ add_community_repo() {
|
||||
fi
|
||||
|
||||
if ! grep -q "^http.*/$alpine_ver/community$" /etc/apk/repositories; then
|
||||
mirror=$(grep '^http.*/main$' /etc/apk/repositories | sed 's,/[^/]*/main$,,' | head -1)
|
||||
echo $mirror/$alpine_ver/community >>/etc/apk/repositories
|
||||
alpine_mirror=$(grep '^http.*/main$' /etc/apk/repositories | sed 's,/[^/]*/main$,,' | head -1)
|
||||
echo $alpine_mirror/$alpine_ver/community >>/etc/apk/repositories
|
||||
fi
|
||||
}
|
||||
|
||||
@ -862,24 +862,95 @@ install_alpine() {
|
||||
fi
|
||||
}
|
||||
|
||||
install_gentoo() {
|
||||
os_dir=/os
|
||||
get_cpu_vendor() {
|
||||
cpu_vendor=$(grep 'vendor_id' /proc/cpuinfo | head -n 1 | cut -d: -f2 | xargs)
|
||||
case "$cpu_vendor" in
|
||||
GenuineIntel) echo intel ;;
|
||||
AuthenticAMD) echo amd ;;
|
||||
*) echo other ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 挂载分区
|
||||
if is_efi || is_xda_gt_2t; then
|
||||
os_part_num=2
|
||||
else
|
||||
os_part_num=1
|
||||
fi
|
||||
install_arch_gentoo() {
|
||||
set_locale() {
|
||||
echo "C.UTF-8 UTF-8" >>$os_dir/etc/locale.gen
|
||||
chroot $os_dir locale-gen
|
||||
}
|
||||
|
||||
mkdir -p /os
|
||||
mount -t ext4 /dev/${xda}*${os_part_num} /os
|
||||
# shellcheck disable=SC2317
|
||||
install_arch() {
|
||||
# 添加 swap
|
||||
create_swap_if_ram_less_than 1024 $os_dir/swapfile
|
||||
|
||||
apk add arch-install-scripts
|
||||
|
||||
# 设置 repo
|
||||
insert_into_file /etc/pacman.conf before '\[core\]' <<EOF
|
||||
SigLevel = Never
|
||||
ParallelDownloads = 5
|
||||
EOF
|
||||
cat <<EOF >>/etc/pacman.conf
|
||||
[core]
|
||||
Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
[extra]
|
||||
Include = /etc/pacman.d/mirrorlist
|
||||
EOF
|
||||
mkdir -p /etc/pacman.d
|
||||
# shellcheck disable=SC2016
|
||||
case "$(uname -m)" in
|
||||
x86_64) dir='$repo/os/$arch' ;;
|
||||
aarch64) dir='$arch/$repo' ;;
|
||||
esac
|
||||
# shellcheck disable=SC2154
|
||||
echo "Server = $mirror/$dir" >/etc/pacman.d/mirrorlist
|
||||
|
||||
# 安装系统
|
||||
# 要安装分区工具(包含 fsck.xxx),用于 initramfs 检查分区数据
|
||||
# base 包含 e2fsprogs
|
||||
pkgs="base grub openssh"
|
||||
if is_efi; then
|
||||
mkdir -p /os/boot/efi
|
||||
mount -t vfat /dev/${xda}*1 /os/boot/efi
|
||||
pkgs="$pkgs efibootmgr dosfstools"
|
||||
fi
|
||||
if [ "$(uname -m)" = aarch64 ]; then
|
||||
pkgs="$pkgs archlinuxarm-keyring"
|
||||
fi
|
||||
pacstrap -K $os_dir $pkgs
|
||||
|
||||
# dns
|
||||
cp -f /etc/resolv.conf $os_dir/etc/resolv.conf
|
||||
|
||||
# 挂载伪文件系统
|
||||
mount_pseudo_fs $os_dir
|
||||
|
||||
# 要先设置语言,再安装内核,不然出现
|
||||
# ==> Creating gzip-compressed initcpio image: '/boot/initramfs-linux.img'
|
||||
# bsdtar: bsdtar: Failed to set default locale
|
||||
# Failed to set default locale
|
||||
set_locale
|
||||
if [ "$(uname -m)" = aarch64 ]; then
|
||||
chroot $os_dir pacman-key --lsign-key builder@archlinuxarm.org
|
||||
fi
|
||||
|
||||
# firmware + microcode
|
||||
if ! is_virt; then
|
||||
chroot $os_dir pacman -Syu --noconfirm linux-firmware
|
||||
|
||||
# amd microcode 包括在 linux-firmware 里面
|
||||
if [ "$(uname -m)" = x86_64 ]; then
|
||||
cpu_vendor="$(get_cpu_vendor)"
|
||||
case "$cpu_vendor" in
|
||||
intel | amd) chroot $os_dir pacman -Syu --noconfirm "$cpu_vendor-ucode" ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
# arm 的内核有多种选择,默认是 linux-aarch64,所以要添加 --noconfirm
|
||||
chroot $os_dir pacman -Syu --noconfirm linux
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
install_gentoo() {
|
||||
# 添加 swap
|
||||
create_swap_if_ram_less_than 2048 $os_dir/swapfile
|
||||
|
||||
@ -898,32 +969,6 @@ install_gentoo() {
|
||||
# 挂载伪文件系统
|
||||
mount_pseudo_fs $os_dir
|
||||
|
||||
# 网络配置
|
||||
apk add cloud-init
|
||||
useradd systemd-network
|
||||
touch net.cfg
|
||||
create_cloud_init_network_config net.cfg
|
||||
# 正常应该是 -D gentoo,但 alpine 的 cloud-init 包缺少 gentoo 配置
|
||||
cloud-init devel net-convert -p net.cfg -k yaml -d $os_dir -D alpine -O networkd
|
||||
|
||||
# 删除网卡名匹配
|
||||
sed -i '/^Name=/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
||||
rm -rf net.cfg
|
||||
apk del cloud-init
|
||||
|
||||
# 修复 onlink 网关
|
||||
if is_staticv4 || is_staticv6; then
|
||||
fix_sh=cloud-init-fix-onlink.sh
|
||||
download $confhome/$fix_sh $os_dir/$fix_sh
|
||||
chroot $os_dir bash /$fix_sh
|
||||
rm -f $os_dir/$fix_sh
|
||||
fi
|
||||
|
||||
# 修改密码
|
||||
sed -i 's/enforce=everyone/enforce=none/' $os_dir/etc/security/passwdqc.conf
|
||||
echo 'root:123@@@' | chroot $os_dir chpasswd >/dev/null
|
||||
sed -i 's/enforce=none/enforce=everyone/' $os_dir/etc/security/passwdqc.conf
|
||||
|
||||
# 下载仓库,选择 profile
|
||||
chroot $os_dir emerge-webrsync
|
||||
profile=$(
|
||||
@ -939,6 +984,11 @@ install_gentoo() {
|
||||
echo "Select profile: $profile"
|
||||
chroot $os_dir eselect profile set $profile
|
||||
|
||||
# 设置 license
|
||||
cat <<EOF >>$os_dir/etc/portage/make.conf
|
||||
ACCEPT_LICENSE="*"
|
||||
EOF
|
||||
|
||||
# 设置线程
|
||||
# 根据 cpu 核数,2G内存一个线程,取最小值
|
||||
threads_by_core=$(nproc --all)
|
||||
@ -982,16 +1032,10 @@ EOF
|
||||
# 下载公钥
|
||||
chroot $os_dir getuto
|
||||
|
||||
# 初始化
|
||||
# /etc/locale.gen 不能为空,否则编译 glibc 时会提示生成所有 locale
|
||||
# Generating all locales; edit /etc/locale.gen to save time/space
|
||||
echo "C.UTF-8 UTF-8" >>$os_dir/etc/locale.gen
|
||||
chroot $os_dir locale-gen
|
||||
chroot $os_dir systemctl preset-all
|
||||
chroot $os_dir systemd-firstboot --force --setup-machine-id
|
||||
chroot $os_dir systemd-firstboot --force --timezone=Asia/Shanghai
|
||||
set_locale
|
||||
|
||||
# 安装 git
|
||||
# 安装 git 会升级 glibc,此时 /etc/locale.gen 不能为空,否则会提示生成所有 locale
|
||||
# Generating all locales; edit /etc/locale.gen to save time/space
|
||||
chroot $os_dir emerge dev-vcs/git
|
||||
|
||||
# 设置 git repo
|
||||
@ -1018,30 +1062,97 @@ EOF
|
||||
chroot $os_dir emerge sys-block/io-scheduler-udev-rules
|
||||
fi
|
||||
|
||||
# 网络
|
||||
chroot $os_dir systemctl enable systemd-networkd
|
||||
chroot $os_dir systemctl enable systemd-resolved
|
||||
if is_efi; then
|
||||
chroot $os_dir emerge sys-fs/dosfstools
|
||||
fi
|
||||
|
||||
# ssh
|
||||
chroot $os_dir systemctl enable sshd
|
||||
allow_root_password_login $os_dir
|
||||
# firmware + microcode
|
||||
if ! is_virt; then
|
||||
chroot $os_dir emerge sys-kernel/linux-firmware
|
||||
|
||||
# ntp 用 systemd 自带的
|
||||
# TODO: firmware + 微码 + vm agent
|
||||
# amd microcode 包括在 linux-firmware 里面
|
||||
if [ "$(uname -m)" = x86_64 ] && [ "$(get_cpu_vendor)" = intel ]; then
|
||||
chroot $os_dir emerge sys-firmware/intel-microcode
|
||||
fi
|
||||
fi
|
||||
|
||||
# 内核 + grub
|
||||
# 安装 grub + 内核
|
||||
# TODO: 先判断是否有 binpkg,有的话不修改 GRUB_PLATFORMS
|
||||
is_efi && grub_platforms="efi-64" || grub_platforms="pc"
|
||||
echo GRUB_PLATFORMS=\"$grub_platforms\" >>$os_dir/etc/portage/make.conf
|
||||
echo "sys-kernel/installkernel dracut grub" >$os_dir/etc/portage/package.use/installkernel
|
||||
chroot $os_dir emerge sys-kernel/gentoo-kernel-bin
|
||||
}
|
||||
|
||||
os_dir=/os
|
||||
|
||||
# 挂载分区
|
||||
if is_efi || is_xda_gt_2t; then
|
||||
os_part_num=2
|
||||
else
|
||||
os_part_num=1
|
||||
fi
|
||||
|
||||
mkdir -p /os
|
||||
mount -t ext4 /dev/${xda}*${os_part_num} /os
|
||||
|
||||
if is_efi; then
|
||||
chroot $os_dir grub-install --efi-directory=/boot/efi --removable
|
||||
mkdir -p /os/efi
|
||||
mount -t vfat /dev/${xda}*1 /os/efi
|
||||
fi
|
||||
|
||||
install_$distro
|
||||
|
||||
# 初始化
|
||||
chroot $os_dir systemctl preset-all
|
||||
chroot $os_dir systemd-firstboot --force --setup-machine-id
|
||||
chroot $os_dir systemd-firstboot --force --timezone=Asia/Shanghai
|
||||
chroot $os_dir systemctl enable systemd-networkd
|
||||
chroot $os_dir systemctl enable systemd-resolved
|
||||
chroot $os_dir systemctl enable sshd
|
||||
allow_root_password_login $os_dir
|
||||
|
||||
# 修改密码
|
||||
[ "$distro" = gentoo ] && sed -i 's/enforce=everyone/enforce=none/' $os_dir/etc/security/passwdqc.conf
|
||||
echo 'root:123@@@' | chroot $os_dir chpasswd >/dev/null
|
||||
[ "$distro" = gentoo ] && sed -i 's/enforce=none/enforce=everyone/' $os_dir/etc/security/passwdqc.conf
|
||||
|
||||
# 网络配置
|
||||
apk add cloud-init
|
||||
useradd systemd-network
|
||||
touch net.cfg
|
||||
create_cloud_init_network_config net.cfg
|
||||
# 正常应该是 -D gentoo,但 alpine 的 cloud-init 包缺少 gentoo 配置
|
||||
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/
|
||||
rm -rf out
|
||||
|
||||
# 删除网卡名匹配
|
||||
sed -i '/^Name=/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network
|
||||
rm -rf net.cfg
|
||||
apk del cloud-init
|
||||
|
||||
# 修复 onlink 网关
|
||||
if is_staticv4 || is_staticv6; then
|
||||
fix_sh=cloud-init-fix-onlink.sh
|
||||
download $confhome/$fix_sh $os_dir/$fix_sh
|
||||
chroot $os_dir bash /$fix_sh
|
||||
rm -f $os_dir/$fix_sh
|
||||
fi
|
||||
|
||||
# ntp 用 systemd 自带的
|
||||
# TODO: vm agent + 随机数生成器
|
||||
|
||||
# grub
|
||||
if is_efi; then
|
||||
# arch gentoo 推荐 efi 挂载在 /efi
|
||||
chroot $os_dir grub-install --efi-directory=/efi
|
||||
chroot $os_dir grub-install --efi-directory=/efi --removable
|
||||
else
|
||||
chroot $os_dir grub-install /dev/$xda
|
||||
fi
|
||||
|
||||
# cmdline
|
||||
# cmdline + 生成 grub.cfg
|
||||
if [ -d $os_dir/etc/default/grub.d ]; then
|
||||
file=$os_dir/etc/default/grub.d/cmdline.conf
|
||||
else
|
||||
@ -1052,6 +1163,7 @@ EOF
|
||||
chroot $os_dir grub-mkconfig -o /boot/grub/grub.cfg
|
||||
|
||||
# fstab
|
||||
# fstab 可不写 efi 条目, systemd automount 会自动挂载
|
||||
apk add arch-install-scripts
|
||||
genfstab -U $os_dir | sed '/swap/d' >$os_dir/etc/fstab
|
||||
apk del arch-install-scripts
|
||||
@ -1228,7 +1340,7 @@ create_part() {
|
||||
mkfs.ext4 -F -L os /dev/$xda*1 #1 os
|
||||
mkfs.ext4 -F -L installer /dev/$xda*2 #2 installer
|
||||
fi
|
||||
elif [ "$distro" = alpine ] || [ "$distro" = gentoo ]; then
|
||||
elif [ "$distro" = alpine ] || [ "$distro" = arch ] || [ "$distro" = gentoo ]; then
|
||||
if is_efi; then
|
||||
# efi
|
||||
parted /dev/$xda -s -- \
|
||||
@ -2820,9 +2932,9 @@ elif is_use_cloud_image; then
|
||||
resize_after_install_cloud_image
|
||||
modify_os_on_disk linux
|
||||
fi
|
||||
elif [ "$distro" = "gentoo" ]; then
|
||||
elif [ "$distro" = "arch" ] || [ "$distro" = "gentoo" ]; then
|
||||
create_part
|
||||
install_gentoo
|
||||
install_arch_gentoo
|
||||
else
|
||||
# 安装模式: windows windows ubuntu 红帽
|
||||
create_part
|
||||
|
Loading…
Reference in New Issue
Block a user