Proxmox & Packer:Packer 构建期间 VM 退出/关机失败。有人知道原因吗?

Proxmox & Packer:Packer 构建期间 VM 退出/关机失败。有人知道原因吗?

我正在尝试使用 Packer 创建 Proxmox VM 模板。但是我收到 Proxmox 错误提示Build 'proxmox' errored: Error converting VM to template, could not stop: VM quit/powerdown failed - got timeout

根据 Proxmox GUI,VM 在关机期间会产生此错误(状态错误),但停止时没有问题(状态 OK)。

我已尝试qemu-guest-agent在 Debian 操作系统的预安装中安装并启用它。

我已尝试安装、启动acpidacpi-support预置 Debian 操作系统。

感谢您的时间。我们欢迎您提出任何想法和建议。

这是我正在尝试构建的 Packer 文件:

{
    "builders": [
        {
            "type": "proxmox",
            "proxmox_url": "https://192.111.1.108:8006/api2/json",
            "insecure_skip_tls_verify": true,
            "username": "root@pam",
            "password": "foobar",
            "vm_name": "pm-prov",
            "vm_id": "200",
            "node": "pve",
            "os": "l26",
            "iso_file": "local:iso/debian-10.4.0-amd64-netinst.iso",
            "ssh_username": "root",
            "ssh_password": "foobar",
            "qemu_agent": false,
            "memory": "2048",
            "communicator": "none",
            "scsi_controller": "virtio-scsi-pci",
            "network_adapters": [
                {
                    "model": "virtio",
                    "bridge": "vmbr0"
                }
            ],
            "disks": [
                {
                    "type": "scsi",
                    "disk_size": "32G",
                    "storage_pool": "local-lvm",
                    "storage_pool_type": "lvm"
                }
            ],
            "boot_command": [
                "<esc><wait>",
                "install <wait>",
                "preseed/url=preseed_url <wait>",
                "debian-installer=en_US.UTF-8 <wait>",
                "auto <wait>",
                "locale=en_US.UTF-8 <wait>",
                "kbd-chooser/method=us <wait>",
                "keyboard-configuration/xkb-keymap=us <wait>",
                "netcfg/get_hostname=debian_proxmox_hostname <wait>",
                "netcfg/get_domain=.local <wait>",
                "fb=false <wait>",
                "debconf/frontend=noninteractive <wait>",
                "console-setup/ask_detect=false <wait>",
                "console-keymaps-at/keymap=us <wait>",
                "grub-installer/bootdev=/dev/sda <wait>",
                "<enter><wait>"
            ]
        }
    ]
}

这是正在运行的预配置:

d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select auto
d-i netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Configure network manually
d-i netcfg/get_ipaddress string 192.168.1.42
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 192.168.1.1
d-i netcfg/get_nameservers string 192.168.1.1
d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string debian-proxmox
d-i netcfg/get_domain string localdomain
d-i mirror/country string manual
d-i mirror/http/hostname string http.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i passwd/root-password password foobar500
d-i passwd/root-password-again password foobar500
d-i passwd/user-fullname string ops
d-i passwd/username string ops
d-i passwd/user-password password foobar500
d-i passwd/user-password-again password foobar500
d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern
d-i clock-setup/ntp boolean true
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto-lvm/new_vg_name string debian
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/disk string /dev/sda
d-i partman-auto/choose_recipe select boot-lvm
d-i partman-auto/expert_recipe string               \
    boot-lvm ::                                     \
        500 500 500 ext4                            \
            $primary{ } $bootable{ }                \
            method{ format } format{ }              \
            use_filesystem{ } filesystem{ ext4 }    \
            mountpoint{ /boot }                     \
        .                                           \
        2048 2048 200% linux-swap                   \
            $lvmok{ }                               \
            lv_name{ swap } in_vg { debian }        \
            $primary{ }                             \
            method{ swap } format{ }                \
        .                                           \
        2048 2048 2048 ext4                         \
            $lvmok{ }                               \
            lv_name{ tmp } in_vg { debian }         \
            $primary{ }                             \
            method{ format } format{ }              \
            use_filesystem{ } filesystem{ ext4 }    \
            mountpoint{ /tmp }                      \
        .                                           \
        4000 4096 4096 ext4                         \
            $lvmok{ }                               \
            lv_name{ var_log } in_vg { debian }     \
            $primary{ }                             \
            method{ format } format{ }              \
            use_filesystem{ } filesystem{ ext4 }    \
            mountpoint{ /var/log }                  \
        .                                           \
        8192 8192 -1 ext4                           \
            $lvmok{ }                               \
            lv_name{ root } in_vg { debian }        \
            $primary{ }                             \
            method{ format } format{ }              \
            use_filesystem{ } filesystem{ ext4 }    \
            mountpoint{ / }                         \
        .
d-i partman-md/device_remove_md boolean true
d-i partman-basicfilesystems/no_mount_point boolean false
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/cdrom/set-next boolean false   
d-i apt-setup/cdrom/set-failed boolean false
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
tasksel tasksel/first multiselect standard, ssh-server
d-i preseed/late_command string \
  in-target rm -rf /var/lib/apt/lists ; \
  in-target apt-get update ; \
  in-target apt-get -y upgrade ; \
  in-target apt-get install qemu-guest-agent -y ; \
  in-target apt-get install acpid -y ; \
  in-target apt-get install acpi-support -y ; \
  in-target systemctl start acpid ; \
  in-target systemctl start acpi-support ; \
  in-target systemctl enable qemu-guest-agent 
d-i pkgsel/include string htop
d-i pkgsel/upgrade select full-upgrade
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev  string /dev/sda
d-i finish-install/reboot_in_progress note

这是终端中的错误:

2020/06/25 14:35:11 packer-builder-proxmox plugin: [INFO] communicator disabled, will not connect
2020/06/25 14:35:11 packer-builder-proxmox plugin: Unable to load communicator config from state to populate provisionHookData
2020/06/25 14:35:11 packer-builder-proxmox plugin: Running the provision hook
==> proxmox: Stopping VM
2020/06/25 14:38:18 packer-builder-proxmox plugin: Unable to load communicator config from state to populate provisionHookData
==> proxmox: Error converting VM to template, could not stop: VM quit/powerdown failed - got timeout
==> proxmox: Provisioning step had errors: Running the cleanup provisioner, if present...
==> proxmox: Stopping VM
==> proxmox: Deleting VM
2020/06/25 14:38:23 [INFO] (telemetry) ending proxmox
2020/06/25 14:38:23 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2020/06/25 14:38:23 machine readable: proxmox,error []string{"Error converting VM to template, could not stop: VM quit/powerdown failed - got timeout"}
==> Builds finished but no artifacts were created.
Build 'proxmox' errored: Error converting VM to template, could not stop: VM quit/powerdown failed - got timeout
2020/06/25 14:38:23 [INFO] (telemetry) Finalizing.

==> Some builds didn't complete successfully and had errors:
--> proxmox: Error converting VM to template, could not stop: VM quit/powerdown failed - got timeout

==> Builds finished but no artifacts were created.
2020/06/25 14:38:23 waiting for all plugin processes to complete...
2020/06/25 14:38:23 /home/linuxbrew/.linuxbrew/Cellar/packer/1.6.0/bin/packer: plugin process exited

答案1

我遇到了这个确切的错误。如果没有 ,Debian 11 将无法使用 /sbin/shutdown(qemu 客户代理调用)正确关闭dbus

要修复,请将其添加dbus到您的预置文件中(或者无论您在构建期间如何安装软件包):

d-i pkgsel/include string dbus

如果这不是一个选项,您可以使用以下脚本:

#!/bin/sh
# run as root to use qm and pvesh
export PACKER_LOG=1
export PACKER_LOG_PATH="/tmp/packer.log"

if packer build -on-error=abort -var-file="variables.auto.pkrvars.hcl" debian11.pkr.hcl; then
    echo "[+] Successfully built: Debian 11"
else
    echo "[E] Failed to build: Debian 11"
    if tail -20 "${PACKER_LOG_PATH}" | grep 'Error converting VM to template'; then
        echo '[+] Detected failed conversion to template, doing it manually...'
        VMID=$(qm list | grep 'debian-11-x64-server-template running' | awk '{print $1}')
        qm stop $VMID
        pvesh create /nodes/pve/qemu/$VMID/template # Convert to template
        pvesh set /nodes/pve/qemu/$VMID/config --delete ide2 # remove the ISO
    else
        exit 3
    fi
fi

这将检查打包程序日志的最后 20 行,如果它检测到将 VM 转换为模板的错误,则将停止 debian 11 VM,将其转换为模板,并删除磁盘驱动器。

答案2

如果这能有所帮助...我发现 qemu / KVM 构建器存在类似问题。我的问题是安装过程卡住了,显示需要接受的错误。我的解决方案是连接查看器来查看屏幕。在我的情况下,构建器打开一个端口以连接 VNC...

另一项要测试的是增加等待时间,我发现生成最终 iso 需要 1 个多小时。为了加快此过程,请尝试增加内存和 CPU。

问候!

相关内容