Custom Raspberry Pi Image

Table of Contents

The following document describes our own method of creating a custom Kali Linux Raspberry Pi ARM image and is targeted at developers. If you would like to install a pre-made Kali image, check out our Install Kali on Raspberry Pi article.

You’ll need to have root privileges to do this procedure, or the ability to escalate your privileges with the command “sudo su”.

01. Create a Kali rootfs

Build a Kali rootfs as described in our Kali documentation, using an armel architecture. By the end of this process, you should have a populated rootfs directory in ~/arm-stuff/rootfs/kali-armel.

02. Create the Image File

Next, we create the physical image file, which will hold our Raspberry Pi rootfs and boot images:

kali@kali:~$ sudo apt install -y kpartx xz-utils sharutils
kali@kali:~$ mkdir -p ~/arm-stuff/images/
kali@kali:~$ cd ~/arm-stuff/images/
kali@kali:~$ dd if=/dev/zero of=kali-custom-rpi.img conv=fsync bs=4M count=7000

03. Partition and Mount the Image File

kali@kali:~$ parted kali-custom-rpi.img --script -- mklabel msdos
kali@kali:~$ parted kali-custom-rpi.img --script -- mkpart primary fat32 0 64
kali@kali:~$ parted kali-custom-rpi.img --script -- mkpart primary ext4 64 -1
kali@kali:~$ loopdevice=`losetup -f --show kali-custom-rpi.img`
kali@kali:~$ device=`kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
kali@kali:~$ device="/dev/mapper/${device}"
kali@kali:~$ bootp=${device}p1
kali@kali:~$ rootp=${device}p2
kali@kali:~$ mkfs.vfat $bootp
kali@kali:~$ mkfs.ext4 $rootp
kali@kali:~$ mkdir -p root
kali@kali:~$ mkdir -p boot
kali@kali:~$ mount $rootp root
kali@kali:~$ mount $bootp boot

04. Copy and Modify the Kali rootfs

kali@kali:~$ rsync -HPavz /root/arm-stuff/rootfs/kali-armel/ root
kali@kali:~$ echo nameserver > root/etc/resolv.conf

05. Compile the Raspberry Pi Kernel and Modules

If you’re not using ARM hardware as the development environment, you will need to set up an ARM cross-compilation environment to build an ARM kernel and modules. Once that’s done, proceed with the following instructions:

kali@kali:~$ mkdir -p ~/arm-stuff/kernel/
kali@kali:~$ cd ~/arm-stuff/kernel/
kali@kali:~$ git clone
kali@kali:~$ git clone raspberrypi
kali@kali:~$ cd raspberrypi/
kali@kali:~$ touch .scmversion
kali@kali:~$ export ARCH=arm
kali@kali:~$ export CROSS_COMPILE=~/arm-stuff/kernel/toolchains/arm-eabi-linaro-4.6.2/bin/arm-eabi-
kali@kali:~$ make bcmrpi_cutdown_defconfig

kali@kali:~$ # configure your kernel !
kali@kali:~$ make menuconfig
kali@kali:~$ make -j$(cat /proc/cpuinfo|grep processor | wc -l)
kali@kali:~$ make modules_install INSTALL_MOD_PATH=~/arm-stuff/images/root
kali@kali:~$ cd ../tools/mkimage/
kali@kali:~$ python ../../raspberrypi/arch/arm/boot/Image
kali@kali:~$ cd ~/arm-stuff/images/
kali@kali:~$ git clone git:// rpi-firmware
kali@kali:~$ cp -rf rpi-firmware/boot/* boot/
kali@kali:~$ rm -rf rpi-firmware
kali@kali:~$ cp ~/arm-stuff/kernel/tools/mkimage/kernel.img boot/
kali@kali:~$ echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > boot/cmdline.txt
kali@kali:~$ umount $rootp
kali@kali:~$ umount $bootp
kali@kali:~$ kpartx -dv $loopdevice
kali@kali:~$ losetup -d $loopdevice

While ‘/dev/sdX’ is used in the command, the ‘/dev/sdX’ should be replaced with the proper device label. ‘/dev/sdX’ will not overwrite any devices, and can safely be used in documentation to prevent accidental overwrites. Please use the correct device label.

Use the dd command to image this file to your SD card. In our example, we assume the storage device is located at /dev/sdX. Change this as needed:

kali@kali:~$ dd if=kali-linux-rpi.img of=/dev/sdX conv=fsync bs=4M

Once the dd operation is complete, unmount and eject the SD card and boot your Pi into Kali Linux

Updated on: 2023-Nov-17
Author: steev