Linux-kickstart无人值守安装Linux

kickstart是种无人职守安装方式,工作原理是通过记录安装过程中所需人工干预填写的各种参数,并生成ks.cfg文件,在其后安装过程中出现所需填写的参数时,程序会首先查找kickstart生成的文件,找到相应的参数。

安装kickstart

[root@foundation80 html]# yum install system-config-kickstart -y            ##首先我们需要安装kickstart
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package system-config-kickstart.noarch 0:2.9.6-1.el7 will be installed
--> Processing Dependency: system-config-keyboard >= 1.3.1 for package: system-config-kickstart-2.9.6-1.el7.noarch
--> Processing Dependency: system-config-date for package: system-config-kickstart-2.9.6-1.el7.noarch
--> Processing Dependency: system-config-language for package: system-config-kickstart-2.9.6-1.el7.noarch
--> Running transaction check
---> Package system-config-date.noarch 0:1.10.6-2.el7 will be installed
--> Processing Dependency: system-config-date-docs for package: system-config-date-1.10.6-2.el7.noarch
---> Package system-config-keyboard.noarch 0:1.4.0-4.el7 will be installed
--> Processing Dependency: system-config-keyboard-base = 1.4.0-4.el7 for package: system-config-keyboard-1.4.0-4.el7.noarch
---> Package system-config-language.noarch 0:1.4.0-7.el7 will be installed
--> Running transaction check
---> Package system-config-date-docs.noarch 0:1.0.11-4.el7 will be installed
---> Package system-config-keyboard-base.noarch 0:1.4.0-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                         Arch       Version           Repository   Size
================================================================================
Installing:
 system-config-kickstart         noarch     2.9.6-1.el7       RHEL7.3     352 k
Installing for dependencies:
 system-config-date              noarch     1.10.6-2.el7      RHEL7.3     619 k
 system-config-date-docs         noarch     1.0.11-4.el7      RHEL7.3     527 k
 system-config-keyboard          noarch     1.4.0-4.el7       RHEL7.3      33 k
 system-config-keyboard-base     noarch     1.4.0-4.el7       RHEL7.3     103 k
 system-config-language          noarch     1.4.0-7.el7       RHEL7.3     132 k

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

Total download size: 1.7 M
Installed size: 6.4 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               30 MB/s | 1.7 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : system-config-date-1.10.6-2.el7.noarch                       1/6 
  Installing : system-config-date-docs-1.0.11-4.el7.noarch                  2/6 
  Installing : system-config-keyboard-base-1.4.0-4.el7.noarch               3/6 
  Installing : system-config-keyboard-1.4.0-4.el7.noarch                    4/6 
  Installing : system-config-language-1.4.0-7.el7.noarch                    5/6 
  Installing : system-config-kickstart-2.9.6-1.el7.noarch                   6/6 
  Verifying  : system-config-kickstart-2.9.6-1.el7.noarch                   1/6 
  Verifying  : system-config-language-1.4.0-7.el7.noarch                    2/6 
  Verifying  : system-config-date-docs-1.0.11-4.el7.noarch                  3/6 
  Verifying  : system-config-keyboard-1.4.0-4.el7.noarch                    4/6 
  Verifying  : system-config-date-1.10.6-2.el7.noarch                       5/6 
  Verifying  : system-config-keyboard-base-1.4.0-4.el7.noarch               6/6 

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

Dependency Installed:
  system-config-date.noarch 0:1.10.6-2.el7                                      
  system-config-date-docs.noarch 0:1.0.11-4.el7                                 
  system-config-keyboard.noarch 0:1.4.0-4.el7                                   
  system-config-keyboard-base.noarch 0:1.4.0-4.el7                              
  system-config-language.noarch 0:1.4.0-7.el7                                   

Complete!

安装成功后,执行system-config-kickstart


Basic Configuration:基本设置,填写一些基本信息,如默认语言、键盘、时区、root用户密码等信息。

Installation Method:配置安装方式和安装源

Boot Loader Options:配置引导信息

Partition Iformation:配置分区信息

Network Configuration:配置网络信息

Authentication:配置认证信息

Firewall Configuration:配置防火墙

Display Configuration:配置显示信息

Package Selection:配置安装、Pre-Installation Script|Post-Installation Script:安装前和安装后执行的操作

配置完成后保存至网络共享位置:

[root@foundation80 html]# cat /var/www/html/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$goqpM5v/$g.GiBuVPjws5X/KYyy59O.
# Use network installation
url --url="http://172.25.254.80/rhel7.3"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=eth0
# 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 --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part swap --fstype="swap" --size=512
part / --fstype="xfs" --grow --size=1

####以下是手动添加的内容####
##安装内容##
%packages
@base                ##基本包
%end
##自动更改yum源
%post
cat >> /etc/yum.repos.d/yum.repo << EOF
[rhel7.3]
name=rhel7.3
baseurl=http://172.25.254.80/rhel7.3
gpgcheck=0
EOF
%end

脚本编写完成,结合一个虚拟机创建脚本来测试ks.cfg文件

[root@foundation80 ~]# cat vm-create.sh             ##查看脚本内容
#!/bin/bash
virt-install \
--ram 1024 \
--cpus 1 \
--disk /vms/$1.qcow2,size=10,bus=virtio \
--name $1 \
--location http://172.25.254.80/rhel7.3 \
--extra-args "ks=http://172.25.254.80/ks.cfg" &
[root@foundation80 ~]# ./vm-create.sh test         ##执行脚本创建虚拟机test

自动创建虚拟机进行安装,自动选择安装内容



登陆虚拟机,查看yum源,自动设置成功。


猜你喜欢

转载自blog.csdn.net/xin1889/article/details/80188960