I am trying to create packer pipeling for Ubuntu 24.04 image(noble-server-cloudimg-amd64.img) and facing an ssh issue

When I run the below scripts with Ubuntu 22.04 image(jammy-server-cloudimg-amd64.img) the packer image gets created successfully,but when I use noble-server-cloudimg-amd64.img image I face the below ssh error.

sabareesraja.rs@sabareesraja:~/packer-pipeline/ubuntu-latest/maas-vm-ubuntu$ PACKER_LOG=1 packer build .
2025/04/28 09:13:57 [INFO] Packer version: 1.12.0 [go1.22.9 linux amd64]
2025/04/28 09:13:57 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2025/04/28 09:13:57 [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/sabareesraja.rs/.packerconfig
2025/04/28 09:13:57 [WARN] Config file doesn't exist: /home/sabareesraja.rs/.packerconfig
2025/04/28 09:13:57 [INFO] Setting cache directory: /home/sabareesraja.rs/.cache/packer
2025/04/28 09:13:57 [TRACE] listing potential installations for <nil> that match "". plugingetter.ListInstallationsOptions{PluginDirectory:"/home/sabareesraja.rs/.config/packer/plugins", BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linux", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc000853080)}}, ReleasesOnly:false}}
2025/04/28 09:13:57 found external [-packer-default-plugin-name- local] provisioner from ansible plugin
2025/04/28 09:13:57 [INFO] found external [-packer-default-plugin-name-] builders from openstack plugin
2025/04/28 09:13:57 plugin "/home/sabareesraja.rs/.config/packer/plugins/github.com/hashicorp/openstack/packer-plugin-openstack_v1.1.1_x5.0_linux_amd64" does not support Protobuf, forcing use of Gob
2025/04/28 09:13:57 [INFO] found external [-packer-default-plugin-name-] builders from qemu plugin
2025/04/28 09:13:57 [TRACE] validateValue: not active for product_version, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for disk_size, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for iso_checksum, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for iso_url, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for ssh_timeout, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for image_name, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for os_version, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for ssh_password, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for ssh_username, so skipping
2025/04/28 09:13:57 [TRACE] validateValue: not active for product_name, so skipping
2025/04/28 09:13:57 [INFO] Starting external plugin /home/sabareesraja.rs/.config/packer/plugins/github.com/hashicorp/qemu/packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 start builder -packer-default-plugin-name-
2025/04/28 09:13:57 Starting plugin: /home/sabareesraja.rs/.config/packer/plugins/github.com/hashicorp/qemu/packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 []string{"/home/sabareesraja.rs/.config/packer/plugins/github.com/hashicorp/qemu/packer-plugin-qemu_v1.1.1_x5.0_linux_amd64", "start", "builder", "-packer-default-plugin-name-"}
2025/04/28 09:13:57 Waiting for RPC address for: /home/sabareesraja.rs/.config/packer/plugins/github.com/hashicorp/qemu/packer-plugin-qemu_v1.1.1_x5.0_linux_amd64
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 Plugin address: unix /tmp/packer-plugin3916646365
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 Waiting for connection...
2025/04/28 09:13:57 Received unix RPC address for /home/sabareesraja.rs/.config/packer/plugins/github.com/hashicorp/qemu/packer-plugin-qemu_v1.1.1_x5.0_linux_amd64: addr is /tmp/packer-plugin3916646365
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 Serving a plugin connection...
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 [TRACE] starting builder -packer-default-plugin-name-
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 [DEBUG] - common: sending ConfigSpec as gob
2025/04/28 09:13:57 [DEBUG] - common: receiving ConfigSpec as gob
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 use detected accelerator: tcg
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 [DEBUG] - common: sending ConfigSpec as gob
2025/04/28 09:13:57 [DEBUG] - common: receiving ConfigSpec as gob
2025/04/28 09:13:57 [INFO] Starting external plugin /usr/bin/packer execute packer-provisioner-shell
2025/04/28 09:13:57 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "execute", "packer-provisioner-shell"}
2025/04/28 09:13:57 Waiting for RPC address for: /usr/bin/packer
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] Packer version: 1.12.0 [go1.22.9 linux amd64]
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/sabareesraja.rs/.packerconfig
2025/04/28 09:13:57 packer-provisioner-shell plugin: [WARN] Config file doesn't exist: /home/sabareesraja.rs/.packerconfig
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] Setting cache directory: /home/sabareesraja.rs/.cache/packer
2025/04/28 09:13:57 packer-provisioner-shell plugin: Plugin address: unix /tmp/packer-plugin2850249268
2025/04/28 09:13:57 packer-provisioner-shell plugin: Waiting for connection...
2025/04/28 09:13:57 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin2850249268
2025/04/28 09:13:57 packer-provisioner-shell plugin: Serving a plugin connection...
2025/04/28 09:13:57 packer-provisioner-shell plugin: [DEBUG] - common: sending ConfigSpec as gob
2025/04/28 09:13:57 [DEBUG] - common: receiving ConfigSpec as gob
2025/04/28 09:13:57 packer-provisioner-shell plugin: [DEBUG] - common: sending ConfigSpec as gob
2025/04/28 09:13:57 [DEBUG] - common: receiving ConfigSpec as gob
2025/04/28 09:13:57 [INFO] Starting external plugin /usr/bin/packer execute packer-provisioner-shell
2025/04/28 09:13:57 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "execute", "packer-provisioner-shell"}
2025/04/28 09:13:57 Waiting for RPC address for: /usr/bin/packer
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] Packer version: 1.12.0 [go1.22.9 linux amd64]
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/sabareesraja.rs/.packerconfig
2025/04/28 09:13:57 packer-provisioner-shell plugin: [WARN] Config file doesn't exist: /home/sabareesraja.rs/.packerconfig
2025/04/28 09:13:57 packer-provisioner-shell plugin: [INFO] Setting cache directory: /home/sabareesraja.rs/.cache/packer
2025/04/28 09:13:57 packer-provisioner-shell plugin: Plugin address: unix /tmp/packer-plugin1012976563
2025/04/28 09:13:57 packer-provisioner-shell plugin: Waiting for connection...
2025/04/28 09:13:57 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin1012976563
2025/04/28 09:13:57 packer-provisioner-shell plugin: Serving a plugin connection...
2025/04/28 09:13:57 packer-provisioner-shell plugin: [DEBUG] - common: sending ConfigSpec as gob
2025/04/28 09:13:57 [DEBUG] - common: receiving ConfigSpec as gob
2025/04/28 09:13:57 packer-provisioner-shell plugin: [DEBUG] - common: sending ConfigSpec as gob
2025/04/28 09:13:57 [DEBUG] - common: receiving ConfigSpec as gob
2025/04/28 09:13:57 Build debug mode: false
qemu.ubuntu_baseimage: output will be in this color.

2025/04/28 09:13:57 Force build: false
2025/04/28 09:13:57 On error:
2025/04/28 09:13:57 Waiting on builds to complete...
2025/04/28 09:13:57 Starting build run: qemu.ubuntu_baseimage
2025/04/28 09:13:57 Running builder: qemu
2025/04/28 09:13:57 [INFO] (telemetry) Starting builder qemu.ubuntu_baseimage
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 Qemu path: /usr/bin/qemu-system-x86_64, Qemu Image path: /usr/bin/qemu-img
==> qemu.ubuntu_baseimage: Retrieving ISO
==> qemu.ubuntu_baseimage: Trying noble-server-cloudimg-amd64.img
2025/04/28 09:13:57 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:13:57 Acquiring lock for: noble-server-cloudimg-amd64.img?checksum=sha256%!A(MISSING)e3a686a3f63eb16c4f2ccd0461b648649b9a561bf30ecf70d70ec64968aae8f7 (/home/sabareesraja.rs/.cache/packer/d004591af4ee0750907139cdb4a8aa13f1dc1dfd.iso.lock)
==> qemu.ubuntu_baseimage: Trying noble-server-cloudimg-amd64.img?checksum=sha256%3Ae3a686a3f63eb16c4f2ccd0461b648649b9a561bf30ecf70d70ec64968aae8f7
==> qemu.ubuntu_baseimage: noble-server-cloudimg-amd64.img?checksum=sha256%3Ae3a686a3f63eb16c4f2ccd0461b648649b9a561bf30ecf70d70ec64968aae8f7 => /home/sabareesraja.rs/packer-pipeline/ubuntu-latest/maas-vm-ubuntu/noble-server-cloudimg-amd64.img
2025/04/28 09:14:00 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:00 Leaving retrieve loop for ISO
2025/04/28 09:14:00 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:00 No floppy files specified. Floppy disk will not be made.
2025/04/28 09:14:00 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:00 No CD files specified. CD disk will not be made.
==> qemu.ubuntu_baseimage: Copying hard drive...
2025/04/28 09:14:00 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:00 Executing qemu-img: []string{"convert", "-O", "qcow2", "/home/sabareesraja.rs/packer-pipeline/ubuntu-latest/maas-vm-ubuntu/noble-server-cloudimg-amd64.img", "output-noble/ubuntu-24.04.qcow2-24.04-ubuntu-1.0.qcow2"}
2025/04/28 09:14:09 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:09 stdout:
2025/04/28 09:14:09 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:09 stderr:
==> qemu.ubuntu_baseimage: Resizing hard drive...
2025/04/28 09:14:09 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:09 Executing qemu-img: []string{"resize", "-f", "qcow2", "output-noble/ubuntu-24.04.qcow2-24.04-ubuntu-1.0.qcow2", "5120M"}
2025/04/28 09:14:10 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:10 stdout: Image resized.
2025/04/28 09:14:10 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:10 stderr:
2025/04/28 09:14:10 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:10 Found available port: 8330 on IP: 0.0.0.0
==> qemu.ubuntu_baseimage: Starting HTTP server on port 8330
2025/04/28 09:14:10 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:10 Looking for available communicator (SSH, WinRM, etc) port between 2222 and 4444
2025/04/28 09:14:10 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:10 Found available port: 2929 on IP: 127.0.0.1
==> qemu.ubuntu_baseimage: Found port for communicator (SSH, WinRM, etc): 2929.
==> qemu.ubuntu_baseimage: Creating temporary RSA SSH key for instance...
==> qemu.ubuntu_baseimage: Looking for available port between 5900 and 6000 on 127.0.0.1
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Looking for available port between 5900 and 6000 on 127.0.0.1
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Found available port: 5912 on IP: 127.0.0.1
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Found available VNC port: 5912 on IP: 127.0.0.1
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Qemu --version output: QEMU emulator version 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.6)
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Qemu version: 8.2.2
==> qemu.ubuntu_baseimage: Starting VM, booting disk image
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Qemu Builder has no floppy files, not attaching a floppy.
==> qemu.ubuntu_baseimage: Overriding default Qemu arguments with qemuargs template option...
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Executing /usr/bin/qemu-system-x86_64: []string{"-vnc", "127.0.0.1:12", "-device", "virtio-scsi-pci,id=scsi0", "-device", "scsi-hd,bus=scsi0.0,drive=drive0", "-device", "virtio-net,netdev=user.0", "-machine", "type=pc,accel=tcg", "-boot", "c", "-name", "ubuntu-24.04.qcow2-24.04-ubuntu-1.0.qcow2", "-netdev", "user,id=user.0,hostfwd=tcp::2929-:22", "-m", "4096M", "-drive", "if=none,file=output-noble/ubuntu-24.04.qcow2-24.04-ubuntu-1.0.qcow2,id=drive0,cache=writeback,discard=unmap,format=qcow2", "-smp", "2", "-smbios", "type=1,serial=ds=nocloud-net;seedfrom=http://10.0.2.2:8330/"}
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Started Qemu. Pid: 128057
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Qemu stderr: [W][49325.217811] pw.conf      | [          conf.c: 1031 try_load_conf()] can't load config client.conf: No such file or directory
2025/04/28 09:14:13 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:14:13 Qemu stderr: [E][49325.218008] pw.conf      | [          conf.c: 1060 pw_conf_load_conf_for_context()] can't load config client.conf: No such file or directory
==> qemu.ubuntu_baseimage: Waiting 2m0s for boot...
==> qemu.ubuntu_baseimage: Connecting to VM via VNC (127.0.0.1:5912)
==> qemu.ubuntu_baseimage: Typing the boot commands over VNC...
2025/04/28 09:16:15 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:16:15 
2025/04/28 09:16:15 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:16:15 [INFO] Attempting SSH connection to 127.0.0.1:2929...
2025/04/28 09:16:15 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:16:15 [DEBUG] reconnecting to TCP connection for SSH
2025/04/28 09:16:15 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:16:15 [DEBUG] handshaking with SSH
2025/04/28 09:16:15 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:16:15 [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:58914->127.0.0.1:2929: read: connection reset by peer
2025/04/28 09:16:22 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:16:22 [INFO] Attempting SSH connection to 127.0.0.1:2929...
2025/04/28 09:16:22 packer-plugin-qemu_v1.1.1_x5.0_linux_amd64 plugin: 2025/04/28 09:16:22

Below are the scripts used,

sabareesraja.rs@sabareesraja:~/packer-pipeline/ubuntu-latest/maas-vm-ubuntu$ cat ubuntu_kvm_baseimage.pkr.hcl
source "qemu" "ubuntu_baseimage" {
  cpus                = "2"
  memory              = "4096"
  format              = "qcow2"
  boot_wait           = "2m"
  ssh_port            = "22"
  disk_discard        = "unmap"
  disk_image          = true
  disk_interface      = "virtio-scsi"
  disk_size           = "5120"
  http_directory      = "cloud-data"
  iso_checksum        = "${var.iso_checksum}"
  iso_url             = "${var.iso_url}"
  qemuargs            = [["-smbios", "type=1,serial=ds=nocloud-net;seedfrom=http://{{ .HTTPIP }}:{{ .HTTPPort }}/"]]
  ssh_password        = "${var.ssh_password}"
  ssh_username        = "${var.ssh_username}"
  ssh_timeout         = "${var.ssh_timeout}"
  shutdown_command    = "sudo /sbin/shutdown -P -h now"
  output_directory    = "output-noble"
  disk_compression    = true
  skip_compaction     = false
  use_default_display = true
  headless            = false
  vm_name             = "${var.image_name}-${var.os_version}-${var.product_name}-${var.product_version}.qcow2"
}

build {
  sources = ["source.qemu.ubuntu_baseimage"]

  provisioner "shell" {
    execute_command = "{{ .Vars }} sudo -E bash '{{ .Path }}'"
    script          = "./cloud-data/user_data.sh"
  }

  provisioner "shell" {
    inline = ["chown -R ubuntu:ubuntu /home/ubuntu/.ansible"]
  }

}
sabareesraja.rs@sabareesraja:~/packer-pipeline/ubuntu-latest/maas-vm-ubuntu$ cat variables.pkr.hcl
variable "disk_size" {
  description = "The size of the hard disk of the VM"
  type        = string
}

variable "iso_checksum" {
  description = "sha256 checksum value of qcow2 image"
  type        = string
}

variable "iso_url" {
  description = "Qcow2 image http URL"
  type        = string
}

variable "ssh_password" {
  description = "Qcow2 image SSH root user password"
  type        = string
  default     = "velocix1"
}

variable "ssh_username" {
  description = "Qcow2 image SSH user name"
  type        = string
  default     = "root"
}

variable "ssh_timeout" {
  description = "The time to wait for SSH to become available"
  type        = string
  default     = "10m"
}

variable "image_name" {
  type = string
}

variable "os_version" {
  type = string
}

variable "product_name" {
  type = string
}

variable "product_version" {
  type = string
}
sabareesraja.rs@sabareesraja:~/packer-pipeline/ubuntu-latest/maas-vm-ubuntu$ cat values.auto.pkrvars.hcl
disk_size        = 8192
iso_url          = "noble-server-cloudimg-amd64.img"
iso_checksum     = "sha256:e3a686a3f63eb16c4f2ccd0461b648649b9a561bf30ecf70d70ec64968aae8f7"
ssh_password     = "velocix1"
ssh_username     = "root"
ssh_timeout      = "10m"
image_name       = "ubuntu-24.04.qcow2"
os_version       = "24.04"
product_name     = "ubuntu"
product_version  = "1.0"

sabareesraja.rs@sabareesraja:~/packer-pipeline/ubuntu-latest/maas-vm-ubuntu$ cat cloud-data/user_data.sh
#!/bin/bash

sed -i "s/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0 /g" /etc/default/grub
update-grub
apt purge telnet rsync -y
apt install -y sshpass genisoimage jq apache2 simplestreams net-tools unzip tcpdump ca-certificates python-is-python3 python3-docker curl gnupg

I tried to use below command

qemu-system-x86_64 \
  -m 4096 \
  -smp 2 \
  -drive file=noble-server-cloudimg-amd64.img,format=qcow2 \
  -net nic -net user,hostfwd=tcp::2222-:22 \
  -nographic

Then connected to the image to check ssh configs(/etc/ssh/sshd_config) and updated below line,

PermitRootLogin yes

Other lines we same as below which did not need any changes,

PasswordAuthentication yes

Port 22

Help me to create the packer image for noble-server-cloudimg-amd64.img. For Ubuntu 22.04 image(jammy-server-cloudimg-amd64.img) image the above scripts are working.