代码之家  ›  专栏  ›  技术社区  ›  Rob Barnes

构建以在KVM挂起时部署来宾

  •  0
  • Rob Barnes  · 技术社区  · 8 年前

    #!/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客户机开始关闭过程后,它会挂起。

    这是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文件中的shutdown选项有关,但不确定。当我用ssh连接到kvm服务器时,我可以看到我新创建的vm,因此脚本可以工作,但Jenkins挂起了。

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

    到目前为止,我已经尝试过关机、重启,显然,kickstart文件中默认的是暂停,但它们对我也不起作用。

    有什么想法可以让构建成功完成吗?如果它挂起,我就无法继续进行构建步骤2。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Rob Barnes    8 年前

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

    推荐文章