脚本实现PXE装机
2024-09-05 07:17:50
#!/bin/bash read -p "请输入您的装机服务器:" ip
read -p "请输入您想要的ip最小值(1-255):" min
read -p "请输入您想要的ip最大值(1-255),必须比最小值小:" max
read -p "请输入您的yum源:" yum_source sub_ip="${ip%.*}" # 从右边开始删除第一个.及其右边的数据
tftp=/var/lib/tftpboot/ # 创建yum仓库
cat>/etc/yum.repo.s/my_yum.repo <<EOF
[development]
name=my_yum
baseurl=$yum_source
enabled=
gpgcheck=
EOF # 安装 httpd dhcp tftp-server syslinux
yum -y install httpd syslinux tftp-server dhcp >/dev/null >/var/log/pxe.error # 配置镜像文件
if [ ! -d /var/www/html/rhel7 ];then
mkdir /var/www/html/rhel7
fi
mount /dev/cdrom /var/www/html/rhel7 >/dev/null >/var/log.pxe.error # 配置资源文件
if [ ! -d /menu ];then
mkdir /menu
fi
mount /dev/cdrom /menu >/dev/null >/var/log.pxe.error # 配置DHCP
cat>/etc/dhcp/dhcpd.conf <<EOF
subnet ${sub_ip}. netmask 255.255.255.0 {
range ${sub_ip}.${min} ${sub_ip}.${max};
option domain-name-servers $ip;
option routers ${sub_ip}.;
default-lease-time ;
max-lease-time ;
next-server $ip;
filename "pxelinux.0";
}
EOF # 配置相关资源
if [ -d ${tftp}pxelinux.cfg ];then
rm -rf ${tftp}pxelinux.cfg
fi
mkdir ${tftp}pxelinux.cfg/ # 创建菜单文件
cp /usr/share/syslinux/pxelinux. $tftp # 网卡引导文件
cp /menu/isolinux/vesamenu.c32 $tftp # 部署图形模块
cp /menu/isolinux/splash.png $tftp # 部署背景图片
cp /menu/isolinux/vmlinuz $tftp # 部署内核
cp /menu/isolinux/initrd.img $tftp # 部署驱动 # 装机基本设置
cat >/var/www/html/ks.cfg <<EOF
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $$/Vr5HpR.$aSGgGZKDOb5j4jp/abcMM0
# Use network installation
url --url="http://$ip/rhel7"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled # Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --grow --size= %post --interpreter=/bin/bash
useradd lily
echo 'redhat' | passwd --stdin lily
%end %packages
@base %end
EOF # 菜单设置
cat >${tftp}/pxelinux.cfg/default <<EOF
default vesamenu.c32
timeout
#display boot.msg
prompt vesamenu.c32 label linux
menu label ^Install RHEL7
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://$ip/ks.cfg
EOF #启动服务
systemctl restart dhcpd
systemctl restart tftp
systemctl restart httpd
最新文章
- guava &ndash; Optional
- flash中htmlText样式
- 颜色空间变换(RGB-HSV)
- asp.net MVC中使用entity framework出现从 datetime2 数据类型到 datetime 数据类型的转换产生一个超出范围的值”的处理
- 我的c++学习(3)字符的输入输出
- LA 3902 Network(树上最优化 贪心)
- 控制反转(IoC)与依赖注入(DI)
- php类获取静态变量值以及调用
- Android 手机应用开发经验 之 通过Socket(TCP/IP)与PC通讯
- Python中三种基本结构的语句
- SocketServer模块
- Java求555 555的约数中最大的三位数。
- Linux目录结构介绍-http://yangrong.blog.51cto.com/6945369/1288072
- 自己动手搭建一个简易的SpringBoot环境
- [Dababase - MySQL- Linux] 数据库安装位置
- 商品详情页系统的Servlet3异步化实践
- 字节码 反编译 APKTool 重新打jar包 MD
- 函数指针(pointer to function)——qsort函数应用实例
- mysql中Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:YES)错误
- Spring中@Resource与@Autowired