简介
安装系统,老是要做一个U盘启动太麻烦,特别是机器多了,老是拿U盘插来插去的麻烦。
可以利用PXE启动,从网卡启动,加载安装程序就可以开始安装了。
启动过程简介
- pxe启动通过dhcpd获取ip
- tftp获取pxelinux.0程序
- http服务提供文件服务来安装repo源
安装工具
通过网络安装就需要安装一些网络服务。
Bash
dnf -y install tftp-server dhcp-server httpd syslinux rsync
systemctl enable tftp dhcpd httpd --now
ISO镜像
ISO镜像有所有安装需要的文件,通过httpd提供安装文件下载。
Bash
mount /dev/sr0 /mnt
mkdir -p /var/www/html/pub
rsync -avP /mnt /var/www/html/pub
pxelinux.0
pxelinux.0可以启动一个简单的内核,然后通过这个简单的内核来加载安装程序。
syslinux提供了pxelinux.0程序,直接复制到tftp服务目录
Bash
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
pxelinux 默认配置append initrd=initrd.img inst.repo=http://192.168.122.12/pub,如果要使用kickstart自动安装需要指定inst.ks=http://192.168.122.12/ks/ks.cfg
Bash
mkdir -p /var/lib/tftpboot/pxelinux.cfg
cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF
default vesamenu.c32
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 PXE install basic Rocky Linux 9.3
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
menu color hotkey 0 #ffffffff #00000000 none
# 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
label linux
menu label ^Install Rocky Linux 9.3 From kickstart
kernel vmlinuz
#append initrd=initrd.img inst.ks=http://192.168.122.12/ks/ks.cfg
append initrd=initrd.img inst.repo=http://192.168.122.12/pub
label memtest
menu label Run a ^memory test
text help
If your system is having issues, a problem with your
system's memory may be the cause. Use this utility to
see if the memory is working correctly.
endtext
kernel memtest
menu separator # insert an empty line
label local
menu label Boot from ^local drive
localboot 0xffff
menu separator # insert an empty line
menu separator # insert an empty line
menu end
EOF
DHCP分配IP
dhcp需要配置分发的网段、网关、tftp服务器、pxelinux在tftp服务的位置
Bash
cat >> /etc/dhcp/dhcpd.conf <<EOF
subnet 192.168.122.0 netmask 255.255.255.0 {
range 192.168.122.40 192.168.122.199;
option routers 192.168.122.1;
option subnet-mask 255.255.255.0;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.122.12;
filename "/pxelinux.0";
}
EOF
重启服务
Bash
systemctl restart httpd tftp dhcpd
注意事项
- 禁用selinux。
- iptables或者firewalld要开放对应的端口,或者直接清空规则
- 同一个网段里面只能有一个dhcp,不然指定的tftp-server配置就无法加载到
总结
为什么不用kickstart安装?
为了快速完成任务。机器配置不一样,手动安装可以灵活一点。当然,kickstart脚本写好就更方便了。