Snapcraft pc-kernel failed

Hi folks, recently I tried to build a pc-kernel snap myself. To test out before customizing the default one, I did the following to clone the stock kernel repo and try to build it:

git clone git:// --branch master --single-branch
cd ubuntu-focal

Everything seems fine until the message below shows up:

CC kernel/jump_label.o
CC kernel/trace/trace_events_trigger.o
CC kernel/iomem.o
CC kernel/rseq.o
CHK kernel/kheaders_data.tar.xz
GEN kernel/kheaders_data.tar.xz
CC [M] kernel/torture.o
CC kernel/trace/trace_events_hist.o
CC kernel/trace/bpf_trace.o
CC kernel/trace/trace_kprobe.o
CC kernel/trace/power-traces.o
CC kernel/trace/rpm-traces.o
CC kernel/trace/trace_kdb.o
CC kernel/trace/trace_dynevent.o
CC kernel/trace/trace_probe.o
CC kernel/trace/trace_uprobe.o
AR kernel/trace/built-in.a
AR kernel/built-in.a
CC [M] kernel/kheaders.o
Sorry, an error occurred in Snapcraft:
Failed to run ‘make -j4 bzImage modules’ for ‘kernel’: Exited with code 2.
Verify that the part is using the correct parameters and try again.

I tried on both VMWare - Ubuntu 20.04 & 16.04 multiple times. The build just failed at the same point with the same error message.

Not sure if anyone meets this issue before, appreciated it if someone can shed some light on this, thanks!

The actual error message is most likely earlier in the log. There is a couple of other topics where people build the ubuntu kernel with snapcraft and had to employ some tweaks eg. Custom core20 image: boot error: file '/kernel.efi' not found

as maciek said, the actual error will be a lot higher up in the log … snapcraft usually runs make with a very high -j value to run as many parallel compiler threads as possible, that usually mixes and meshes the log a lot …

Hi @mborzecki and @ogra, thanks for your replies.

You are right. The error is at the beginning of the compilation. It turns out to be a certification error as shown below:

UPD include/generated/compile.h CC init/do_mounts.o make[1]: *** No rule to make target ‘debian/canonical-certs.pem’, needed by ‘certs/x509_certificate_list’. Stop. make[1]: *** Waiting for unfinished jobs… CC certs/system_keyring.o AS [M] arch/x86/crypto/camellia-x86_64-asm_64.o CC [M] arch/x86/crypto/camellia_glue.o CC kernel/bpf/verifier.o make: *** [Makefile:1760: certs] Error 2 make: *** Waiting for unfinished jobs… AS [M] arch/x86/crypto/blowfish-x86_64-asm_64.o CC kernel/cgroup/cgroup.o CC [M] arch/x86/crypto/blowfish_glue.o

What I did to rectify this was: Add in an extra entry to overwrite the CONFIG_SYSTEM_TRUSTED_KEYS to “” instead of “debian/canonical-certs.pem”.

parts: kernel: plugin: kernel source: . source-type: git kconfigflavour: generic kconfigs: - CONFIG_DEBUG_INFO=n - CONFIG_SYSTEM_TRUSTED_KEYS="" override-build: | *cp debian/scripts/retpoline-extract-one * $SNAPCRAFT_PART_BUILD/scripts/ubuntu-retpoline-extract-one snapcraftctl build kernel-with-firmware: false firmware: plugin: nil stage-packages: - linux-firmware organize: lib/firmware: firmware prime: - -usr - -lib build-packages: - cpio - libssl-dev

After the changes, it can now produce the pc-kernel.snap. I haven’t tried the pc-kernel snap though, hope it works. :joy:


There is another issue though. After I successfully generated the pc-kernel snap.

I created the image using that pc-kernel snap with “ubuntu-image”.

I boot the image with VirtualBox and it shows /kernel.efi not found. I found this post: Custom core20 image: boot error: file '/kernel.efi' not found. However, the kernel.efi is for kernel version I tried to copy the kernel.efi into my pc-kernel snap (prime the kernel.efi) and build the image again, it does boot up, however, there’s no network access. The first-time configuration page cannot detect any of the network interfaces.

I’m suspecting the kernel.efi somehow doesn’t fit my kernel. May I know if there’s any way to generate the kernel.efi specifically for my kernel source? Thanks!

The kernel.efi file is a EFI binary that contains the kernel and initramfs. You need to build this from your kernel source tree, you can’t swap it for some other random binary from a different kernel.

Yes, but I’m quite new to kernel compilation steps. Would you mind shedding some light on how to build the EFI binary with the kernel source I have? Appreciate your help!

Hi, the reason why I asked is that there is no .efi binary generated when I “snapcraft” to build the snap (cloned from focal master branch: This is what I got inside the snap package after I successfully compiled and built the snap package:

With the following snapcrafy.yaml:

name: pc-kernel
version: 0.1
version-script: |
    . debian/debian.env
    dpkg-parsechangelog -l $DEBIAN/changelog -S version
summary: The Ubuntu generic Linux kernel
description: This Ubuntu generic Linux kernel
grade: stable
confinement: devmode
type: kernel

    plugin: kernel
    source: .
    source-type: local
    kconfigflavour: generic
    override-build: |
      cp debian/scripts/retpoline-extract-one \
      snapcraftctl build
    kernel-with-firmware: false
    plugin: nil
      - linux-firmware
      lib/firmware: firmware
      - -usr
      - -lib
      - cpio
      - libssl-dev

No luck that there’s no kernel.efi generated, it does have kernel.img and initrd.img though. However, as you said we need kernel.efi to boot, could you help to clarify the steps on how to create the kernel.efi? I tried to look for the information on internet about .efi but I’m having hard time piecing them altogether. Appreciate your help!

After I copied the kernel.efi downloaded from

I was able to boot into UC20 without any error. Please see below for kernel.efi added.

Not sure if this is the right way to do the thing (would kernel.efi replaces the initrd.img & kernel.img generated by the source result in both .img becoming useless?) or would it affect other things down the road.

there’s an example of snapcraft.yaml with some modifications right here:

Note how KERNEL_IMAGE_FORMAT is set there.

Hi, I have read through the Makefiles especially Makefile.efi. The script seems to just grab a copy of kernel.efi from the Ubuntu server and copy it to the local directory. It doesn’t have any step on building the kernel.efi. Please correct me if I’m wrong. Thank you!