From 4e85095016e7552764ab0bf29163a87d7cbc211a Mon Sep 17 00:00:00 2001 From: bin456789 Date: Thu, 3 Aug 2023 22:41:30 +0800 Subject: [PATCH] =?UTF-8?q?redhat:=20=E4=B8=BA=E4=BA=91=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E7=A6=81=E7=94=A8=20selinux=20/=20kdump=20crashkernel=20?= =?UTF-8?q?=E9=A2=84=E7=95=99=E5=86=85=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans.sh | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/trans.sh b/trans.sh index ea7b077..5fe98f0 100644 --- a/trans.sh +++ b/trans.sh @@ -498,6 +498,34 @@ create_swap() { fi } +disable_selinux_kdump() { + os_dir=$1 + releasever=$(awk -F: '{ print $5 }' <$os_dir/etc/system-release-cpe) + + if ! chroot $os_dir command -v grubby; then + if [ "$releasever" = 7 ]; then + chroot $os_dir yum -y --disablerepo=* --enablerepo=base,updates grubby + else + chroot $os_dir dnf -y --disablerepo=* --enablerepo=baseos --setopt=install_weak_deps=False grubby + fi + fi + + # selinux + sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' $os_dir/etc/selinux/config + # https://access.redhat.com/solutions/3176 + if [ "$releasever" -ge 9 ]; then + chroot $os_dir grubby --update-kernel ALL --args selinux=0 + fi + + # kdump + chroot $os_dir grubby --update-kernel ALL --args crashkernel=no + if [ "$releasever" -eq 7 ]; then + # el7 上面那条 grubby 命令不能设置 /etc/default/grub + sed -iE 's/crashkernel=[^ "]*/crashkernel=no/' $os_dir/etc/default/grub + fi + rm -rf $os_dir/etc/systemd/system/multi-user.target.wants/kdump.service +} + install_cloud_image() { apk add qemu-img lsblk @@ -592,6 +620,9 @@ install_cloud_image() { mv /os/etc/resolv.conf /os/etc/resolv.conf.orig cp /etc/resolv.conf /os/etc/resolv.conf + # selinux kdump + disable_selinux_kdump /os + # cloud-init download_cloud_init_config /os @@ -611,15 +642,6 @@ install_cloud_image() { sed -i '/[[:blank:]]\/boot\/efi[[:blank:]]/d' /os/etc/fstab fi - # selinux - use_selinux=false - if $use_selinux; then - touch /os/.autorelabel - else - # TODO: 还有cmdline el9 - sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /os/etc/selinux/config - fi - distro_full=$(awk -F: '{ print $3 }'