Centos PXE无人值守安装操作系统

PXE无人值守安装操作系统

安装包

yum install -y httpd syslinux xinetd tftp-server dhcp-server

挂载

# 创建挂载镜像目录
mkdir /mnt/iso  && mkdir /var/www/html/cdrom       
# 把源挂载到/mnt/iso
mount /dev/cdrom /mnt/iso
# 复制
cp -prv /mnt/iso/* /var/www/html/cdrom/

http

# 复制自动应答文件
cp ~/anaconda-ks.cfg /var/www/html/ks.cfg   
# 编辑/var/www/html/ks.cfg   
vim /var/www/html/ks.cfg  
#version=RHEL8
# Use text mode install 
text                                                #文本安装
url     --url="http://10.10.10.101/cdrom"           #http提供镜像
repo --name="AppStream" --baseurl=http://10.10.10.101/cdrom/AppStream/  #自动设置需要的配置

%packages
@^minimal-environment                              #最小化安装
kexec-tools

%end

# System language                                                             
lang en_US.UTF-8                                   #语言格式

# Network information
network  --hostname=localhost.localdomain

# Use CDROM installation media                  
#cdrom                                              #安装介质cdrom方式安装,注释掉

# Run the Setup Agent on first boot
firstboot --enable
# Do not configure the X Window System
skipx

ignoredisk --only-use=nvme0n1                      #注意硬盘名字
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=nvme0n1 #注意硬盘名字
autopart
# Partition clearing information
clearpart --all --initlabel --drives=nvme0n1           #清空硬盘所有数据 

# System timezone
timezone America/New_York --isUtc                     #时间地区

# Root password
rootpw --iscrypted      		                       #密码 
$6$b0y28.qHTD3b0E/L$L9Wpc50bN5.cjiYhvFGRd6JwwVJ6zr.Xknzz0GbIwaoj2pnRYagNVpx./fr9y3Z3Ij0SC090djnoqX
HiipRje.

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
reboot                        #加载完需要点击回车,添加后直接就自动重启了

tftp

# 主要复制的是pxelinux.0但由于缺少文件全复制,pxe引导程序文件
cp -prfv /usr/share/syslinux/ /var/lib/tftpboot/    
# 初始化镜像文件和内核文件
cp -pr /var/www/html/cdrom/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/ 
# 创建菜单目录
mkdir /var/lib/tftpboot/pxelinux.cfg/  
# 复制启动菜单文件
cp -pr /var/www/html/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default  
# 配置启动菜单文件
vim /var/lib/tftpboot/pxelinux.cfg/default
default linux                     #启动菜单改为linux为了节省时间 
timeout 600					     #超时时间

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title Rocky Linux 8
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line
#64行默认  只需要更改第一行和最后一行,ks就可以了。
label linux                            #图形化安装,自定义启动选项
  menu label ^Install Rocky Linux 8    #启动菜单名字
  kernel vmlinuz                       #加载内核
  append initrd=initrd.img ks=http://10.10.10.101/ks.cfg  quiet #加载初始化引导文件和ks.cfg自动应答文件  

DHCP

#复制dhcp配置文件
cp  /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
vim /etc/dhcp/dhcpd.conf 
subnet 10.10.10.10.0 netmask 255.255.255.0 {        # 地址网段范围和掩码
  range 10.10.10.10 10.10.20.19;                    # 地址池
  option domain-name-servers skills.com;            # 域名
  option routers 10.10.10.254;                      # 路由地址就是官关
        filename        "pxelinux.0";  		       # 指定pxe引导程序文件
        next-server     10.10.10.101;		       # 指定tfpt服务器地址
}

权限

chmod 777 -R  /var/lib/tftpboot /var/www/html/ks.cfg 

防火墙放行

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=tftp
firewall-cmd --permanent --add-service=dhcp
firewall-cmd --reload
setenforce 0								#临时关闭selinux

重启服务

systemctl enable --now httpd tftp.socket xinetd dhcpd
systemctl restart httpd tftp.socket xinted dhcpd

测试:

内存选择2G以上

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值