PXE实现自动化安装系统

前提条件:
网卡:仅主机,关闭vmware 的dhcp服务

1.HTTP服务

yum install httpd
systemctl start httpd
systemctl enable httpd
PXE实现自动化安装系统
/dev/sr0 挂载到 /var/www/html/centos/7/os/x86_64
/dev/sr1 挂载到 /var/www/html/centos/6/os/x86_64

2.准备KS文件

system-config-kickstart创建应答文件
/var/www/html/ks7_mini.cfg
url --url="http://192.168.36.7/centos/7/os/x86_64/" 设置光盘路径
/var/www/html/ks6_mini.cfg
url --url="http://192.168.36.7/centos/6/os/x86_64/"

3.tftp

yum install tftp-server
systemctl start tftp
systemctl enable tftp
/var/lib/tftpboot工作目录

4.DHCP服务

yum install dhcp
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
option domain-name "magedu.com";
option domain-name-servers 114.114.114.114, 223.5.5.5;
default-lease-time 86400 ;
max-lease-time 864000;
subnet 192.168.36.0 netmask 255.255.255.0 {
range 192.168.36.10 192.168.36.100;
option routers 192.168.36.254;
next-server 192.168.36.7;
filename "pxelinux.0";
}
PXE实现自动化安装系统_第1张图片
PXE实现自动化安装系统_第2张图片
systemctl start dhcpd
systemctl enable dhcpd

5.准备启动文件

yum install syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot
cp /misc/cd/isolinux/vmlinuz /var/lib/tftpboot/
cp /misc/cd/isolinux/initrd.img /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│   └── default
└── vmlinuz

6.准备启动菜单文件

vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 60
menu title Auto Install CentOS
label centos7
menu label Install CentOS ^Mini 7
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.36.7/ksdir/ks7_mini.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
PXE实现自动化安装系统_第3张图片

7.修改为支持多系统

mkdir /var/lib/tftpboot/kernel{6,7}
cd /var/lib/tftpboot/
mv vmlinuz initrd.img kernel7/
cp /var/www/html/centos/6/os/x86_64/isolinux/vmlinuz kernel6
cp /var/www/html/centos/6/os/x86_64/isolinux/initrd.img kernel6/
[root@centos7 tftpboot]#tree /var/lib/tftpboot/
PXE实现自动化安装系统_第4张图片

vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 60
menu title Auto Install CentOS
label centos7
menu label Install CentOS ^Mini 7
kernel kernel7/vmlinuz
append initrd=kernel7/initrd.img ks=http://192.168.36.7/ksdir/ks7_mini.cfg
label centos6
menu label Install CentOS Mi^ni 6
kernel kernel6/vmlinuz
append initrd=kernel6/initrd.img ks=http://192.168.36.7/ksdir/ks6_mini.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
PXE实现自动化安装系统_第5张图片