CentOS自动安装(kickstart)

kickstart

kickstart是红帽发行版中的一种安装方式,它通过以配置文件的方式来记录linux系统安装是的各项参数和想要安装的软件。只要配置正确,整个安装过程中无需人工交互参与,达到无人值守安装的目的。

kickstart配置文件生成

1). 自动化安装系统

yum install system-config-kickstart.noarch -y

2). 安装完成后,执行如下命令启动kickstart

system-config-kickstart 

3). 启动选择配置安装系统的root用户密码,安装方式,案例中使用HTTP方式进行安装

CentOS自动安装(kickstart)

4). 选择bootloader安装方式,清除原硬盘上的所有分区

CentOS自动安装(kickstart)

5). 创建磁盘分区

CentOS自动安装(kickstart)

6). 选择网卡并配置网卡信息

CentOS自动安装(kickstart)

7). 不安装图形界面

CentOS自动安装(kickstart)

8). 保存配置文件

CentOS自动安装(kickstart)

9). 由于没有选择安装包,需要在文件末尾指定需要安装的软件

vim ks.cfg #编辑文件,指定安装过程中需要安装的软件,在文件末尾添加

CentOS自动安装(kickstart)

10). 检测语法是否正确

ksvalidator ks.cfg 


利用生成的配置文件进行自动安装

1). 安装配置Web服务器,使用缺省目录(案例中使用目录/home/www/html), 监听端口为8081

将镜像文件挂载到http://192.168.20.230:8081/CentOS8目录下

[root@h230]#mkdir /home/www/html/CentOS8
[root@h230]#mount  /home/admin/Images/CentOS-7-x86_64-DVD-1810.iso /home/www/html/CentOS8/
mount: /dev/loop0 is write-protected, mounting read-only

2). 开始创建虚拟机并执行自动安装

virt-install 
--connect qemu:///system 
--virt-type kvm 
--name CentOS8 
--vcpus 2,maxvcpus=2 
--ram 4096 
--disk path=/home/admin/VM/CentOS8.qcow2,size=40,format=qcow2,bus=virtio,sparse 
--network bridge=br0,model=virtio 
--nographics 
--location http://192.168.20.230:8081/CentOS8 
--extra-args "ks=http://192.168.20.230:8081/ks.cfg  console=ttyS0" 
--force  
--video=cirrus

#若出现如下错误表示没有将将镜像正确挂载

ERROR Error validating install location: Could not find an installable distribution at 'http://192.168.20.230/CentOS8': The URL could not be accessed, maybe you mistyped?

出现如下错误,则可能是DHCP Server没有正确配置,虚拟机网口起来时没有正确获取到地址所致

Warning: dracut-initqueue timeout - starting timeout scripts


制作kickstart启动镜像

1). 将原始的镜像文件挂载到/home/www/html/CentOS8目录下(需要事先创建该目录)

 mount /home/admin/Images/CentOS-8.1.1911-x86_64-dvd1.iso /home/www/html/CentOS8

2). 创建/home/myiso目录,将镜像文件同步到该目录下

mkdir  /home/myiso
rsync -a /home/www/html/CentOS8/ /home/myiso/

3). 将创建好的ks.cfg文件复制到/home/myiso, 并修改安装方式为cdrom

cp /home/www/html/ks.cfg /home/myiso/ks.cfg
vim  /home/myiso/ks.cfg
#验证ks配置文件正确性
 ksvalidator /home/myiso/ks.cfg 

3). 编辑/home/myiso/isolinux/isolinux.cfg

chmod 777 /home/myiso/isolinux/isolinux.cfg 
vim /home/myiso/isolinux/isolinux.cfg 
增加ks启动项
label ks
  menu label ^kickstart
  menu default
  kernel vmlinuz
  append ks ks=cdrom:/ks.cfg initrd=initrd.img console=ttyS0,115200n8

4). 制作ISO镜像文件

mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 
          --boot-info-table -V "CentOS 6.8 x86_64 boot" 
	        -b isolinux/isolinux.bin -c isolinux/boot.cat 
       	-o /home/CentOS8.kickstart.iso /home/myiso/

5). 使用新的镜像文件安装虚拟机

virt-install 
--connect qemu:///system 
--virt-type kvm 
--name CentOS8.2 
--vcpus 1,maxvcpus=1 
--ram 4096 
--disk path=/home/admin/VM/CentOS8.2.qcow2,size=40,format=qcow2,bus=virtio,sparse 
--network bridge=br1,model=virtio 
--nographics 
--location=/home/CentOS8.kickstart.iso 
--extra-args "console=ttyS0" 
--video=cirrus

#自动启动配置文件内容示例:

#version=RHEL7 Kickstart
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use text mode install
text
# Shutdown after installation
shutdown
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --disable
# ignoredisk --drives="/dev/disk/by-label/CentOSx207x20x8*"
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
#SELinux configuration
selinux --disable
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=static --hostname=localhost.localdomain
# Root password
rootpw 123.com
# Do not configure the X Window System
skipx
# System services
services --disabled="abrtd,atd,chronyd,avahi-daemon,postfix"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
%include /tmp/bootloader.cfg
#autopart --type=lvm
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype=ext4 --size=500
part / --fstype=ext4 --grow --size=2000

%packages 
@base
@core
@php
freeradius
ftp
ntp
perl-core
php-mysql
sqlite-devel
telnet
%end
展开阅读全文

页面更新:2024-03-31

标签:目的   末尾   正确性   示例   网卡   虚拟机   正确   错误   编辑   案例   方式   文件   目录   系统   科技   软件

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top