Last active
May 14, 2021 07:45
-
-
Save 24HOURSMEDIA/96c472f3301f594b38d78755bef2124e to your computer and use it in GitHub Desktop.
auto_decompress_kernel for ubuntu20.04 server / rpi usb boot (improved)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# Put this script in the root of the boot partition (i.e. system-boot) and chmod it with +x | |
# Set Variables | |
BTPATH=/boot/firmware | |
CKPATH=$BTPATH/vmlinuz | |
DKPATH=$BTPATH/vmlinux | |
#Check if compression needs to be done. | |
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 failed, kernel will be compressed\e[0m" | |
fi | |
fi | |
#Backup the old decompressed kernel | |
mv -f $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".............." | |
zcat $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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
sudo echo 'DPkg::Post-Invoke {"/bin/bash /boot/firmware/auto_decompress_kernel"; };' > /etc/apt/apt.conf.d/999_decompress_rpi_kernel | |
sudo chmod +x /etc/apt/apt.conf.d/999_decompress_rpi_kernel |
Instructions.
1. Before booting, add the auto compress kernel script to the system-boot partition
2. On first boot, as root, install the auto compress kernel script:
curl https://gist.githubusercontent.com/24HOURSMEDIA/96c472f3301f594b38d78755bef2124e/raw/709eec71bfe69120ec472d92659e81eea420f939/install_999_decompress_rpi_kernel | bash
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The file above should be placed in /etc/apt/apt.conf.d/999_decompress_rpi_kernel