This is the 15th day of my participation in the More text Challenge. For more details, see more text Challenge


A lifelong learner, practitioner, and sharer committed to the path of technology, an original blogger who is busy and sometimes lazy, and a teenager who is occasionally boring and sometimes humorous.

Welcome to search “Jge’s IT Journey” on wechat!

In RHEL 6, DHCP+TFTP+FTP+PXE+Kickstart implements unattended installation

1. What is PXE?

Strictly speaking, PXE is not a way to install, but a way to boot. The prerequisite for PXE installation is that the computer to be installed contains a NETWORK interface card (NIC) that supports PXE. That is, the NIC must contain a PXE Client.

The pre-Boot Execution Environment (PXE) protocol enables computers to boot over a network. The PXE client is stored in the ROM of the network adapter. When the computer is booted, the BIOS invokes the PXE client to the memory and executes the PXE client. The PXE client downloads files on the remote end to the local end over the network.

To run the PXE protocol, configure the DHCP server and TFTP server. The DHCP server assigns an IP address to the PXE client (host on which the SYSTEM is to be installed). Therefore, you need to configure PXE Settings when configuring the DHCP server.

In addition, the TFTP client already exists in the ROM of the PXE Client. The PXE Client downloads required files from the TFTP Server through TFTP.

What is Kickstart?

KickStart is an unattended installation mode. KickStart records various parameters required by manual intervention during a typical installation process and generates a file named ks. CFG.

Later in the installation process (not limited to the machine where the KickStart installation file was generated), the installer will first look for the KickStart generated file when a parameter is required.

When appropriate parameters are found, the found parameters are adopted, and when no suitable parameters are found, manual intervention by the installer is required.

This way, if the KickStart file covers all the parameters that need to be filled in during the installation, the installer can just tell the installer where to get the ks.cfg file and go about its business. After the installation is complete, the installation program will restart the system according to the restart options set in ks. CFG and end the installation.

3. PXE network installation principle description

  • PXE Client: indicates the Client on which the OPERATING system is to be installed.
  • TFTP Server: indicates the machine on which the TFTPD service is installed.
  • DHCP Server: indicates the machine on which the DHCPD service is installed.

In actual operations, the TFTP Server and DHCP Server are usually deployed on the same machine.

4. Basic process of PXE network installation

  • The client sends an IP address request message to the DHCP server. The DHCP server checks whether the client is valid. If the client is valid, the DHCP server returns the IP address of the client and sends the location information of the startup file pxelinux.0 to the client.
  • The client sends the pxelinux.0 message to TFTP on the server. After receiving the message, TFTP sends the pxelinux.0 size information to the client to test whether the client is satisfied. TFTP sends pxelinux.0 to the client after receiving the size information returned by the client.
  • The client runs the received pxelinux.0 file.
  • The client sends the configuration file information (recorded in the pxelinux. CFG directory on TFTP) to TFTP. TFTP sends the configuration file to the client, and the client performs subsequent operations based on the configuration file.
  • The client sends a request for Linux kernel information to TFTP. After receiving the message, TFTP sends the kernel information to the client.
  • The client sends a request for the root file to TFTP. After receiving the message, TFTP returns to the Linux root file system.
  • The client starts the Linux kernel.
  • The client enters the installation mode.

5. Application scenarios of PXE network installation

  • If the SERVER does not have a CD/DVD-ROM drive or the CD/DVD-ROM drive is damaged, install the Linux OS
  • Improper system maintenance results in frequent Linux installation
  • The Linux operating system needs to be deployed in large batches (for enterprise applications)

6. Prerequisites for installing the PXE network

  • The client NIC supports PXE (integrated with BOOTROM chip), and the mainboard supports network boot (adjusted in BIOS).
  • In the network, a DHCP server automatically assigns network addresses to clients and specifies the location of boot files.
  • The server downloads boot image files through Trivial File Transfer Protocol (TFTP).

The pre-boot Execution Environment (PXE) is configured with Kickstart to implement unattended automatic installation

7. Deploy in the PXE environment

Server IP address: 192.168.200.254

# service iptables stop
# setenforce 0
Copy the code

Configure the YUM Repository

Mount /dev/cdrom/MNT / # RPM -i/MNT /Packages/ vsftpd-2.2.11.el64.1.x86_64. RPM # umount /dev/cdrom # mkdir /var/ftp/rhel6 # mount /dev/cdrom /var/ftp/rhel6/ # service vsftpd restartCopy the code

# vim/etc/yum. Repos. D/yum repo/base / / warehouse category name = Red Hat Enterprise Linux 6 / / warehouse name baseurl = ftp://192.168.3.10/rhel6 //URL Access path gpgCheck =0 // Verify the signature of the software packageCopy the code

Install and enable the TFTP service

TFTP services are provided by the tftp-server software package and managed through the xinetd super service by default. You need to change disable=yes in /etc/xinetd.d/ TFTP to Disable =no. Restart the xinetd service.

# yum -y install tftp-server

# vim /etc/xinetd.d/tftp 

service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
} 
# service xinetd restart
Copy the code

Prepare the Linux kernel and initialize the image file

The initialization image files vmlinuz and initrd.img are located in images/pxeboot. Copy the two files to the root directory of the TFTP service.

# cd /var/ftp/rhel6/images/pxeboot/
# cp vmlinuz initrd.img /var/lib/tftpboot/
Copy the code

Prepare the PXE boot program and launch the menu file

The boot program used for PXE network installation is pxelinux.0 provided by the sysLinux software package. After installing the software package, copy the file to the root directory of the TFTP service.

# yum -y install syslinux
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
Copy the code

The boot menu is used to guide the boot process of the client, including how to call the kernel and how to load the initialization image. The default boot menu is default and should be placed in the pxelinux.cfg subdirectory of the TFTP root directory.

# mkdir/var/lib/tftpboot/pxelinux CFG # cat/var/lib/tftpboot/pxelinux CFG/default default auto prompt 1 / / / / the default entry name 1: waits for user control. Label Auto kernel vmlinuz append initrd=initrd.img devfs=nomount ramdisk_size=8192Copy the code

Three portals are defined, namely graphical install (default), text install, and rescue mode

  • Prompt: Sets whether to wait for user selection
  • Label: Defines and separates startup items
  • Kernel Append: Defines boot parameters

Unattended installation requires only one entry

Install and enable the DHCP service

Used to automatically assign addresses and specify boot file locations to clients (bare metal)

# yum -y install DHCP # cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcpd.dhcpd.conf cp: Check whether to overwrite the /etc/dhcp/dhcpd.conf file. y # vim /etc/dhcp/dhcpd.conf ddns-update-style none; Next - server 192.168.200.254; Filename "pxelinux.0"; Subnet 192.168.200.0 netmask 255.255.255.0 {option routers 192.168.200.254; Option subnet configures - mask 255.255.255.0. option domain-name "crushlinux.com"; Option domain - name - the servers 202.106.0.20 8.8.8.8; The range 192.168.200.100 192.168.200.200; default-lease-time 21600; max-lease-time 43200; } # service dhcpd startCopy the code

Verify the PXE network installation

  • Newly purchased servers do not need additional Settings to start directly;
  • When a server with an existing operating system is booting, adjust the Boot options in the BIOS. Set Network or LAN to the first option, and then start the server.

Press Enter or type Auto in boot: to enter the default graphical installation entry

Select the appropriate language

Setting the keyboard type

Select install by URL

Edit card

Example Set the PXE network installation server

Kickstart unattended installation is implemented

The kickstart tool is used to configure the kickstart response file. The kickstart tool automatically installs all Settings during the installation without manual intervention, improving installation efficiency

  • Use the system-config-kickstart tool to generate a configuration file
  • Modify the existing /root/anaconda-ks. CFG file in the system
# yum -y install system-config-kickstart
# system-config-kickstart
Copy the code

In a production environment

Pre-installation script: allows users to install and load external card drivers, such as RAID card drivers. Post-installation script: allows users to set initial configurations

Name the file ks. CFG and save it to /var/ftp.pub

1 root root 1204 December 19 00:31 /var/ftp.pub/ks.cfgCopy the code

Edit the boot menu file default

# vim /var/lib/tftpboot/pxelinux.cfg/default default auto prompt 0 label auto kernel vmlinuz append Ks initrd = = ftp://192.168.200.254/pub/ks.cfg initrd. Img would = nomount ramdisk_size = 8192Copy the code

Original is not easy, if you think this article is a little useful to you, please give me a like, comment or forward for this article, because this will be my power to output more quality articles, thanks!

See you next time!