简体   繁体   English

用于在KVM上部署来宾的构建挂起

[英]Build to deploy guest on KVM hangs

I'm using Jenkins to automate the deploy of a virtual appliance. 我正在使用Jenkins自动化虚拟设备的部署。 The first step is to build a standard CentOS 7 minimal vm in KVM. 第一步是在KVM中构建标准的CentOS 7最低vm。 I wrote a short bash script to do this task which works when running locally on the KVM machine: 我编写了一个简短的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 address i have changed for the purposes of security) (出于安全考虑,我更改了IP地址)

The ISO and the kickstart file are stored on another server and they can both be accessed via http for the purposes of making this script work. ISO和kickstart文件存储在另一台服务器上,为了使此脚本正常工作,都可以通过http访问它们。 To be clear, the script does work. 需要明确的是,脚本确实可以工作。

The problem I have is, when I put this script into Jenkins as a build step, the script works; 我的问题是,当我将此脚本作为构建步骤放入Jenkins时,该脚本有效; however, it hangs at the end after the OS has been installed and the kvm guest begins the shutdown process. 但是,在安装完操作系统并且kvm guest虚拟机开始关闭过程之后,它会挂起。

here is the kickstart file: 这是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

I suspect it's something to do with the shutdown option in the Kickstart file but unsure. 我怀疑这与Kickstart文件中的shutdown选项有关,但不确定。 When I ssh to the kvm server, I can see my newly created vm so the script does work but Jenkins hangs. 当我SSH到kvm服务器时,可以看到我新创建的vm,因此脚本可以正常工作,但是Jenkins挂起。

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

So far I have tried shutdown, reboot and obviously halt is default in the kickstart file and they have not worked for me either. 到目前为止,我已尝试关闭,重新启动,并且在kickstart文件中显然默认为停止,它们对我也不起作用。

Any ideas how I can get the build to complete successfully? 有什么想法可以使构建成功完成吗? If it hangs, I can't move on to what will be build step number 2. 如果挂起,我将无法继续进行第2步构建。

Help please :-) 请帮助 :-)

Ok so I managed to figure out what the issue was. 好的,所以我设法弄清楚了问题所在。 The issue was nothing to do with Jenkins or the script but rather to do with the kickstart file. 问题与Jenkins或脚本无关,而与kickstart文件有关。 In a nutshell, I was editing the wrong kickstart file. 简而言之,我正在编辑错误的kickstart文件。 The file i was editing was the default kickstart file in the /root/ directory but that is not the same file that was being injected into memory by the script so the changes I made were having no effect. 我正在编辑的文件是/ root /目录中的默认kickstart文件,但是该脚本注入的文件与该文件不同,因此所做的更改没有任何效果。

Note to self - just because the script works, does not mean the answer to the problem isn't written in the script. 自我注意-仅仅因为脚本有效,并不意味着问题的答案没有写在脚本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM