Rocky Linux 9 Kernel Panic on Packer Launched qemu-kvm

Rocky Linux 9 is out, therefore it’s time to build new Packer images.

The Problem

When trying to create a Rocky Linux 9 VM with Packer and Qemu builder running on Rocky Linux 8.6, the installer fails due to kernel panic.

It turns out that direct invocation of qemu-kvm is not supported in RHEL 9. Notes taken from RHEL 9 documentation:

While Qemu is an essential component of the architecture, it is not intended to be used directly on RHEL 9 systems, due to security concerns. Therefore, using qemu-* commands is not supported by Red Hat, and it is highly recommended to interact with Qemu using libvirt.

The Workaround

We need to update qemu-kvm args to pass the flag “-cpu host”.

This is how our Rocky Linux 8 Packer template looks like:

      "qemuargs": [
        [
          "-m",
          "{{user `ram`}}M"
        ],
        [
          "-smp",
          "{{user `cpu`}}"
        ]
      ],

And this is an updated Packer template for Rocky Linux 9:

      "qemuargs": [
        [
          "-m",
          "{{user `ram`}}M"
        ],
        [
          "-smp",
          "{{user `cpu`}}"
        ],
        [
          "-cpu",
          "host"
        ]
      ],

Build Rocky Linux 9 image using the updated template:

$ PACKER_LOG=1 packer build ./rocky9.json

References

https://github.com/hashicorp/packer-plugin-qemu/issues/76

Leave a Reply

Your email address will not be published. Required fields are marked *