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://kernel.ubuntu.com/ubuntu/ubuntu-focal.git --branch master --single-branch cd ubuntu-focal snapcraft
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!
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 …
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 5.4.0.74. 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: https://kernel.ubuntu.com/git/ubuntu/ubuntu-focal.git/?h=master). This is what I got inside the snap package after I successfully compiled and built the snap package:
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!
UPDATED:
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.
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!