跨网段PXE安装操作系统

2021-02-11 18:02:39 浏览数 (1)

通过VMware启3台虚拟机,

第一台DHCP Server,主要功能是pxe server和dhcp server给裸机安装操作系统。

第二台DHCP Relay,主要是模拟交换机的dhcp relay的功能以及网关。

第三台pxe,模拟裸机。

网络连线如下图所示:

网络拓扑图网络拓扑图

安装部署:

安装DHCP Server:

1、挂载iso镜像到/mnt

# mount xxx.iso /mnt

配置本地yum源,repo文件如下所示:

# cat /etc/yum.repos.d/local.repo

[local] name=local baseurl=file:///mnt/ gpgcheck=0

2、安装相关的包

# yum install dhcp tftp-server syslinux httpd -y

3、配置tftp

传统模式legacy的配置:

# mkdir -p /var/lib/tftpboot/{linux7,pxelinux.cfg}

# cp -rf /mnt/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/linux7/

# cp -rf /mnt/isolinux/{boot.msg,memtest,splash.jpg,vesamenu.c32} /var/lib/tftpboot/

# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

创建/var/lib/tftpboot/pxelinux.cfg/default文件,内容如下所示:

default vesamenu.c32 timeout 5 prompt 0 menu resolution 800 600 menu vshift 2 menu rows 14 menu margin 6 menu background splash.jpg # 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 title Enterprise Linux 7 U2 (64-bit) menu color border 0 #ffffffff #00000000 menu color sel 7 #ffffffff #ff000000 menu color title 0 #ffffffff #00000000 menu color tabmsg 0 #ffffffff #00000000 menu color unsel 0 #ffffffff #00000000 menu color hotsel 0 #ff000000 #ffffffff menu color hotkey 7 #ffffffff #ff000000 menu color scrollbar 0 #ffffffff #00000000 menu hidden menu hiddenrow 5 label linux menu label ^Install or upgrade an existing system IPAPPEND 2 kernel linux7/vmlinuz append initrd=linux7/initrd.img ksdevice=bootif ks=http://192.168.181.130/ks.cfg label vesa menu label Install system with ^basic video driver kernel linux7/vmlinuz append initrd=linux7/initrd.img xdriver=vesa nomodeset ks=http://192.168.181.130/ks.cfg label rescue menu label ^Rescue installed system kernel linux7/vmlinuz append initrd=linux7/initrd.img rescue #label local # menu label Boot from ^local drive # localboot 0xffff label memtest86 menu label ^Memory test kernel memtest append -

UEFI模式的配置:

# mkdir -p /var/lib/tftpboot/linux7

# cp -rf /mnt/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/linux7/

# cp /mnt/EFI/BOOT/grub.cfg /var/lib/tftpboot/

修改/var/lib/tftpboot/grub.cfg文件

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 gzio insmod part_gpt insmod ext2 set timeout=10 ### END /etc/grub.d/00_header ### search --no-floppy --set=root -l 'Linux 7 x86_64' ### BEGIN /etc/grub.d/10_linux ### menuentry 'Install Enterprise Linux 7' --class fedora --class gnu-linux --class gnu --class os { linuxefi (tftp)/linux7/vmlinuz inst.repo=http://192.168.181.130/linux7 inst.ks=http://192.168.181.130/ks.cfg initrdefi (tftp)/linux7/initrd.img } ~ 略 ~

# yum install grub2-efi-modules -y (或者是grub2-efi-x64-modules.noarch)

生成bootx64.efi文件

# grub2-mkstandalone -d /usr/lib/grub/x86_64-efi/ -O x86_64-efi --modules="tftp net efinet linux part_gpt efifwsetup" -o /var/lib/tftpboot/bootx64.efi

启动tftp服务

# systemctl start tftp

# systemctl enable tftp

4、配置httpd服务

# mkdir -p /var/www/html/linux7/

# cp -rf /mnt/* /var/www/html/linux7/

ks文件可以拷贝/root/anaconda-ks.cfg文件并进行修改里面的内容,这里就省略了。

# cp /root/anaconda-ks.cfg /var/www/html/ks.cfg

启动httpd服务

# systemctl start httpd

# systemctl enable httpd

5、配置dhcpd服务,跨网段pxe安装系统是这里需要配置多个子网。

# cat /etc/dhcp/dhcpd.conf

# # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example # see dhcpd.conf(5) man page # 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 192.168.181.0 netmask 255.255.255.0 { range 192.168.181.10 192.168.181.60; option routers 192.168.181.128; option subnet-mask 255.255.255.0; } subnet 192.168.159.0 netmask 255.255.255.0 { range 192.168.159.150 192.168.159.160; option routers 192.168.159.128; option subnet-mask 255.255.255.0; } class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; next-server 192.168.181.130; if option architecture-type = 00:07 { filename "bootx64.efi"; } elsif option architecture-type = 00:09 { filename "bootx64.efi"; } else { filename "pxelinux.0"; } }

启动DHCP服务

# systemctl start dhcpd

# systemctl enable dhcpd

以上DHCP Server上安装的服务部署完成。

安装DHCP Relay

安装的是Linux8的系统并安装dhcp-relay-4.3.6-30.el8.x86_64

启动dhcp relay

# dhcrelay 192.168.181.130

pxe裸机上电

直接上电pxe启动,可以看到分配了192.168.159.150的ip,并进行操作系统的安装。

0 人点赞