How to build an image using a locally patched kernel

Hi. I want to build an Ubuntu Jammy image, but instead of an upstream kernel, I want to use a kernel that I patched and compiled on my local machine. Is this possible through packer or do I have to build from scratch? If it is possible through packer can I get a reference to any resource which tells me how to do that?

Hi @anishnandhan03

I think it should be possible. Please check the script that allows you to specify a custom kernel. I believe that you just need to add information about your kernel to /curtin/CUSTOM_KERNEL

@troyanov Thanks for replying.

But doesn’t this script just install a kernel from Ubuntu repos?

Right. But nothing stops you from modifying it and injecting your custom kernel instead.

This script will be executed from within QEMU right?

Correct. Packer is using QEMU VM and thats where all the scripts preparing an image are executed.

  provisioner "shell" {
    environment_vars = [
      "CLOUDIMG_CUSTOM_KERNEL=${var.kernel}",
      "DEBIAN_FRONTEND=noninteractive"
    ]
    scripts = ["${path.root}/scripts/cloudimg/install-custom-kernel.sh"]
  }