Automatic installation system (1)

System installation process

  • load bootloader
  • load boot installer menu
  • Load the kernel and initrd files
  • mount the root system
  • Run the anaconda installation wizard

Installation-related files on the installation CD

The /misc directory will appear automatically after installing autofs and starting.

Add CD/DVD to the virtual machine settings, use the system ISO file, and mount /dev/cdrom /misc after logging in to the system

  • boot.cat: equivalent to the first stage of grub
  • isolinux.bin: CD boot program, the file path needs to be clearly given in the mkisofs option, this file belongs to the SYSLINUX project
  • isolinux.cfg : The configuration file of the boot menu, when the CD is started (i.e. run isolinux.bin), it will automatically find the isolinux.cfg file
  • vesmenu.c32: It is the graphical interface of the startup menu after the CD is started, and it also belongs to the SYSLINUX project. menu.c32 provides a plain text menu
  • memtest: memory testing program
  • splash.png: The background image of the CD boot menu interface
  • vmlinuz: kernel image
  • initrd.img: ramfs file

isolinux.cfg parameters

Correspondence between parameters and installation process

1、

2、

 

 

Choosing different options is actually a difference in kernel parameters.

  • Load the kernel: isolinuz/vmlinuz
  • Pass parameters to the kernel: append initrd=initrd.img parameter

Choose to install CentOS Linux 8 directly, the kernel parameters are: append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-2-2004-x86_64-dvd quiet

Select the test medium, if it is correct, install Test this media & install CentOS Linux 8, the kernel parameters are: append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-2-2004-x86_64-dvd rd.live. check quiet

Choose to install Install CentOS Linux 8 in basic graphics mode, the kernel parameters are: append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-2-2004-x86_64-dvd nomodeset quiet

Select the rescue system Rescue a CentOS Linux system, the kernel parameters are: append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-2-2004-x86_64-dvd rescue quiet

For example, to enter rescue mode, you can do this

1. When the cursor is positioned on Install Centos Linux 8, press the Tab key

Enter the rescue mode kernel parameter rescue at the end to enter the rescue mode

2. Press the ESC key on this interface, then boot:rescue to enter the rescue mode

Common Kernel Parameters

1. text: The GUI graphical interface installation interface is started by default, and the installation interface in text mode can be specified

2. rescue: enter rescue mode

3. inst.repo=path: Specify the path of the installation source file, which can be in the following format
Centos 6
DVD drive repo=cdrom:device
Hard Drive repo=hd:device/path
HTTP Server repo= http://host/path
HTTPS Server repo= https://host/path
FTP Server repo=ftp://username:password@host/path
NFS Server repo=nfs:server:/path
ISO images on an NFS Server repo=nfsiso:server:/path

Centos 7
Any CD/DVD drive inst.repo=cdrom
Hard Drive inst.repo=hd:device:/path
HTTP Server inst.repo=http://host/path
HTTPS Server inst.repo=https://host/path
FTP Server inst.repo=ftp://username:password@host/path
NFS Server inst.repo=nfs:[options:]server:/path

askmethod: Select the method to obtain the installation source file, providing various installation sources such as CD, local hard disk, NFS, FTP, and HTTP. This item is obsolete after Centos 7

ks=path: Specify the path of the automated installation answer file, such as: initrd=initrd.img inst.ks= http://192.168.8.8/ksdir/ks8.cfg

ip= : Specify IP address information ip=method, method can specify a specific interface
for dhcp ip=interface:method ip=ip::gateway:netmask:hostname:interface:none Static IP

anaconda

Anaconda is a Linux system installation program that provides two styles of installation interface

1. GUI: graphics window

2. TUI: text window of curses based on graphics library

anaconda work process

1. The language used in the installation process

2. Keyboard type

3. Time zone and time

4. Installation source file path

5. Select the package to install

6. Install the target storage device and partition settings

Basic Storage: local disk

Special device: iSCSI

KDUMP function

Set hostname and configure network interface

security strategy

administrator password

Create a normal user

The configuration method of anaconda:

1. Interactive configuration mode

2. Automatically complete the configuration by reading the given configuration file in advance, and add the kernel parameter: ks=/path to indicate the location of the kickstart file. The various path formats are as follows:

​ DVD drive:ks=cdrom:/PATH/TO/KICKSTART_FILE
​ Hard drive:ks=hd:device:/directory/KICKSTART_FILE
​ HTTP server:ks=http://host:port/path/to/KICKSTART_FILE
​ FTP server:ks=ftp://host:port/path/to/KICKSTART_FILE
​ HTTPS server:ks=https://host:port/path/to/KICKSTART_FILE
​ NFS server:ks=nfs:host:/path/to/KICKSTART_FILE

Implementing an automated installation answer file

To realize automatic installation, it is necessary to prepare a corresponding installation answer file in advance, called a kickstart file, which is used to save the options that need to be specified during the installation process.

Kickstart file usage process

1. Create a kickstart file.

2. Place the kickstart file on removable media, hard drive or network location.

3. Create boot media, which will be used to start the installation.

4. Provide the installation source.

5. Start the kickstart installation.

kickstart file format

There is anaconda-ks.cfg file in the root home directory, please refer to

1. Command section

Indicate various pre-installation configurations, such as keyboard type, etc.

keyboard Set keyboard type
lang language type
zerombr clear MBR
clearpart clear partition
part create partition
rootpw set root password
timezone Time zone
text text installation interface
network specify network settings
firewall set up firewall
selinux selinux settings
reboot Automatic restart after installation
user Create a new user for the system after installation
url Configure the installation source

2. Package segment

Indicates package groups or packages to install, packages not to install, etc.

%packages
@^environment group: Specify the environment package group, such as: @^minimal-environment
@group_name
package
-package
%end

3, screenplay stage

%pre: pre-installation script

%post: post-installation script 

Notice:

  • The kickstart file formats of different versions of CentOS 8, 7, and 6 are different and cannot be mixed
  • %addon (extension), %packages (software package), %onerror, %pre, %post must end with %end, otherwise the installation will fail

Create a kickstart file

Way

  • Use the creation tool: system-config-kickstart, note: this method is no longer supported by CentOS 8
  • Modify and generate a new configuration according to a certain template; after CentOS is installed, it will automatically refer to the installation process of the current system to generate a kickstart file /root/anaconda-ks.cfg

check grammar

Install pykickstart, use the ksvalidator tool to check kickstart syntax errors

[ root@wenzi ~]#ls
anaconda-ks.cfg
[root@wenzi~]#yum -y install pykickstart.noarch

[root@wenzi ~]#ksvalidator anaconda-ks.cfg

Create a kickstart file using system-config-kickstart in centos7

centos7 address 192.168.28.141

1. Install xmanager on the physical machine for graphical operation

2、

[root@wenzi ~]# yum list | grep pykickstart
pykickstart.noarch 1.99.66.22-1.el7 @base
#192.168.28.1 is the address of the physical machine VMware Network Adapter VMnet8
[root@wenzi ~]# export DISPLAY=192.168.28.1 :0.0

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

A graphical interface will appear

Step on the pit:

If there are garbled characters in the graphical interface

Change the Linux system language from LANG="zh_CN.UTF-8" to LANG="en_US.UTF-8"

3. Set the installation options

 

 

 

The default network card name of centos7 is ens33. If it is written as eth0 here, you need to modify the kernel parameter net.ifnames=0, and use the traditional naming method of the network card eth0

 

 

 

 

 

Select the software package to be installed. Web Server is used as an example.

 

Step on the pit:

Click on the right side of Package Selection to load the list, and modify the file vim /etc/yum.repos.d/CentOS-Base.repo to the style shown below. Comment out [base], add [development]; restart system-config-kickstart

Pay attention to the wording of the yum source in the figure below, and escape characters must be added before variables such as $releasever

Click File-save on the upper left to save to the system, view the content of the ks.cfg file, which is the configuration of the installation process, and you can continue to manually modify the file, such as changing the time zone timezone Africa/Abidjan to timezone Asia/Shanghai

Correction to the configuration of the graphical interface, otherwise the installation system using the ks.cfg file will fail to start:

bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda

[root@wenzi ~]# ll
total 8
-rw-------. 1 root root 1333 Aug 11 04:39 anaconda-ks.cfg
-rw-r--r--  1 root root 1580 Aug 12 10:56 ks.cfg

[root@wenzi ~]# cat ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext admin
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/"
# System bootloader configuration
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=1024
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1

%post
useradd friends
echo admin | passwd --stdin mates

mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/* /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/Base.repo <<EOF
[development]
name=CentOS-\$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
        http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

EOF

yum -y install vim
%end

%packages
@web-server

%end

use answer file

Share the ks and cfg files on centos7, and access the test through the browser of the physical machine, and you can see the contents of the files successfully

[root@wenzi ~]# yum -y install httpd

[root@wenzi ~]# mv ks.cfg /var/www/html/
[root@wenzi ~]# systemctl start httpd

Create a new virtual machine and specify an answer file at startup. Press ESC to enter the following process when booting into the reading interface

Select the second one in the interface below, press ESC

After entering this interface, enter linux ks=http://192.168.28.141/ks.cfg and press Enter to start the installation

The kickstart files of centos6, centos7, and centos8 are different and cannot be mixed. For the kickstart files of each minimal installation, please refer to the answer file for automatic installation-Operation and Maintenance Pie

Realize semi-automatic installation of Linux based on ISO file

centos8 preparations

centos8 address 192.168.28.151

#Install httpd, as the system image, kickstart answer file network storage address

[root@wenzi ~]# dnf -y install httpd

[root@wenzi ~]# systemctl start httpd

1. Customize the kickstart answer file

[root@wenzi ~]# cp anaconda-ks.cfg centos8_ks.cfg
[root@wenzi ~]# vim centos8_ks.cfg
#version=RHEL8
#只使用系统中的第一块磁盘
ignoredisk --only-use=nvme0n1
#清除所有磁盘的分区表
zerombr
#文本方式安装
text
#graphical
#成功安装后重启
reboot
# 清除系统上所有分区
clearpart --all --initlabel
#关闭selinux
selinux --disabled
#关闭防火墙
firewall --disabled
#通过http远程服务器的目录树安装
url --url=http://192.168.28.151/centos/8/
#键盘
keyboard --vckeymap=us --xlayouts='us'
#系统语言
lang en_US.UTF-8
#网络配置
network --bootproto=dhcp --device=ens160 --ipv6=auto --activate
#network  --bootproto=static --device=ens160 --gateway=192.168.28.2 --ip=192.168.28.152 --nameserver=223.5.5.5,180.76.76.76 --netmask=255.255.255.0 --ipv6=auto --activate
#主机名
network  --hostname=wenzi
#root加密后的密码
rootpw --iscrypted $6$CEK/siEJwPyzpudd$cJ/rz9oiqDmc8LmI1uZmI8BRFxje4OnuGS0qLBRZ4cAFWqKg482sPuN1BstCMY62NN58ivBzZ.bGD.0QFaYnf/
# Run the Setup Agent on first boot
firstboot --enable
#不启动图形化
skipx
#开机时启动或关闭的服务
services --disabled="chronyd"
#系统时区
timezone Asia/Shanghai --isUtc --nontp
#分区信息
part /boot --fstype="ext4" --ondisk=nvme0n1 --size=1024
part /swap --fstype="swap" --ondisk=nvme0n1 --size=2048
part / --fstype="xfs" --ondisk=nvme0n1 --grow --size=1  #根分区/使用磁盘剩余的所有空间

#需要的安装包
%packages
@^minimal-environment
kexec-tools
vim
%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

2. Customize the boot menu

The /misc directory will appear automatically after centos8 installs autofs and starts.

Add CD/DVD in the virtual machine settings, use the system ISO file, mount /dev/cdrom /misc after logging in to the system

#创建定制ISO文件目录
[root@wenzi ~]# mkdir /data/myiso -p
[root@wenzi ~]# cp -r /misc/isolinux/ /data/myiso/
[root@wenzi ~]# tree /data/myiso/
/data/myiso/
└── isolinux
    ├── boot.cat
    ├── boot.msg
    ├── grub.conf
    ├── initrd.img
    ├── isolinux.bin
    ├── isolinux.cfg
    ├── ldlinux.c32
    ├── libcom32.c32
    ├── libutil.c32
    ├── memtest
    ├── splash.png
    ├── TRANS.TBL
    ├── vesamenu.c32
    └── vmlinuz

#编辑菜单文件
[root@wenzi ~]# vim /data/myiso/isolinux/isolinux.cfg
......
menu separator # insert an empty line
menu separator # insert an empty line

#自动安装系统
label linux
  menu label ^Auto Install CentOS Linux 8 #菜单名字可自行修改
  kernel vmlinuz
  #指定应答文件路径
  append initrd=initrd.img quiet ks=http://192.168.28.151/centos8_ks.cfg

#救援系统
label rescue
  menu label ^Rescue a CentOS Linux system
  kernel vmlinuz
  #指定救援系统路径
  append initrd=initrd.img rescue quiet inst.repo=http://192.168.28.151/centos/8

#启动本地系统
label local
  menu default
  menu label Boot from ^local drive
  localboot 0xffff

menu separator # insert an empty line
menu separator # insert an empty line

#返回主菜单
label returntomain
  menu label Return to ^main menu
  menu exit

menu end

#安装mkisofs工具
[root@wenzi ~]# dnf install genisoimage.x86_64
#创建自己的ISO文件,此条命令可通用,只修改路径即可
[root@wenzi ~]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 8.0 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso  /data/myiso/

#boot.iso即是生成的定制ISO文件
[root@wenzi ~]# ls
anaconda-ks.cfg  boot.iso  centos8_ks.cfg

3. Deploy system image resources and kickstart response files to httpd

[root@wenzi ~]# mv centos8_ks.cfg /var/www/html/centos8_ks.cfg
[root@wenzi ~]# chmod 644 /var/www/html/centos8_ks.cfg
[root@wenzi ~]# mkdir /var/www/html/centos/8 -p
[root@wenzi ~]# mount /dev/cdrom /var/www/html/centos/8/
[root@wenzi ~]# ll /var/www/html/
total 4
drwxr-xr-x 3 root root   15 Aug 13 10:56 centos
-rw-r--r-- 1 root root 1719 Aug 13 17:11 centos8_ks.cfg
[root@wenzi ~]# systemctl restart httpd

Access the test via browser

Transfer the boot.iso to the physical machine, create a new virtual machine, use the boot.iso, select the first Auto Install Centos Linux 8, and wait for the login interface to appear after the installation is complete.

Guess you like

Origin blog.csdn.net/qq_40875048/article/details/132047957