Linux system (redhat7) unattended automatic installation

1. Environment:

#Author: WangKeZhen

#mail:[email protected]

Please execute as root user

Environment: Configure two network cards as much as possible, and the virtual machine can be connected to the Internet.

2. Install dhcp, tftp, httpd server, graphical tools for kickstart files

###########################################
## Configure yum source
##
###########################################
mount /dev/cdrom /mnt
rm -rf /etc/yum.repos.d/rhel-source.repo
touch /etc/yum.repos.d/rhel-source.repo
cat >> /etc/yum.repos.d/rhel-source.repo << EOF
[rhel-source]
name=Red Hat Enterprise
baseurl=file:///mnt
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
#############################################
yum install -y dhcp tftp-server syslinux httpd system-config-kickstart

3. Configure dhcp

[root@jtxy ~]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
subnet 192.168.177.0 netmask 255.255.255.0 {
  range 192.168.177.30 192.168.177.60;
  option domain-name-servers 192.168.177.6;
  option domain-name "jtxy.com";
  option routers 192.168.0.1;
  option broadcast-address 192.168.177.255;
  default-lease-time 3600;
  max-lease-time 7200;
  next-server 192.168.177.6; #Designate to this machine to download the file pxelinux.0
  filename "/pxelinux.0"; #This file is a binary file, the content is to find the startup configuration file isolinux.cfg
}
systemctl restart dhcpd.service
netstat -antup | grep dhcpd #Check if the port is started

4. Configure tftp and enable tftp function

xinetd is a daemon process

vim /etc/xinetd.d/tftp #xinetd is a daemon process
disable = no

systemctl restart tftp
cat /etc/services | grep tftp
netstat -anplut | grep :69 #Check if tftp port is open
cat /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 = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot #tftp will share the files in this directory
disable = no
per_source = 11
cps = 100 2
flags=IPv4
}

tftp shares the files in the /var/lib/tftpboot directory

PXE (Pre-boot Execution Environment, Pre-boot Execution Environment) PXE is a protocol that can #boot the operating system through the network without installing the operating system in the local disk.

The pxelinux.cfg directory contains basic information for managing PXELINUX configuration files

mkdir /var/lib/tftpboot/pxelinux.cfg
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom

CD-ROM files required for installation

cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
cp /mnt/cdrom/isolinux/* /var/lib/tftpboot/
chmod 644 /var/lib/tftpboot/pxelinux.cfg/default

5. Configuration startup file

vim /var/lib/tftpboot/pxelinux.cfg/default

default linux #Find the linux option, edit it, do not modify the others

timeout 600

label linux

menu label ^Install Red Hat Enterprise Linux 7.0

kernel vmlinuz

append initrd=initrd.img ks=http://192.168.177.6/ks.cfg inst.repo=http://192.168.177.6/cdrom quiet

#ks: Specify configuration options for the installation process inst.repo: Specify the location of the installation CD

6. Configure kickstart

1. Mount the CD to the website directory

mkdir /var/www/html/cdrom
mount /dev/cdrom /var/www/html/cdrom
systemctl restart httpd
#Test: access CD via http
firefox 192.168.177.7/cdrom

2. Configure the kickstart file

Kickstart is a way to automate the installation of Red Hat systems, similar to automated installs in Windows and preconfiguration and automation scripts in #Linux

Kickstart configuration mainly consists of a text file, usually called ks.cfg file, which contains all the information needed for the installation process, such as partitions, users, software packages, network configuration, and so on. The installer can automatically read this file at startup and perform an automated installation according to the configuration options and parameters specified in it

system-config-kickstart

Save to /var/www/html/ks.cfg

3. Improve the ks.cfg file

vim /var/www/html/ks.cfg

%packages

@^graphical-server-environment

@base

@core

@desktop-debugging

@dial-up

@fonts

@gnome-desktop

@guest-agents

@guest-desktop-agents

@hardware-monitoring

@input-methods

@internet-browser

@kde-desktop

@multimedia

@print-client

@x11

kexec-tools

%end

systemctl restart httpd.service

7. Create a new virtual machine for testing. If the system can be automatically installed after booting, it means success