Automatic Installation of Linux PXE + Kickstart

Keywords: Linux network ftp vim yum

When installed on a large scale, it is easy to operate manually and improve efficiency by using unattended equipment.

PXE Network Installation

Configuration of Dual Network Cards

  • Here, ens33 is a nat network, ens37 is a host-only network, and ens37 is configured.
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens37
[root@localhost network-scripts]# vim ifcfg-ens37 
TYPE=Ethernet
BOOTPROTO=static
DEVICE=ens37
ONBOOT=yes
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
  • service network restart
[root@localhost ~]# service network restart
Restarting network (via systemctl):                        [  OK  ]
  • View Network Card Address
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.28.128  netmask 255.255.255.0  broadcast 192.168.28.255
        inet6 fe80::605e:3c48:bafd:e550  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:bc:ab:96  txqueuelen 1000  (Ethernet)
        RX packets 635342  bytes 935571060 (892.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 288265  bytes 17505470 (16.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost ~]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.100  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::20c:29ff:febc:aba0  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:bc:ab:a0  txqueuelen 1000  (Ethernet)
        RX packets 1514  bytes 461770 (450.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 186  bytes 31726 (30.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

DHCP services

  • Install DHCP package
[root@localhost ~]# yum install dhcp -y
  • Edit DHCP configuration file
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp: overwrite '/etc/dhcp/dhcpd.conf'? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 
  • Configure segment information in lines 27-40.
subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.20 192.168.100.50;
  option routers 192.168.100.100;
  option domain-name-servers 114.114.114.114;
  next-server 192.168.100.100;
  filename "pxelinux.0";
}
  • Install syslinux package
[root@localhost ~]# yum install syslinux -y
  • Find the pxelinux.0 bootstrapper
[root@localhost ~]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0

TFTP services

  • Install the tftp-server package
[root@localhost ~]# yum install tftp-server -y
  • View the tftp-server file list
[root@localhost ~]# rpm -ql tftp-server
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot
  • Copy bootstrapper pxelinux.0 to tftp site
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
  • Edit the tftp configuration file
[root@localhost ~]# vim /etc/xinetd.d/tftp 
  • Edit line 14 and change yes to no to turn on tftp
        disable                 = no

FTP services

  • Install vsftp package
[root@localhost ~]# yum install vsftpd -y
  • Mount Mirror Files
[root@localhost ~]# mkdir /var/ftp/centos7
[root@localhost ~]# mount /dev/cdrom /var/ftp/centos7/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs        20G  4.3G   16G  22% /
devtmpfs       devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda5      xfs        10G   37M   10G   1% /home
/dev/sda1      xfs       2.0G  174M  1.9G   9% /boot
tmpfs          tmpfs     378M   40K  378M   1% /run/user/0
/dev/sr0       iso9660   4.3G  4.3G     0 100% /var/ftp/centos7
  • Copy system initialization file initrd.img and compress kernel vmlinuz to tftp site
[root@localhost ~]# cd /var/ftp/centos7/images/pxeboot/
[root@localhost pxeboot]# cp initrd.img vmlinuz /var/lib/tftpboot/
  • Create the Start Menu default
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 1

label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.100.100/centos7

label linux text
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.100.100/centos7

label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
  • Check to see if the required files are complete
[root@localhost ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── initrd.img
├── pxelinux.0
├── pxelinux.cfg
│   └── default
└── vmlinuz

1 directory, 4 files
  • Start all related services
[root@localhost ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@localhost ~]# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl start vsftpd

Close the firewall

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

After this step, you can use the network boot to install the machine, but you need to manually select the relevant installation configuration.

PXE Installation Verification

  • Start with network boot. After this interface returns, it can load relevant files for installation.

kickstart unattended installation

Installation package

[root@localhost ~]# yum install system-config-kickstart -y

Startup program

[root@localhost ~]# system-config-kickstart

Create an automatic response file

  • Basic configuration

  • Installation method

  • Bootloader options

  • Zoning information

  • Partition boot information

  • Partition home information

  • Partition swap information

  • Partition/Information

  • network configuration

  • Verification

  • Firewall configuration

  • Display configuration

  • Package selection

  • Pre-installation script

  • Post-installation script

  • Save the response file to / var/ftp

Edit ks.cfg

[root@localhost ~]# ls /var/ftp/
centos7  ks.cfg  pub
  • Copy the parameters of the package you need to install from / root/anaconda-ks.cfg
[root@localhost ~]# vim /root/anaconda-ks.cfg 
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools

%end
  • Paste installation package parameters to the end of ks.cfg file
[root@localhost ~]# vim /var/ftp/ks.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$MzI8tkpP$whWLRJqNdsvOMTgOewQ0i1
# Use network installation
url --url="ftp://192.168.100.100/centos7"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part /home --fstype="xfs" --size=5120
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1

%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools

%end

Edit Start Menu

[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 
default auto
prompt 1

label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg

label linux text
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.100.100/centos7

label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7

Now the installation can be automatically completed after booting from the network, without manual operation, and the unattended installation can be completed.

Posted by greedyisg00d on Mon, 07 Oct 2019 15:33:16 -0700