No ssh connection

396 views
Skip to first unread message

Jouni

unread,
Jan 25, 2022, 5:20:33 AM1/25/22
to Packer
Hi, I'm, trying this ubuntu.json

{
  "variables": {
    "serial": ""
  },

  "builders": [
    {
      "accelerator": "kvm",
      "boot_command": [
        "",
        "append console=ttyS0,115200n8 autoinstall ds=no-cloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/user-data",
        "initrd=casper/initrd ",
        "kernel=casper/vmlinuz ",
        ""
      ],
      "boot_wait": "10s",
      "disk_interface": "virtio",
      "disk_size": "50G",
      "disk_cache": "none",
      "disk_compression": true,
      "headless": "true",
      "use_default_display": false,
      "format": "qcow2",
      "http_directory": "./http",
      "iso_checksum": "sha256:f8e3086f3cea0fb3fefb29937ab5ed9d19e767079633960ccb50e76153effc98",
      "iso_urls": [
        "/Scripts/ubuntu-20.04.3-live-server-amd64.iso"
      ],
      "name": "ubuntu-packer1",
      "net_device": "virtio-net",
      "output_directory": "output/ubuntu",
      "shutdown_command": "shutdown -P now",
      "ssh_handshake_attempts": "20",
      "ssh_password": "ubuntu",
      "ssh_timeout": "20m",
      "ssh_username": "ubuntu",
      "type": "qemu",
      "cpus": "1",
      "memory": "1024"
    }
  ],
  "provisioners": [
    {
      "inline": [
        "ls /"
      ],
      "type": "shell"
    }
  ]
}

I'm connected to build host trough ssh without X, so no graphics. I get this into packer.log:
2022/01/25 11:28:02 packer-builder-qemu plugin: [INFO] Attempting SSH connection to 127.0.0.1:3299...
2022/01/25 11:28:02 packer-builder-qemu plugin: [DEBUG] reconnecting to TCP connection for SSH
2022/01/25 11:28:02 packer-builder-qemu plugin: [DEBUG] handshaking with SSH

But there's no ssh available, ssh does not respond from cmd line to 127.0.0.1 -p 3299 either. Kickstart file was generated from manual install I did earlier. I'm newbie with Packer so what I doing wrong here?

Br, Jouni

Edward Cheadle

unread,
Jan 31, 2022, 7:06:25 PM1/31/22
to Packer
In your user-data file, do you have the early and late commands:
#cloud config
autoinstall:
  version: 1
  early-commands:
    - sudo systemctl stop ssh


At the bottom:

late--commands:
- sudo systemctl start ssh


Also is the password encrypted?  I use  $mkpasswd --method=SHA-512 --rounds=4096

These are things I had to do in order to make the ssh connection.

Jouni

unread,
Feb 4, 2022, 3:33:13 AM2/4/22
to Packer
Hi!
T tried to add early-commands and late-commands as you recommended but it did no change behavior, it still freeze into 'Waiting for SSH to become available...' My #cloud-config is created from manual install and yes I have encrypted password. I have connected to build host  with ssh and I don't have X, so I need txt not graphical install and right now I don't see anything that would be related to connection to install iso?

Br, Jouni

Edward Cheadle

unread,
Feb 4, 2022, 4:53:51 PM2/4/22
to Packer
My git repository is https://github.com/echeadle/packer-tpls.git  In it is a folder that has server 2004.  I has the preseed file and the user-data file.   The folder started as a clone from geerlingguy/packer-boxes, but my goal is to change to the HCL2 packer templates.  So it is a mix of the hcl2 files and the new way Ubuntu is doing things.   You might check the boot_command.   I have tried many others, but this one works.   The 21.10 Ubuntu Server folder does not have a preseed file, because they are moving forward to using subiquity.

If you have a git repo maybe I could take a look.  I can't promise anything, I am new to packer, and I have not studied the startup files of servers for several years, so I am just beginning investigating how grub and systemd start up a server.

The biggest problem I am having is the boot_command.   THere is no documetnation and no one ever explains the process they go through to build the boot_command.   I get a lot of examples that don't work.   But if you want to see ones that do work, the Bento github repository is a place that builds a lot of vagrant boxes automaticaly and it is where I found the boot_command that worked with 21.10.

Edward Cheadle

unread,
Feb 4, 2022, 4:57:49 PM2/4/22
to Packer
THis is my boot command.  You might try putting the line linux /casper/vmlinux quiet<wait> before the autoinstall line.
boot_command      =  [
                " <wait>",
                " <wait>",
                " <wait>",
                " <wait>",
                " <wait>",
                "c",
                "<wait>",
                "set gfxpayload=keep",
                "<enter><wait>",
                "linux /casper/vmlinuz quiet<wait>",
                " autoinstall<wait>",
                " ds=nocloud-net<wait>",
                "\\;s=http://<wait>",
                "{{.HTTPIP}}<wait>",
                ":{{.HTTPPort}}/<wait>",
                " ---",
                "<enter><wait>",
                "initrd /casper/initrd<wait>",
                "<enter><wait>",
                "boot<enter><wait>"]


On Tuesday, January 25, 2022 at 3:20:33 AM UTC-7 rosenl...@gmail.com wrote:

Edward Cheadle

unread,
Feb 4, 2022, 5:00:17 PM2/4/22
to Packer
Sorry this is for my 21.10 install but I think putting the linux line before the autoinstall is something to try.

My boot command for 20.04
"boot_command":  ["<enter><enter><f6><esc><wait> ", "autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/", "<wait><enter>"]

Edward Cheadle

unread,
Feb 4, 2022, 6:33:16 PM2/4/22
to packe...@googlegroups.com
I looked at your json code. I have never tried making a vagrant box for kvm with packer.   Also the terminal connection is something for which I am not familiar.  Good luck.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Packer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/packer-tool/5LXVHM_9PcI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/5f1747b0-ba0d-4df5-840c-78c7da414c4bn%40googlegroups.com.

Jouni

unread,
Feb 5, 2022, 2:17:25 PM2/5/22
to Packer
I tried this:


  "builders": [
    {
      "accelerator": "kvm",
      "boot_command": [
        "<enter><enter><f6><esc><wait> ",
        "autoinstall ds='nocloud-net;s=http://127.0.0.1:3003/'",
        "<wait><enter>"
      ],
      "boot_wait": "10s",
      "cpus": "1",

      "disk_cache": "none",
      "disk_compression": true,
      "disk_interface": "ide",
      "disk_size": "30G",
      "format": "qcow2",
      "headless": "true",

      "http_directory": "./http",
      "iso_checksum": "sha256:f8e3086f3cea0fb3fefb29937ab5ed9d19e767079633960ccb50e76153effc98",
      "iso_urls": [
        "/var/lib/libvirt/images/ubuntu-20.04.3-live-server-amd64.iso"
      ],
      "memory": "1024",

      "name": "ubuntu-packer1",
      "net_device": "virtio-net",
      "net_bridge": "virbr0",

      "output_directory": "output/ubuntu",
      "shutdown_command": "shutdown -P now",
      "ssh_handshake_attempts": "20",
      "ssh_password": "huuhaa",
      "ssh_pty": "true",

      "ssh_timeout": "20m",
      "ssh_username": "ubuntu",
      "type": "qemu",
      "use_default_display": false

    }
  ],
  "provisioners": [
    {
      "inline": [
        "ls /"
      ],
      "type": "shell"
    }
  ]
}

user-data:
#cloud-config

autoinstall:
  version: 1
  early-commands:
    - sudo systemctl stop ssh
  identity:
    hostname: ubuntu-vm
    password: "$6$Yvfsk9tx64XW.w77$4mq6vQDclsQiJMAEc.TwPguRRRntVWmINa9ubpZwJG4SpAJgNYgBaBjwIokSO3X3bkulCeZr2bqMfXeiOupL.1"
    username: ubuntu
  locale: en_US.UTF-8
  keyboard:
    layout: fi
  user-data:
    disable_root: false
    timezone: Europe/Helsinki
  late-commands:
    - echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu

    - sudo systemctl start ssh

2022/02/05 21:14:26 ui: ==> ubuntu-packer1: Waiting for SSH to become available...
2022/02/05 21:14:26 packer-builder-qemu plugin: [INFO] Attempting SSH connection to 192.168.122.78:22...
2022/02/05 21:14:26 packer-builder-qemu plugin: [DEBUG] reconnecting to TCP connection for SSH
2022/02/05 21:14:26 packer-builder-qemu plugin: [DEBUG] handshaking with SSH
2022/02/05 21:14:28 packer-builder-qemu plugin: [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain
2022/02/05 21:14:28 packer-builder-qemu plugin: [DEBUG] Detected authentication error. Increasing handshake attempts.

Jouni

unread,
Feb 7, 2022, 6:55:45 AM2/7/22
to Packer
I finally got step forward, somehow installer does get ip from default virbr0 but can not route to host from where seed was provided. Only way to get autoinstall forward was stop using http and provide user-data from iso.

Thanks for help!

Br, Jouni

Edward Cheadle

unread,
Feb 7, 2022, 10:15:36 AM2/7/22
to Packer
Like I said before, i have never used packer to build kvm boxes, but I found this https://github.com/goffinet/packer-kvm.git   There are builds for a number of different distros.  It may have code that helps.

On Tuesday, January 25, 2022 at 3:20:33 AM UTC-7 rosenl...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages