hashicorp / packer-plugin-qemu

Packer plugin for QEMU Builder
https://www.packer.io/docs/builders/qemu
Mozilla Public License 2.0
63 stars 44 forks source link

Packer Qemu Rocky9 ssh connection refused #126

Open hc-github-team-packer opened 1 year ago

hc-github-team-packer commented 1 year ago

This issue was originally opened by @sreekanth-ragi in https://github.com/hashicorp/packer/issues/12125 and has been migrated to this repository. The original issue description is below.


Packer Version: 1.8.4 QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.40) Rocky-9.0-20220808.0-x86_64-dvd.iso

Trying to build Rocky 9 image using ISO with static IP assignment, but getting issues with packer not being able to SSH into the guest VM. I can login to the guest VM directly by using VNC.

If do not provide the flags for net configuration, then everything is working fine. I want to understand if the process I'm following to assign the gues VM with a specific IP Address is correct or am I missing additional steps that would make this work.

"builders": [
    {
      "accelerator": "kvm",
      "boot_command": [
            "<esc><wait>",
            "vmlinuz initrd=initrd.img ",
            "<wait10><tab>linux inst.sshd inst.ks=hd:/dev/sr1:ks.cfg<enter>"
      ],
      "cd_files": ["ks.cfg"],
      "cd_label": "OEMDRV",
      "boot_wait": "30s",
      "cpus": 2,
      "disk_interface": "virtio",
      "disk_size": "100G",
      "format": "raw",
      "headless": true,
      "http_directory": "./rocky9",
      "iso_checksum": "<shavalue>",
      "iso_url": "Rocky-9.0-20220808.0-x86_64-dvd.iso",
      "memory": 8096,
      "output_directory": "az_images_cis/Rocky9",
      "shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
      "ssh_password": "<password>",
      "ssh_port": 22,
      "ssh_timeout": "30m",
      "ssh_username": "<ssh user>",
      "type": "qemu",
      "vm_name": "rocky9",
      "qemuargs": [
                    ["-cpu", "host"],
                    ["-netdev", "user,id=user.0,",
                     "hostfwd=tcp:127.0.0.1:4406-:22,",
                     "net=10.210.240.0/24,",
                     "dhcpstart=10.210.240.9",
                     ""
                    ],
                    ["-device", "virtio-net,netdev=user.0"]
                  ]

    }

Seeing the following error.

022/11/22 18:32:50 packer-builder-qemu plugin: Sending char ':', code 0x3A, shift true
2022/11/22 18:32:51 packer-builder-qemu plugin: Sending char 'k', code 0x6B, shift false
2022/11/22 18:32:51 packer-builder-qemu plugin: Sending char 's', code 0x73, shift false
2022/11/22 18:32:51 packer-builder-qemu plugin: Sending char '.', code 0x2E, shift false
2022/11/22 18:32:51 packer-builder-qemu plugin: Sending char 'c', code 0x63, shift false
2022/11/22 18:32:52 packer-builder-qemu plugin: Sending char 'f', code 0x66, shift false
2022/11/22 18:32:52 packer-builder-qemu plugin: Sending char 'g', code 0x67, shift false
2022/11/22 18:32:52 packer-builder-qemu plugin: Special code '<enter>' found, replacing with: 0xFF0D
    qemu: Not using a NetBridge -- skipping StepWaitGuestAddress
==> qemu: Using SSH communicator to connect: 127.0.0.1
2022/11/22 18:32:52 packer-builder-qemu plugin: [INFO] Waiting for SSH, up to timeout: 30m0s
==> qemu: Waiting for SSH to become available...
2022/11/22 18:32:52 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:32:57 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:02 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:07 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:12 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:17 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:22 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:27 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:32 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:37 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:42 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:47 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:52 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:33:57 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: connect: connection refused
2022/11/22 18:34:02 packer-builder-qemu plugin: [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:4293: 

Thanks in Advance for the help.

Sreekanth

kebairia commented 1 year ago

any updates on this issue, please?? I'm facing the same issue with RockyLinux9.1.

wim-vandijck-sp commented 1 year ago

I am seeing the same, using a Debian iso, on Apple ARM (From the bento repo). Packer : 1.8.6 qemu-system-aarch64 : QEMU emulator version 7.2.1

Full command :

PACKER_LOG=1  PYTHONPATH=/Library/Frameworks/ParallelsVirtualizationSDK.framework/Versions/10/Libraries/Python/3.7 packer build -only=qemu.vm -var-file=os_pkrvars/debian/debian-11-aarch64.pkrvars.hcl -var "qemu_accelerator=hvf" ./packer_templates

From debug output :

2023/04/07 14:13:00 [INFO] (telemetry) Starting builder qemu.vm
2023/04/07 14:13:00 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:00 Qemu path: /opt/homebrew/bin/qemu-system-aarch64, Qemu Image path: /opt/homebrew/bin/qemu-img
==> qemu.vm: Retrieving ISO
==> qemu.vm: Trying https://cdimage.debian.org/debian-cd/current/arm64/iso-dvd/debian-11.6.0-arm64-DVD-1.iso
2023/04/07 14:13:00 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:00 Acquiring lock for: https://cdimage.debian.org/debian-cd/current/arm64/iso-dvd/debian-11.6.0-arm64-DVD-1.iso?checksum=sha256%3Ab27ff768c10808518790d72d670c5588cdc60cf8934ef92773a89274a193a65f (/Users/wim.vandijck/.cache/packer/e4335719c1f02152968cbf9251bd3ad250b0f44f.iso.lock)
==> qemu.vm: Trying https://cdimage.debian.org/debian-cd/current/arm64/iso-dvd/debian-11.6.0-arm64-DVD-1.iso?checksum=sha256%3Ab27ff768c10808518790d72d670c5588cdc60cf8934ef92773a89274a193a65f
2023/04/07 14:13:03 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:03 Leaving retrieve loop for ISO
==> qemu.vm: https://cdimage.debian.org/debian-cd/current/arm64/iso-dvd/debian-11.6.0-arm64-DVD-1.iso?checksum=sha256%3Ab27ff768c10808518790d72d670c5588cdc60cf8934ef92773a89274a193a65f => /Users/wim.vandijck/.cache/packer/e4335719c1f02152968cbf9251bd3ad250b0f44f.iso
2023/04/07 14:13:03 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:03 No floppy files specified. Floppy disk will not be made.
2023/04/07 14:13:03 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:03 No CD files specified. CD disk will not be made.
==> qemu.vm: Copying hard drive...
2023/04/07 14:13:03 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:03 Executing qemu-img: []string{"convert", "-O", "qcow2", "/Users/wim.vandijck/.cache/packer/e4335719c1f02152968cbf9251bd3ad250b0f44f.iso", "builds/packer-debian-11.6-aarch64-qemu/debian-11.6-aarch64"}
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 stdout:
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 stderr:
==> qemu.vm: Resizing hard drive...
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Executing qemu-img: []string{"resize", "-f", "qcow2", "builds/packer-debian-11.6-aarch64-qemu/debian-11.6-aarch64", "65536M"}
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 stdout: Image resized.
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 stderr:
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Found available port: 8233 on IP: 0.0.0.0
==> qemu.vm: Starting HTTP server on port 8233
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Looking for available communicator (SSH, WinRM, etc) port between 2222 and 4444
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Found available port: 2747 on IP: 127.0.0.1
==> qemu.vm: Found port for communicator (SSH, WinRM, etc): 2747.
==> qemu.vm: Looking for available port between 5900 and 6000 on 127.0.0.1
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Looking for available port between 5900 and 6000 on 127.0.0.1
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Found available port: 5935 on IP: 127.0.0.1
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Found available VNC port: 5935 on IP: 127.0.0.1
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Qemu --version output: QEMU emulator version 7.2.1
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Qemu version: 7.2.1
==> qemu.vm: Starting VM, booting disk image
    qemu.vm: The VM will be run headless, without a GUI. If you want to
    qemu.vm: view the screen of the VM, connect via VNC without a password to
    qemu.vm: vnc://127.0.0.1:5935
    qemu.vm: view the screen of the VM, connect via VNC without a password to
    qemu.vm: vnc://127.0.0.1:5935
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Qemu Builder has no floppy files, not attaching a floppy.
==> qemu.vm: Overriding default Qemu arguments with qemuargs template option...
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Executing /opt/homebrew/bin/qemu-system-aarch64: []string{"-smp", "2", "-device", "virtio-net,netdev=user.0", "-drive", "file=builds/packer-debian-11.6-aarch64-qemu/debian-11.6-aarch64,if=virtio,cache=writeback,discard=ignore,format=qcow2", "-vnc", "127.0.0.1:35", "-name", "debian-11.6-aarch64", "-netdev", "user,id=user.0,hostfwd=tcp::2747-:22", "-machine", "type=virt,accel=hvf", "-m", "2048M", "-boot", "strict=off"}
2023/04/07 14:13:06 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:06 Started Qemu. Pid: 9283
==> qemu.vm: Waiting 10s for boot...
==> qemu.vm: Connecting to VM via VNC (127.0.0.1:5935)
2023/04/07 14:13:18 packer-plugin-qemu_v1.0.9_x5.0_darwin_arm64 plugin: 2023/04/07 14:13:18 Connected to VNC desktop: QEMU (debian-11.6-aarch64)
==> qemu.vm: Typing the boot commands over VNC...

When I connect to the VNC, I see the QEmu monitor prompt. Then I see the boot command being typed, but this clearly isn't the boot prompt from the booted ISO.

aakondakov commented 1 year ago

Hi, you can try to change the qemuargs block as mentioned in the documentation https://developer.hashicorp.com/packer/plugins/builders/qemu#qemuargs

"qemuargs": [
              ["-cpu", "host"],
              ["-netdev", "user,id=user.0,",
               "hostfwd=tcp::{{ .SSHHostPort }}-:22,",
               "net=10.210.240.0/24,",
               "dhcpstart=10.210.240.9",
               ""
              ],
              ["-device", "virtio-net,netdev=user.0"]
            ]