PXE Server 配置

PXE Server Setup

一、PXE原理介绍

预启动执行环境(Preboot eXecution Environment,PXE)也被称为预执行环境,提供了一种使用网络接口(Network Interface)启动计算机的机制。这种机制让计算机的启动可以不依赖本地数据存储设备(如硬盘)或本地已安装的操作系统。
要实现pxe,至少需要3个服务:

DHCP:提供网络参数,告知客户端TFTP位置
TFTP:提供boot loader及kernel file下载路径
HTTP/FTP/NFS:三种架构提供内核文件

1.1、PXE框架

在这里插入图片描述

1.2、PXE流程

以Legacy模式为例介绍
在这里插入图片描述

PXE启动过程的文字注释:

1)client向pxe server上的dhcp发送IP地址请求消息,dhcp检测client是否合法,同事将pxe环境下的boot loader文件pxelinux.0的位置信息发给client
2)client向pxe server上的tftp请求pxelinux.0,tftp收到消息向client发送pxelinux.0大小信息,试探client是否满意,当tftp收到client发回的统一大小信息后,发送pxelinux.0.
3)client执行接收到的pxelinux.0
4)client向TFTP请求pxelinux.cfg文件(其实是目录,里面放了启动菜单,即grub的配置文件),TFTP将配置文件发回client,继而client根据配置文件执行后续的操作
5)client向TFTP发送linux内核请求信息,TFTP发送内核
6)client向TFTP发送根文件请求信息,TFTP接受到消息之后返回linux根文件系统
7)client加载linux内核(启动参数已经在4中的配置文件中设置好了)。
8)client通过nfs/ftp/http下载系统安装文件进行安装,如果4中的配置文件指定了kickstart路径,则回根据此文件自动应答安装系统

1.3、文件介绍

  • vmlinuz:核心文件(kernel file);
  • initrd.img:开启过程中核心组件的参数;
  • isolinux.cfg --> demo:Legace pxe选择菜单配置参考;
  • EFI/BOOT/grub.cfg --> deme: UEFI pxe选择菜单配置参考;

1.4、Legacy BIOS和EFI BIOS引导区别:

  • 传统Legacy BIOS:
    一般使用syslinux提供的pxelinux.0来引导。
    传统Legacy BIOS引导,在pxelinux.0引导后,它会请求并加载server端tftpboot目录中,与pxelinux.0同目录下的pxelinux.cfg目录里的default文件。

    Oct 12 21:43:35 Simonlinux in.tftpd[20331]: Client 192.168.15.34 finished legacy/pxelinux.0
    Oct 12 21:43:35 Simonlinux in.tftpd[20342]: Client 192.168.15.34 finished legacy/pxelinux.cfg/default
    Oct 12 21:43:35 Simonlinux in.tftpd[20343]: Client 192.168.15.34 finished legacy/vesamenu.c32
    Oct 12 21:43:35 Simonlinux in.tftpd[20344]: Client 192.168.15.34 finished legacy/pxelinux.cfg/default
    Oct 12 21:43:35 Simonlinux in.tftpd[20345]: Client 192.168.15.34 finished legacy/pxelinux.cfg/graphics.conf
    Oct 12 21:43:39 Simonlinux in.tftpd[20347]: Client 192.168.15.34 finished legacy/vesamenu.c32
    Oct 12 21:43:39 Simonlinux in.tftpd[20348]: Client 192.168.15.34 finished legacy/pxelinux.cfg/graphics.conf
    Oct 12 21:43:39 Simonlinux in.tftpd[20349]: Client 192.168.15.34 finished legacy/pxelinux.cfg/centos_install
    Oct 12 21:43:39 Simonlinux in.tftpd[20350]: Client 192.168.15.34 finished legacy/pxelinux.cfg/graphics.conf
    Oct 12 21:43:44 Simonlinux in.tftpd[20352]: Client 192.168.15.34 finished /boot/centos/76/vmlinuz
    Oct 12 21:44:12 Simonlinux in.tftpd[20353]: Client 192.168.15.34 finished /boot/centos/76/initrd.img
    
  • EFI BIOS引导:
    对于EFI BIOS,需要使用efi文件引导,一般可使用Grub2。为实现UEFI SecureBoot,大多数Linux使用shim.efi嵌套调用grubx64.efi来引导。
    grubx64.efi和shimx64.efi有什么区别呢?在安全启动(serureboot)关闭的情况下,你可以使用grubx64.efi。如果安全启动打开则需要选择shimx64.efi。
    在shim.efi嵌套引导了grubx64.efi之后,它会请求grubx64.efi同目录下的grub.cfg配置文件(redhat7),同时加载显示引导菜单。而对于RHEL6来说,它并不支持SecureBoot,所以必须要使用grub-efi 0.97来引导,一般是BOOTX64.efi,同时它会请求同目录下的efidefault配置文件(redhat6),加载并显示引导菜单。

    Oct 12 22:00:35 Simonlinux in.tftpd[21265]: Client 192.168.15.34 finished uefi/grubx64.efi
    Oct 12 22:00:35 Simonlinux in.tftpd[21275]: Client 192.168.15.34 finished /uefi/grub.cfg
    Oct 12 22:00:35 Simonlinux in.tftpd[21280]: Client 192.168.15.34 finished /uefi/grub.cfg
    Oct 12 22:00:53 Simonlinux in.tftpd[21289]: Client 192.168.15.34 finished /boot/centos/76/vmlinuz
    Oct 12 22:01:24 Simonlinux in.tftpd[21290]: Client 192.168.15.34 finished /boot/centos/76/initrd.img
    

二、PXE部署

首先完成准备工作,然后开始安装DHCP、TFTP,接着提供bootloader及配置文件,挂着ISO镜像把内核文件copy到tftp目录,部署httpd/vsftp/nfs提供文件服务,设置菜单及提供系统安装软件。

功能OSIP用途
PXE服务器Redhat 7.6192.168.0.5DHCP、TFTP、HTTP、PXE
客户端NA192.168.0.*测试机,通过PXE安装OS

2.1、准备工作

关闭防火墙(service iptables stop)和SElinux (setenforcing 0)

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i '/SELINUX/s/enforcing/disabled/g' /etc/selinux/config

2.2、安装组件

  • 组件功能介绍

Kickstart: 将安装过程的参数写入到ks.cfg文件,实现自动安装配置达到无人值守自动安装;
TFTP: 支持PXE 引导的网卡中从tftp服务器端下载pxelinux.0/shim.efi(grubx64.efi)文件、vmlinuz、initrd.img等内核引导文件;
DHCP: PXE引导过程中先获取IP地址,并提供pxelinux.0(legacy)/shim.efi(uefi)文件位置;
HTTP: 用于下载ks.cfg以及系统镜像文件。

[root@server ~]# yum install httpd
[root@server ~]# yum install dhcp
[root@server ~]# yum install tftp-server
[root@server ~]# yum install xinetd
[root@server ~]# yum install syslinux

2.3、DHCP配置

2.3.1 配置静态网络IP
[root@server ~]# vim /etc/sysconfig/network-script/ifcfg-eth0
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
NETBOOT=yes
#UUID="2a9f70b5-5920-4b44-bec6-986446613315"
IPV6INIT=yes
BOOTPROTO=static
#BOOTPROTO=none
IPV6ADDR=2001:db8:ffff:100:1::10
IPV6_DEFAULTGE=2001:db8:ffff:100:1::1
IPADDR=192.168.0.5
GATEWAY=192.168.0.39
NETMASK=255.255.255.192
TYPE=Ethernet
2.3.2 修改dhcp配置文件
  • dhcp4
[root@server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@server ~]# vim /etc/dhcp/dhcpd.conf
allow booting;
allow bootp;
ddns‐update‐style none; 
ignore client‐updates; 
option arch code 93 = unsigned integer 16;
option domain-name-servers 192.168.0.5;
default-lease-time 14400;
subnet 192.168.0.0 netmask 255.255.255.192 {
        range 192.168.0.40 192.168.0.60;
        option broadcast‐address 192.168.0.63; 
        option routers 192.168.0.39;
        option subnet‐mask 255.255.255.192; 
        default-lease-time 14400;
        max-lease-time 172800;
        next-server 192.168.0.5;

        class "pxeclients" {
                  match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";

                        if option arch = 00:07 or option arch = 00:09 {
                                filename "/uefi/shim.efi";
                                #filename "/uefi/BOOTX64.efi";
                        } else {
                                filename "pxelinux.0";
                        }
                }

        class "httpclients" {
                match if substring (option vendor-class-identifier, 0, 10) = "HTTPClient";
                option vendor-class-identifier "HTTPClient";
                if option arch = 00:10 {
                       filename "http://192.168.0.5/httpboot/shim.efi";
                }

        }
}
  • dhcp6
[root@server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd6.conf.example /etc/dhcp/dhcpd6.conf
[root@server ~]# vim /etc/dhcp/dhcpd6.conf
allow booting;
allow bootp;
option dhcp6.bootfile-url code 59 = string;
option dhcp6.client-arch-type code 61 = array of unsigned integer 16;
option dhcp6.vendor-class code 16 = {integer 32, integer 16, string};
option dhcp6.name-servers 2001:db8:ffff:100::10;

if option dhcp6.client-arch-type = 00:07 or option dhcp6.client-arch-type = 00:09 {
        #option dhcp6.bootfile-url "tftp://[2001:db8:ffff:100::10]/uefi/shim.efi";
        option dhcp6.bootfile-url "tftp://[2001:db8:ffff:100::10]/uefi/grubx64.efi";
}
else {
        option dhcp6.bootfile-url "tftp://[2001:db8:ffff:100::10]/pxelinux.0";
}

if option dhcp6.client-arch-type = 00:10 {
        option dhcp6.bootfile-url "http://[2001:db8:ffff:100::10]/uefi/grubx64.efi";
        option dhcp6.name-servers 2001:db8:ffff:100::10;
        option dhcp6.vendor-class 0 10 "HTTPClient";
}

subnet6 2001:db8:ffff:100::/64 {
        range6 2001:db8:ffff:100::10 2001:db8:ffff:100::1000;
}

另外dhcp配置文件可以做绑定,用Mac绑定某台主机的ip地址

host clientA {
        hardware ethernet 38:68:dd:16:af:84;
        fixed-address 192.168.0.62;
}

RHEL7以支持UEFI SecureBoot。通过TFTP把shim.efi加载后会继续嵌套加载引导同目录下的grubx64.efi,然后grub会获取同目录下的grub.cfg以显示引导菜单。
 对于EFI模式下RHEL6 PXE引导,需要dhcpd.conf指定filename “uefi/BOOTX64.efi”,它其实是grub 0.97。通过TFTP加载了BOOTX64.efi之后它会继续加载同目录下的efidefault引导配置文件,并显示引导菜单。

2.3.4 启动服务

systemctl start dhcpd
systemctl enable dhcpd
systemctl start dhcpd6
systemctl enable dhcpd6

2.4. TFTP配置

从流程得知boot loader文件以及内核相关的配置文件主要都是由TFTP来提供的

2.4.1 编辑配置文件
[root@server ~]# vim /etc/xinetd.d/tftp 

# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd  
        server_args             = -s /var/lib/tftpboot # tftp 目录
        disable                 = no  # 开启tftp只需要改为no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

TFTP是由xinetd这个super daemon所管理的,因此设定好TFTP之后,要启动的是xinetd;

2.4.2 启动服务
[root@server ~]# systemctl restart tftp
[root@server ~]# systemctl enable tftp
[root@server ~]# systemctl restart xinetd
[root@server ~]# systemctl enable xinetd
2.4.3 服务验证
[root@server ~]# netstat -untlp | grep :69
udp        0      0 0.0.0.0:69              0.0.0.0:*                           6857/xinetd 

2.5、文件共享服务器搭建(vsftp/nfs/http)

2.5.1 ISO挂载拷贝到/pxeimg目录
[root@server ~]# mkdir /pxeimg/centos/7.6/os/x86_64 -p
[root@server ~]# mkdir /pxeimg/centos/8.5/os/x86_64 -p
[root@server ~]# tree /pxeimg/
/pxeimg/
└── centos
    ├── 7.6
    │   └── os
    │       └── x86_64
    └── 8.5
        └── os
            └── x86_64

7 directories, 0 files


[root@server ~]# mount -o loop CentOS-7.6-x86_64-DVD-1810.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[root@server ~]# cp -fr /mnt/* /pxeimg/centos/7.6/os/x86_64/
[root@server ~]# umount /mnt/
[root@server ~]# mount -o loop CentOS-8.5.2111-x86_64-dvd1.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[root@server ~]# cp -fr /mnt/* /pxeimg/centos/8.5/os/x86_64/

2.5.2 文件共享服务搭建

  • 搭建http server
    1. 安装http rpm包
    [root@server ~]# yum install httpd
    
    1. 开启http服务
    systemctl restart httpd
    systemctl enable httpd
    
    1. 将/pxeimg 链接到http共享目录
    ln -s /pxeimg /var/www/html
    
  • 搭建nfs server
    1. 安装nfs rpm包
    [root@server ~]# yum install nfs-utils
    
    1. 修改nfs配置文件
    [root@server ~]# vim /etc/exports
    /nfs *(rw,no_root_squash)
    /var/lib/tftpboot *(rw,no_root_squash)
    
    1. 重启nfs设置开机自启动
    [root@server ~]# systemctl restart nfs
    [root@server ~]# systemctl enable nfs
    
    1. 将/pxeimg软链接到nfs共享目录
    ln -s /pxeimg /nfs
    
  • 搭建vsftp server
    1. 安装vsftp rpm包
    [root@server ~]# rpm -ivh vsftp
    
    1. 重启vsftp设置开机自启动
    [root@server ~]# systemctl restart vsftp
    [root@server ~]# systemctl enable vsftp
    
    1. 将/pxeimg软链接到nfs共享目录
    ln -s /pxeimg /var/ftp
    

2.6、BootLoader及boot文件准备

  • Legacy

    vesamenu.c32和menu.c32是syslinux所拥有众多模块中的两个,它们的功能是制定启动器使用什么模式。 vesamenu.c32图形模式,menu.c32文本模式。同时还需要pxelinux.0文件,它对整个引导器的作用就如同内核对系统的作用,它可以解释default文件(配置引导菜单的文件)中的每个配置项,并根据配置项做出不同的反应,如等待的时间、启动器背景、启动菜单、内核引导等。

    [root@server ~]# yum install syslinux* -y
    [root@server ~]# cd /var/lib/tftpboot
    [root@server tftpboot]# cp /usr/share/syslinux/{vesamenu.c32,menu.c32,pxelinux.0} .  
    [root@server tftpboot]# mkdir pxelinux.cfg 
    [root@server tftpboot]# mkdir boot/centos/{7.6,8.5}               
    [root@server tftpboot]# cp /pxeimg/centos/7.6/os/x86_64/isolinux/{vmlinuz,initrd.img} boot/centos/7.6
    
    # Centos8环境拷贝以下文件
    [root@server ~]# cd /var/lib/tftpboot/
    [root@server tftpboot]# cp /pxeimg/centos/8.5/os/x86_64/isolinux/{ldlinux.c32,libutil.c32,libcom32.c32} .
    [root@server tftpboot]# cp /pxeimg/centos/8.5/os/x86_64/isolinux/{vmlinuz,initrd.img} boot/centos/8.5
    
    # 目录结构
    [root@server lib]# tree tftpboot/
    tftpboot/
    ├── boot
    │   └── centos
    │       ├── 7.6
    │       │   ├── initrd.img
    │       │   └── vmlinuz
    │       └── 8.5
    │           ├── initrd.img
    │           └── vmlinuz
    ├── ldlinux.c32
    ├── libcom32.c32
    ├── libutil.c32
    ├── menu.c32
    ├── pxelinux.0
    ├── pxelinux.cfg
    └── vesamenu.c32
    
    5 directories, 10 files
    
  • UEFI
    从RHEL7.6光盘中提取shim.efi和grubx64.efi
    [root@server ~]# mount -o loop rhel-server-7.6-x86_64-dvd.iso /mnt 
    [root@server ~]# cp /mnt/Packages/shim-0.9-2.el7.x86_64.rpm /tmp 
    [root@server ~]# cp /mnt/Packages/grub2-efi-2.02-0.44.el7.x86_64.rpm /tmp 
    [root@server ~]# rpm2cpio /tmp/shim-0.9-2.el7.x86_64.rpm | cpio -dimv 
    [root@server ~]# rpm2cpio /tmp/grub2-efi-2.02-0.44.el7.x86_64.rpm| cpio -dimv 
    [root@server ~]# mkdir -p /var/lib/tftpboot/uefi/ 
    [root@server ~]# cp /tmp/boot/efi/EFI/redhat/shim.efi /var/lib/tftpboot/uefi/ 
    [root@server ~]#cp /tmp/boot/efi/EFI/redhat/grubx64.efi /var/lib/tftpboot/uefi/ 
    [root@server ~]#cp /mnt/EFI/BOOT/BOOTX64.EFI /var/lib/tftpboot/uefi/ 
    [root@server ~]#cp /mnt/EFI/BOOT/grub.cfg /var/lib/tftpboot/uefi/
    [root@server ~]# tree tftpboot/
    tftpboot/
    ├── boot
    │   └── centos
    │       ├── 7.6
    │       │   ├── initrd.img
    │       │   └── vmlinuz
    │       └── 8.5
    │           ├── initrd.img
    │           └── vmlinuz
    ├── ldlinux.c32
    ├── libcom32.c32
    ├── libutil.c32
    ├── menu.c32
    ├── pxelinux.0
    ├── pxelinux.cfg
    ├── uefi
    │   ├── BOOTX64.EFI
    │   ├── efidefault
    │   ├── grub.cfg
    │   ├── grubx64.efi
    │   └── shim.efi
    └── vesamenu.c32
    
    grubx64.efi和shimx64.efi有什么区别呢?在安全启动(serureboot)关闭的情况下,你可以使用grubx64.efi。如果安全启动打开则需要选择shimx64.efi。

2.7、启动引导配置

  • default文件配置(Legacy)

    [root@server tftpboot]# vim pxelinux.cfg/default
    default menu.c32
    timeout 600
    menu title ########## Legacy PXE Boot Menu ##########
    label centos7.6
        menu label install centos 7.6 via http
        kernel boot/centos/7.6/vmlinuz
        append initrd=boot/centos/7.6/initrd.img method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64
        #append initrd=boot/centos/7.6/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64
        #append initrd=boot/centos/7.6/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64
    
    label centos8.5
        menu label install centos 8.5 via http
        kernel boot/centos/8.5/vmlinuz
        append initrd=boot/centos/8.5/initrd.img method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64
        #append initrd=boot/centos/8.5/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64
        #append initrd=boot/centos/8.5/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64
    
    label local
        menu default
        menu label ^Boot from local drive
        localboot 0xffff
    
  • grub.cfg文件配置(UEFI)

    [root@server tftpboot]# vim uefi/grub.cfg 
    set timeout=5 
    menuentry 'Install CentOS 7.6 via http' { 
    linuxefi boot/centos/7.6/vmlinuz method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64 
    # linuxefi boot/centos/7.6/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64 
    # linuxefi boot/centos/7.6/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64 
    initrdefi boot/centos/7.6/initrd.img 
    } 
    
    menuentry 'Install CentOS 8.5 via http' { 
    linuxefi boot/centos/8.5/vmlinuz method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64 
    # linuxefi boot/centos/8.5/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64 
    # linuxefi boot/centos/8.5/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64 
    initrdefi boot/centos/8.5/initrd.img 
    } 
    

2.8、测试

1. IPV4:

  • Legacy PXE
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • UEFI PXE
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • UEFI httpboot
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

2. IPV6:
将选择菜单default/grub.cfg中ipv4 address改为ipv6 address,同理进行测试。

  • Legacy PXE
  • UEFI PXE
  • UEFI httpboot

2.9、已知问题

  1. ipv6 httpboot 需要使用centos7.8以上版本的grub2 bootloader进行引导,低版本不支持 http ipv6
    [Bug 1732765 - UEFI HTTP boot over IPv6 does not work][https://bugzilla.redhat.com/show_bug.cgi?id=1732765]

三、Kickstart 自动化安装

3.1、 简介

kickstart是一个利用Anconda工具实现服务器自动化安装的方法;通过生成的kickstart配置文件ks.cfg,服务器安装可以实现从裸机到全功能服务的的非交互式(无人值守式)安装配置;
ks.cfg是一个简单的文本文件,文件包含Anconda在安装系统及安装后配置服务时所需要获取的一些必要配置信息(如键盘设置,语言设置,分区设置等);Anconda直接从该文件中读取必要的配置,只要该文件信息配置正确无误且满足所有系统需求,就不再需要同用户进行交互获取信息,从而实现安装的自动化;但是配置中如果忽略任何必需的项目,安装程序会提示用户输入相关的项目的选择,就象用户在典型的安装过程中所遇到的一样。一旦用户进行了选择,安装会以非交互的方式(unattended)继续。

3.2、流程

在这里插入图片描述

文字描述过程:

1. PXE Client 从⾃⼰的PXE⽹卡启动,向本⽹络中的DHCP服务器索取IP︔
2. DHCP 服务器返回分配给客户机的IP 以及PXE文件的放置位置︔
3. PXE Client 向本⽹络中的TFTP服务器索取pxelinux.0 文件︔
4. PXE Client 取得pxelinux.0 文件后之执⾏该文件︔
5. PXE Client 请求下载kickstart⽣成的配置文件(*.ks)︔
6. PXE Client ks文件访问NFS服务器并完成⾃动装机。
Note:
1. PXE Client 需要带有⽀持PXE的⽹卡,并且从PXE模式启动。
2. 以上逻辑图和原理放在实际⽣产中,只需要把DHCP、TFTP、NFS和Kickstart架设在同⼀个
Server/PC即可

使用kickstart优势:

1. 流线化自动化的安装;
2. 快速大量的裸机部署;
3. 强制建立的一致性(软件包,分区,配置,监控,安全性)
4. 减少人为的部署失误

3.3、kickstart服务安装和使⽤

3.3.1 服务安装
  • 如果PXE的Server是文字界⾯,需要安装gdm,图形界⾯⽆需此步骤
    yum -y install gdm
    
  • 安装kickstart服务包
    yum -y install system-config-kickstart
    
3.3.2 创建development.repo

以CentOS7.6为例

  1. Copy and mount centos7.6 iso file to SUT.
    # mount -o loop CentOS-7.6-x86_64-DVD-1810.iso /mnt
    
  2. Create local yum repo for SUT
    # vim /etc/yum.repos.d/development.repo
    [development]                   #必须是development,否则kickstart读取不到                       
    name=development	
    baseurl=file:///mnt/	#iso挂载本地光盘的路径 
    gpgcheck=0		#检查GPG-KEY,0为不检查
    enabled=1		#启用yum源,0为不启用,1为启用
    
  3. Download yum repository data to cache
    # yum makecache
    
3.3.3 制作kickstart文件

使⽤条件:图形界⾯

  • 执行system-config-kickstart
    #system-config-kickstart
    
    制作过程省略
    [root@server ~]# cat /root/ks.cfg 
    #platform=x86, AMD64, or Intel EM64T
    #version=DEVEL
    # Install OS instead of upgrade
    install
    # Keyboard layouts
    keyboard 'us'
    # Root password
    rootpw --iscrypted $1$Mz5Qd9s6$xnnbW5O.9FdsOPPvUiOU01
    # Use network installation
    url --url="http://192.168.15.10/image/centos/76"
    # System language
    lang en_US
    # System authorization information
    auth  --useshadow  --passalgo=sha512
    # Use graphical install
    graphical
    # Run the Setup Agent on first boot
    firstboot --enable
    # SELinux configuration
    selinux --enforcing
    
    # Firewall configuration
    firewall --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
    
    %packages
    @additional-devel
    @anaconda-tools
    @backup-client
    @backup-server
    @base
    @compat-libraries
    @console-internet
    @core
    @debugging
    @desktop-debugging
    @development
    %end
    
3.3.4 检查kickstart文件语法及完整性
[root@server ~]# ksvalidator /root/Desktop/ks.cfg 
[root@server ~]# 

3.4、使用kickstart文件自动部署

3.4.1 创建kickstart共享文件目录
[root@server ~]# mkdir /kickstart
[root@server ~]# ln -s /kickstart /var/www/html/ #for http 
[root@server ~]# ln -s /kickstart /nfs/ # for nfs
[root@server ~]# ln -s /kickstart /var/ftp/ # for vsftp
3.4.2 将步骤三创建的ks文件拷贝到/kickstart目录
[root@server ~]# mkdir -p /kickstart/centos/76
[root@server ~]# cp ks.cfg /kickstart/centos/76
3.4.3 更新引导菜单
  • Legacy
    [root@server tftpboot]# vim pxelinux.cfg/default
    default menu.c32
    timeout 600
    menu title ########## Legacy PXE Boot Menu ##########
    label centos7.6
        menu label install centos 7.6 via http
        kernel boot/centos/7.6/vmlinuz
        append initrd=boot/centos/7.6/initrd.img method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64
        #append initrd=boot/centos/7.6/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64
        #append initrd=boot/centos/7.6/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64
    
    label centos8.5
        menu label install centos 8.5 via http
        kernel boot/centos/8.5/vmlinuz
        append initrd=boot/centos/8.5/initrd.img method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64
        #append initrd=boot/centos/8.5/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64
        #append initrd=boot/centos/8.5/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64
    
    label centos7.6-auto
      menu label install centos 7.6 via http+kickstart
      kernel boot/centos/7.6/vmlinuz
      append initrd=boot/centos/7.6/initrd.img ks=http://192.168.0.5/kickstart/centos/7.6/ks.cfg
      #append initrd=boot/centos/7.6/initrd.img ks=nfs://192.168.0.5:/nfs/kickstart/centos/7.6/ks.cfg
      #append initrd=boot/centos/7.6/initrd.img ks=ftp://192.168.0.5:/kickstart/centos/7.6/ks.cfg
    
    label local
        menu default
        menu label ^Boot from local drive
        localboot 0xffff
    
  • UEFI
    [root@server tftpboot]# vim uefi/grub.cfg 
    set timeout=5 
    submenu '01 Manual Install Menu-->' {
      menuentry 'Install CentOS 7.6 via http' { 
      linuxefi boot/centos/7.6/vmlinuz method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64 
      # linuxefi boot/centos/7.6/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64 
      # linuxefi boot/centos/7.6/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64 
      initrdefi boot/centos/7.6/initrd.img 
      } 
    
      menuentry 'Install CentOS 8.5 via http' { 
      linuxefi boot/centos/8.5/vmlinuz method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64 
      # linuxefi boot/centos/8.5/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64 
      # linuxefi boot/centos/8.5/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64 
      initrdefi boot/centos/8.5/initrd.img 
      } 
    }
    
    submenu '02 KickStart Auto Install Menu-->' {
      menuentry 'Install CentOS 7.6 via http+kickstart' { 
      linuxefi boot/centos/7.6/vmlinuz ks=http://192.168.0.5/kickstart/centos/7.6/ks.cfg 
      # linuxefi boot/centos/7.6/vmlinuz ks=nfs://192.168.0.5:/nfs/kickstart/centos/7.6/ks.cfg 
      # linuxefi boot/centos/7.6/vmlinuz ks=ftp://192.168.0.5:/kickstart/centos/7.6/ks.cfg  
      initrdefi boot/centos/7.6/initrd.img 
      }
    }
    
### 设置和使用Legacy BIOS模式下的PXE服务器 #### 配置网络环境 为了使PXE工作正常,在局域网内需有一个DHCP服务器来分配IP地址给客户端,并告知其TFTP服务器的位置。通常,这可以通过配置现有的路由器或专门的Linux机器实现。 对于基于Debian/Ubuntu系统的Linux发行版来说,可以利用`isc-dhcp-server`包提供DHCP服务[^2]。 ```bash sudo apt-get update && sudo apt-get install isc-dhcp-server tftpd-hpa syslinux-common nfs-kernel-server apache2 ``` #### 安装并配置TFTP服务器 TFTP(Trivial File Transfer Protocol)用于传输引导文件到客户机上执行。安装`tftpd-hpa`之后编辑配置文件 `/etc/default/tftp-hpa`, 将其中的服务选项修改如下: ```plaintext RUN_DAEMON="yes" OPTIONS="-l -s /var/lib/tftpboot" ``` 重启tftpd服务以应用更改: ```bash sudo systemctl restart tftpd-hpa.service ``` #### 准备启动镜像及相关资源 下载所需的ISO映像或其他操作系统源码至本地存储位置,比如NFS共享目录下。接着创建必要的引导加载程序文件如`pxelinux.cfg/default`放置于 TFTP根目录(`/var/lib/tftpboot`)中定义默认菜单条目指向这些资源。 针对Legacy BIOS架构,应确保包含了适合此类硬件平台使用的initrd/initramfs 和 vmlinuz/kernel 文件版本。 #### DHCP服务器设置 调整`dhcpd.conf`中的参数以便支持PXE启动请求。下面是一个简单的例子展示如何指定next-server(即TFTP服务器)以及filename字段指示初始引导文件名(pxelinux.0): ```conf allow booting; allow bootp; subnet 192.168.1.0 netmask 255.255.255.0 { range dynamic-bootp 192.168.1.100 192.168.1.200; option routers 192.168.1.1; filename "pxelinux.0"; next-server 192.168.1.2; # 这里填写实际的TFTP服务器IP地址 } ``` 完成上述操作后保存退出并重新启动ISC-DHCP-Server让新的设定生效。 #### 测试与验证 最后一步是在目标计算机BIOS设置中将Boot Order优先级设为Network Boot(PXE),随后尝试开机看能否成功获取IP并通过网络加载系统镜像进行安装过程。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值