I recently experienced the error Failed creating Qemu driver: exec: “qemu-system-x86_64”: executable file not found in $PATH while trying to create a Qcow2 image for KVM/QEMU using Packer on a CentOS 8 system. After some google searches trying to solve the issue I discovered the quickest solution is hard copying “qemu-kvm” to “qemu-system-x86_64” , in /usr/libexec

Locate the path of qemu-kvm binary:

$ which qemu-kvm

Copy the /usr/libexec/qemu-kvm file to /usr/libexec/qemu-system-x86_64:

sudo su -
cp /usr/libexec/qemu-kvm /usr/libexec/qemu-system-x86_64

Once the file is copied add /usr/libexec to your PATH

export PATH=$PATH:/usr/libexec

You can also persist this in bash profile.

$ vim ~/.bash_profile
export PATH

You can then rerun packer command to build your OS image with debug on:

export PACKER_LOG=1
packer build <options> <hcl-or-json-file>

I hope this guide was helpful in solving the said error message.

Also check:

Ansible check if software package is installed on Linux

Provision VMs on Openstack with Terraform

Automate Let’s Encrypt Certificates Generation and Renewal with acme.sh