【问题标题】:Build to deploy guest on KVM hangs构建以在 KVM 上部署来宾挂起
【发布时间】:2017-09-22 16:36:12
【问题描述】:

我正在使用 Jenkins 自动部署虚拟设备。第一步是在 KVM 中构建一个标准的 CentOS 7 最小 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 时,该脚本有效;但是,在安装完 OS 并且 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。

请帮忙:-)

【问题讨论】:

    标签: bash jenkins centos7 kvm


    【解决方案1】:

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

    自我注意 - 脚本有效,并不意味着问题的答案没有写在脚本中。

    【讨论】:

      猜你喜欢
      • 2021-10-29
      • 2018-01-19
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      相关资源
      最近更新 更多