Best way to manually decompress kernel

I'm on Raspberry Pi 4 usb booting ssd.
OS: Ubuntu desktop 20.04.2 64bit arm64

To boot on usb without sd card I configure my boot to boot on a decompress vmlinux.

This is due by the missing capability to boot on usb using a compressed kernel vmlinuz

so I use a script binding to apt event that decompress the kernel after it was update.
My script is like this:

#... controls
zcat vmlinuz > vmlinux
#... 

It works, but now, I have discover, relate to the kernel version updated, this script:
/usr/src/linux-raspi-headers-5.4.0-1028/scripts/extract-vmlinux

To me seems that this script decompress kernel too.

My question is: is better to use this script unless zcat?

like this command: # extract-vmlinux vmlinuz > vmlinux
is this command correct?

2 Answers

It is better to use extract-vmlinux for several reasons:

  • You don't know what kind of compression is used. It could be gzip, LZ4, Bzip2, XZ, … The latest extract-vmlinux script knows how to extract every kind of compressed kernel, though you will still need the relevant command line utility.
  • Compressed kernels aren't like simple compressed files. They are self-extracting so contain a binary header. The kernel image itself may have other binary objects before or after it also. I'm surprised that zcat worked for you; simply using lz4cat doesn't work for me with LZ4-compressed kernels.

For a different reason than yours I wrote a kernel install hook script that uses extract-vmlinux to decompress LZ4-compressed Ubuntu kernels. This should help you along in your quest to have the same for Raspberry Pi.

1

I will integrate your solution with mine.
I will execute on post update apt hook
but will think abaut to move in kernel post install hook
this is my code:

#!/bin/bash -e
#Set Variables
BTPATH=/boot/firmware
CKPATH=$BTPATH/vmlinuz
DKPATH=$BTPATH/vmlinux
EXTRACT_VMLINUX="/usr/src/linux-headers-$(uname -r)/scripts/extract-vmlinux"
if ! [ -x $EXTRACT_VMLINUX ]; then echo -e "\e[32m$EXTRACT_VMLINUX is not executable\e[0m" echo -e "\e[32mI will use zcat!\e[0m" EXTRACT_VMLINUX="zcat -qf"
fi
if [ -e $BTPATH/check.md5 ]; then if md5sum --status --ignore-missing -c $BTPATH/check.md5; then echo -e "\e[32mFiles have not changed, Decompression not needed\e[0m" exit 0 else echo -e "\e[31mHash check failed, kernel will be furter investigate\e[0m" fi
fi
mv $DKPATH $DKPATH.bak
if [ ! $? == 0 ]; then echo -e "\e[31mDECOMPRESSED KERNEL BACKUP FAILED!\e[0m" exit 1
else echo -e "\e[32mDecompressed kernel backup was successful\e[0m"
fi
# Decompress the new kernel
echo "Decompressing kernel: "$CKPATH".............."
$EXTRACT_VMLINUX $CKPATH > $DKPATH
if [ ! $? == 0 ]; then echo -e "\e[31mKERNEL FAILED TO DECOMPRESS!\e[0m" exit 1
else echo -e "\e[32mKernel Decompressed Succesfully\e[0m"
fi
#Hash the new kernel for checking
md5sum $CKPATH $DKPATH > $BTPATH/check.md5
if [ ! $? == 0 ]; then echo -e "\e[31mMD5 GENERATION FAILED!\e[0m"
else echo -e "\e[32mMD5 generated Succesfully\e[0m"
fi
#Exit
exit 0

UPDATE

there is a problem:
if I execute$EXTRACT_VMLINUX /boot/firmware/vmlinuz && echo 'ok'
the output will be:

extract-vmlinux: Cannot find vmlinux.
ok

extract-vmlinux if fail do not throw error: do not do exit 1
this is a bad new
if we use zcat -qf vmlinuz > vmlinux it work and if fail we can check it

so is better not use extract-vmlinux and use zcat instead.

for rpi user

on Ubuntu 20.04.2 there is no more need to decompress kernel on usb on raspberry pi 4:

in config.txt we can use kernel=vmlinuz and it work without decompression.

best regards

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like