PXE——Unattended automatic installation of Linux operating system (stepping on the pit record)

Insert picture description here

DHCP service

The DHCP server is mainly used to allocate network parameters such as IP addresses to clients on the internal network of the enterprise .

Unattended environment, when a client selects from the network is started, it will by transmitting broadcast data packet in the form of finding the DHCP server , the DHCP to obtain the IP address after the read start parameters can be shared file via TFTP.

(1) Install DHCP service operation yum install -y dhcp
(2) Modify the configuration file to allocate network parameters to the client

[root@python ~]# vim /etc/dhcp/dhcp.conf
#dhcpd.conf
#
# Sample configuration file for ISC dhcpd
log-facility local7;

# A slightly different configuration for an internal subnet.
subnet 192.168.213.0 netmask 255.255.255.0 {
  range 192.168.213.3 192.168.213.254;
  option domain-name-servers 192.168.213.163;
  option subnet-mask 255.255.255.0;
  option routers 192.168.213.2;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 192.168.213.163;
  filename "pxelinux.0";
}
[root@python ~]# systemctl start dhcpd
[root@python ~]# systemctl enable dhcpd
[root@python ~]# netstat -tunpl|grep 67
udp        0      0 0.0.0.0:67              0.0.0.0:*                           5440/dhcpd
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1506/dnsmasq

TFTP service

The TFTP service provides a simple file sharing for the client. He does not have the rich functions as FTP, but due to the simple design, TFTP is very suitable for transferring small and simple PXE startup files.

#安装TFTP
[root@python ~]# yum install -y tftp-server
#修改配置文件
[root@python ~]# cat /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
}

Install tftp's dynamic management tool
tfpt is a service dynamically managed by xinetd. To start the service, just start xinetd

[root@python ~]# yum install xinetd
#将客户端所需要的启动引导文件复制到TFTP服务器
[root@python ~]# yum install -y syslinux	#通过该软件包获取引导文件
[root@python ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@python ~]# mount -o loop -t iso9660 /iso/CentOS-7-x86_64-DVD-1908.iso /var/ftp/centos7u7
[root@python ~]# cp /var/ftp/centos7u7/isolinux/vmlinuz /var/lib/tftpboot/centos7u7/
[root@python ~]# cp /var/ftp/centos7u7/isolinux/vesamenu.c32 /var/lib/tftpboot
[root@python ~]# cp /var/ftp/centos7u7/isolinux/initrd.img /var/lib/tftpboot/centos7u7/
[root@python ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@python ~]# cp /var/ftp/centos7u7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@python ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@python pxelinux.cfg]# chmod 644 default
[root@python ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 60
display boot.msg
menu background splash.jpg
menu title CentOS X of Zhao

label centos7 64 <Auto Installation>
  menu label Install CentOS Linux ^7 x86_64 <Auto>
  kernel centos7u7/vmlinuz
  append initrd=centos7u7/initrd.img inst.stage2=ftp://192.168.213.163/centos7u7 inst.repo=ftp://192.168.213.163/centos7u7 inst.ks=ftp://192.168.213.163/centos-7-ks.cfg

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

menu end
#准备图片
[root@python ~]# cp splash.jpg /var/lib/tftpboot/splash.jpg
[root@python ~]# systemctl start xinetd
[root@python ~]# systemctl enable xinetd
[root@python ~]# ss -nutlp|grep 69
udp    UNCONN     0      0         *:69                    *:*                   users:(("xinetd",pid=14264,fd=5))

FTP service

FTP (file transfer protocol) file transfer protocol, vsftp is a software that uses the FTP protocol for data sharing. The main feature of vsftp is to provide a secure data sharing service .

Use vsftp as the Centos system file sharing service platform. When the client starts from the network and enters the installation interface formally, it also needs to read the system files in the Centos CD to complete the final installation. These files are shared with vsftp to Internet users.

[root@python ~]# yum install -y vsftpd
[root@python ~]# systemctl start vsftpd
[root@python ~]# systemctl enable vsftpd

Automated installation example

Initialize the system environment

[root@python ~]# systemctl stop firewalld
[root@python ~]# systemctl disable firewalld
[root@python ~]# sed -i.bak 's/=enforcing/=disabled/' /etc/sysconfig/selinux
[root@python ~]# sed -i.bak 's/=enforcing/=disabled/' /etc/selinux/config
[root@python ~]# setenforce 0
[root@python ~]# cd /var/ftp/

Create installation directory structure

[root@python ftp]# mkdir centos6u8
[root@python ftp]# mkdir centos7u7
[root@python ftp]# cd /var/lib/tftpboot/
[root@python tftpboot]# mkdir centos6u8
[root@python tftpboot]# mkdir centos7u7

Configure to start DHCP

Configure startup TFTP

Create an automatic answer file

[root@python ~]# yum install system-config-kickstart
[root@python ~]# system-config-kickstart
#检查有无语法错误
[root@python ~]# ksvalidator ks.cfg
[root@python ~]# mv ks.cfg /var/ftp/centos-7-ks.cfg

Automatically install virtual machine test

Step on the pit

(1) Boot loader options
Insert picture description here

# System bootloader configuration
bootloader --location=mbr	#在主引导记录(MBR)中安装引导装载程序
# Partition clearing information
clearpart --all

If you do not install the boot loader (see below), you will get a black screen and you willbooting from local disk

# System bootloader configuration
bootloader --location=none

Adding kernel parameters net.ifnames=0 biosdevname=0will modify the network card name to eth0

# System bootloader configuration
bootloader --append="net.ifnames=0 biosdevname=0" --location=mbr

(2) Installation method
Insert picture description hereFTP directory can also be centos-7-ks.cfgmodified in the configuration file

(3) Remember to mount the image
mount -o loop -t iso9660 /iso/CentOS-7-x86_64-DVD-1908.iso /var/ftp/centos7u7

If it is not mounted, an error will be reported can't find installer maininage path in .treeinfo

Warning: can't find installer maininage path in .treeinfo
Warning: Downloading 'ftp://192.168.213.163/centos7u7/Live0S/squashfs.img' failed!
Warning anaconda: failed to fetch stage2 from ftp://192.168.213.163/centos7u7

(4) After exporting the ks.cfg file, modify the name and add the following content at the end

%packages
@^minimal
@core
%end

(5) The installed picture has the size (640 pixels * 480 pixels) requirements, and the pictures that fail to meet the requirements may display failure
(6) Incorrect mirroring may cause the operating system installation to fail

The test CentOS-6.10-x86_64-minimal.isocannot be installed automatically
Insert picture description here
(7) The error failed to fetch kickstat from ftp
may be selinux or ftp is not set to anonymous mode
(8) VMware Workstation is not compatible with Device / Credential Guard
Run Windows Powershell as administrator (administrator) ( Windows key + X), run the command bcdedit /set hypervisorlaunchtype off, restart the computer

This problem should be related to the system version of windows, which appeared after the automatic update of windows 10

Guess you like

Origin www.cnblogs.com/zhaoya2019/p/12761520.html