- 1. 安装前准备
- 2. 安装相关软件包并启动
- 3. PXE在BIOS启动模式下的配置
- 3.1. 配置DHCP服务
- 3.2. 准备yum 源和相关目录
- 3.3. 准备kickstart文件
- 3.4. 准备PXE启动相关文件
- 3.5. 准备启动菜单文件
- 3.6. 客户端PXE网络引导
- 4. UEFI模式下PXE配置
- 4.1. 拷贝相关文件
- 4.2. 修改DHCP配置文件
- 4.3. 修改启动菜单
- 4.4. 创建KS启动文件
- 4.4. 客户端网络启动
- 4.4.1. CentOS 7客户端网络安装示例
- 4.4.2. CentOS 8客户端网络安装示例
关闭防火墙和SELINUX,DHCP服务器静态IP
网络要求:关闭Vmware软件中的DHCP服务,基于NAT模式
一台CentOS 8.4版本的虚拟机
注意:使用 1G 以下内存的主机安装CentOS 7,8 会提示空间不足,建议2G以上
[root@centos8 ~]#dnf -y install dhcp-server tftp-server httpd syslinuxnonlinux(或者syslinux-tftpboot) [root@centos8 ~]#systemctl enable --now httpd tftp dhcpd3. PXE在BIOS启动模式下的配置 3.1. 配置DHCP服务
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp-server/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
option domain-name "meng.com";
option domain-name-servers 192.168.8.140, 192.168.8.1;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.8.0 netmask 255.255.255.0 {
range 192.168.8.70 192.168.8.75;
option routers 192.168.8.1;
next-server 192.168.8.18;
filename "pxelinux/pxelinux.0";
}
[root@centos8 ~]#systemctl start dhcpd
3.2. 准备yum 源和相关目录
[root@centos8 ~]#mkdir -pv /var/www/html/centos/{6,7,8}/
[root@centos8 ~]#mount /dev/sr0 /var/www/html/centos/6/
[root@centos8 ~]#mount /dev/sr1 /var/www/html/centos/7/
[root@centos8 ~]#mount /dev/sr2 /var/www/html/centos/8/
[root@cent8 centos]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 879M 0 879M 0% /dev
tmpfs 909M 0 909M 0% /dev/shm
tmpfs 909M 29M 880M 4% /run
tmpfs 909M 0 909M 0% /sys/fs/cgroup
/dev/mapper/cl-root 65G 27G 38G 42% /
/dev/mapper/cl-home 32G 273M 32G 1% /home
/dev/sda2 1014M 237M 778M 24% /boot
/dev/sda1 599M 8.7M 591M 2% /boot/efi
tmpfs 182M 1.2M 181M 1% /run/user/42
192.168.8.140:/OSO 700G 646G 55G 93% /nfs
/dev/loop0 4.4G 4.4G 0 100% /var/www/html/centos/7
/dev/loop3 9.3G 9.3G 0 100% /var/www/html/centos/8
/dev/sr0 9.3G 9.3G 0 100% /mnt/iso
/dev/loop5 3.7G 3.7G 0 100% /var/www/html/centos/6
tmpfs 182M 0 182M 0% /run/user/0
通过浏览器访问验证
[root@centos8 ~]#mkdir /var/www/html/ks/ [root@centos8 ~]#vim /var/www/html/ks/centos6.cfg [root@centos8 ~]#vim /var/www/html/ks/centos7.cfg [root@centos8 ~]#vim /var/www/html/ks/centos8.cfg [root@cent8 centos]#cd /var/www/html/ks/ [root@cent8 ks]#ll total 20 -rw-r--r-- 1 root root 709 Oct 14 21:07 cent6.cfg -rw-r--r-- 1 root root 1314 Oct 14 21:26 cent7.cfg -rw-r--r-- 1 root root 1340 Oct 22 16:48 cent7uefi.cfg -rw-r--r-- 1 root root 1580 Oct 15 15:23 cent8.cfg -rw-r--r-- 1 root root 1583 Oct 22 16:23 cent8uefi.cfg 可以使用openssl来生成密码的加密串,也可以使用明文密码 [root@cent8 ~]#openssl passwd -1 123456 $1$QCzxR7vD$lsl/kFiVM8Nr9NpYXmfaz1 [root@cent8 ks]#cat cent6.cfg install text reboot url --url=http://192.168.8.18/centos/6 lang en_US.UTF-8 keyboard us network --onboot yes --device eth0 --bootproto dhcp --noipv6 #rootpw --iscrypted $6$b6C5mM/BwOMBoK8H$cYZFrHoNlOL0iDsxOTRhwnWJ3yfFmf7mRJBOxEqGoI56UMrT8J7qlrGwX7tS rootpw --plaintext 123456 firewall --disabled authconfig --enableshadow --passalgo=sha512 selinux --disabled timezone Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" zerombr clearpart --all --initlabel part /boot --fstype=ext4 --size=1024 part / --fstype=ext4 --size=50000 part /data --fstype=ext4 --size=30000 part swap --size=2048 %packages @core @server-policy @workstation-policy autofs vim-enhanced %end [root@cent8 ks]#cat cent7.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password #rootpw --iscrypted $1$L5LsvU6D$VgWY8DM1lfztissFfvZRR1 rootpw --plaintext 123456 # Use network installation url --url="http://192.168.8.18/centos/7" # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # Run the Setup Agent on first boot firstboot --enable # SELinux configuration selinux --disabled # Firewall configuration firewall --disabled # Network information network --bootproto=dhcp # Reboot after installation reboot # System timezone timezone Asia/Shanghai # System bootloader configuration #bootloader --location=none #bootloader --location=mbr --boot-drive=sda bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="ext4" --size=2048 part / --fstype="xfs" --size=10240 part swap --fstype="swap" --size=2048 %packages @development -byacc -cscope -ctags -diffstat -doxygen -elfutils -gcc-gfortran -git -indent -intltool -patchutils -rcs -subversion -swig -systemtap %end %pre i am pre %end %post i am post %end [root@cent8 ks]#cat cent8.cfg ignoredisk --only-use=sda zerombr text reboot clearpart --all --initlabel selinux --disabled firewall --disabled url --url=http://192.168.8.18/centos/8 keyboard --vckeymap=us --xlayouts='us' lang en_US.UTF-8 #bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda #此行必须指定 bootloader --location=mbr --boot-drive=sda network --bootproto=dhcp --device=ens192 --activate network --hostname=centos8.magedu.org #rootpw --iscrypted $6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRvgHBpqgc5n0RypMsPTQnVDcpO01 rootpw --plaintext 123456 firstboot --enable skipx services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp user --name=wang --password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang" #autopart --type=lvm #part / --fstype xfs --size 1 --grow --ondisk sda 可以实现根自动使用所有剩余空间 part / --fstype="xfs" --ondisk=sda --size=102400 part /data --fstype="xfs" --ondisk=sda --size=51200 part swap --fstype="swap" --ondisk=sda --size=2048 part /boot --fstype="ext4" --ondisk=sda --size=1024 %packages @^minimal-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 %post useradd mage echo magedu | passwd --stdin mage &> /dev/null %end3.4. 准备PXE启动相关文件
[root@centos8 ~]#mkdir -p /var/lib/tftpboot/pxelinux/centos{6,7,8}
#准备CentOS6,7,8各自的内核相关文件
[root@centos8 ~]#cp
/var/www/html/centos/6/isolinux/{vmlinuz,initrd.img}
/var/lib/tftpboot/pxelinux/centos6
[root@centos8 ~]#cp
/var/www/html/centos/7/isolinux/{vmlinuz,initrd.img}
/var/lib/tftpboot/pxelinux/centos7
[root@centos8 ~]#cp /var/www/html/centos/8/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/pxelinux/centos8
[root@centos8 ~]#cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/pxelinux
#以下三个文件是CentOS8安装所必须文件,CentOS6,7则不需要
[root@centos8 ~]#cp
/var/www/html/centos/8/os/x86_64/isolinux/{ldlinux.c32,libcom32.c32,libutil.c32}
/var/lib/tftpboot/pxelinux
#生成安装菜单文件
[root@centos8 ~]#mkdir /var/lib/tftpboot/pxelinux/pxelinux.cfg/
[root@centos8 ~]#cp /var/www/html/centos/8/isolinux/isolinux.cfg
/var/lib/tftpboot/pxelinux/pxelinux.cfg/default
#最终目录结构如下, etc, grub, image ppc这些文件夹不需要
[root@cent8 tftpboot]#tree pxelinux/
pxelinux/
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── centos8
│ ├── initrd.img
│ └── vmlinuz
├── etc
├── grub
│ └── images -> ../images
├── images
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── ppc
├── pxelinux.0
└── pxelinux.cfg
└── default
9 directories, 12 files
[root@cent8 tftpboot]#
3.5. 准备启动菜单文件
[root@cent8 pxelinux.cfg]#cat default default menu.c32 timeout 600 menu title Install CentOS Linux label linux8 menu label Auto Install CentOS Linux ^8 kernel centos8/vmlinuz append initrd=centos8/initrd.img ks=http://192.168.8.18/ks/cent8.cfg label linux7 menu label Auto Install CentOS Linux ^7 kernel centos7/vmlinuz append initrd=centos7/initrd.img ks=http://192.168.8.18/ks/cent7.cfg label linux6 menu label Auto Install CentOS Linux ^6 kernel centos6/vmlinuz append initrd=centos6/initrd.img ks=http://192.168.8.18/ks/cent6.cfg label manual menu label ^Manual Install CentOS Linux 8.0 kernel centos8/vmlinuz append initrd=centos8/initrd.img inst.repo=http://192.168.8.18/centos/8/ label rescue menu label ^Rescue a CentOS Linux system 8 kernel centos8/vmlinuz append initrd=centos8/initrd.img inst.repo=http://192.168.8.18/centos/8/ rescue label local menu default menu label Boot from ^local drive localboot 0xffff3.6. 客户端PXE网络引导
注意:一定要将要改成BIOS引导,UEFI是无法引导的,下面会介绍如何引导UEFI,CentOS8会默认使用UEFI启动,CentOS6,7默认使用BIOS启动
[root@cent8 tftpboot]#mkdir /var/lib/tftpboot/centos{7,8}
[root@cent8 BOOT]#cp /var/www/html/centos/8/EFI/BOOT/{BOOTX64.EFI,grub.cfg,grubx64.efi} /var/lib/tftpboot/
[root@centos8 ~]#cp /var/www/html/centos/8/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos8/
[root@centos8 ~]#cp /var/www/html/centos/7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7/
[root@cent8 tftpboot]#tree /var/lib/tftpboot
/var/lib/tftpboot
├── BOOTX64.EFI
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── centos8
│ ├── initrd.img
│ └── vmlinuz
├── grub.cfg
├── grubx64.efi
└── pxelinux
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── centos8
│ ├── initrd.img
│ └── vmlinuz
├── etc
├── grub
│ └── images -> ../images
├── images
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── ppc
├── pxelinux.0
└── pxelinux.cfg
└── default
12 directories, 19 files
4.2. 修改DHCP配置文件
[root@cent8 pxelinux.cfg]#cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp-server/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
option domain-name "meng.com";
option domain-name-servers 192.168.8.140, 192.168.8.1;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.8.0 netmask 255.255.255.0 {
range 192.168.8.70 192.168.8.75;
option routers 192.168.8.1;
next-server 192.168.8.18;
filename "BOOTX64.EFI";
}
启动文件从pxelinux.0修改为BOOTX64.EFI
4.3. 修改启动菜单
[root@cent8 tftpboot]#cat grub.cfg
set default=“0”
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=10
menuentry ‘Install CentOS Linux 8.4’ {
linuxefi centos8/vmlinuz inst.ks=http://192.168.8.18/ks/cent8uefi.cfg
initrdefi centos8/initrd.img
}
menuentry ‘Install CentOS Linux 7.6’ {
linuxefi centos7/vmlinuz inst.ks=http://192.168.8.18/ks/cent7uefi.cfg
initrdefi centos7/initrd.img
}
[root@cent8 ks]#cat cent8uefi.cfg ignoredisk --only-use=sda zerombr text reboot clearpart --all --initlabel selinux --disabled firewall --disabled url --url=http://192.168.8.18/centos/8 keyboard --vckeymap=us --xlayouts='us' lang en_US.UTF-8 #bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda #此行必须指定 bootloader --location=mbr --boot-drive=sda network --bootproto=dhcp --device=ens192 --activate network --hostname=centos8.magedu.org #rootpw --iscrypted $6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRvgHBpqgc5n0RypMsPTQnVDcpO01 rootpw --plaintext 123456 firstboot --enable skipx services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp user --name=wang --password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang" autopart --type=lvm #part / --fstype xfs --size 1 --grow --ondisk sda 可以实现根自动使用所有剩余空间 #part / --fstype="xfs" --ondisk=sda --size=102400 #part /data --fstype="xfs" --ondisk=sda --size=51200 #part swap --fstype="swap" --ondisk=sda --size=2048 #part /boot --fstype="ext4" --ondisk=sda --size=1024 %packages @^minimal-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 %post useradd mage echo magedu | passwd --stdin mage &> /dev/null %end 主要是Boot分区启动有些变化,BIOS下启动文件在boot分区下,UEFI下启动文件在boot/efi下,且分区格式是vfat格式, 本示例中是自动分区的(autopart --type=lvm) [root@cent8 ks]#cat cent7uefi.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password #rootpw --iscrypted $1$L5LsvU6D$VgWY8DM1lfztissFfvZRR1 rootpw --plaintext 123456 # Use network installation url --url="http://192.168.8.18/centos/7" # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # Run the Setup Agent on first boot firstboot --enable # SELinux configuration selinux --disabled # Firewall configuration firewall --disabled # Network information network --bootproto=dhcp # Reboot after installation reboot # System timezone timezone Asia/Shanghai # System bootloader configuration #bootloader --location=none #bootloader --location=mbr --boot-drive=sda bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel autopart --type=lvm # Disk partitioning information #part /boot/efi --fstype="vfat" --size=2048 #part / --fstype="xfs" --size=10240 #part swap --fstype="swap" --size=2048 %packages @development -byacc -cscope -ctags -diffstat -doxygen -elfutils -gcc-gfortran -git -indent -intltool -patchutils -rcs -subversion -swig -systemtap %end %pre i am pre %end %post i am post %end 配置完成后需要重启启动tftp dhcpd两个服务 [root@cent8 tftpboot]#systemctl restart tftp dhcpd4.4. 客户端网络启动
CentOS 8 在vsphere下默认使用的EFI启动,而CentOS 7下默认使用的BIOS,所以自动安装CentOS7时需要手动修改为EFI启动
4.4.1. CentOS 7客户端网络安装示例



