reinstall/redhat.cfg

165 lines
4.9 KiB
INI
Raw Normal View History

2024-02-01 01:02:35 +08:00
# shellcheck disable=SC2148
2023-05-03 22:22:21 +08:00
# 设置
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
timezone Asia/Shanghai --utc
2023-05-04 22:00:59 +08:00
rootpw --plaintext 123@@@
2023-05-03 22:22:21 +08:00
text
reboot
%include /tmp/include-url-command
# 分区
%include /tmp/include-disk-only-use
2023-08-08 23:21:28 +08:00
%include /tmp/include-bootloader
2023-05-03 22:22:21 +08:00
clearpart --all --initlabel
2023-08-07 23:26:56 +08:00
reqpart # 如果需要,自动创建 efi 或 biosboot 分区
part / --fstype=xfs --grow
2023-05-03 22:22:21 +08:00
# 软件
%packages --ignoremissing # el9 minimal.iso fedora Server repo/iso 没有 tuned
@^Minimal Install
%include /tmp/include-packages-for-resize
2023-05-13 00:14:46 +08:00
%include /tmp/exclude-packages-for-vm
2023-05-03 22:22:21 +08:00
%end
# 禁用防火墙
# firewall --disabled
# 禁用 selinux
selinux --disabled
# 禁用 kdump
%addon com_redhat_kdump --disable
%end
##############################################
%pre
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)
2023-05-13 00:14:46 +08:00
# 重新整理 extragrub把两侧的引号吃掉了eval出错要重新添加引号
2024-02-01 00:59:34 +08:00
# 提取 extra.confhome extra.mirrorlist extra.main_disk
2023-05-13 00:14:46 +08:00
prefix=extra
for var in $(grep -o "\b$prefix\.[^ ]*" /proc/cmdline | xargs); do
2024-02-01 01:02:35 +08:00
eval "$(echo "$var" | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
2023-05-13 00:14:46 +08:00
done
# centos7 证书链未更新,需要 --no-check-certificate
2024-02-01 00:59:34 +08:00
# 只使用主硬盘
include=/tmp/include-disk-only-use
2024-03-05 23:01:24 +08:00
xda=$(wget --no-check-certificate --tries=5 "$confhome/get-xda.sh" -O- | sh -s)
echo "ignoredisk --only-use=$xda" >$include
2023-08-08 23:21:28 +08:00
# 设置 tty
include=/tmp/include-bootloader
2024-02-01 01:02:35 +08:00
# shellcheck disable=SC2154
2024-03-05 23:01:24 +08:00
console_cmdline=$(wget --no-check-certificate --tries=5 "$confhome/ttys.sh" -O- | sh -s console=)
2023-09-03 19:35:01 +08:00
echo "bootloader --append=\"$console_cmdline\"" >$include
2023-08-08 23:21:28 +08:00
2023-05-03 22:22:21 +08:00
# 有 installer 分区,表示用了两步安装
include=/tmp/include-packages-for-resize
touch $include
2023-05-03 22:22:21 +08:00
if [ -e /dev/disk/by-label/installer ]; then
# 1g内存下安装器默认开启了zram 但安装f38还是不够内存
# 具体表现为不断重启安装界面所以还要开启swap
ram_size=$(lsmem -b 2>/dev/null | grep 'Total online memory:' | awk '{ print $NF/1024/1024 }')
2024-02-01 01:02:35 +08:00
if [ -z "$ram_size" ] || [ "$ram_size" -le 1024 ]; then
mount /dev/disk/by-label/installer /run/install/repo -o remount,rw
swapfile=/run/install/repo/swapfile
if command -v fallocate; then
fallocate -l 1G $swapfile
else
dd if=/dev/zero of=$swapfile bs=1M count=1024
fi
chmod 0600 $swapfile
mkswap $swapfile
swapon $swapfile
2023-05-03 22:22:21 +08:00
fi
# feroda 默认不包含 cronie
echo cronie >>$include
# el7 的parted不支持在线扩容要用 growpart 和 gdisk 处理 gpt 分区
if [ "$releasever" = "7" ]; then
echo cloud-utils-growpart >>$include
echo gdisk >>$include
fi
2023-05-03 22:22:21 +08:00
fi
2023-05-13 00:14:46 +08:00
# 排除虚拟机用不上的组件
include=/tmp/exclude-packages-for-vm
touch $include
2023-05-17 22:54:26 +08:00
if systemd-detect-virt -v; then
2023-05-13 00:14:46 +08:00
cat <<EOF >$include
# 不删除usb相关的包 因为甲骨文云有usb设备 作用未知
# -usb_modeswitch
# -usbutils
# 无线
-iw
-crda
-rfkill
-iwl*-firmware
# 其他
-irqbalance # 多核+直通设备可能有用?
-microcode_ctl
-smartmontools
# 各种固件
-aic94xx-firmware
-alsa-firmware
-ivtv-firmware
# -linux-firmware # 去除后安装centos 8会报错
# fedora 特有固件
-amd-gpu-firmware
-atheros-firmware
-brcmfmac-firmware
-intel-gpu-firmware
-mt7xxx-firmware
-nvidia-gpu-firmware
-realtek-firmware
EOF
fi
2023-05-03 22:22:21 +08:00
# 设置安装源
include=/tmp/include-url-command
# shellcheck disable=SC2154
if [ "$localtest" = 1 ]; then
echo "url --url=$confhome/$releasever/" >$include
# echo cdrom >$include
else
echo "url --mirrorlist=$mirrorlist" >$include
# 对于el7/fedora, 添加了 updates repo 才会安装最新的包
if [ "$releasever" = "7" ] || [ "$distro" = "fedoraproject" ]; then
echo "repo --name=updates" >>$include
fi
fi
%end
##############################################
%post
# el9/fedora的sshd默认不允许root密码登录需手动开启
2023-05-03 22:22:21 +08:00
# rootpw --allow-ssh 9.1 以上才支持
distro=$(awk -F: '{ print $3 }' </etc/system-release-cpe)
releasever=$(awk -F: '{ print $5 }' </etc/system-release-cpe)
if [ "$releasever" = "9" ] || [ "$distro" = "fedoraproject" ]; then
echo "PermitRootLogin yes" >/etc/ssh/sshd_config.d/01-permitrootlogin.conf
fi
# 分步安装的系统要将最后一个分区installer合并到系统分区
if [ -e /dev/disk/by-label/installer ]; then
2023-05-13 00:14:46 +08:00
# 提取 extra.localtest extra.confhome extra.mirrorlist
prefix=extra
for var in $(grep -o "\b$prefix\.[^ ]*" /proc/cmdline | xargs); do
2024-02-01 01:02:35 +08:00
eval "$(echo "$var" | sed -E "s/$prefix\.([^=]*)=(.*)/\1='\2'/")"
2023-05-13 00:14:46 +08:00
done
2023-05-03 22:22:21 +08:00
cd /
2024-02-01 01:02:35 +08:00
curl -O "$confhome/resize.sh"
2023-05-03 22:22:21 +08:00
echo '@reboot root bash /resize.sh' >/etc/cron.d/resize
fi
%end