完善扩容逻辑,减少软件下载

This commit is contained in:
bin456789 2023-05-04 20:57:49 +08:00
parent 652784717d
commit f118616215
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
2 changed files with 29 additions and 15 deletions

24
ks.cfg
View File

@ -55,8 +55,12 @@ selinux --disabled
##############################################
%pre
touch /tmp/include-packages-for-resize
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)
# 有 installer 分区,表示用了两步安装
include=/tmp/include-packages-for-resize
touch $include
if [ -e /dev/disk/by-label/installer ]; then
# 1g内存下安装器默认开启了zram 但安装f38还是不够内存所以还要开启swap
mkdir /installer
@ -72,14 +76,14 @@ if [ -e /dev/disk/by-label/installer ]; then
mkswap $swapfile
swapon $swapfile
# 两步安装最后扩容要用的软件
# feroda 默认不包含 cronie
# cloud-utils-growpart 需要用到 gdisk 处理 gpt 分区
cat <<EOF >/tmp/include-packages-for-resize
cronie
cloud-utils-growpart
gdisk
EOF
echo cronie >>$include
# el7 的parted不支持在线扩容要用 growpart 和 gdisk 处理 gpt 分区
if [ "$releasever" = "7" ]; then
echo cloud-utils-growpart >>$include
echo gdisk >>$include
fi
fi
# 重新整理 extra因为grub会处理掉引号要重新添加引号
@ -90,8 +94,6 @@ done
# 设置安装源
include=/tmp/include-url-command
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)
# shellcheck disable=SC2154
if [ "$localtest" = 1 ]; then
echo "url --url=$confhome/$releasever/" >$include
@ -107,7 +109,7 @@ fi
##############################################
%post
# el9/fedora 需手动开启 root ssh 密码登录
# el9/fedora的sshd默认不允许root密码登录需手动开启
# rootpw --allow-ssh 9.1 以上才支持
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)

View File

@ -7,9 +7,17 @@ update_part() {
udevadm settle
}
# rh 自带 fdisk parted
# el 自带 fdisk parted (el7的part不支持在线扩容)
# ubuntu 自带 fdisk growpart
# 删除分区用
# el/ubuntu fdisk
# 扩容分区用
# el7 grownparted 额外安装
# el8/9/fedora parted
# ubuntu grownpart
# 找出主硬盘
xda=$(lsblk -dn -o NAME | grep -E 'nvme0n1|.da')
@ -30,9 +38,13 @@ part_num=$(ls -1v /dev/$xda* | tail -1 | grep -o '[0-9]*$')
part_fstype=$(lsblk -no FSTYPE /dev/$xda$part_num)
# 扩容分区
# rh 7 不能用parted在线扩容而fdisk扩容会改变 PARTUUID所以用 growpart
# printf 'yes\n100%%' | parted /dev/$xda resizepart $part_num ---pretend-input-tty
growpart /dev/$xda $part_num
# ubuntu 和 el7 用 growpart其他用 parted
# el7 不能用parted在线扩容而fdisk扩容会改变 PARTUUID所以用 growpart
if grep -E -i 'centos:7|ubuntu' /etc/os-release; then
growpart /dev/$xda $part_num
else
printf 'yes\n100%%' | parted /dev/$xda resizepart $part_num ---pretend-input-tty
fi
update_part /dev/$xda
# 扩容最后一个分区的文件系统