Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packer - can't lock file '/var/lock/qemu-server/lock- #290

Open
steveDecot opened this issue Oct 12, 2024 · 5 comments
Open

Packer - can't lock file '/var/lock/qemu-server/lock- #290

steveDecot opened this issue Oct 12, 2024 · 5 comments
Labels

Comments

@steveDecot
Copy link

Hi everyone !

I' ve issues with packer and my proxmox cluster.

I would like create a Rocky Linux 9.4 template for starting. After that the idea is to use Terraform with this template.
I'm stuck on packer step.
This is the permissions through my token

Code:

pveum acl list | grep -i "packergrp"
/      | Administrator | group | packergrp | 1 |

My packer version
Code:

packer --version
Packer v1.11.2


Packer use the token for user "packer" who is member of "packergrp" .
This is my hcl code

Code:

packer {
  required_plugins {
    proxmox = {
      version = ">= 1.2.1"
      source  = "github.com/hashicorp/proxmox"
    }
  }
}

variable "proxmox_api_url" {
  type = string
}

variable "proxmox_api_token_id" {
  type = string
}

variable "proxmox_api_token_secret" {
  type = string
  sensitive = true
}

variable "ssh_username" {
  type = string
}

variable "ssh_password" {
  type = string
}



source "proxmox" "rocky-linux" {
  proxmox_url               = "${var.proxmox_api_url}"
  username                  = "${var.proxmox_api_token_id}"
  token                     = "${var.proxmox_api_token_secret}"
  insecure_skip_tls_verify  = true

  node                      = "proxmoxve"
  vm_name                   = "rocky-linux-with-ks"
  template_description      = "Rocky Linux avec KS.cfg"

  iso_file                  = "local:iso/Rocky-9.4-x86_64-minimal.iso"
  iso_storage_pool          = "local"
  unmount_iso               = true
  qemu_agent                = true

  scsi_controller           = "virtio-scsi-single"
  cores                     = "4"
  sockets                   = "2"
  memory                    = "4096"

  cpu_type                  = "host"    # CPU type host
  bios                      = "seabios" # SeaBIOS

  disks {
    disk_size               = "20G"
    format                  = "raw"
    storage_pool            = "local-lvm"
    type                    = "scsi"
    io_thread                = true  
  }

  network_adapters {
    model                   = "virtio"
    bridge                  = "vmbr0"
    firewall                = "false"
  }

  boot_command = [  
    "<tab><bs><bs><bs><bs><bs>text nomodeset noapic acpi=off inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
  ]
#"boot_command": "<tab> inst.text inst.ks=https://raw.githubusercontent.com/xxx/xxx/xxx/centos-7.cfg <enter><wait>",
  boot                      = "c"
  boot_wait                 = "15s"
  communicator              = "ssh"

  http_directory            = "./http"  
  http_port_min             = 8098
  http_port_max             = 8098

  ssh_username              = "${var.ssh_username}"
  ssh_password              = "${var.ssh_password}"

  ssh_timeout               = "30m"
  ssh_pty                   = true
  ssh_handshake_attempts    = 15
}

build {
  name    = "rocky-linux-with-ks"
  sources = [
    "source.proxmox.rocky-linux"
  ]
}

I've my kickstart file in http dir and my variables.pkvars.hcl.
Everything is fine exept at the end, especially on stopping VM for create the template.

On pve side I've this

Code:

trying to acquire lock...
TASK ERROR: can't lock file '/var/lock/qemu-server/lock-104.conf' - got timeout

and on packer side

Code:

rocky-linux-with-ks.proxmox.rocky-linux: output will be in this color.

==> rocky-linux-with-ks.proxmox.rocky-linux: Creating VM
==> rocky-linux-with-ks.proxmox.rocky-linux: No VM ID given, getting next free from Proxmox
==> rocky-linux-with-ks.proxmox.rocky-linux: Starting VM
==> rocky-linux-with-ks.proxmox.rocky-linux: Starting HTTP server on port 8098
==> rocky-linux-with-ks.proxmox.rocky-linux: Waiting 15s for boot
==> rocky-linux-with-ks.proxmox.rocky-linux: Typing the boot command
==> rocky-linux-with-ks.proxmox.rocky-linux: Waiting for SSH to become available...
==> rocky-linux-with-ks.proxmox.rocky-linux: Connected to SSH!
==> rocky-linux-with-ks.proxmox.rocky-linux: Stopping VM
==> rocky-linux-with-ks.proxmox.rocky-linux: Error converting VM to template, could not stop: VM quit/powerdown failed
==> rocky-linux-with-ks.proxmox.rocky-linux: Provisioning step had errors: Running the cleanup provisioner, if present...
==> rocky-linux-with-ks.proxmox.rocky-linux: Stopping VM
==> rocky-linux-with-ks.proxmox.rocky-linux: Deleting VM
Build 'rocky-linux-with-ks.proxmox.rocky-linux' errored after 8 minutes 13 seconds: Error converting VM to template, could not stop: VM quit/powerdown failed

I tried

To use a different id : same issue
To update my repo on packer : same
When I tested the code, I had some issues and I stopped many time the code ( CTRL + C ) and the machines have been poweroff, even if my linux work .

I think the problem is on the templating phase.
I check the new version of code here : https://github.com/hashicorp/packer-plugin-proxmox/blob/main/docs/builders/iso.mdx . But elements are missing ( like
iso_storage_pool , umount_iso ... )
Do you have any ideas please ?

@steveDecot
Copy link
Author

Anyone can help me please ?

@mpywell
Copy link
Contributor

mpywell commented Oct 21, 2024

@steveDecot this could be that the QEMU agent (package qemu-guest-agent) isn't installed and running on the build guest. VM shutdowns in Proxmox rely on the agent to initiate a soft shutdown of the OS rather than a Power Off (hard stop).

A Ctrl+C during a packer build executes a Power Off (hard stop) which doesn't wait for the OS to signal that it's shut down.

@steveDecot
Copy link
Author

@mpywell Hi ! Thx for answer me ! :) I've this on my ks file

`%post
dnf install -y qemu-guest-agent
systemctl enable qemu-guest-agent
%end

Reboot after the installation is complete.

--eject attempt to eject the media before rebooting.

reboot --eject`

The machine reboot correctly and I check the logs

2024/10/18 21:25:35 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:25:35 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running 2024/10/18 21:25:40 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:25:40 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running 2024/10/18 21:25:45 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:25:45 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running 2024/10/18 21:25:50 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:25:50 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running 2024/10/18 21:25:55 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:25:55 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running 2024/10/18 21:26:00 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:26:00 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running 2024/10/18 21:26:05 ui error: Cancelling build after receiving interrupt 2024/10/18 21:26:05 Cancelling builder after context cancellation context canceled 2024/10/18 21:26:05 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:26:05 Received interrupt signal (count: 1). Ignoring. 2024/10/18 21:26:05 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:26:05 [WARN] Interrupt detected, quitting waiting for SSH. 2024/10/18 21:26:05 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/10/18 21:26:05 [DEBUG] SSH wait cancelled. Exiting loop. 2024/10/18 21:26:05 ui: ==> rocky-linux-with-ks.proxmox.rocky-linux: Stopping VM 2024/10/18 21:26:07 ui: ==> rocky-linux-with-ks.proxmox.rocky-linux: Deleting VM 2024/10/18 21:26:09 [INFO] (telemetry) ending proxmox.rocky-linux 2024/10/18 21:26:09 ui error: Build 'rocky-linux-with-ks.proxmox.rocky-linux' errored after 18 minutes 6 seconds: build was cancelled 2024/10/18 21:26:09 ui: ==> Wait completed after 18 minutes 6 seconds

I think it's my nic card is not correctly enabled or qemu issues .

I will try and tell you

@steveDecot
Copy link
Author

So I tried, qemu was installed through ksfile.cfg correctly.
I've this
`
rocky-linux-with-ks.proxmox.rocky-linux: output will be in this color.

==> rocky-linux-with-ks.proxmox.rocky-linux: Creating VM
==> rocky-linux-with-ks.proxmox.rocky-linux: No VM ID given, getting next free from Proxmox
==> rocky-linux-with-ks.proxmox.rocky-linux: Starting VM
==> rocky-linux-with-ks.proxmox.rocky-linux: Starting HTTP server on port 8098
==> rocky-linux-with-ks.proxmox.rocky-linux: Waiting 1m0s for boot
==> rocky-linux-with-ks.proxmox.rocky-linux: Typing the boot command
==> rocky-linux-with-ks.proxmox.rocky-linux: Waiting for SSH to become available...
==> rocky-linux-with-ks.proxmox.rocky-linux: Connected to SSH!
==> rocky-linux-with-ks.proxmox.rocky-linux: Stopping VM
==> rocky-linux-with-ks.proxmox.rocky-linux: Error converting VM to template, could not stop: can't lock file '/var/lock/qemu-server/lock-104.conf' - got timeout
==> rocky-linux-with-ks.proxmox.rocky-linux: Provisioning step had errors: Running the cleanup provisioner, if present...
==> rocky-linux-with-ks.proxmox.rocky-linux: Stopping VM
==> rocky-linux-with-ks.proxmox.rocky-linux: Error stopping VM. Please stop and delete it manually: can't lock file '/var/lock/qemu-server/lock-104.conf' - got timeout
Build 'rocky-linux-with-ks.proxmox.rocky-linux' errored after 18 minutes 16 seconds: Error converting VM to template, could not stop: can't lock file '/var/lock/qemu-server/lock-104.conf' - got timeout

==> Wait completed after 18 minutes 16 seconds

==> Some builds didn't complete successfully and had errors:
--> rocky-linux-with-ks.proxmox.rocky-linux: Error converting VM to template, could not stop: can't lock file '/var/lock/qemu-server/lock-104.conf' - got timeout

==> Builds finished but no artifacts were created.`

Same error.
Qemu seems ok. Why I've this lock file ?
From console remote, I see this
capture

@steveDecot
Copy link
Author

Hi !

I found the problem,

In my ks.cfg file, I disable acpi ! --> acpi=off

This command create my issue, even the shutdown command was stuck in the same way than packer

I remove them and it's work fine !

Have nice day !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants