首页 文章

构建以在KVM挂起上部署guest虚拟机

提问于
浏览
0

我正在使用Jenkins自动部署虚拟设备 . 第一步是在KVM中构建标准的CentOS 7 minimal vm . 我写了一个简短的bash脚本来执行此任务,该任务在KVM机器上本地运行时有效:

#!/bin/bash

#Variables
diskpath="/var/lib/libvirt/images/"
buildname=$(date +"%m-%d-%y-%H-%M")
vmextension=".dsk"

#Change to images directory
cd /var/lib/libvirt/images/

#Deploy VM with with kickstart file
sudo virt-install \
--name=$buildname \
--nographics \
--hvm \
--virt-type=kvm \
--file=$diskpath$buildname$vmextension \
--file-size=20 \
--nonsparse \
--vcpu=2 \
--ram=2048 \
--network bridge=br0 \
--os-type=linux \
--os-variant=generic \
--location=http://0.0.0.0/iso/ \
--initrd-inject /var/lib/libvirt/images/autobuild-ks.cfg \
--extra-args="ks=http://0.0.0.0/ks/autobuild-ks.cfg console=ttyS0"

(出于安全考虑,我已更改IP地址)

ISO和kickstart文件存储在另一台服务器上,并且可以通过http访问它们以使该脚本正常工作 . 要清楚,脚本确实有效 .

我遇到的问题是,当我将这个脚本作为构建步骤放入Jenkins时,脚本可以工作;但是,在安装操作系统并且kvm guest虚拟机开始关闭过程后,它会在最后挂起 .

这是kickstart文件:

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use Network installation media
url --url=http://0.0.0.0/iso
# Use graphical install
#graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=gb --xlayouts='gb'
# System language
lang en_GB.UTF-8

# Network information
network  --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network  --hostname=hostname.domain.com

# Root password
rootpw --iscrypted 
taken_encryption_output_out_for_the_purposes_of_security
#Shutdown after installation
shutdown
# System services
services --enabled="chronyd"
# System timezone
timezone Europe/London --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-
drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel

%packages
@^minimal
@core
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --
notempty
pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --
notempty
pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --
notempty
%end

我怀疑它与Kickstart文件中的关闭选项有关,但不确定 . 当我ssh到kvm服务器时,我可以看到我新创建的vm,所以脚本可以工作,但Jenkins挂起 .

[root@sut-kvm01 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     09-22-17-16-21                 shut off

到目前为止,我已经尝试了关机,重新启动,显然暂停是kickstart文件中的默认设置,它们也没有为我工作 .

我有什么想法可以让构建成功完成?如果它挂起,我无法继续前进到第2步的构建步骤 .

请帮忙 :-)

1 回答

  • 0

    好的,所以我设法找出问题所在 . 这个问题与Jenkins或脚本无关,而是与kickstart文件有关 . 简而言之,我正在编辑错误的kickstart文件 . 我正在编辑的文件是/ root /目录中的默认kickstart文件,但这与脚本注入内存的文件不同,因此我所做的更改没有任何效果 .

    自我注意 - 只是因为脚本有效,并不意味着问题的答案不会写在脚本中 .

相关问题