ftp://10.10.10.53/ks.cfg

Time:2022-5-10

PXE description

PXE (preboot execution environment) supports the client to download the system image from the server through the network and install it. During the installation process, you can realize unattended installation through kickstart configuration file and customize the operating system.

PXE server components:

DHCP: it is responsible for assigning network IP address and specifying the of system startup file through DHCP package.

Syslinux: pre boot program

TFTP: PXE client obtains boot file through TFTP.

FTP: PXE client downloads system image content through FTP.

initialize server

Configure fixed IP address for PXE server;

[[email protected] ~]$ sudo vim /etc/sysconfig/network-scripts/ifcfg-ens192
[sudo] password for it:
[[email protected] ~]$ cat /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens192
UUID=6346f97a-42c5-4fff-ad62-93bdfd90f417
DEVICE=ens192
ONBOOT=yes
IPADDR=10.10.10.53
PREFIX=24
GATEWAY=10.10.10.1
DNS1=10.10.10.1
IPV6_PRIVACY=no

Close the firewall;

[[email protected] ~]$ sudo systemctl stop firewalld.service 
[[email protected] ~]$ sudo systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

DHCP

Install DHCP server role;

[[email protected] ~]$ sudo yum install dhcp-server -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:12:17 ago on Sat 10 Oct 2020 04:06:12 PM CST.
Dependencies resolved.
================================================================================================================
 Package                    Arch                  Version                        Repository                Size
================================================================================================================
Installing:
 dhcp-server                x86_64                12:4.3.6-30.el8                localREPO                529 k

Transaction Summary
================================================================================================================
Install  1 Package
... ... ... ...
... ... ... ...
... ... ... ...

Configure DHCP;

[[email protected] ~]$ sudo vim /etc/dhcp/dhcpd.conf
[[email protected] ~]$ sudo cat /etc/dhcp/dhcpd.conf | grep -v ^#
allow bootp;
allow booting;

default-lease-time 600;
max-lease-time 7200;

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 10.10.10.0 netmask 255.255.255.0 {
 option routers 10.10.10.1;
 range 10.10.10.100 10.10.10.199;

 class "pxeclients" {
   match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
   next-server 10.10.10.53;         #pxe server IP 

   if option architecture-type = 00:07 {
     filename "uefi/BOOTX64.EFI";     # UEFI boot
     } else {
     filename "pxelinux.0";          # BIOS boot
   }
}
}

Start DHCP service and configure startup;

[[email protected] ~]$ sudo systemctl enable --now dhcpd.service 
Created symlink /etc/systemd/system/multi-user.target.wants/dhcpd.service → /usr/lib/systemd/system/dhcpd.service.

syslinux

Install syslinux tftpboot;

[[email protected] ~]$ sudo yum install syslinux-tftpboot -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:46:30 ago on Mon 12 Oct 2020 11:18:21 AM CST.
Dependencies resolved.
================================================================================================================
 Package                         Arch                 Version                     Repository               Size
================================================================================================================
Installing:
 syslinux-tftpboot               noarch               6.04-1.el8                  localREPO               462 k
Installing dependencies:
 syslinux                        x86_64               6.04-1.el8                  localREPO               576 k
 syslinux-nonlinux               noarch               6.04-1.el8                  localREPO               554 k

Transaction Summary
================================================================================================================
Install  3 Packages
... ... ... ...
... ... ... ...
... ... ... ...

Configure the Startup menu (there are only two menus, oneInstall Red Hat Enterprise Linux 8.0, one isBoot from local drive(default choice)), and configure the files required to start the system image and the directory to download the system image in the first menu;

[[email protected] ~]$ sudo mkdir /tftpboot/pxelinux.cfg 
[[email protected] ~]$ sudo cp /os/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
[[email protected] ~]$ sudo vim /tftpboot/pxelinux.cfg/default
[[email protected] ~]$ sudo cat /tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 600

display boot.msg

menu title Red Hat Enterprise Linux 8.0

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux
  menu label ^Install Red Hat Enterprise Linux 8.0
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=ftp://10.10.10.53/rhel8.2 repo=ftp://10.10.10.53/rhel8.2 ip=dhcp quiet

label local
  menu label ^Boot from local drive
  menu default
  localboot 0xffff

The Startup menu file default can be obtained by modifying the sample file or creating it yourself.
Copy the system image boot file to the corresponding location

[[email protected] ~]$ sudo cp /os/isolinux/{boot.msg,vesamenu.c32} /tftpboot/
[[email protected] ~]$ sudo cp /os/images/pxeboot/{vmlinuz,initrd.img} /tftpboot/

TFTP

Install the TFTP server role (PXE client obtains the startup file through TFTP);

[[email protected] ~]$ sudo yum install tftp-server -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:45:23 ago on Mon 12 Oct 2020 08:05:39 AM CST.
Dependencies resolved.
================================================================================================================
 Package                    Arch                  Version                    Repository                    Size
================================================================================================================
Installing:
 tftp-server                x86_64                5.2-24.el8                 localREPO_APP                 50 k

Transaction Summary
================================================================================================================
Install  1 Package
... ... ... ...
... ... ... ...
... ... ... ...

Configure TFTP server (modify the path of TFTP to / tftpboot);

[[email protected] ~]$ sudo vim /usr/lib/systemd/system/tftp.service 
[[email protected] ~]$ sudo cat /usr/lib/systemd/system/tftp.service 
[Unit]
Description=Tftp Server
Requires=tftp.socket
Documentation=man:in.tftpd

[Service]
ExecStart=/usr/sbin/in.tftpd -s /tftpboot
StandardInput=socket

[Install]
Also=tftp.socket

Start TFTP service and configure startup;

[[email protected] ~]$ sudo systemctl enable --now tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.

FTP

Install FTP server (for PXE client to download system image files);

[[email protected] ~]$ sudo yum install vsftpd -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:01:41 ago on Sat 10 Oct 2020 04:06:12 PM CST.
Dependencies resolved.
================================================================================================================
 Package                Arch                   Version                      Repository                     Size
================================================================================================================
Installing:
 vsftpd                 x86_64                 3.0.3-28.el8                 localREPO_APP                 180 k

Transaction Summary
================================================================================================================
Install  1 Package
... ... ... ...
... ... ... ...

Configure FTP server, enable anonymous access, and specify the directory of anonymous access;

[[email protected] ~]$ sudo vim /etc/vsftpd/vsftpd.conf 
[sudo] password for it: 
[[email protected] ~]$ sudo grep -e anonymous -e anon_root /etc/vsftpd/vsftpd.conf | grep -v ^#
anonymous_enable=YES
anon_root=/home/ISO/

Start FTP service and configure startup;

[[email protected] ~]$ sudo systemctl enable --now vsftpd.service 
Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /usr/lib/systemd/system/vsftpd.service.

Create a directory accessed anonymously by FTP, and then copy the system image content to the directory;

[[email protected] ~]$ sudo mkdir /home/ISO/rhel8.2
mount RHEL-8-0-0-BaseOS-x86_64.iso /mnt/rhel8.2
[[email protected] ~]$ sudo cp -r /mnt/rhel8.2/* /home/ISO/rhel8.2
**Note: * * if there is a problem with the copied installation source. You can try copying and pasting manually.

Test start

Start the client host through BIOS (Legacy) for testing

Configuration supports UEFI startup

Configure UEFI Startup menu

[[email protected] ~]$ sudo mkdir /tftpboot/uefi
[sudo] password for it: 
[[email protected] ~]$ sudo cp -r /os/EFI/BOOT/* /tftpboot/uefi/
[[email protected] ~]$ vim /tftpboot/uefi/grub.cfg 
[[email protected] ~]$ sudo vim /tftpboot/uefi/grub.cfg
[[email protected] ~]$ sudo cat /tftpboot/uefi/grub.cfg 
[sudo] password for it: 
set default="1"

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=60
### END /etc/grub.d/00_header ###

search --no-floppy --set=root -l 'RHEL-8-0-0-BaseOS-x86_64'

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Red Hat Enterprise Linux 8.0' --class fedora --class gnu-linux --class gnu --class os {
 linuxefi vmlinuz inst.stage2=ftp://10.10.10.53/rhel8.2 repo=ftp://10.10.10.53/rhel8.2 ip=dhcp quiet
 initrdefi initrd.img
}
menuentry 'Test this media & install Red Hat Enterprise Linux 8.0' --class fedora --class gnu-linux --class gnu --class os {
 linuxefi vmlinuz inst.stage2=ftp://10.10.10.53/dvd quiet
 initrdefi initrd.img
}

Set boot file permissions
Set the permissions of five files in the path / var / lib / tftpboot / UEFI to 777

cd /tftpboot/uefi
chmod 777 *

Restart service

[[email protected] ~]$ sudo systemctl restart dhcpd.service 
[[email protected] ~]$ sudo systemctl restart tftp.socket

Test start

Start the client host through UEFI for testing.

Automatic installation of operating system through PXE (2): kickstart response file

Kickstart file is the answer file to realize the automatic installation of the system.

Sample file

#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Use graphical install
graphical
# Reboot after installation
reboot
repo --name="AppStream" --baseurl=ftp://10.10.10.53/rhel8.2/AppStream
# Use network installation
url --url="ftp://10.10.10.53/rhel8.2"
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# Run the Setup Agent on first boot
firstboot --disable
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=ens192 --ipv6=auto --activate
network  --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$VrOUsKRz8dywq5D5$1SbE62Vu/YPtzqd.4Y0U/M6fqILDluHAPFU5Kt9GkAS8eZVC7.yA/aBCzkWbNx0MJicFBR2MmipOItFBdqW6X.
# X Window System configuration information
xconfig  --startxonboot
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --groups=wheel --name=it --password=$6$fI8GAHa5Q6JG1BB3$6/Dv5ndCa4KMIkVFBkmVzvnV.SvwSO5.h0ppaaI75f53G9dH4.l6yUR.IUYGTKX/ctKwyzliKJQtOpV7TAZqI. --iscrypted --gecos="it"

%packages
@^graphical-server-environment
kexec-tools
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'
%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

Kickstart file description
Ignoredisk: control the connection to the disk during installation. If you use automatic partition, you can specify the disk to be ignored by automatic partition through ignoredisk — driver = SDC during installation. If you have multiple disks and only want to use one of them for automatic partition and install the operating system, you can use ignoredisk — only use = SDA to specify that only SDA is used.

Autopart: automatically create the root partition (/), swap partition (SWAP) and appropriate boot partition (/ boot), and / home partition on a large enough drive. Specify the partition type with — type =, such as LVM used in the example. You can also specify the system file type through — fstype =, such as XFS, ext4, etc. the default is XFS. You can also encrypt all partitions through the — encrypted option.

Clearpart: delete the existing partition before partitioning. You can specify the disk to delete the partition through — drives =, or you can clear the partition of all devices through — all.

Graphical: the installation process is carried out graphically, just like manual installation. You can also use the text command to display the installation process in text.

Reboot: reboot after installation.

Repo: specify additional package installation sources.

URL: the location of the installation file when installing over the network.

Keyboard: Specifies the keyboard layout. Specify which vconsole keyboard mode should be used by — vckeymap =. Specify the layout of the keyboard with — xlayouts =.

Firstboot: whether initial setup is displayed when the system is started for the first time. If enabled, you must install the initial setup package. If not specified, this option is disabled by default. – Enable means to start the initial setup, and – disable means to disable the initial setup. If you use — enable, you can also use the — reconfigure option to start the reconfiguration mode when booting the system. In this mode, you can newly configure the system language, keyboard and mouse, root password, system security level, time zone and some network configurations.

Lang: configure the system language.

Network: network configuration. Use — bootproto = to specify how the computer obtains IP, DCHP or static. Use — device = to specify the name of the device to be configured. Use — activate to activate the device. If your — bootproto = uses static, you can use IP = to specify the IP address, – netmask = to specify the subnet mask, – gateway = to specify the gateway, and – nameserver = to specify DNS. Use IPv6 = to specify IPv6 configuration, and use Auto to indicate automatic configuration. Use — hostname to configure the hostname.

Rootpw: Specifies the password of the root user. – Iscrypted means that the password is displayed as ciphertext Plaintext indicates that the password is displayed in clear text. You can also use — lock to lock the root user.

When you use – iscrypted, you can generate the ciphertext of the password through Python on a machine with the system installed (if it is Python 3, the corresponding command should be Python 3).
$ python -c ‘import crypt; print(crypt.crypt(“My Password”))’
1
Xconfig: configure x windows system Startxonboot means to log in using the graphical interface in the installed system.

Services: configure the default state of the service Disabled = specify the service disabled by default, and use — enabled = to specify the service enabled by default.

Timezone: Specifies the time zone.

User: add additional users. Specify the user name through — name =, specify the group to be added by the user through — groups = (except the default group), and specify the password of the user through — password =, – iscrypted means that the password is encrypted–gecos=Define user’s gecos information, such as user’s full name, etc.

%Packages indicates the software package to be installed.

Specify the package group through @ such as:

%packages
@core
@X Window System
@Desktop
%end

Specify the environment group through @ ^, such as:

%packages
@^graphical-server-environment
%end

Directly enter the software package name and specify an independent software package, such as:

%packages
@core
@desktop
sqlite
curl
%end

Debug a package in the package group with the – number

%packages
@Development Tools
-pkgconf
-pkgconf-m4
-pkgconf-pkg-config
-redhat-rpm-config
%end

%Package should end with% end
%Addon configures kdump Enable indicates that it is on, and specifies the memory size reserved for kdump through — reserve MB =, and auto indicates automatic. To end with% end.

%The anaconda section specifies the password policy, which also ends with% end.

You can also specify the script to be executed before disk partition through% pre and the script to be executed after system installation through% post. These modules need to end with% end.

For more information about the syntax of kickstart response file, please refer to the system installation guide on the official website. So far, there is no installation guide for RHEL 8 on red hat’s official website. You can refer to the installation guide for RHEL 7.

Add the kickstart response path in the Startup menu file
After editing the kickstart response file, save it as KS CFG (the file name can be customized) and uploaded to the FTP root directory (the path is also customized). For example, the file path of this example is:ftp://10.10.10.53/ks.cfg

BISO (Legacy) mode startup:

[[email protected] ~]$ sudo vim /tftpboot/pxelinux.cfg/default
[[email protected] ~]$ sudo cat /tftpboot/pxelinux.cfg/default
... ... ... ...
... ... ... ...
label linux
  menu label ^Install Red Hat Enterprise Linux 8.0
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=ftp://10.10.10.53/rhel8.2 inst.ks=ftp://10.10.10.53/ks.cfg quiet
... ... ... ...
... ... ... ...

UEFI mode startup:

[[email protected] ~]$ sudo vim /tftpboot/uefi/grub.cfg
[[email protected] ~]$ sudo cat /tftpboot/uefi/grub.cfg 
[sudo] password for it: 
... ... ... ...
... ... ... ...
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Red Hat Enterprise Linux 8.0' --class fedora --class gnu-linux --class gnu --class os {
 linuxefi vmlinuz inst.stage2=ftp://10.10.10.53/rhel8.2 inst.ks=ftp://10.10.10.53/ks.cfg quiet
 initrdefi initrd.img
}
... ... ... ...
... ... ... ...

At this point, you can automatically install RHEL 8 operating system through PXE server.

Reference link:

Automatically install the operating system through PXE (1): deploy PXE server:
https://mp.weixin.qq.com/s/E90teVh2XIf3c244m5b3Qg

Automatically install the operating system through PXE (2): deploy PXE server:
https://mp.weixin.qq.com/s/PgVHBIqoRG9q57RlNrFpAw

Recommended Today

Inventory of development artifacts in go

This article has been included https://github.com/lkxiaolou/lkxiaolou Welcome, star. In Java, we use JUnit as unit test, jmh as performance benchmark, async profiler to analyze CPU performance, and jstack, jmap, Arthas, etc. to troubleshoot problems.As a relatively new programming language, are these tools of golang easier to use? unit testing Java unit testing requires the use […]