pxe+kickstart无人自动安装系统

一、如何搭建PXE安装服务器(本文操作系统是Centos7)

1.1PXE介绍。

PXE(Preboot Execution Environment)是一种网络启动技术,允许计算机通过网络从远程服务器下载操作系统,并在启动时执行。要搭建PXE服务器,需要完成以下步骤:

  1. 准备一台服务器或PC,安装一个支持PXE的操作系统,如Centos、Ubuntu等。

  2. 配置DHCP服务器,为PXE客户端分配IP地址、网关和DNS服务器等网络配置信息。DHCP服务器还应该为PXE客户端提供PXE启动所需的引导文件(如pxelinux.0等)。

  3. 安装和配置TFTP服务器,用于存储PXE客户端启动时需要下载的操作系统镜像、驱动程序和其他文件。TFTP服务器可以使用开源软件,如tftp-hpa、atftp等。

  4. 下载并配置相应的PXE启动文件,如pxelinux.0和pxelinux.cfg/default等。这些文件将指定PXE客户端需要下载的操作系统镜像文件、内核、initrd等信息。

  5. 将操作系统镜像和相关文件上传到TFTP服务器上的指定目录中,以便PXE客户端能够通过TFTP协议下载它们。

  6. 启动PXE客户端,在BIOS设置中启用PXE启动选项,并将其设置为首选启动选项。

  7. 当PXE客户端启动时,它将从DHCP服务器获取IP地址和PXE启动文件信息,并从TFTP服务器下载操作系统镜像和其他文件。一旦下载完成,PXE客户端将启动操作系统并执行。

1.2安装TFTP服务

[root@localhost ~]# yum -y install tftp-server xinetd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package tftp-server.x86_64 0:5.2-22.el7 will be installed
---> Package xinetd.x86_64 2:2.3.15-14.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                      Arch                    Version                          Repository             Size
===================================================================================================================
Installing:
 tftp-server                  x86_64                  5.2-22.el7                       base                   47 k
 xinetd                       x86_64                  2:2.3.15-14.el7                  base                  128 k

Transaction Summary
===================================================================================================================
  stall  2 Packages

Total download size: 175 k
Installed size: 325 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/tftp-server-5.2-22.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for tftp-server-5.2-22.el7.x86_64.rpm is not installed
(1/2): tftp-server-5.2-22.el7.x86_64.rpm                                                    |  47 kB  00:00:00     
(2/2): xinetd-2.3.15-14.el7.x86_64.rpm                                                      | 128 kB  00:00:00     
-------------------------------------------------------------------------------------------------------------------
Total                                                                              437 kB/s | 175 kB  00:00:00     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-9.2009.1.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:xinetd-2.3.15-14.el7.x86_64                                                                   1/2 
  Installing : tftp-server-5.2-22.el7.x86_64                                                                   2/2 
  Verifying  : tftp-server-5.2-22.el7.x86_64                                                                   1/2 
  Verifying  : 2:xinetd-2.3.15-14.el7.x86_64                                                                   2/2 

Installed:
  tftp-server.x86_64 0:5.2-22.el7                           xinetd.x86_64 2:2.3.15-14.el7                          

Complete!
[root@localhost ~]

1.3配置tftp配置文件,并设置开机自启tftp服务

[root@localhost ~]# vim /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    #关闭(no表示客户机可以多台一起连接,yes表示客户机只能一台一台连接)
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no    #表示开启TFTP服务
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

[root@localhost ~]# systemctl enable --now tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl enable --now xinetd
[root@localhost ~]# 
[root@localhost ~]# 

1.4安装并启动DHCP服务

[root@localhost ~]# yum -y install dhcp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-83.el7.centos.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package             Arch                  Version                                  Repository              Size
=================================================================================================================
Installing:
 dhcp                x86_64                12:4.2.5-83.el7.centos.1                 updates                515 k

Transaction Summary
=================================================================================================================
Install  1 Package

Total download size: 515 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-83.el7.centos.1.x86_64.rpm                                                     | 515 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 12:dhcp-4.2.5-83.el7.centos.1.x86_64                                                          1/1 
  Verifying  : 12:dhcp-4.2.5-83.el7.centos.1.x86_64                                                          1/1 

Installed:
  dhcp.x86_64 12:4.2.5-83.el7.centos.1                                                                           

Complete!

首先将DHCP文件进行备份一下,再修改DHCP配置文件

[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 ~]# 
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf


ddns-update-style none;    #取消注释,禁用 DNS 动态更新


修改47-55行的内容,不需要的则去掉
subnet 192.168.65.0 netmask 255.255.255.0 {   #声明要分配的网段地址
  range 192.168.65.100 192.168.65.200;       #设置地址池
  option routers 192.168.65.1;                #默认网关地址指向TFTP服务器的IP地址
  option domain-name-servers 114.114.114.114; #设置dns
  next-server 192.168.65.130;                 #指定 TFTP 服务器的地址
  filename "pxelinux.0";                      #指定 PXE 引导程序的文件名
}

1.5准备 Linux 内核、初始化镜像文件。首先需要将光盘挂载/mnt目录下

[root@localhost ~]# mount -t iso9660 /dev/sr0 /mnt/images/pxeboot/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  895M     0  895M   0% /dev
tmpfs          tmpfs     910M     0  910M   0% /dev/shm
tmpfs          tmpfs     910M   12M  899M   2% /run
tmpfs          tmpfs     910M     0  910M   0% /sys/fs/cgroup
/dev/sda3      xfs        35G  4.7G   31G  14% /
/dev/sda1      xfs      1014M  183M  832M  18% /boot
tmpfs          tmpfs     182M   44K  182M   1% /run/user/1000
tmpfs          tmpfs     182M     0  182M   0% /run/user/0
/dev/sr0       iso9660   4.5G  4.5G     0 100% /mnt/images/pxeboot
[root@localhost ~]# 
[root@localhost ~]# cd /mnt/images/pxeboot/
[root@localhost pxeboot]# ls
initrd.img  TRANS.TBL  vmlinuz
[root@localhost pxeboot]# cp vmlinuz /var/lib/tftpboot/
[root@localhost pxeboot]# cp initrd.img /var/lib/tftpboot/

1.6准备PXE引导程序,安装syslinux软件包,并复制PXE引导程序到TFTP根目录下

[root@localhost pxeboot]# yum -y install syslinux
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package syslinux.x86_64 0:4.05-15.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                    Arch                     Version                        Repository              Size
=================================================================================================================
Installing:
 syslinux                   x86_64                   4.05-15.el7                    base                   990 k

Transaction Summary
=================================================================================================================
Install  1 Package

Total download size: 990 k
Installed size: 2.3 M
Downloading packages:
syslinux-4.05-15.el7.x86_64.rpm                                                           | 990 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : syslinux-4.05-15.el7.x86_64                                                                   1/1 
  Verifying  : syslinux-4.05-15.el7.x86_64                                                                   1/1 

Installed:
  syslinux.x86_64 0:4.05-15.el7                                                                                  

Complete!
[root@localhost pxeboot]# cd /usr/share/syslinux
[root@localhost syslinux]# ls
[root@localhost syslinux]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost syslinux]# 

1.7安装FTP服务,准备Centos 7的安装源。并设置开机自启FTP服务

[root@localhost syslinux]# yum -y install vsftpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-29.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                 Arch                    Version                          Repository                Size
=================================================================================================================
Installing:
 vsftpd                  x86_64                  3.0.2-29.el7_9                   updates                  173 k

Transaction Summary
=================================================================================================================
Install  1 Package

Total download size: 173 k
Installed size: 353 k
Downloading packages:
vsftpd-3.0.2-29.el7_9.x86_64.rpm                                                          | 173 kB  00:00:00     
  nning transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : vsftpd-3.0.2-29.el7_9.x86_64                                                                  1/1 
  Verifying  : vsftpd-3.0.2-29.el7_9.x86_64                                                                  1/1 

Installed:
  vsftpd.x86_64 0:3.0.2-29.el7_9                                                                                 

Complete!
[root@localhost syslinux]# cd /var/ftp/
[root@localhost ftp]# ls
pub
[root@localhost ftp]# mkdir /var/ftp/centos7    #创建名为centos7的目录
[root@localhost ftp]# ls
centos7  pub
[root@localhost ftp]# cp -r /mnt/* /var/ftp/centos7/    #将操作系统镜像和其他相关文件从安装介质中复制到TFTP服务器上的指定目录,以供PXE客户端进行远程安装操作系统。
[root@localhost ftp]# systemctl enable --now vsftpd     #开机自动ftp服务
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

1.8配置启动菜单文件。默认启动菜单在TFTP根目录下的/pxelinux.cfg目录下        

[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# 
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  vmlinuz
[root@localhost tftpboot]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  pxelinux.cfg  vmlinuz

[root@localhost tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default
default auto            #指定默认入口名称
prompt 1                #设置是否等待用户选择,“1”表示等待用户控制

label auto              #图形安装(默认)引导入口,label 用来定义启动项
kernel vmlinuz          #kernel 和 append用来定义引导参数
append initrd=initrd.img method=ftp://192.168.65.130/centos7

label linux text        #文本安装引导入口,label 用来定义启动项
kernel vmlinuz          #kernel 和 append用来定义引导参数
append text initrd=initrd.img method=ftp://192.168.65.130/centos7

label linux rescue      #救援模式引导入口,label 用来定义启动项
kernel vmlinuz          #kernel 和 append用来定义引导参数
append rescue initrd=initrd.img method=ftp://192.168.65.130/centos7

1.9关闭防火墙和selinux

[root@localhost tftpboot]# systemctl stop firewalld.service 
[root@localhost tftpboot]# setenforce 0

二、Kickstart自动化安装

kickstart具体配置步骤如下

2.1准备安装应答文件

安装system-config-kickstart 工具

[root@localhost ~]# yum install -y system-config-kickstart.noarch
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package system-config-kickstart.noarch 0:2.9.7-1.el7 will be installed
--> Processing Dependency: system-config-keyboard >= 1.3.1 for package: system-config-kickstart-2.9.7-1.el7.noarch
--> Processing Dependency: system-config-language for package: system-config-kickstart-2.9.7-1.el7.noarch
--> Processing Dependency: system-config-date for package: system-config-kickstart-2.9.7-1.el7.noarch
--> Running transaction check
---> Package system-config-date.noarch 0:1.10.6-3.el7.centos will be installed
--> Processing Dependency: system-config-date-docs for package: system-config-date-1.10.6-3.el7.centos.noarch
--> Processing Dependency: gnome-python2-canvas for package: system-config-date-1.10.6-3.el7.centos.noarch
---> Package system-config-keyboard.noarch 0:1.4.0-5.el7 will be installed
--> Processing Dependency: system-config-keyboard-base = 1.4.0-5.el7 for package: system-config-keyboard-1.4.0-5.el7.noarch
---> Package system-config-language.noarch 0:1.4.0-9.el7 will be installed
--> Processing Dependency: usermode-gtk for package: system-config-language-1.4.0-9.el7.noarch
--> Running transaction check
---> Package gnome-python2-canvas.x86_64 0:2.28.1-14.el7 will be installed
--> Processing Dependency: gnome-python2(x86-64) = 2.28.1-14.el7 for package: gnome-python2-canvas-2.28.1-14.el7.x86_64
--> Processing Dependency: libgnomecanvas(x86-64) >= 2.8.0 for package: gnome-python2-canvas-2.28.1-14.el7.x86_64
--> Processing Dependency: libgnomecanvas-2.so.0()(64bit) for package: gnome-python2-canvas-2.28.1-14.el7.x86_64
--> Processing Dependency: libart_lgpl_2.so.2()(64bit) for package: gnome-python2-canvas-2.28.1-14.el7.x86_64
---> Package system-config-date-docs.noarch 0:1.0.11-4.el7 will be installed
--> Processing Dependency: rarian-compat for package: system-config-date-docs-1.0.11-4.el7.noarch
---> Package system-config-keyboard-base.noarch 0:1.4.0-5.el7 will be installed
---> Package usermode-gtk.x86_64 0:1.111-6.el7 will be installed
--> Running transaction check
---> Package gnome-python2.x86_64 0:2.28.1-14.el7 will be installed
---> Package libart_lgpl.x86_64 0:2.3.21-10.el7 will be installed
---> Package libgnomecanvas.x86_64 0:2.30.3-8.el7 will be installed
---> Package rarian-compat.x86_64 0:0.8.1-11.el7 will be installed
--> Processing Dependency: rarian = 0.8.1-11.el7 for package: rarian-compat-0.8.1-11.el7.x86_64
--> Processing Dependency: rarian for package: rarian-compat-0.8.1-11.el7.x86_64
--> Processing Dependency: librarian.so.0()(64bit) for package: rarian-compat-0.8.1-11.el7.x86_64
--> Running transaction check
---> Package rarian.x86_64 0:0.8.1-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                                Arch              Version                          Repository       Size
=================================================================================================================
Installing:
 system-config-kickstart                noarch            2.9.7-1.el7                      base            348 k
Installing for dependencies:
 gnome-python2                          x86_64            2.28.1-14.el7                    base             47 k
 gnome-python2-canvas                   x86_64            2.28.1-14.el7                    base             34 k
 libart_lgpl                            x86_64            2.3.21-10.el7                    base             67 k
 libgnomecanvas                         x86_64            2.30.3-8.el7                     base            226 k
 rarian                                 x86_64            0.8.1-11.el7                     base             98 k
 rarian-compat                          x86_64            0.8.1-11.el7                     base             66 k
 system-config-date                     noarch            1.10.6-3.el7.centos              base            591 k
 system-config-date-docs                noarch            1.0.11-4.el7                     base            527 k
 system-config-keyboard                 noarch            1.4.0-5.el7                      base             33 k
 system-config-keyboard-base            noarch            1.4.0-5.el7                      base            103 k
 system-config-language                 noarch            1.4.0-9.el7                      base            133 k
 usermode-gtk                           x86_64            1.111-6.el7                      base            110 k

Transaction Summary
=================================================================================================================
Install  1 Package (+12 Dependent packages)

Total download size: 2.3 M
Installed size: 8.3 M
Downloading packages:
(1/13): gnome-python2-2.28.1-14.el7.x86_64.rpm                                            |  47 kB  00:00:01     
(2/13): libart_lgpl-2.3.21-10.el7.x86_64.rpm                                              |  67 kB  00:00:01     
(3/13): libgnomecanvas-2.30.3-8.el7.x86_64.rpm                                            | 226 kB  00:00:01     
(4/13): rarian-0.8.1-11.el7.x86_64.rpm                                                    |  98 kB  00:00:00     
(5/13): rarian-compat-0.8.1-11.el7.x86_64.rpm                                             |  66 kB  00:00:00     
(6/13): system-config-keyboard-1.4.0-5.el7.noarch.rpm                                     |  33 kB  00:00:00     
(7/13): system-config-keyboard-base-1.4.0-5.el7.noarch.rpm                                | 103 kB  00:00:00     
(8/13): system-config-date-docs-1.0.11-4.el7.noarch.rpm                                   | 527 kB  00:00:00     
(9/13): system-config-date-1.10.6-3.el7.centos.noarch.rpm                                 | 591 kB  00:00:00     
(10/13): system-config-kickstart-2.9.7-1.el7.noarch.rpm                                   | 348 kB  00:00:00     
(11/13): system-config-language-1.4.0-9.el7.noarch.rpm                                    | 133 kB  00:00:00     
(12/13): usermode-gtk-1.111-6.el7.x86_64.rpm                                              | 110 kB  00:00:00     
(13/13): gnome-python2-canvas-2.28.1-14.el7.x86_64.rpm                                    |  34 kB  00:00:02     
-----------------------------------------------------------------------------------------------------------------
Total                                                                            829 kB/s | 2.3 MB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libart_lgpl-2.3.21-10.el7.x86_64                                                             1/13 
  Installing : libgnomecanvas-2.30.3-8.el7.x86_64                                                           2/13 
  Installing : gnome-python2-2.28.1-14.el7.x86_64                                                           3/13 
  Installing : gnome-python2-canvas-2.28.1-14.el7.x86_64                                                    4/13 
  Installing : usermode-gtk-1.111-6.el7.x86_64                                                              5/13 
  Installing : system-config-language-1.4.0-9.el7.noarch                                                    6/13 
  Installing : rarian-0.8.1-11.el7.x86_64                                                                   7/13 
  Installing : rarian-compat-0.8.1-11.el7.x86_64                                                            8/13 
  Installing : system-config-date-docs-1.0.11-4.el7.noarch                                                  9/13 
  Installing : system-config-date-1.10.6-3.el7.centos.noarch                                               10/13 
  Installing : system-config-keyboard-base-1.4.0-5.el7.noarch                                              11/13 
  Installing : system-config-keyboard-1.4.0-5.el7.noarch                                                   12/13 
  Installing : system-config-kickstart-2.9.7-1.el7.noarch                                                  13/13 
  Verifying  : libgnomecanvas-2.30.3-8.el7.x86_64                                                           1/13 
  Verifying  : system-config-keyboard-base-1.4.0-5.el7.noarch                                               2/13 
  Verifying  : system-config-date-docs-1.0.11-4.el7.noarch                                                  3/13 
  Verifying  : system-config-language-1.4.0-9.el7.noarch                                                    4/13 
  Verifying  : system-config-date-1.10.6-3.el7.centos.noarch                                                5/13 
  Verifying  : system-config-keyboard-1.4.0-5.el7.noarch                                                    6/13 
  Verifying  : system-config-kickstart-2.9.7-1.el7.noarch                                                   7/13 
  Verifying  : gnome-python2-canvas-2.28.1-14.el7.x86_64                                                    8/13 
  Verifying  : rarian-compat-0.8.1-11.el7.x86_64                                                            9/13 
  Verifying  : rarian-0.8.1-11.el7.x86_64                                                                  10/13 
  Verifying  : usermode-gtk-1.111-6.el7.x86_64                                                             11/13 
  Verifying  : libart_lgpl-2.3.21-10.el7.x86_64                                                            12/13 
  Verifying  : gnome-python2-2.28.1-14.el7.x86_64                                                          13/13 

Installed:
  system-config-kickstart.noarch 0:2.9.7-1.el7                                                                   

Dependency Installed:
  gnome-python2.x86_64 0:2.28.1-14.el7                   gnome-python2-canvas.x86_64 0:2.28.1-14.el7            
  libart_lgpl.x86_64 0:2.3.21-10.el7                     libgnomecanvas.x86_64 0:2.30.3-8.el7                   
  rarian.x86_64 0:0.8.1-11.el7                           rarian-compat.x86_64 0:0.8.1-11.el7                    
  system-config-date.noarch 0:1.10.6-3.el7.centos        system-config-date-docs.noarch 0:1.0.11-4.el7          
  system-config-keyboard.noarch 0:1.4.0-5.el7            system-config-keyboard-base.noarch 0:1.4.0-5.el7       
  system-config-language.noarch 0:1.4.0-9.el7            usermode-gtk.x86_64 0:1.111-6.el7                      

Complete!
[root@localhost ~]# 

2.2如何打开Kickstart 配置程序”窗口

在虚拟机中通过桌面菜单“应用程序”–>“系统工具”–>“Kickstart” 打开

或执行 “system-config-kickstart” 命令打开都可

2.2.1第一步:Kickstart 基本配置

(1)默认语言设为“中文(简体)”(也可以选择英文的)

(2)时区设为“Asia/Shanghai”

(3)设置root密码,勾选上给root密码加密

(4)高级配置中勾选“安装后重启”。

2.2.2第二步:Kickstart 安装方法

(1)选择执行全新安装

(2)选FTP;FTP服务器:ftp://192.168.65.130

(3)FTP目录:centos7

2.2.3第三步:引导装载程序选项

(1)安装类型:安装新引导装载程序

(2)GRUB选项:可以理解为启动管理器。可以通过设置GRUB选项来控制系统的启动行为(可设置也可以不设置)
(3)安装选项:在主引导记录(MBR)中安装引导装载程序

2.2.4第四步:分区信息(具体信息根据情况分配)

(1)主引导记录:清除主引导记录
(2)分区:删除所有现存分区
(3)磁盘标签:初始化磁盘标签
(4)布局:添加分区
         挂载点:/boot,文件系统类型:xfs,固定大小:500M(我这边设置的是512M)
         文件系统类型:swap,固定大小:4096M
         挂载点:/,文件系统类型:xfs,使用磁盘上全部未使用空间

添加分区设置

2.2.5第五步:网络配置

(1)添加网络设备:ens33
(2)网络类型设为:DHCP

2.2.6第六步:防火墙配置 

(1)禁用 SELinux

(2)禁用防火墙

2.2.7第七步:安装后脚本

(1)勾选“使用解释程序”:/bin/bash
(2)在下面写入自己的%post脚本
mkdir /etc/yum.repos.d/repo.bak        #创建yum源备份目录mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo.bak        #将yum源文件移动到创建的目录下

#下面是配置YUM 软件包管理器的软件源

  • [local] 表示这个软件源的名称是 local
  • name=local 表示这个软件源的名称是 local
  • baseurl=ftp:///mnt 表示软件源的基本 URL 地址是 ftp:///mnt,这里使用的是 FTP 协议,路径为 /mnt
  • enabled=1 表示启用这个软件源。
  • gpgcheck=0 表示关闭 GPG 检查,即不验证软件包的数字签名。

echo '[local]
name=local
baseurl=ftp:///mnt
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
 

2.2.8第八步:保存自动应答文件

选择“Kickstart 配置程序”窗口的“文件”–>“保存”命令,选择指定保存位置,文件名为ks.cfg 默认保存在/root/ks.cfg

[root@localhost ~]# ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Music     Public     Videos
Desktop          Downloads  ks.cfg                Pictures  Templates
[root@localhost ~]# 

2.2.9第九步:配置需要安装的软件包

将/root/anaconda-ks.cfg 的软件包安装脚本复制到 ks.cfg文件中,只需要复制%packages 到%end 部分即可。
 

[root@localhost ~]# vim anaconda-ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
  Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network  --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $6$0Ut3nftULVcrNOjv$tBjAJPIESQwde84xxNPqWutBTpID2msDgvacRTxB9wqWsp93J7YnSTthL2HH3d2H4.gQuOYQWB
Bo9MCcmeJFN1
# System services
services --enabled="chronyd"
# System timezone
timezone America/New_York --isUtc
# X Window System configuration information
xconfig  --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=1024
part swap --fstype="swap" --ondisk=sda --size=4096
part / --fstype="xfs" --ondisk=sda --size=35839

%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

图形化安装

[root@localhost ~]# vim ks.cfg 
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
  Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="ftp://192.168.65.130/centos7"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=512
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1

%post --interpreter=/bin/bash
mkdir /etc/yum.repos.d/repo.bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo.bak

echo '[local]
name=local
baseurl=ftp:///mnt
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
%end

%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-tool

%end

最小化安装:
vim ksmini.cfg
%packages
@^minimal
%end

[root@localhost ~]# vim ksmini.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$wtvq9Yoe$VSYLDer24MLLE/T1ucBJs/
# System language
lang zh_CN
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="ftp://192.168.65.130/centos7"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=512
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1

%post --interpreter=/bin/bash
mkdir /etc/yum.repos.d/repo.bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo.bak

echo '[local]
name=local
baseurl=ftp:///mnt
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
%end

%packages
@^minimal
%end

最后编辑引导菜单文件 default,添加 ks 引导参数

以上都配置好了之后,新建一个虚拟机进行测试即可!如下自动安装系统后并重启!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值