Vagrant images using packer

Hello,

I know it’s early, but I wanted to try and setup some base rocky images so we are ready to migrate.

I’ve used packer to create our current centos 8 images, I tried switching out the ISO url to the rocky one but no luck the VM is stuck waiting for something on the dracut side:

The hcl I’ve used:

source "hyperv-iso" "rocky8" {
  boot_command                     = [
    "c",
    "setparams 'kickstart'<enter>",
    "linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=Rocky-8-3-x86_64-dvd inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter>",
    "initrdefi /images/pxeboot/initrd.img<enter>",
    "boot<enter>"
  ]
  boot_wait                        = "2s"
  enable_dynamic_memory            = true
  enable_virtualization_extensions = false
  generation                       = 2
  http_directory                   = "."
  iso_checksum                     = "sha256:fba979fde098027df79b4b686359a8e22daad7f6b269f34887dbe3a53f7cf73a"
  iso_url                          = "https://download.rockylinux.org/pub/rocky/8.3/isos/x86_64/Rocky-8.3-x86_64-minimal.iso"
  output_directory                 = "build"
  shutdown_command                 = "echo 'packer' | sudo -S shutdown -P now"
  ssh_password                     = "vagrant"
  ssh_timeout                      = "10m"
  ssh_username                     = "vagrant"
  vm_name                          = "packer_vdl-rocky8"
}

build {
  sources = ["source.hyperv-iso.rocky8"]

  post-processor "vagrant" {
    keep_input_artifact  = true
    output               = "build/vdl-rocky8_{{ .Provider }}.box"
    vagrantfile_template = "./Vagrantfile.template"
  }
}
1 Like

What does your kickstart look like?

Also, you reference the HD label as the DVD and then use the minimal install iso is that intentional?

“Stripped down” version:

install
cdrom
lang en_US.UTF-8 --addsupport=en_GB.UTF-8,fr_BE.UTF-8
keyboard be
network --bootproto=dhcp
rootpw vagrant
firewall --disabled
timezone UTC
bootloader --location=mbr
text
skipx
zerombr
clearpart --all --initlabel
autopart --nohome --nolvm
firstboot --disabled
eula --agreed
services --enabled=NetworkManager,sshd,hypervfcopyd,hypervkvpd,hypervvssd
user --name=vagrant --plaintext --password=vagrant --groups=wheel
reboot
%packages --excludedocs
@Base
@Core
openssh-clients
sudo
net-tools
curl
# hyperv stuff
hyperv-daemons
# unnecessary stuff for servers
-cockpit
-quota
-fprintd*
-parted
# unnecessary firmware
-aic94xx-firmware
-alsa-firmware
-alsa-tools-firmware
-atmel-firmware
-b43-openfwwf
-bfa-firmware
-dracut-config-rescue
-ipw*-firmware
-irqbalance
-ivtv-firmware
-iwl*-firmware
-kernel-firmware
-libertas-usb8388-firmware
-microcode_ctl
-ql*-firmware
-rt61pci-firmware
-rt73usb-firmware
-xorg-x11-drv-ati-firmware
-zd1211-firmware
%end
%post
set -x
dnf update -y
dnf clean all
echo 'SUBSYSTEM=="memory", ACTION=="add", ATTR{state}="online"' > /etc/udev/rules.d/100-hyperv-dynamic-memory.rules
echo 'ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/scheduler}="none"' > /etc/udev/rules.d/100-hyperv-none-scheduler.rules
# sudo
echo "vagrant        ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
mkdir -p /home/vagrant/.ssh
(umask 0077 && curl -sLo /home/vagrant/.ssh/authorized_keys https://github.com/hashicorp/vagrant/raw/master/keys/vagrant.pub)
chown -R vagrant: /home/vagrant/.ssh
%end

Because the label of the iso is wrong, the minimal iso has the same label as the dvd:

$ isoinfo -d -i packer_cache/dddb8a2d7e41ad397d9d92442fb00d0241ecda6f.iso | grep 'Volume id'
Volume id: Rocky-8-3-x86_64-dvd

Not sure what happened, but the file I was using didn’t contain :LABEL= in the inst.stage2 param. Adding it back and it works perfectly.
Also, I had to switch to the DVD image since minimal doesn’t contain the hyperv daemons.

1 Like