Packer template waiting for ssh

I am trying to create a VM Template using packer and https://github.com/acavella/packer-Rocky9/blob/main/rocky9.json as a reference. I cloned the repo and made 2 changes.

“iso_url”: “https://download.rockylinux.org/pub/rocky/9/isos/x86_64/Rocky-9.1-x86_64-boot.iso”,
“iso_checksum”: “none”,

But the process is stuck at “Waiting for SSH to become available…” I am new to packer but hoping to get it working and use this as a building block. Any idea what is going on? And how to fix it?

=> virtualbox-iso: Starting HTTP server on port 8105
==> virtualbox-iso: Creating virtual machine…
==> virtualbox-iso: Creating hard drive output-virtualbox-iso\Rocky-9-x86_64.vdi with size 40960 MiB…
==> virtualbox-iso: Mounting ISOs…
virtualbox-iso: Mounting boot ISO…
==> virtualbox-iso: Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port 2918)
==> virtualbox-iso: Executing custom VBoxManage commands…
virtualbox-iso: Executing: modifyvm Rocky-9-x86_64 --memory 2048
virtualbox-iso: Executing: modifyvm Rocky-9-x86_64 --cpus 2
==> virtualbox-iso: Starting the virtual machine…
==> virtualbox-iso: Waiting 30s for boot…
==> virtualbox-iso: Typing the boot command…
==> virtualbox-iso: Using SSH communicator to connect: 127.0.0.1
==> virtualbox-iso: Waiting for SSH to become available…

Looking at the at the Virtualbox console looks like the vm is not getting the kickstart file. I can see the text get input but it goes so fast I can’t catch all of it. I don’t see much info in the boot command that’s of help.

I’m kind of curious why so few people are converting their json file to hcl2.

Anyway, what I think the process is, is

  1. The iso is downloaded from the iso_url.
  2. The ISO gets loaded as a liveVM and the boot_command is run.
  3. Once the boot_command is run, the liveVM is shut down and an SSH connection is made.

I think the reason packer does step 3 is due to the boot_command input being rather slow?
At least that’s the case for me, every letter is typed at 1 letter per second for me.

So your cfg file is run and then the liveVM tries to make an SSH connection and what likely is going on is that there’s no SSH daemon running, so you need to have the SSH service running if packer wants to make an SSH connection.

like so in ks.cfg

services --enabled=NetworkManager,sshd

NetworkManager is probably not needed by the way. I’m just copy-pasting from another example.
And if you ask yourself, how did it work before for the last guy if they didn’t start the sshd service when that’s one of the main reasons to the run kickstart file in the first place? I’m at a loss at that myself. I’ve had the same issue.

As a bonus, you can try creating a ssh key instead of using a password

rocky9.hcl

...
variable "ssh_private_key_file" {
  type    = string
  default = "~/.ssh/id_rocky9"
}
...
source "virtualbox" "main" {  
...
    ssh_username           = "${var.ssh_username}" 
    ssh_private_key_file   = "${var.ssh_private_key_file}"
...
}
...

ks.cfg (using vagrant as the user)

...
(
  mkdir /home/vagrant/.ssh
  chmod 0700 /home/vagrant/.ssh
  cd /home/vagrant/.ssh
  echo "ssh-ed25519 AAAA... vagrant@vagrant" > authorized_keys
  chmod 0600 authorized_keys
  chown vagrant:vagrant authorized_keys
  cd /home/vagrant
  chown vagrant:vagrant /home/vagrant/.ssh
)
...

By the way, I think I’ll be using a kickstart cfg file myself instead of using a bash script file that was given as a template example for my type of setup.

Actually, at the boot screen the text is entered so fast I can’t seem to get a screen shot of the full command. But I was able to see it enter inst.ks=http://10.0. not able to capture the rest of the command not sure where it’s getting the IP from
The process seams stuck it says dracut-initqueue Warning: Problem: timeout will retry in 2 seconds 2 retries left. The VM is not even getting to the install part.


The IP is your local IP address, this is to reach the file on your local computer from what I call the liveVM.
And it’s not getting to the install part because you need to have a proper SSH connection.
I’m having similar issues with a kickstart config file to be honest, so I’m back using a script.

[edit]
Oh, I see now. kickstart config files are for Red Hat Linux family operating systems.
You should keep using that then.
[/edit]

Do you know if Rocky Linux uses SysV or Systemd?

[edit]
Systemd
[/edit]

You’ll have to show your current kickstart file.

Please note that for the Virtuabox builder, the IP address of the HTTP server Packer launches for you to access files like the preseed file in the example above ({{ .HTTPIP }}) is hardcoded to 10.0.2.2. If you change the network of your VM you must guarantee that you can still access this HTTP server.

Here is the example ks.cfg file

# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/performing_an_advanced_rhel_installation/kickstart-commands-and-options-reference_installing-rhel-as-an-experienced-user

# Set the authentication options for the system
auth --passalgo=sha512 --useshadow
# License agreement
eula --agreed
# Use network installation
url --url="https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/"
repo --name="AppStream" --baseurl=https://download.rockylinux.org/pub/rocky/9/AppStream/x86_64/os/
# Use text mode install
text
# Disable Initial Setup on first boot
firstboot --disable
# Keyboard layout
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=link --activate
network --hostname=rocky9.localdomain
# Root password
rootpw $2b$10$INZSJ5B/np1u3f02P79wiectoCrHSoKlc6IX9CIsouGMv6/BxWq0G --iscrypted
# SELinux configuration
selinux --enforcing
# Do not configure the X Window System
skipx
# System timezone
timezone US/Eastern
# Add a user named packer
user --groups=wheel --name=packer --password=$6$Jaa5U0EwAPMMp3.5$m29yTwr0q9ZJVJGMXvOnm9q2z13ldUFTjB1sxPHvaiW4upMSwQ50181wl7SjHjh.BTH7FGHx37wrX..SM0Bqq. --iscrypted --gecos="packer"
# System bootloader configuration
bootloader --location=mbr --append="crashkernel=auto"
# Clear the Master Boot Record
zerombr
# Remove partitions
clearpart --all --initlabel
# Automatically create partitions using LVM
autopart --type=lvm
# Reboot after successful installation
reboot

%packages --ignoremissing
# dnf group info minimal-environment
@^minimal-environment
# Exclude unnecessary firmwares
-iwl*firmware
%end

%post --nochroot --logfile=/mnt/sysimage/root/ks-post.log
# Disable quiet boot and splash screen
sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/etc/default/grub
sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/boot/grub2/grubenv

# Passwordless sudo for the user 'packer'
echo "packer ALL=(ALL) NOPASSWD: ALL" >> /mnt/sysimage/etc/sudoers.d/packer
%end

dracut can’t connect to this IP address. Check your VirtualBox VM network IP range.
Since you can’t change the IP on Packer side, you need to make sure the VM network range includes that IP, e.g. 10.0.0.0/16

I kind of get what you are saying. Where would I check the VM network IP range? It looks like the VM network adaptor is set to NAT.


Source: PPT - Virtual Machine and VirtualBox PowerPoint Presentation, free download - ID:9632412

The above changes fixed part of my problem. Now the VM will get the kickstart file. I need to figure out how to set the default NAT to the NAT Network. I added NAT but when I go to the VM created by packer and click on settings>Network the attached to pull down shows NAT and NAT Network. I also think something is wrong with my kickstart. But that’s a different issue.
NAT Network