pxe.sh_替换/var/www/html/ks/中ks.cfg

#!/bin/bash
osversion=kylin_HPC
cdromdir="/mnt"
tftpdir="/var/lib/tftpboot"
dhcpNet="168.7.10.0"
netMask="255.255.255.0"
dhcpRange="168.7.10.100 168.7.10.200"
nextServer="168.7.10.70"
isoimage="/root/*.iso"
httpServer=$nextServer

#-----------------------------------------------------------
function v_base(){
iptables -F || echo ""
systemctl stop firewalld
systemctl disable firewalld
sed -i '/SELINUX=/ s#enforcing#disabled#g' /etc/selinux/config
setenforce 0 || echo ""
mount $isoimage $cdromdir || echo ""
cp $cdromdir/EFI/BOOT/grubaa64.efi  $tftpdir
cp $cdromdir/EFI/BOOT/grub.cfg  $tftpdir
cp $cdromdir/images/pxeboot/* $tftpdir
cd /var/www/html || mkdir -p /var/www/html/ 
cp -r $cdromdir/* /var/www/html/
chmod 755 -R /var/www/html/
cat>/etc/yum.repos.d/${osversion}_http.repo<<EOF
[${osversion}_http]
name=${osversion}_http
baseurl=http://$nextServer
enabled=1
gpgcheck=0
EOF
}

function v_dhcp(){
#-- dhcp
yum --disablerepo="*" --enablerepo="${osversion}_http" install -y net-tools vim vsftpd tftp tftp-server dhcp 
cat>/etc/dhcp/dhcpd.conf<<EOF
subnet $dhcpNet netmask $netMask {
        range $dhcpRange;
        option subnet-mask $netMask;
        default-lease-time 21600;
        max-lease-time 43200;
        next-server $nextServer;
        filename "grubaa64.efi";
}
EOF
}

function v_tftp(){
#-- tftp
sed -i '/disable/ s#yes#no#g' /etc/xinetd.d/tftp || echo ""

systemctl start dhcpd && systemctl enable dhcpd
systemctl start tftp && systemctl enable tftp
systemctl start httpd && systemctl enable httpd

cat>$tftpdir/grub.cfg<<'EOF'
set default="1"

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2

set timeout=3
### END /etc/grub.d/00_header ###
EOF

cat>>$tftpdir/grub.cfg<<EOF

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install ${osversion}' --class red --class gnu-linux --class gnu --class os {
set root=(tftp,$nextServer)
 linux  /vmlinuz ro inst.geoloc=0 console=ttyAMA0 console=tty0 rd.iscsi.waitnet=0 inst.ks=http://$httpServer/ks/${osversion}-ks.cfg
 initrd /initrd.img
}
EOF
}

mkdir -p /var/www/html/ks/

function v_ks(){
cat>/var/www/html/ks/${osversion}-ks.cfg<<EOF

#version=DEVEL
# Use graphical install
graphical

#---------------------------------------------------------
# Keyboard layouts
keyboard --xlayouts='us','cn (altgr-pinyin)'

#---------------------------------------------------------
# System language
lang en_US.UTF-8

##################################################################################################
#此处保留,其他的内容用新的ks.cfg文件替换
#1. Use CDROM installation media
# 安装镜像
url --url=http://$httpServer

#2. Network information
network  --hostname=localhost.localdomain
network  --bootproto=dhcp --device=enp4s0 --onboot=on  --ipv6=auto --activate
#network  --bootproto=static --device=enp4s0 --gateway=168.7.10.1 --ip=168.7.10.105 --nameserver=114.114.114.114 --netmask=255.255.255.0 --onboot=off --ipv6=off --activate

#3. Partition clearing information
clearpart --all --initlabel

##################################################################################################

#---------------------------------------------------------
%packages
@^minimal-environment
@development
%end

#---------------------------------------------------------
# System timezone
timezone Asia/Shanghai --utc
#---------------------------------------------------------
# Run the Setup Agent on first boot
firstboot --enable

# System services
services --disabled="chronyd"

# 在那块磁盘安装OS
ignoredisk --only-use=vda

#---------------------------------------------------------
# Partition clearing information
clearpart --all --initlabel

#---------------------------------------------------------
# Disk partitioning information
# 分区表
part swap --fstype="swap" --ondisk=vda --size=10240
part / --fstype="ext4" --ondisk=vda --size=174078
part /boot/efi --fstype="efi" --ondisk=vda --size=5120 --fsoptions="umask=0077,shortname=winnt"
part /tmp --fstype="ext4" --ondisk=vda --size=51200
part /boot --fstype="ext4" --ondisk=vda --size=5120
#---------------------------------------------------------
# Root password
rootpw --iscrypted $6$XpbpyyInoUzlkmbP$vCHN5jPj18a2loOIV8tZhr19xW08R7K8lpNKqU7/WhhyGo0I7E5zK01JWGTSOxDJ5Kkl7zAgF8Zdi9k5yv1M51
#---------------------------------------------------------
%addon com_redhat_kdump --disable --reserve-mb='128'
%end

%anaconda
pwpolicy root --minlen=8 --minquality=1 --strict --nochanges --notempty
pwpolicy user --minlen=8 --minquality=1 --strict --nochanges --emptyok
pwpolicy luks --minlen=8 --minquality=1 --strict --nochanges --notempty
%end
#reboot
EOF
}
############################

v_base
v_dhcp
v_tftp
v_ks
chmod 777 -R /var/lib/tftpboot/
chmod 777 -R /var/www/html/ks

systemctl restart tftp dhcpd httpd


systemctl enable tftp dhcpd httpd

 使用方法:

1、 修改变量中IP地址为自己定义的网段

2、执行脚本

3、本地安装一台OS,用本地/root/*.cfg文件替换脚本/var/www/html/ks/目录中的文件,/var/www/html/ks/目录中文件权限和名称不允许更改

4、如果/var/www/html/ks/*.cfg文件中内容与以下内容冲突,使用以下内容替换,否则添加如下内容,。

network --hostname=localhost.localdomain
#enp4s0更改为实际网卡名
network --bootproto=dhcp --device=enp4s0 --onboot=on --ipv6=auto --activate
#重置分区表
clearpart --all --initlabel

 

# Generated by Anaconda 36.16.5
# Generated by pykickstart v3.34
#version=DEVEL
# Use graphical install
graphical

# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=enp125s0f0 --ipv6=auto --no-activate
network  --bootproto=dhcp --device=enp125s0f1 --onboot=off --ipv6=auto
network  --bootproto=dhcp --device=enp125s0f2 --onboot=off --ipv6=auto
network  --bootproto=dhcp --device=enp125s0f3 --onboot=off --ipv6=auto

# Use hard drive installation media
harddrive --dir= --partition=LABEL=openEuler-22.03-LTS-SP2-aarch64

%packages
@^minimal-environment
@development

%end

# Run the Setup Agent on first boot
firstboot --enable

# Generated using Blivet version 3.4.2
ignoredisk --only-use=sdb
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information
part pv.485 --fstype="lvmpv" --ondisk=sdb --size=6852398
part /boot/efi --fstype="efi" --ondisk=sdb --size=5120 --fsoptions="umask=0077,shortname=winnt"
part /boot --fstype="ext4" --ondisk=sdb --size=5120
volgroup openeuler --pesize=4096 pv.485
logvol /var/log --fstype="ext4" --size=204800 --name=var_log --vgname=openeuler
logvol / --fstype="ext4" --size=6438700 --name=root --vgname=openeuler
logvol swap --fstype="swap" --size=4096 --name=swap --vgname=openeuler
logvol /tmp --fstype="ext4" --size=204800 --name=tmp --vgname=openeuler

# System timezone
timezone Asia/Shanghai --utc

# Root password
rootpw --iscrypted $y$j9T$3RaUl4QlA6zkuHsOF1JTUg90$z7G3TW2kw4rWI31VJeRQ85YVwe5T5TDVhirxDfoEmN1
~
openeuler22.03.sp2__anaconda-ks.cfg

 

posted @ 2024-08-19 20:14  vmsysjack  阅读(8)  评论(0编辑  收藏  举报