ptrsr/pi-ci

About dockerfile build kernel image

Closed this issue · 2 comments

Hi mate, thx for this project. I have a question about this lines from dockerfile. Why do you compile 2x "Image" file? The last compile looks like overwrite previous compiled Image file. What could I be missing?

# Compile default VM guest image
RUN make -C $BUILD_DIR/linux defconfig kvm_guest.config \
 && make -C $BUILD_DIR/linux -j$(nproc) Image # the first compiled image file

# Customize guest image
COPY src/conf/custom.conf $BUILD_DIR/linux/kernel/configs/custom.config
RUN make -C $BUILD_DIR/linux custom.config \
 && make -C $BUILD_DIR/linux -j$(nproc) Image \ 
 && mv $BUILD_DIR/linux/arch/arm64/boot/Image $BUILD_DIR/kernel.img # this is the second compiled image file

Hi @syntaxbender , thank you for your interest in the project.

You have a keen eye. Rebuilding the kernel image is done on purpose, and the reason is quite peculiar.

You see, this is the kernel image which the VM (QEMU) uses to start the virtual raspberry pi. Normally, the kernel has a lot of plugins for things like file system and networking support. However, as we use an external kernel, we cannot use these plugins. Therefore, certain functionalities do not work in the virtual machine by default. Luckily we can include these plugins in the kernel image using the rules in custom.conf.

In practise this may require experimenting with kernel parameter rules (custom.conf) to get a certain application to run. In my use case, Docker in the virtual pi (yes, really).

As each experimentental test build requires rebuilding the kernel image, it is smart to cache the "bare bone" kernel image before modification. This saves a lot of time in between test builds. So;

  1. Cache bare bones kernel build
  2. Include plugins in cached kernel build

Recompilation time went from minutes to seconds, and its barely noticable in a full docker build.

I hope that answered your question!

thx mate, it's a good idea haha. i close the issue.