文章目录
- X Window System configuration information
- Keyboard layouts
- old format: keyboard us
- new format:
- System language
- Firewall configuration
- System authorization information
- Use hard drive installation media
- Use text mode install
- Run the Setup Agent on first boot
- SELinux configuration
- Do not configure the X Window System
- System services
- Network information
- Reboot after installation
- System timezone
- Partition clearing information
- Clear the Master Boot Record
- System bootloader configuration
- X Window System configuration information
- Keyboard layouts
- old format: keyboard us
- new format:
- System language
- Use network installation
- Use text mode install
- Run the Setup Agent on first boot
- Do not configure the X Window System
- Reboot after installation
- System timezone
- Partition clearing information
- System bootloader configuration
概要
现在在很多得时候都会选择使用pxe去安装os,或者是使用pxe去boot这样就可以更加得方便os得使用和安装,其中需要注意一下,安装的客户端的机器是需要在BIOS中确认一下PXE的功能有没有打开,还有就是在BIOS中EFI 的网络功能需不需要打开,这些都是使用pxe的先决条件。
PXE server搭建
如果需要搭建pxe serve,需要什么东西,一下就是一些需要的环境需求:
os: centos 7 或者centos 8 或者centos 9
需要在os中安装一下几个server
dhcp server
ftp server
tftp server
xinted
你可以跑这条指令安装
yum install dhcp-server tftp tftp-server syslinux httpd xinetd -y
DHCP配置
编辑/etc/dhcp/dhcpd.conf文件
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
#default-lease-time 72000;
#max-lease-time 86400;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.20 192.168.0.100;
option routers 192.168.0.1;
option broadcast-address 192.168.0.255;
next-server 192.168.0.1;
class “pxeclients” {
match if substring
(option vendor-class-identifier, 0, 9) =
“PXEClient”;
if option architecture-type = 00:07 or
option architecture-type = 00:09 {
# EFI BIOS
filename “/uefi/shim.efi”;
# filename “images/BOOTX64.efi”;
} else {
# Legacy non-EFI BIOS
filename “pxelinux.0”;
}
}
default-lease-time 72000;
max-lease-time 86400;
}
在dhcpd.conf文件中需要注意一下EFI和Legacy模式,这两个模式是需要有不同的安装条件的,基于现在都使用EFI模式,所以还是使用EFI相关的配置比较好。
其中EFI 模式使用 filename “/uefi/shim.efi”;
Legacy 模式使用这个 filename “pxelinux.0”;
TFTP配置
当配置tftp的时候,就需要确认xinted这个server 是不是已经准备好了,这里还涉及到了xinted的配置。因为需要通过xinted这个功能同步到tftp上面。
当下载完xinted,需要在创建 /etc/xinetd.d/tftp 并且配置如下:
# default: off
# description: The tftp server serves files using the trivial file transfer
# protocol. The tftp protocol is often used to boot diskless
# workstations, download configuration files to network-aware printers,
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = no
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
其中需要主要确认的东西就是 disable= no, 其他的参数基本一致。
(note : 这里的tftp的配置可以使用到网络下载一些自己定义的iso里面的东西,或者可以使用samba和网络共享盘之类NFS这样的方式将自己的定制化的东西一样放到pxeserver上面;eg: tftp 192.168.0.1 -c get filename)
之后需要将在pxe boot的时候的相关文件拷贝到/var/lib/tftpboot下面:
cp -rf /usr/share/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32,ldlinux.c32,libutil.c32} /var/lib/tftpboot
之后需要在/var/lib/tftpboot下面创建一个pxelinux.cfg的文件夹,并且创建一个default文件内容如下
default menu.c32
timeout 600
menu title #############Legacy PXE BOOT Menu#############
label RHEL 7.6
menu label Instll RHEL 7.6 via ftp
kernel vmlunz
append initrd=initrd.img method=ftp://192.168.0.1/centos7
label local
menu default
menu label Boot from local drive
localboot 0xffff
当然这个配置主要是提供给Legacy 的,还需要将EFI的也添加进去
在/var/lib/tftpboot中创建一个文件夹为uefi
需要在uefi下面准备如下文件:
BOOTX.EFI efidefault grub.cfg grubx64.efi shim.efi
其中BOOTX.EFI grub.cfg grubx64.ef 在可以在/boot/efi/EFI/centos/下面找到,如果没有shim.efi,可以使用yum 下载,文件也可能是shimx64.efi,但是这两个文件是一样的只需要修改一个tftp的配置内容就可以了。
grub.cfg文件配置如下:
set timeout=5
menuentry ‘Install CENTOS STREAM9’{
#linuxefi vmlinuz method=ftp://192.168.0.1:/stream9
#linuxefi vmlinuz inst.repo=ftp://192.168.0.1:/stream9 console=ttyS0,57600n8 net.ifnames=0 biosdevname=0
linuxefi vmlinuz inst.ks=ftp://192.168.0.1:/centos9/isolinux/ks-network.cfg console=ttyS0,57600n8 net.ifnames=0 biosdevname=0
#linuxefi vmlinuz inst.repo=http://192.168.0.1/stream9 console=ttyS0,57600n8 8250.nr_uarts=4 net.ifnames=0 biosdevname=0
#linuxefi vmlinuz ks=ftp://192.168.0.1:/centos9/isolinux/ks.cfg console=ttyS0,57600n8 8250.nr_uarts=4 net.ifnames=0 biosdevname=0
initrdefi initrd.img
}
efidefault 可忽略
default menu.c32
timeout 600
menu title #############UEFI PXE BOOT Menu#############
label RHEL 7.6
menu label Instll RHEL 7.6 via ftp
kernel vmlunz
append initrd=initrd.img method=ftp://192.168.0.1/centos7
label local
menu default
menu label Boot from local drive
localboot 0xffff
其中在grub.cfg文件中我们调用了ks-network.cfg这个文件,这个文件是后面放在ftp下面的,其配置如下:
ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
X Window System configuration information
#xconfig --startxonboot
Keyboard layouts
old format: keyboard us
new format:
keyboard --vckeymap=us --xlayouts=‘us’
#Root password (passwd : 111111 or 123456 or 11)
rootpw --iscrypted $6
0
E
F
q
/
v
H
w
t
m
J
j
t
g
/
K
0EFq/vHwtmJjtg/K
0EFq/vHwtmJjtg/KrLJ8vPVFkBu3.heTHJhiYIM.ITy1fBJnvA45OwSc6nbOlgV7xjUeJ.DwjxNtbdje6ALhPb7Cn4gTumiOBLbEx1
System language
lang en_US.UTF-8
Firewall configuration
firewall --disabled
System authorization information
authselect --enableshadow --passalgo=sha512
Use hard drive installation media
#cdrom
harddrive --dir= --partition=LABEL=CENTOS-STRE
Use text mode install
text
repo --name=“AppStream” --baseurl=file:///run/install/sources/mount-0000-hdd-device/AppStream
Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=nvme0n1
autopart
SELinux configuration
selinux --disabled
Do not configure the X Window System
skipx
System services
services --disabled=“chronyd”
Network information
network --bootproto=dhcp --device=eno3 --ipv6=auto --activate
Reboot after installation
reboot
System timezone
timezone Asia/Shanghai --nontp
Partition clearing information
clearpart --all --initlabel --drives=nvme0n1
Clear the Master Boot Record
zerombr
System bootloader configuration
bootloader --append=“crashkernel=auto” --location=mbr --boot-drive=nvme0n1
autopart
%packages
@^minimal-environment
vim
dhcp-client
net-tools
i2c-tools
minicom
iperf3
chkconfig
zip
ipmitool
python3-pip
gcc
g++
tar
stress-ng
libgpiod-utils
ledmon
bc
automake
tftp
pciutils
libnsl
mcelog
compat-openssl11
lm_sensors
smartmontools
tpm2-tss
tpm2-tools
tpm2-abrmd
expect
libicu
double-conversion
wget
%end
%addon com_redhat_kdump --enable --reserve-mb=‘auto’
%end
%post --nochroot
cp -rf /run/install/sources/mount-0000-hdd-device/tools /mnt/sysimage/root/
%end
ks-network.cfg (使用http的架构可以自行搭建http的server)
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
X Window System configuration information
#xconfig --startxonboot
Keyboard layouts
old format: keyboard us
new format:
keyboard --vckeymap=us --xlayouts=‘us’
#Root password
rootpw --iscrypted $6
0
E
F
q
/
v
H
w
t
m
J
j
t
g
/
K
0EFq/vHwtmJjtg/K
0EFq/vHwtmJjtg/KrLJ8vPVFkBu3.heTHJhiYIM.ITy1fBJnvA45OwSc6nbOlgV7xjUeJ.DwjxNtbdje6ALhPb7Cn4gTumiOBLbEx1
System language
lang en_US.UTF-8
Use network installation
url --url=“http://192.168.0.1/centos9/”
Use text mode install
text
#install source (Appstream)
repo --name=“AppStream” --baseurl=http://192.168.0.1/centos9/AppStream
Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=nvme0n1
Do not configure the X Window System
skipx
Reboot after installation
reboot
System timezone
timezone Asia/Shanghai --nontp
Partition clearing information
clearpart --all --initlabel --drives=nvme0n1
System bootloader configuration
bootloader --append=“crashkernel=auto” --location=mbr --boot-drive=nvme0n1
autopart
%packages
@^minimal-environment
vim
dhcp-client
net-tools
i2c-tools
minicom
iperf3
chkconfig
zip
ipmitool
python3-pip
gcc
g++
tar
stress-ng
libgpiod-utils
ledmon
bc
automake
tftp
pciutils
libnsl
mcelog
compat-openssl11
lm_sensors
smartmontools
tpm2-tss
tpm2-tools
tpm2-abrmd
expect
libicu
double-conversion
wget
%end
%post --nochroot
wget http://192.168.0.1/centos9/tools.zip
cp -rf tools.zip /mnt/sysimage/root/
cd /mnt/sysimage/root/
unzip tools.zip
%end
ftp server搭建
下载好了ftp之后,ftp主要是用来存放我们的os的内容的,所以需要创建一个文件centos9之后将所有的os放入进去,将配置链接到这个,之后就可以pxe就可以从这里拿os的内容了。其中如果定义了ks文件,就需要将ks文件放入到os中isolinux下面,并且在grub.cfg调用这个ks文件,就可以通过ks安装了。没有ks文件,就需要在grub.cfg修改指向文件夹就可以了。
最后只需要将所有的server启动就可以实现pxe安装了
[root@server ~]# systemctl restart tftp
[root@server ~]# systemctl enable tftp
[root@server ~]# systemctl restart xinetd
[root@server ~]# systemctl enable xinetd
[root@server ~]# systemctl restart vsftp
[root@server ~]# systemctl enable vsftp
可能遇到的问题
在通过pxe安装的过程中在一定的过程中可能会遇到这样的一个问题:[*** ] A start job is running for nm-wait-…itrd.service (1min 52s / no limit)
其中 nm-wait-…itrd.service指的就是nm-wait-online-initrd.service,nm-wait-online-initrd.service 是由 NetworkManager 提供的服务,它用于确保在启动过程中网络接口保持在线状态。如果你想要跳过这个服务,可以通过设置服务的启动设置为禁用或者改变其启动排序来实现。但是因为是安装的情况下面所以不能停止服务这个情况初步感觉可以通过grub来解决,猜测主要是和这个有关系:net.ifnames=0 biosdevname=0。(经过查询之后发现这个问题主要还是centos自己的问题,而且这个问题在后面的版本已经修改为等待90秒,当然如果想要自己修改也是有办法的可以修改文件系统里面的这个等待功能)
总结
这里只是使用ftp来搭建pxe,但是也可以使用nfs和http来搭建pxe