mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
完善扩容逻辑,减少软件下载
This commit is contained in:
parent
652784717d
commit
f118616215
24
ks.cfg
24
ks.cfg
@ -55,8 +55,12 @@ selinux --disabled
|
|||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
%pre
|
%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 分区,表示用了两步安装
|
# 有 installer 分区,表示用了两步安装
|
||||||
|
include=/tmp/include-packages-for-resize
|
||||||
|
touch $include
|
||||||
if [ -e /dev/disk/by-label/installer ]; then
|
if [ -e /dev/disk/by-label/installer ]; then
|
||||||
# 1g内存下,安装器默认开启了zram ,但安装f38还是不够内存,所以还要开启swap
|
# 1g内存下,安装器默认开启了zram ,但安装f38还是不够内存,所以还要开启swap
|
||||||
mkdir /installer
|
mkdir /installer
|
||||||
@ -72,14 +76,14 @@ if [ -e /dev/disk/by-label/installer ]; then
|
|||||||
mkswap $swapfile
|
mkswap $swapfile
|
||||||
swapon $swapfile
|
swapon $swapfile
|
||||||
|
|
||||||
# 两步安装最后扩容要用的软件
|
|
||||||
# feroda 默认不包含 cronie
|
# feroda 默认不包含 cronie
|
||||||
# cloud-utils-growpart 需要用到 gdisk 处理 gpt 分区
|
echo cronie >>$include
|
||||||
cat <<EOF >/tmp/include-packages-for-resize
|
|
||||||
cronie
|
# el7 的parted不支持在线扩容,要用 growpart 和 gdisk 处理 gpt 分区
|
||||||
cloud-utils-growpart
|
if [ "$releasever" = "7" ]; then
|
||||||
gdisk
|
echo cloud-utils-growpart >>$include
|
||||||
EOF
|
echo gdisk >>$include
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 重新整理 extra,因为grub会处理掉引号,要重新添加引号
|
# 重新整理 extra,因为grub会处理掉引号,要重新添加引号
|
||||||
@ -90,8 +94,6 @@ done
|
|||||||
|
|
||||||
# 设置安装源
|
# 设置安装源
|
||||||
include=/tmp/include-url-command
|
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
|
# shellcheck disable=SC2154
|
||||||
if [ "$localtest" = 1 ]; then
|
if [ "$localtest" = 1 ]; then
|
||||||
echo "url --url=$confhome/$releasever/" >$include
|
echo "url --url=$confhome/$releasever/" >$include
|
||||||
@ -107,7 +109,7 @@ fi
|
|||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
%post
|
%post
|
||||||
# el9/fedora 需手动开启 root ssh 密码登录
|
# el9/fedora的sshd默认不允许root密码登录,需手动开启
|
||||||
# rootpw --allow-ssh 9.1 以上才支持
|
# rootpw --allow-ssh 9.1 以上才支持
|
||||||
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
|
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
|
||||||
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)
|
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)
|
||||||
|
20
resize.sh
20
resize.sh
@ -7,9 +7,17 @@ update_part() {
|
|||||||
udevadm settle
|
udevadm settle
|
||||||
}
|
}
|
||||||
|
|
||||||
# rh 自带 fdisk parted
|
# el 自带 fdisk parted (el7的part不支持在线扩容)
|
||||||
# ubuntu 自带 fdisk growpart
|
# ubuntu 自带 fdisk growpart
|
||||||
|
|
||||||
|
# 删除分区用
|
||||||
|
# el/ubuntu fdisk
|
||||||
|
|
||||||
|
# 扩容分区用
|
||||||
|
# el7 grownparted 额外安装
|
||||||
|
# el8/9/fedora parted
|
||||||
|
# ubuntu grownpart
|
||||||
|
|
||||||
# 找出主硬盘
|
# 找出主硬盘
|
||||||
xda=$(lsblk -dn -o NAME | grep -E 'nvme0n1|.da')
|
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)
|
part_fstype=$(lsblk -no FSTYPE /dev/$xda$part_num)
|
||||||
|
|
||||||
# 扩容分区
|
# 扩容分区
|
||||||
# rh 7 不能用parted在线扩容,而fdisk扩容会改变 PARTUUID,所以用 growpart
|
# ubuntu 和 el7 用 growpart,其他用 parted
|
||||||
# printf 'yes\n100%%' | parted /dev/$xda resizepart $part_num ---pretend-input-tty
|
# el7 不能用parted在线扩容,而fdisk扩容会改变 PARTUUID,所以用 growpart
|
||||||
growpart /dev/$xda $part_num
|
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
|
update_part /dev/$xda
|
||||||
|
|
||||||
# 扩容最后一个分区的文件系统
|
# 扩容最后一个分区的文件系统
|
||||||
|
Loading…
x
Reference in New Issue
Block a user