3

I have compiled a custom Raspbian kernel from source because i need to enable the CONFIG_AUDIT flags for installing SELinux & Auditd.

Following the Official Kernel Documentation i was able to do this and it works well.

I now need to package this into a *.deb so i am able to install it on other Pi's with without having to manually copy the *.dtb and *.img and run sudo make modules_install on every pi i want to deploy this to.


This is where i run into problems

I have done some investigations and found a few ways to do this on Standard Debian following this Guide and using the recommended make deb-pkg although when i run dpkg -i linux-*.deb on a fresh Pi and reboot it bricks it.

I have also tried to create my own *.deb file. By copying the zImage modules dtbs into the custom dpkg-deb along with redirecting the modules install path to that package too with make INSTALL_MOD_PATH=$INSTALLDIR modules_install and running dpkg-deb --build [custom-dir]. This also failed

i have not been able to find out how to create a rpikernelhack pkg either as seen here


Any help in packaging a custom kernel for the Raspberry Pi 3b+ would be appreciated.

evilKumara
  • 33
  • 3
  • Hello. Have you tried comparing your efforts with the official Raspberry Pi kernel packages to see if there's an oddity you're missing? Might shed some light on the matter. – Roger Jones Jul 17 '19 at 07:20
  • Probably simpler to just write a simple install script and pack it in a tarball with the required files. – goldilocks Jul 17 '19 at 18:48

1 Answers1

1

I have written a bash script capable to do this: create-debian-rpi-package.sh

#!/usr/bin/bash
#
#   @Ephemeral
#
#   USAGE:
#
#   sudo bash create-debian-rpi-package.sh create PACKAGENAME
#   sudo dpkg -i PACKAGENAME.deb
#   sudo bash create-debian-rpi-package.sh clean PACKAGENAME
#
# sudo tail -f /var/log/dpkg.log

ARCHITECTURE="armhf" # RPi3B, test: raspbian buster

PROJECT=/tmp

function CREATE(){ if [ ! -d "${PROJECT}/package/DEBIAN" ];then mkdir -p "${PROJECT}/package/DEBIAN" else echo "A temporary directory ${PROJECT}/package already exists !" echo "You can use 'sudo bash create-debian-rpi-package.sh clean'" exit 0 fi; cd "${PROJECT}/package"

echo "creating embeded files..." #mkdir -p ./boot/overlays #cp arch/arm/boot/dts/dtb ./boot #cp arch/arm/boot/dts/overlays/.dtb* ./boot/overlays/ #cp arch/arm/boot/dts/overlays/README ./boot/overlays/ #cp arch/arm/boot/zImage ./boot/$KERNEL.img mkdir -p ./usr/bin/ echo "ip a" > ./usr/bin/mytool.sh

cd "DEBIAN"

echo "creating pre install file, use this for saving KERNEL..." cat << EOF > preinst #!/bin/sh echo "pre install job" BACKUP_DIR="/home/pi/boot-backup-$(date +%m-%d-%Y_%H-%M-%S)" echo "Creating /boot backup in ${BACKUP_DIR}" if [ ! -d "${BACKUP_DIR}" ];then mkdir "${BACKUP_DIR}" cp -R /boot "${BACKUP_DIR}" fi; exit 0 EOF chmod 0755 preinst

echo "creating control file..." cat << EOF > control Package: ${PACKAGENAME} Version: 0.1-0 Architecture: ${ARCHITECTURE} Maintainer: ${PACKAGENAME} <${PACKAGENAME}@debian.org> Description: utility package EOF

echo "creating post install file..." cat << EOF > postinst #!/bin/sh echo "post install job" #chmod -R +x /boot/overlays #chmod +x /boot/$KERNEL.img #chmod +x /boot/*.dtb exit 0 EOF chmod 0755 postinst

echo "building debian package ${PACKAGENAME}.deb ..." cd .. dpkg-deb --build /tmp/package if [ ${?} -eq "0" ];then mv /tmp/package.deb /tmp/${PACKAGENAME}.deb echo "SUCCESS building /tmp/${PACKAGENAME}.deb" echo -e "\nINSTALL\nsudo dpkg -i /tmp/${PACKAGENAME}.deb\n\n" fi }

function CLEAN(){ rm -R /tmp/package rm -R /tmp/${PACKAGENAME}.deb dpkg --purge ${PACKAGENAME} }

if [ -z "${SUDO_USER}" ];then echo "Sorry you must an sudo user for running this script." exit 0 fi case ${1} in create|CREATE|Create)if [ -z "${2}" ];then echo "You must provide the package name."; exit 0; else PACKAGENAME="${2}";fi; CREATE;; clean|CLEAN|Clean)if [ -z "${2}" ];then echo "You must provide the package name."; exit 0;else PACKAGENAME="${2}";fi; CLEAN;; *)echo -e "Unknown option ${1}\nOptions are: CREATE or CLEAN";; esac

The output of the script when I create a package named mypackage:

pi@raspberrypi:~ $ sudo bash create-debian-rpi-package.sh create mypackage
creating embeded files...
creating pre install file, use this for saving KERNEL...
creating control file...
creating post install file...
building debian package mypackage.deb ...
dpkg-deb: building package 'mypackage' in '/tmp/package.deb'.
SUCCESS building /tmp/mypackage.deb

INSTALL sudo dpkg -i /tmp/mypackage.deb

pi@raspberrypi:~$ sudo dpkg -i /tmp/mypackage.deb Selection of the previously unselected mypackage package. (Reading the database... 152119 files and directories already installed.) Preparing unpacking of /tmp/mypackage.deb ... pre install job Creating /boot backup in /home/pi/boot-backup-07-10-2019_18-17-05 Unpacking mypackage (0.1-0) ... Parameterization of mypackage (0.1-0) ... post install job

pi@raspberrypi:~$sudo bash create-debian-rpi-package.sh clean mypackage (Reading the database ... 152120 files and directories already installed.) Deleting mypackage (0.1-0) ...

But, because it's relativly dangerous to copy file into /boot directory, I have not uncommented the code for your case precisly (all cp arm/...) . I have put an example with /usr/bin directory and a bash script installation. I have added a pre-install function, this function create a backup directory in /home/pi/boot-backup-$(date) of the /boot directory before installing any files.

For your case you must :

  • uncomment the line where you copy your new kernel, adjust full arm/ path and adjust $KERNEL.img name.
  • uncomment the chmod +x because all file in /boot seems to are executable in the post install file creation (yes after the copy of your files, they must exist so that we can apply them the rights).

Additionally

As specified here, you can add, once the installation is done and thus in the posinst file, a line with sed for example to replace kernel=kernel-myconfig.img in /boot/config.txt with the name of your kernel img and then ask the user if he wants to restart or not with his new kernel for example ...

Ephemeral
  • 2,157
  • 1
  • 6
  • 19
  • 1
    Thank-you this was exactly what i needed and worked a treat. a few small modifications, some of the move directories were hard set to /tmp/ an easy fix to {$PROJECT}, and i also added the kernel modules to the script too i was able to do this by make INSTALL_MOD_PATH=$INSTALLDIR modules_install and copying the contents into the *.deb

    but a very handy little script Cheers.

    – evilKumara Jul 18 '19 at 03:14