core: 支持安装 gentoo 云镜像

This commit is contained in:
bin456789 2023-09-16 20:00:07 +08:00
parent ef67973707
commit 11dc3c7a95
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
3 changed files with 92 additions and 16 deletions

View File

@ -31,6 +31,7 @@
alpine 3.16|3.17|3.18 alpine 3.16|3.17|3.18
opensuse 15.4|15.5|tumbleweed (只支持云镜像) opensuse 15.4|15.5|tumbleweed (只支持云镜像)
arch (只支持云镜像) arch (只支持云镜像)
gentoo (只支持 amd64 云镜像)
可选参数: --ci 强制使用云镜像 可选参数: --ci 强制使用云镜像
@ -57,7 +58,7 @@ https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh
--iso=https://example.com/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso \ --iso=https://example.com/en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso \
--image-name='Windows 10 Enterprise LTSC 2021' --image-name='Windows 10 Enterprise LTSC 2021'
### 参数: ### 参数:
`--iso` 不需要提前添加 virtio/xen/aws nitro 驱动 `--iso` 官方原版镜像,不需要提前添加 virtio/xen/aws nitro 驱动
`--image-name` 一个 iso 里会有一个或多个映像,此参数用于指定要安装的映像 `--image-name` 一个 iso 里会有一个或多个映像,此参数用于指定要安装的映像
@ -88,10 +89,11 @@ https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh
| ---- | ---- | ---- | | ---- | ---- | ---- |
| Debian | 384M | 512M | | Debian | 384M | 512M |
| Ubuntu | 1G | 512M | | Ubuntu | 1G | 512M |
| 红帽系 | 1G | 512M | | CentOS / Alma / Rocky / Fedora | 1G | 512M |
| Alpine | ? | 不支持 | | Alpine | 512M? | - |
| openSUSE | 不支持 | 512M | | openSUSE | 暂不支持 | 512M |
| Arch | 不支持 | 512M | | Arch | 暂不支持 | 512M |
| Gentoo | 暂不支持 | 512M |
| Windows | 1G | - | | Windows | 1G | - |
## 网络要求: ## 网络要求:
@ -102,10 +104,10 @@ https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh
要求有 IPv4、DHCPv4 !!!!! 要求有 IPv4、DHCPv4 !!!!!
## 默认密码: ## 默认密码:
| 用户名 | 密码 | | 系统 | 用户名 | 密码 |
| ---- | ---- | | ---- | ---- | ---- |
| root | 123@@@ | | Linux | root | 123@@@ |
| administrator | 123@@@ | | Windows| administrator | 123@@@ |
## TODO: ## TODO:
- 静态 IP / IPV6 - 静态 IP / IPV6

View File

@ -27,6 +27,7 @@ Usage: reinstall.sh centos 7|8|9
alpine 3.16|3.17|3.18 alpine 3.16|3.17|3.18
opensuse 15.4|15.5|tumbleweed opensuse 15.4|15.5|tumbleweed
arch arch
gentoo
dd --img=xxx dd --img=xxx
windows --iso=xxx --image-name=xxx windows --iso=xxx --image-name=xxx
EOF EOF
@ -353,6 +354,22 @@ setos() {
eval ${step}_img=$ci_mirror/images/latest/Arch-Linux-x86_64-cloudimg.qcow2 eval ${step}_img=$ci_mirror/images/latest/Arch-Linux-x86_64-cloudimg.qcow2
} }
setos_gentoo() {
cloud_image=1
if is_in_china; then
ci_mirror=https://mirrors.tuna.tsinghua.edu.cn/gentoo
else
ci_mirror=https://distfiles.gentoo.org
fi
if [ "$basearch_alt" = arm64 ]; then
error_and_exit 'Not support arm64 for gentoo cloud image.'
fi
# openrc 镜像没有附带兼容 cloud-init 的网络管理器
eval ${step}_img=$ci_mirror/experimental/$basearch_alt/openstack/gentoo-openstack-$basearch_alt-systemd-latest.qcow2
}
setos_opensuse() { setos_opensuse() {
cloud_image=1 cloud_image=1
@ -528,6 +545,7 @@ verify_os_string() {
'alpine 3.16|3.17|3.18' \ 'alpine 3.16|3.17|3.18' \
'opensuse 15|15.4|15.5|tumbleweed' \ 'opensuse 15|15.4|15.5|tumbleweed' \
'arch' \ 'arch' \
'gentoo' \
'windows' \ 'windows' \
'dd'; do 'dd'; do
ds=$(awk '{print $1}' <<<"$os") ds=$(awk '{print $1}' <<<"$os")
@ -663,7 +681,7 @@ check_ram() {
ram_cloud_image=512 ram_cloud_image=512
case "$distro" in case "$distro" in
opensuse | arch) cloud_image=1 ;; opensuse | arch | gentoo) cloud_image=1 ;;
esac esac
# ram 足够就用普通方法安装否则如果内存大于512就用 cloud image # ram 足够就用普通方法安装否则如果内存大于512就用 cloud image

View File

@ -529,6 +529,17 @@ create_part() {
echo #2 os 用目标系统的格式化工具 echo #2 os 用目标系统的格式化工具
mkfs.ext4 -F -L installer /dev/$xda*3 #3 installer mkfs.ext4 -F -L installer /dev/$xda*3 #3 installer
fi fi
else
# gentoo 的镜像解压后是 3.5g,因此设置 installer 分区 1g这样才能在5g硬盘上安装
[ "$distro" = gentoo ] && installer_part_size=1GiB || installer_part_size=2GiB
parted /dev/$xda -s -- \
mklabel gpt \
mkpart '" "' ext4 1MiB -$installer_part_size \
mkpart '" "' ext4 -$installer_part_size 100%
update_part /dev/$xda
mkfs.ext4 -F -L os /dev/$xda*1 #1 os
mkfs.ext4 -F -L installer /dev/$xda*2 #2 installer
fi fi
else else
# 安装红帽系或ubuntu # 安装红帽系或ubuntu
@ -748,6 +759,41 @@ modify_dd_os() {
chroot $os_dir zypper install -y wicked chroot $os_dir zypper install -y wicked
rm -f $os_dir/etc/resolv.conf rm -f $os_dir/etc/resolv.conf
fi fi
# gentoo
if [ -f $os_dir/etc/gentoo-release ]; then
# 挂载伪文件系统
mount_pseudo_fs $os_dir
# 在这里修改密码而不是用cloud-init因为我们的默认密码太弱
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
if false && [ ! -d $os_dir/var/db/repos/gentoo/ ]; then
cp -f /etc/resolv.conf $os_dir/etc/resolv.conf
chroot $os_dir emerge-webrsync
profile=$(chroot $os_dir eselect profile list | grep '/[0-9\.]*/systemd (stable)' | awk '{print $2}')
chroot $os_dir eselect profile set $profile
fi
# 删除 resolv.conf不然 systemd-resolved 无法创建软链接
rm -f $os_dir/etc/resolv.conf
# 启用网络服务
chroot $os_dir systemctl enable systemd-networkd
chroot $os_dir systemctl enable systemd-resolved
# systemd-networkd 有时不会运行
# https://bugs.gentoo.org/910404 补丁好像没用
# https://github.com/systemd/systemd/issues/27718#issuecomment-1564877478
# 临时的解决办法是运行 networkctl如果启用了systemd-networkd服务会运行服务
insert_into_file $os_dir/lib/systemd/system/systemd-logind.service after '\[Service\]' <<EOF
ExecStartPost=-networkctl
EOF
fi
} }
install_cloud_image_by_dd() { install_cloud_image_by_dd() {
@ -982,7 +1028,7 @@ EOF
parted /dev/$xda -s rm 3 parted /dev/$xda -s rm 3
else else
# debian ubuntu arch opensuse # debian ubuntu arch opensuse gentoo
if true; then if true; then
modprobe nbd modprobe nbd
qemu_nbd -c /dev/nbd0 $qcow_file qemu_nbd -c /dev/nbd0 $qcow_file
@ -1062,13 +1108,23 @@ EOF
dd if=/first-1M of=/dev/$xda dd if=/first-1M of=/dev/$xda
update_part /dev/$xda update_part /dev/$xda
# 修复 vultr 512m debian 10/11 generic/genericcloud 首次启动 kernel panic # 提前扩容
if [ "$distro" = debian ]; then # 1 修复 vultr 512m debian 10/11 generic/genericcloud 首次启动 kernel panic
# 2 修复 gentoo websync 时空间不足
if [ "$distro" = debian ] || [ "$distro" = gentoo ]; then
apk add parted apk add parted
if parted /dev/$xda -s print 2>&1 | grep 'Not all of the space'; then if parted /dev/$xda -s print 2>&1 | grep 'Not all of the space'; then
printf "fix" | parted /dev/$xda print ---pretend-input-tty printf "fix" | parted /dev/$xda print ---pretend-input-tty
printf "yes" | parted /dev/$xda resizepart 1 100% ---pretend-input-tty # TODO: 获取 ext4 分区编号
[ "$distro" = debian ] && system_part_num=1 || system_part_num=3
printf "yes" | parted /dev/$xda resizepart $system_part_num 100% ---pretend-input-tty
update_part /dev/$xda update_part /dev/$xda
if [ "$distro" = gentoo ]; then
apk add e2fsprogs-extra
e2fsck -p -f /dev/$xda$system_part_num
resize2fs /dev/$xda$system_part_num
fi
fi fi
fi fi