pxe batch management and kickstart unattended installation

1, What is pxe

The full name of PXE is preboot execute environment. It is actually a standard proposed by Intel a long time ago for booting the system through the network. Allow the client to download the boot image from the remote server through the network and load the installation file or the entire operating system.

There are three boot modes for system installation: hard disk, optical drive and network

pxe is booted through the network card

1.1 hardware conditions for implementation

1.BIOS support

2. Network card support (now basically supported)

3. The switch needs to be turned on in the bios, but the server is not turned on (it is turned on in the bmc interface)

4. There is a DHCP server in the network to automatically assign addresses and specify boot file locations for clients

5. The server provides downloading of system kernel and boot image through tftp service (simple file transfer protocol)

2, pxe advantages

1. Scale: assemble multiple servers at the same time
2. Automation: install the system and configure various services
3. Remote implementation: No CD, U SB flash disk and other installation media are required

3, Operation process

Approximate process

  1. Address (profile) assigned to new machines in the same LAN
  2. Start tftp server
  3. Install syslinux to obtain pxelinux.0 files, and vsftpd services
  4. Mount the installation source (mount /dev/sr0 /var/ftp/centos7)
  5. Copy the four files into / var/lib/tftpboot (initrd.img pxelinux.0 pxelinux.cfg/default vmlinuz)
  6. Turn on the service, turn off the firewall and selinux

Specific operation steps:
Add a network card, set it to host only mode, and change the / etc / sysconfig / network scripts / ifcfg-ens37 file
Install dhcp

[root@localhost ~]# yum install -y dhcp

If the process is occupied, delete the process

[root@localhost ~]# rm -rf /run/yum.pid

Copy the configuration file template to the dhcp directory

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf 
#DHCP Server Configuration file.
#see /usr/share/doc/dhcp*/dhcpd.conf.example
#see dhcpd.conf(5) man page
[root@localhost ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp: Overwrite"/etc/dhcp/dhcpd.conf"? y

Edit the / etc / DHCP / DHCP pd.conf file to add your own network segment

subnet netmask {
  option routers;
  filename "pxelinux.0";

Install TFTP server

[root@localhost ~]# yum install -y tftp-server
[root@localhost ~]# rpm -ql tftp-server 

Edit / etc/xinetd.d/tftp and change the disable d yes to no

[root@localhost ~]# vim /etc/xinetd.d/tftp

Install syslinux

[root@localhost ~]# yum install -y syslinux

Locate the / usr/share/syslinux/pxelinux.0 file

[root@localhost ~]# rpm -ql syslinux |grep pxelinux.0

Copy this file to the / var/lib/tftpboot / directory

[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls

Install vsftpd

[root@localhost tftpboot]# yum install -y vsftpd

cd to / var/ftp / directory and create a new centos7 directory

[root@localhost tftpboot]# cd /var/ftp/
[root@localhost ftp]# ls
[root@localhost ftp]# mkdir centos7

Mount / dev/sr0 to the / var/ftp/centos7 directory

[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7/
mount: /dev/sr0 Write protected, will mount as read-only
[root@localhost ftp]# cd centos7/
[root@localhost centos7]# ls
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL
[root@localhost centos7]# cd images/
[root@localhost images]# ls
efiboot.img  pxeboot  TRANS.TBL
[root@localhost images]# cd pxeboot/
[root@localhost pxeboot]# ls
initrd.img  TRANS.TBL  vmlinuz

Copy initrd.img and vmlinuz in the directory to / var/lib/tftpboot /

[root@localhost pxeboot]# cp initrd.img vmlinuz /var/lib/tftpboot/

Enter the / var/lib/tftpboot / directory to create a folder named pxelinux.cfg, and enter the pxelinux.cfg folder to create and edit the default file

[root@localhost pxeboot]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  vmlinuz
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default

Add information to it

default auto
prompt 1

label auto
        kernel vmlinuz
        append initrd=initrd.img method=

label linux text
        kernel vmlinuz
        append text initrd =initrd.img method=

label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=

Start three services, turn off the firewall and selinux, and then you can call semi-automatic

[root@localhost pxeboot]# systemctl stop firewalld.service
[root@localhost pxeboot]# systemctl start dhcpd
[root@localhost pxeboot]# systemctl start tftp
[root@localhost pxeboot]# systemctl start vsftpd
[root@localhost pxeboot]# setenforce 0

4, kickstart unattended installation

Install kickstart

[root@localhost ~]# yum install -y system-config-kickstart.noarch

Then enter the virtual machine and you can see that kickstart has been successfully installed

Add the root password, change the time zone to Shanghai, and check the restart after installation option

ftp mode is selected in the installation method. The server is its own IP address and the directory is centos7

The boot loader option selects to install a new boot loader

Delete all three partitions, and then add three partitions

Add a network card named ens33 to the network configuration

Firewall selection disabled

Then save the file in / var/ftp

You can see that the file already exists

[root@localhost tftpboot]# cd /var/ftp/
[root@localhost ftp]# ls
centos7  ks.cfg  pub
[root@localhost ftp]# 

Copy some information from anaconda-ks.cfg in the home directory to ks.cfg

[root@localhost ftp]# vim ~/anaconda-ks.cfg


Enter / var/lib/tftpboot/pxelinux.cfg, edit the default file, and add ks=ftp after the first label:/

default auto
prompt 1

label auto
        kernel vmlinuz
        append initrd=initrd.img method= ks=ftp:/

label linux text
        kernel vmlinuz
        append text initrd =initrd.img method=

label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=

At this time, create a new virtual machine, set the memory to about 4G, set the network card to host only mode, turn on the machine, and press enter after seeing boot to automatically install the system.

Tags: Linux Operation & Maintenance CentOS

Posted on Mon, 18 Oct 2021 19:48:41 -0400 by kevo1162