×

Centos7 自动安装ks文件

hqy hqy 发表于2024-12-25 16:14:44 浏览32 评论0

抢沙发发表评论


install

cdrom

cmdline

lang en_US.UTF-8

keyboard us

rootpw  password

firewall --disabled

authconfig --enableshadow --passalgo=sha512

selinux --disable

timezone Asia/Shanghai

eula --agreed

firstboot --disable

bootloader --location=mbr

poweroff



%packages --ignoremissing

@^minimal

@Core

bind-utils

net-tools

mtr

tcpdump

vconfig

nmap-ncat

strace

telnet

wget

psmisc

sysstat

traceroute

lsof

vim

%end



zerombr

%include /tmp/network.ks

%include /tmp/disk.txt

%include /tmp/part.ks







%pre

curTTY=$(tty)

exec < $curTTY > $curTTY 2> $curTTY

clear



echo -e "******************************* Please select network type ***********************************

\t1)dhcp

\t2)static"

read -t 60 -p "Your select (1 or 2 ,default: 1) : " INPUT

echo



echo "******************************* Please select interface name *********************************"

for i in $(ip -br link|grep -v LOOPBACK|awk '{print $1}' ); do

dev=$(echo "$(ip -br link show $i) $(ethtool $i|grep Speed)"|awk '{print "\t"$1"\t"$2"\t"$3"\t"$5,$6 }')

echo $dev

status=$(echo $dev | awk '{if ( $2 == "UP" ) print $1}')

devi=$(echo $dev|awk '{print $1}')

if [ -n "$status" ];then

echo $devi >> /tmp/dev_list

fi

done

echo



while true; do

read -t 60 -p "select interface name(eth0 or eth1 or ...) : " INTERFACE

if [ -n $INTERFACE ];then

echo $INTERFACE > /tmp/dev_list

ip addr show $INTERFACE >/dev/null 2>&1  && break

fi

done



echo

echo "**********************************************************************************************"



if [ "$INPUT" == "2" ];then

ANSWER="n"

while [ x"$ANSWER" != "xy" ] && [ x"$ANSWER" != "xY" ] ; do

read -p "Enter IP Address      : " IPADDR

read -p "Enter NetMask         : " NETMASK

read -p "Enter Gateway         : " GATEWAY

echo

echo "You entered:"

echo -e "\tIP Address: $IPADDR"

echo -e "\tNetMask: $NETMASK"

echo -e "\tGateway: $GATEWAY"

echo -n "Is this correct? [y/n] "; read ANSWER

done

sleep 1

echo "network --bootproto=static --gateway=$GATEWAY --ip=$IPADDR --netmask=$NETMASK --noipv6 --nodns --onboot=on ${INTERFACE:+--device=$INTERFACE}" >/tmp/network.ks

else

echo "Use dhcp ................."

cat /tmp/dev_list | while read active_dev

do

echo "network --bootproto=dhcp ${active_dev:+--device=$active_dev}" > /tmp/network.ks

done

#echo "network --bootproto=dhcp ${INTERFACE:+--device=$INTERFACE}" > /tmp/network.ks

fi

cat /tmp/network.ks

#%end



#%pre

curTTY=$(tty)

exec < $curTTY > $curTTY 2> $curTTY



echo "******************************* Please select install disk **************************************"

alldisk=$(lsblk -ldno name,size,type,tran|awk '$3=="disk"{print $1,$2,$4}'|cat -n)

echo "$alldisk"|awk '{printf "%-4s%-8s%4s%8s\n", "\t"$1,$2,$3,$4 }'

echo "*************************************************************************************************"



disknum=noselect

while echo $disknum |grep -q '[^0-9]';do

read -t 60 -p "select disk numbers(1 or 2 or ...)     : " disknum

done

if [ -n "$disknum" ];then

DISK=$(echo -n "$alldisk"|awk '$1=='$disknum'{print $2}')

else

USB=$(lsblk -lno name,label|grep -i "CentOS 7 x86_64"|awk 'NR==1{print $1}'|tr -d '0-9')

DISK=$(lsblk -lno name,label,type|grep -v $USB|grep -v fd|awk '$NF~/disk/{print $1}'|head -1)

fi

echo $DISK > /run/.disk



echo -e "bootloader --append=\"crashkernel=auto biosdevname=0 net.ifnames=1 rhgb quiet\" --location=mbr --driveorder=$DISK --boot-drive=$DISK\nignoredisk --only-use=$DISK\nclearpart --all --initlabel " > /tmp/disk.txt



cat /tmp/disk.txt

parted -s /dev/$DISK  mklabel gpt



echo "part biosboot --fstype=biosboot --size=1" >/tmp/part.ks

echo "part /boot --fstype=ext4 --size=1024 --label boot" >>/tmp/part.ks

size=$(awk '/'$DISK'/{print $3}' /proc/partitions|head -1)

if [ $size -gt 110100480 ]; then

echo "part / --fstype=ext4 --size=100000 --label root" >>/tmp/part.ks

else

echo "part / --fstype=ext4 --grow --size=1 --label root" >>/tmp/part.ks

fi

cat /tmp/part.ks

partprobe

%end



%post --nochroot

# Mount CDROM

mkdir -p /mnt/cdrom

mount -r -t iso9660 /dev/cdrom /mnt/cdrom

cp /mnt/cdrom/extras/extras.tar /mnt/sysimage/tmp/extras.tar

cp /run/install/repo/extras/extras.tar /mnt/sysimage/tmp/extras.tar

# Unmount CDROM

umount /mnt/cdrom

%end





##

%post --log=/tmp/ks-post.log



cat >/etc/yum.repos.d/epel.repo << EOF

[epel]

name=EPEL for redhat/centos \$releasever - \$basearch

baseurl=http://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey=http://mirrors.cloud.tencent.com/epel/RPM-GPG-KEY-EPEL-7

EOF







cat >/etc/yum.repos.d/CentOS-Base.repo << EOF

[os]

name=Qcloud centos os - \$basearch

baseurl=http://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/

enabled=1

gpgcheck=1

gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7



[updates]

name=Qcloud centos updates - \$basearch

baseurl=http://mirrors.cloud.tencent.com/centos/\$releasever/updates/\$basearch/

enabled=1

gpgcheck=1

gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7



[centosplus]

name=Qcloud centosplus - \$basearch

baseurl=http://mirrors.cloud.tencent.com/centos/\$releasever/centosplus/\$basearch/

enabled=0

gpgcheck=1

gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7



[cr]

name=Qcloud centos cr - \$basearch

baseurl=http://mirrors.cloud.tencent.com/centos/\$releasever/cr/\$basearch/

enabled=0

gpgcheck=1

gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7



[extras]

name=Qcloud centos extras - \$basearch

baseurl=http://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch/

enabled=1

gpgcheck=1

gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7



[fasttrack]

name=Qcloud centos fasttrack - \$basearch

baseurl=http://mirrors.cloud.tencent.com/centos/\$releasever/fasttrack/\$basearch/

enabled=0

gpgcheck=1

gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7

EOF





cat >>/etc/sysctl.conf << EOF

net.netfilter.nf_conntrack_max = 2621440

net.core.rmem_default = 4194304

net.core.rmem_max = 4194304

net.core.default_qdisc = fq

net.ipv4.tcp_congestion_control = bbr

EOF



tar xvf /tmp/extras.tar -C /tmp

echo "options ixgbe allow_unsupported_sfp=1" >/etc/modprobe.d/ixgbe.conf

rpm -Uvh /tmp/extras/packages/*



grub2-set-default 'CentOS Linux (5.15.1-1.el7.elrepo.x86_64) 7 (Core)'

dracut -N -f  /boot/initramfs-5.15.1-1.el7.elrepo.x86_64.img 5.15.1-1.el7.elrepo.x86_64

sed -i 's/net.ifnames=1/net.ifnames=0/g' /etc/default/grub

grub2-mkconfig -o /boot/grub2/grub.cfg



bash  /tmp/extras/frpc/install_frpc.sh > /tmp/frpc_install.log 2>&1

%end


打赏

本文链接:https://www.kinber.cn/post/4361.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客