Security and Package Manager Setup
Disable firewalld and SELinux enforcement to avoid network blocks during provisioning. Configure the Alibaba Cloud mirror for faster package retrieval.
systemctl disable --now firewalld
setenforce 0
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache
Service Layer Installation
Install and enable the mandatory network provisioning services: Apache HTTPD, TFTP, DHCP, and the xinetd super-server.
yum -y install httpd tftp-server dhcp xinetd
systemctl enable httpd tftp dhcp xinetd --now
TFTP Service Definition
Create the TFTP configuration within xinetd. The server root is set to /var/lib/tftpboot and listens on UDP.
# /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
}
DHCP Server Configuration
Define the subnet, dynamic addres pool, and point clients to the PXE boot loader and server IP.
# /etc/dhcp/dhcpd.conf
ddns-update-style none;
filename "bootx64.efi";
next-server 10.0.17.100;
subnet 10.0.17.0 netmask 255.255.255.0 {
range 10.0.17.200 10.0.17.230;
option routers 10.0.17.2;
option domain-name-servers 114.114.114.114;
}
HTTP Repository Preparation
Simplify the default HTTP welcome page and mount the CentOS ISO content at a dedicated directory.
cat > /etc/httpd/conf.d/welcome.conf << 'WELCOME'
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
WELCOME
mkdir -p /var/www/html/centos
mount -o loop /var/www/html/centos.iso /var/www/html/centos
UEFI Boot Artifacts
Copy kernel and initrd from the mounted image, then generate a standalone GRUB EFI binary with the necessary network and filesystem modules.
cp /var/www/html/centos/images/pxeboot/initrd.img /var/lib/tftpboot/initrd
cp /var/www/html/centos/images/pxeboot/vmlinuz /var/lib/tftpboot/vmlinuz
cp /var/www/html/centos/EFI/BOOT/grubx64.efi /var/lib/tftpboot/grubx64.efi
yum install -y grub2-efi-x64 shim-x64 grub2-efi-x64-modules
grub2-mkstandalone -d /usr/lib/grub/x86_64-efi/ \
-O x86_64-efi \
--modules="tftp net efinet linux part_gpt efifwsetup" \
-o /var/lib/tftpboot/bootx64.efi
chmod 777 /var/lib/tftpboot
Boot Menu Definition
Create the GRUB configuration that loads essential video and filesystem drivers and defines the installation entry. The target ISO and Kickstart file are fetched over HTTP.
# /var/lib/tftpboot/grub.cfg
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=5
menuentry 'CentOS 7 Unattended Install' --class fedora --class gnu-linux --class gnu --class os {
set gfxpayload=keep
linuxefi (tftp)/vmlinuz ip=dhcp inst.repo=http://10.0.17.100/centos ks=http://10.0.17.100/ks.cfg
initrdefi (tftp)/initrd
}
Kickstart Answer File
Install the graphical Kickstart configuration tool and set up a local repository file pointing to the mounted source.
yum install -y system-config-kickstart
cat > /etc/yum.repos.d/development.repo << EOF
[development]
name=development
baseurl=file:///var/www/html/centos
gpgcheck=0
EOF
The ks.cfg file defines a fully automated installation: disk partitioning with LVM on /dev/sda, UEFI boot, disabled firewall, DHCP networking, and a post-installation script that switches the package sources to Alibaba Cloud mirrors and a local repo.
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
install
graphical
auth --useshadow --passalgo=sha512
firewall --disabled
firstboot --enable
ignoredisk --only-use=sda
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=link --activate
network --hostname=pxe-client.local
timezone Asia/Shanghai --isUtc
rootpw --plaintext changeme123
selinux --permissive
services --enabled="chronyd"
reboot
url --url="http://10.0.17.100/centos"
user --name=operator --password=$6$R3b.LTR/NkobA1Sv$quYMCv3b6czowr6o6y9Yz53yg/DR9PSQxlUMJCD.GnbMewAPeFePAzL7pQQ4HEW.LdGjJw4OUnPCVWjg12UKV/ --iscrypted --gecos="operator"
xconfig --startxonboot
bootloader --location=mbr --boot-drive=sda
zerombr
clearpart --all --initlabel
bootloader --location=mbr --boot-drive=sda
part /boot/efi --fstype="efi" --ondisk=sda --size=200 --fsoptions="umask=0077,shortname=winnt"
part /boot --fstype="xfs" --ondisk=sda --size=1024
part pv.01 --fstype="lvmpv" --ondisk=sda --grow
volgroup vg_centos --pesize=4096 pv.01
logvol swap --fstype="swap" --size=2048 --name=swap --vgname=vg_centos
logvol / --fstype="xfs" --grow --name=root --vgname=vg_centos
%post --log=/root/ks-post.log
/bin/cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
/bin/cat > /etc/yum.repos.d/CentOS-Base.repo << 'BASE'
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
BASE
/bin/mkdir -p /etc/yum.repos.d/bak
/bin/mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/bak 2>/dev/null
/bin/cat > /etc/yum.repos.d/local.repo << 'LOCAL'
[local]
name=Local Repository
baseurl=http://10.0.17.100/centos
enabled=1
gpgcheck=0
LOCAL
yum clean all
yum makecache
%end
%packages
@base
@core
chrony
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
The system reboots upon completion.