4. 配置PXE 中
PXE
Quick Start Guide. The following operations are performed on Ubuntu 20.04.
Install Required Software
apt install tftpd-hpa isc-dhcp-server nginx
Download Operating System ISO Images
rhel-server-7.9-x86_64-dvd.iso
rhel-8.3-x86_64-dvd.iso
Kylin-Server-10-SP1-Release-Build20-20210518-x86_64.iso
Kylin-Server-10-SP2-x86-Release-Build09-20210524.iso
Create a Local Repository
Using RHEL 7.9 as an example. The process is similar for other distributions.
mkdir -p /mnt/rhel79
mount rhel-server-7.9-x86_64-dvd.iso /mnt/rhel79
mkdir -p /var/www/html/rhel79/x86_64
cp -r /mnt/rhel79 /var/www/html/rhel79/x86_64/base
$ sudo vim /etc/nginx/sites-enabled/default
server {
listen 80 default_server;
root /var/www/html;
autoindex on;
}
Create a Kickstart File
You can obtain this file from /root/anaconda-ks.cfg after manually installing the operating system.
mkdir /var/www/html/kickstart
cp rhel79.cfg /var/www/html/kickstart/
# The final directory structure is as follows:
/var/www/html
├── kickstart
│ ├── cdh.cfg
│ ├── gbase.cfg
│ ├── rhel79.cfg
│ ├── v10sp1.cfg
│ └── v10sp2.cfg
├── rhel79
│ └── x86_64
│ ├── addons
│ ├── base
│ └── updates
├── rhel83
│ └── x86_64
│ ├── addons
│ ├── base
│ └── updates
├── rhel84
│ └── x86_64
│ ├── addons
│ ├── base
│ └── updates
├── v10sp1
│ └── x86_64
│ ├── addons
│ ├── base
│ └── updates
└── v10sp2
└── x86_64
├── addons
├── base
└── updates
Configure DHCP
Note: First, configure the local machine’s IP address to 10.0.0.1.
$ sudo vim /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
option arch code 93 = unsigned integer 16;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.10 10.0.0.50;
next-server 10.0.0.1;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option arch = 00:07 or option arch = 00:09 {
# x86-64 EFI BIOS
filename "efi/x86_64/BOOTX64.EFI";
} else if option arch = 00:0b {
# ARM64 aarch64 EFI BIOS
filename "efi/aarch64/BOOTAA64.EFI";
} else {
# Legacy non-EFI BIOS
filename "bios/x86_64/pxelinux.0";
}
}
}
$ sudo vim /etc/rsyslog.d/dhcp-relay.conf
local7.* -/var/log/dhcp-relay.log
# Restart the service
systemctl restart isc-dhcp-server
Configure TFTP
$ sudo vim /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure -vvv"
# Create BIOS directory
mkdir -p /srv/tftp/bios/x86_64
# Prepare pxelinux.0 and vesamenu.c32 files
cp /var/www/html/rhel79/x86_64/base/Packages/syslinux-4.05-15.el7.x86_64.rpm .
rpm2cpio syslinux-4.05-15.el7.x86_64.rpm | cpio -dimv
cp usr/share/syslinux/pxelinux.0 /srv/tftp/bios/x86_64/
cp usr/share/syslinux/vesamenu.c32 /srv/tftp/bios/x86_64/
# Prepare vmlinuz and initrd.img files
mkdir -p /srv/tftp/bios/x86_64/images/rhel79
cp /var/www/html/rhel79/x86_64/base/images/pxeboot/vmlinuz //srv/tftp/bios/x86_64/images/rhel79
cp /var/www/html/rhel79/x86_64/base/images/pxeboot/initrd.img /srv/tftp/bios/x86_64/images/rhel79
# Prepare the default file
mkdir /srv/tftp/bios/x86_64/pxelinux.cfg
cp /var/www/html/rhel79/x86_64/base/isolinux/isolinux.cfg /srv/tftp/bios/x86_64/pxelinux.cfg/default
$ sudo vim /srv/tftp/bios/x86_64/pxelinux.cfg/default
default vesamenu.c32
timeout 600
label local
menu label Boot from ^local drive
menu default
localboot 0xffff
label rhel79
menu label ^Install Red Hat Enterprise Linux 7.9
kernel images/rhel79/vmlinuz
append initrd=images/rhel79/initrd.img inst.ks=http://10.0.0.1/kickstart/rhel79.cfg quiet
label rhel83
menu label ^Install Red Hat Enterprise Linux 8.3
kernel images/rhel83/vmlinuz
append initrd=images/rhel83/initrd.img inst.ks=http://10.0.0.1/kickstart/rhel83.cfg quiet
label v10sp1
menu label ^Install Kylin Linux Advanced Server V10 SP1
kernel images/v10sp1/vmlinuz
append initrd=images/v10sp1/initrd.img inst.ks=http://10.0.0.1/kickstart/v10sp1.cfg quiet
label v10sp2
menu label ^Install Kylin Linux Advanced Server V10 SP2
kernel images/v10sp2/vmlinuz
append initrd=images/v10sp2/initrd.img inst.ks=http://10.0.0.1/kickstart/v10sp2.cfg quiet
# Create UEFI directory
mkdir -p /srv/tftp/efi/x86_64
# Prepare BOOTX64.EFI, grubx64.efi, and grub.cfg files
cp /var/www/html/rhel79/x86_64/base/EFI/BOOT/BOOTX64.EFI /srv/tftp/efi/x86_64/
cp /var/www/html/rhel79/x86_64/base/EFI/BOOT/grubx64.efi /srv/tftp/efi/x86_64/
cp /var/www/html/rhel79/x86_64/base/EFI/BOOT/grub.cfg /srv/tftp/efi/x86_64/
chmod 644 /srv/tftp/efi/x86_64/BOOTX64.EFI
chmod 644 /srv/tftp/efi/x86_64/grubx64.efi
# Prepare vmlinuz and initrd.img files
mkdir -p /srv/tftp/efi/x86_64/images/rhel79
cp /var/www/html/rhel79/x86_64/base/images/pxeboot/vmlinuz /srv/tftp/efi/x86_64/images/rhel79/
cp /var/www/html/rhel79/x86_64/base/images/pxeboot/initrd.img /srv/tftp/efi/x86_64/images/rhel79/
# Prepare grub.cfg file
$ sudo vim /srv/tftp/efi/x86_64/grub.cfg
set timeout=5
set default=0
menuentry 'Install Red Hat Enterprise Linux 7.9' {
linuxefi efi/x86_64/images/rhel79/vmlinuz ip=dhcp inst.ks=http://10.0.0.1/kickstart/rhel79.cfg
initrdefi efi/x86_64/images/rhel79/initrd.img
}
menuentry 'Install Kylin Linux Advanced Server V10 SP1' {
linuxefi efi/x86_64/images/v10sp1/vmlinuz ip=dhcp inst.ks=http://10.0.0.1/kickstart/v10sp1.cfg
initrdefi efi/x86_64/images/v10sp1/initrd.img
}
menuentry 'Install Kylin Linux Advanced Server V10 SP2' {
linuxefi efi/x86_64/images/v10sp2/vmlinuz ip=dhcp inst.ks=http://10.0.0.1/kickstart/v10sp2.cfg
initrdefi efi/x86_64/images/v10sp2/initrd.img
# The final directory structure is as follows:
/srv/tftp
├── bios
│ └── x86_64
│ ├── images
│ │ ├── rhel79
│ │ │ ├── initrd.img
│ │ │ └── vmlinuz
│ │ ├── v10sp1
│ │ │ ├── initrd.img
│ │ │ └── vmlinuz
│ │ └── v10sp2
│ │ ├── initrd.img
│ │ └── vmlinuz
│ ├── pxelinux.0
│ ├── pxelinux.cfg
│ │ └── default
│ └── vesamenu.c32
└── efi
└── x86_64
├── BOOTX64.EFI
├── grub.cfg
├── grubx64.efi
└── images
├── rhel79
│ ├── initrd.img
│ └── vmlinuz
├── v10sp1
│ ├── initrd.img
│ └── vmlinuz
└── v10sp2
├── initrd.img
└── vmlinuz
View Logs
tail -f /var/log/syslog | grep dhcp
tail -f /var/log/syslog | grep tftp
tail -f /var/log/nginx/access.log
Debugging
# Test the repository
curl 10.0.0.1
curl 10.0.0.1/kickstart/rhel79.cfg
# Test DHCP
sudo nmap --script broadcast-dhcp-discover
sudo nmap --script broadcast-dhcp-discover -e eth0
dhcp-lease-list
# Test TFTP
$ tftp 10.0.0.1
tftp> get bios/x86_64/pxelinux.0
Received 27158 bytes in 0.1 seconds
tftp>
References
- Change permissions for grub2/shim.efi
- How to set-up and configure a PXE Server
- Create a PXE bootserver to install multiple Linux distributions
- Understanding PXE Booting and Kickstart Technology
- Kickstart Server
- Preparing for a Network Installation
- Making the Kickstart File Available
- Automated Installation Using Kickstart
- s14.Operation Automation for System Deployment — Practical Case: Kickstart File Creation Process
- Sample kickstart partition example (RAID, LVM, Multipath, Simple,..)
- How to install and configure isc-dhcp-server
- Installing and Configuring TFTP Server on Ubuntu
- Need to set up yum repository for locally-mounted DVD on Red Hat Enterprise Linux 7
- Automated Installation Tool - Kickstart
- How do I configure syslinux to boot immediately
- dhcp-relay custom log file
- Kickstart Syntax Reference
- Kickstart Documentation
- error: ../../grub-core/net/net.c:1795:timeout reading initrd.img
- How To Install createrepo on Ubuntu 18.04
- How to Create Your Own Repositories for Packages
- PXELINUX
- 01-Automated Installation Tool - Kickstart
- 27.2. How Do You Perform a Kickstart Installation?