create uefi or legacy pxeserver script

本文介绍了一种使用PXE(预启动执行环境)自动化安装CentOS 7系统的脚本实现方法,包括配置DHCP、TFTP、HTTP服务,以及创建必要的配置文件和目录,适用于Legacy和UEFI模式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash

make a pxe machine

v1.0 by 2020-03-30

name=centos
host_ip=$(ip a|grep brd|grep inet|awk ‘{print $2}’|awk -F ‘/’ '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲') host_vlan=(ip a|grep brd|grep inet|awk ‘{print $2}’|awk -F ‘/’ ‘{print $1}’|awk -F ‘.’ ‘{print $1"."$2"."$3}’)
ISO=/root/CentOS-7-x86_64-Everything-1810.iso
tmp_dir=/mnt
yum_dir=/etc/yum.repos.d
apache_dir=/var/www/html
tftp_dir=/var/lib/tftpboot

service_install() {
if [ $? -eq 0 ];then
yum install -y $1 &>/dev/null
if [ $? -eq 0 ];then
echo “$1 service is installed secuessfully!”
else
exit 2
fi
fi
}

menu() {
cat <<-EOF
##########################################
# a. install legacy mode pxe machine #
# b. install uefi mode pxe machine #
# c. 待完善 #
# d. 待完善 #
##########################################
EOF
}

menu
read -p "please press [a|b|c|d] to select your machine: " num

sed -ri ‘/^SELINUX=/cSELINUX=disabled’ /etc/selinux/config
setenforce 0
systemctl stop firewalld &>/dev/null
systemctl disable firewalld &>/dev/null

mount |grep $tmp_dir
if [ $? -ne 0 ];then
mount $ISO $tmp_dir &>/dev/null
echo “ISO is mounted secussfully!”
fi

if [ -d $yum_dir/bak ];then
continue
else
mkdir $yum_dir/bak; mv $yum_dir/*.repo $yum_dir/bak
fi

if [ -f yumdir/yum_dir/yumdir/name.repo ];then
echo "name.repoisexist!"elsecat>name.repo is exist!" else cat >name.repoisexist!"elsecat>yum_dir/name.repo<<−EOF[name.repo<<-EOF [name.repo<<EOF[name]
name=namebaseurl=file://name baseurl=file://namebaseurl=file://tmp_dir
enabled=1
gpgcheck=0
EOF
echo “$name.repo is created secussfully!”
fi

case “$num” in
a)
yum makecache >/dev/null
service_install httpd
service_install dhcp
service_install tftp-server
service_install xinetd
service_install syslinux
service_install vim

umount $tmp_dir
if [ $? -eq 0 ];then
	cat >$yum_dir/$name.repo <<-EOF
	[$name]
	name=$name
	baseurl=http://${host_ip}/$name
	enabled=1
	gpgcheck=0
	EOF
else
	exit 2
fi

if [ $? -eq 0 ];then
	cat >/etc/dhcp/dhcpd.conf <<-EOF 
	subnet $host_vlan.0 netmask 255.255.255.0 {
	  range $host_vlan.1 $host_vlan.253;
	  option routers $host_vlan.254;
	  option broadcast-address $host_vlan.255;
	  default-lease-time 600;
	  max-lease-time 1800;
	  next-server ${host_ip};
	  filename "pxelinux.0";
	}
	EOF
else 
	echo "dhcpd error......"
fi

systemctl start dhcpd
if [ $? -eq 0 ];then
	echo "dhcp service is up!"
	systemctl enable dhcpd &>/dev/null
else
	echo "Error......please check dhcp config file!"
fi

if [ $? -eq 0 ];then
	cat >/etc/xinetd.d/tftp <<-EOF
	service tftp
	{
		socket_type		= dgram
		protocol		= udp
		wait			= yes
		user			= root
		server			= /usr/sbin/in.tftpd
		server_args		= -s /var/lib/tftpboot
		disable			= no
		per_source		= 11
		cps			= 100 2
		flags			= IPv4
	}
EOF
else
	echo "xinetd error......"
fi

systemctl start xinetd
if [ $? -eq 0 ];then
	echo "tftp service is up!"
	systemctl enable xinetd &>/dev/null
else
	echo "Error......"
fi

mkdir -p $apache_dir/$name
if [ $? -eq 0 ];then
	cat >>/etc/fstab<<-EOF
	$ISO $apache_dir/$name iso9660 defaults 0 0
	EOF
fi
mount -a &>/dev/null
mkdir -p $tftp_dir/pxelinux.cfg
cp $apache_dir/$name/isolinux/isolinux.cfg $tftp_dir/pxelinux.cfg/default
cp $apache_dir/$name/images/pxeboot/initrd.img $tftp_dir
cp $apache_dir/$name/images/pxeboot/vmlinuz $tftp_dir
cp /usr/share/syslinux/pxelinux.0 $tftp_dir
chmod a+w $tftp_dir/pxelinux.cfg/default
cat >$tftp_dir/pxelinux.cfg/default<<-EOF
default $name
timeout 600
label $name
  menu label ^Install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img ks=http://$host_ip/ks.cfg
EOF
 
systemctl start httpd
if [ $? -eq 0 ];then
	echo "httpd service is up!"
	systemctl enable httpd &>/dev/null
fi
;;

b)
yum makecache >/dev/null
service_install httpd
service_install tftp-server
service_install xinetd
service_install dhcp
service_install grub2-efi-modules

umount $tmp_dir
if [ $? -eq 0 ];then
	cat >$yum_dir/$name.repo<<-EOF
	[$name]
	name=$name
	baseurl=http://${host_ip}/$name
	enabled=1
	gpgcheck=0
	EOF
else
	exit 2
fi

cat >/etc/dhcp/dhcpd.conf<<-EOF 
log-facility local7;
allow booting;
allow bootp;
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;
subnet $host_vlan.0 netmask 255.255.255.0 {
range $host_vlan.1 $host_vlan.253;
option routers $host_vlan.254;
next-server ${host_ip};
filename "bootx64.efi";
}
EOF
systemctl start dhcpd
if [ $? -eq 0 ];then
	echo "dhcp service is up!"
	systemctl enable dhcpd &>/dev/null
else
	echo "Error......please check dhcp config file!"
fi

cat >/etc/xinetd.d/tftp <<-EOF
service tftp
{
	socket_type		= dgram
	protocol		= udp
	wait			= yes
	user			= root
	server			= /usr/sbin/in.tftpd
	server_args		= -s /var/lib/tftpboot
	disable			= no
	per_source		= 11
	cps			= 100 2
	flags			= IPv4
}
EOF
systemctl start xinetd
if [ $? -eq 0 ];then
	echo "tftp service is up!"
	systemctl enable xinetd &>/dev/null
else
	echo "Error......"
fi

mkdir -p $apache_dir/$name
if [ $? -eq 0 ];then
	cat >>/etc/fstab<<-EOF
	$ISO $apache_dir/$name iso9660 defaults 0 0
	EOF
fi
mount -a &>/dev/null
 
cp $apache_dir/$name/images/pxeboot/initrd.img $tftp_dir
cp $apache_dir/$name/images/pxeboot/vmlinuz $tftp_dir
grub2-mkstandalone -d /usr/lib/grub/x86_64-efi/ -O x86_64-efi --modules="tftp net efinet linux part_gpt efifwsetup" -o $tftp_dir/bootx64.efi &>/dev/null
if [ ! -f $tftp_dir/bootx64.efi ];then
	exit 2
fi

cp $apache_dir/$name/EFI/BOOT/grub.cfg $tftp_dir
if [ $? -eq 0 ];then
	cat >$tftp_dir/grub.cfg<<-EOF	
	set default="0"
	    
	function load_video {
	insmod efi_gop
	insmod efi_uga
	insmod video_bochs
	insmod video_cirrus
	insmod all_video
	}	

	load_video
	set gfxpayload=keep
	insmod net
	insmod efinet
	insmod tftp
	insmod gzio
	insmod part_gpt
	insmod ext2

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

	search --no-floppy --set=root -l 'CentOS 7 x86_64'

	### BEGIN /etc/grub.d/10_linux ###
	menuentry 'Install CentOS 7' --class fedora --class gnu-linux --class gnu --class os {
	    linuxefi (tftp)/vmlinuz inst.repo=http://${host_ip}/centos ks=http://${host_ip}/ks.cfg ip=dhcp
	    initrdefi (tftp)/initrd.img
	}	
	EOF
fi

systemctl start httpd
if [ $? -eq 0 ];then
	echo "httpd service is up!"
	systemctl enable httpd &>/dev/null
else
	echo "httpd service is failed......"
fi
;;

c)

;;

*)
menu
esac

echo “please put the ks.cfg and ip.txt on $apache_dir catalogue !”
echo “finish… !”

内容概要:本文针对国内加密货币市场预测研究较少的现状,采用BP神经网络构建了CCi30指数预测模型。研究选取2018年3月1日至2019年3月26日共391天的数据作为样本,通过“试凑法”确定最优隐结点数目,建立三层BP神经网络模型对CCi30指数收盘价进行预测。论文详细介绍了数据预处理、模型构建、训练及评估过程,包括数据归一化、特征工程、模型架构设计(如输入层、隐藏层、输出层)、模型编译与训练、模型评估(如RMSE、MAE计算)以及结果可视化。研究表明,该模型在短期内能较准确地预测指数变化趋势。此外,文章还讨论了隐层节点数的优化方法及其对预测性能的影响,并提出了若干改进建议,如引入更多技术指标、优化模型架构、尝试其他时序模型等。 适合人群:对加密货币市场预测感兴趣的研究人员、投资者及具备一定编程基础的数据分析师。 使用场景及目标:①为加密货币市场投资者提供一种新的预测工具和方法;②帮助研究人员理解BP神经网络在时间序列预测中的应用;③为后续研究提供改进方向,如数据增强、模型优化、特征工程等。 其他说明:尽管该模型在短期内表现出良好的预测性能,但仍存在一定局限性,如样本量较小、未考虑外部因素影响等。因此,在实际应用中需谨慎对待模型预测结果,并结合其他分析工具共同决策。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值