Custom Beaglebone Black Image

The following document describes our own method of creating a custom Kali Linux Beaglebone Black ARM image and is targeted at developers. If you would like to install a pre-made Kali image, check out our Install Kali on Beaglebone Black 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 armhf architecture. By the end of this process, you should have a populated rootfs directory in ~/arm-stuff/rootfs/kali-armhf.

02. Create the Image File

Next, we create the physical image file, which will hold our Beaglebone Black rootfs and boot images.

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

03. Partition and Mount the Image File

[email protected]:~$ parted --script kali-custom-bbb.img mklabel msdos
[email protected]:~$ fdisk kali-custom-bbb.img <<EOF
n
p
1

+64M
t
e
p
w
EOF
[email protected]:~$ parted --script kali-custom-bbb.img set 1 boot on
[email protected]:~$ fdisk kali-custom-bbb.img <<EOF
n
p
2

w
EOF
[email protected]:~$ loopdevice=`losetup -f --show kali-custom-bbb.img`
[email protected]:~$ device=`kpartx -va $loopdevice| sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
[email protected]:~$ device="/dev/mapper/${device}"
[email protected]:~$ bootp=${device}p1
[email protected]:~$ rootp=${device}p2
[email protected]:~$
[email protected]:~$ mkfs.vfat -F 16 $bootp -n boot
[email protected]:~$ mkfs.ext4 $rootp -L kaliroot
[email protected]:~$ mkdir -p boot
[email protected]:~$ mkdir -p root
[email protected]:~$ mount $bootp boot
[email protected]:~$ mount $rootp root

04. Copy and Modify the Kali rootfs

[email protected]:~$ rsync -HPavz /root/arm-stuff/rootfs/kali-armhf/ root
[email protected]:~$ echo nameserver 8.8.8.8 > root/etc/resolv.conf

05. Compile the Beaglebone Black 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.

[email protected]:~$ cd ~/arm-stuff/
[email protected]:~$ wget https://launchpad.net/linaro-toolchain-binaries/trunk/2013.03/+download/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux.tar.bz2
[email protected]:~$ tar -xjf gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux.tar.bz2
[email protected]:~$ export CC=`pwd`/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin/arm-linux-gnueabihf-
[email protected]:~$
[email protected]:~$ git clone git://git.denx.de/u-boot.git
[email protected]:~$ cd u-boot/
[email protected]:~$ git checkout v2013.04 -b beaglebone-black
[email protected]:~$ wget https://raw.github.com/eewiki/u-boot-patches/master/v2013.04/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
[email protected]:~$ patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
[email protected]:~$ make ARCH=arm CROSS_COMPILE=${CC} distclean
[email protected]:~$ make ARCH=arm CROSS_COMPILE=${CC} am335x_evm_config
[email protected]:~$ make ARCH=arm CROSS_COMPILE=${CC}
[email protected]:~$ cd ../
[email protected]:~$
[email protected]:~$ mkdir -p kernel/
[email protected]:~$ cd kernel/
[email protected]:~$ git clone git://github.com/RobertCNelson/linux-dev.git
[email protected]:~$ cd linux-dev/
[email protected]:~$ git checkout origin/am33x-v3.8 -b tmp
[email protected]:~$ ./build_kernel.sh
[email protected]:~$ mkdir -p ../patches/
[email protected]:~$ wget http://patches.aircrack-ng.org/mac80211.compat08082009.wl_frag+ack_v1.patch -O ../patches/mac80211.patch
[email protected]:~$ cd KERNEL/
[email protected]:~$ patch -p1 --no-backup-if-mismatch < ../../patches/mac80211.patch
[email protected]:~$ cd ../
[email protected]:~$ ./tools/rebuild.sh
[email protected]:~$ cd ../
[email protected]:~$
[email protected]:~$ cat <<EOF > boot/uEnv.txt
mmcroot=/dev/mmcblk0p2 ro
mmcrootfstype=ext4 rootwait fixrtc
uenvcmd=run loaduimage; run loadfdt; run mmcargs; bootz 0x80200000 - 0x80F80000
EOF
[email protected]:~$
[email protected]:~$ cp -v kernel/linux-dev/deploy/3.8.13-bone20.zImage boot/zImage
[email protected]:~$ mkdir -p boot/dtbs
[email protected]:~$ tar -xovf kernel/linux-dev/deploy/3.8.13-bone20-dtbs.tar.gz -C boot/dtbs/
[email protected]:~$
[email protected]:~$ tar -xovf kernel/linux-dev/deploy/3.8.13-bone20-modules.tar.gz -C root/
[email protected]:~$ tar -xovf kernel/linux-dev/deploy/3.8.13-bone20-firmware.tar.gz -C root/lib/firmware/
[email protected]:~$
[email protected]:~$ cat <<EOF > root/etc/fstab
/dev/mmcblk0p2 / auto errors=remount-ro 0 1
/dev/mmcblk0p1 /boot/uboot auto defaults 0 0
EOF
[email protected]:~$
[email protected]:~$ umount $rootp
[email protected]:~$ kpartx -dv $loopdevice
[email protected]:~$ losetup -d $loopdevice

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

[email protected]:~$ dd if=kali-linux-bbb.img of=/dev/sdb conv=fsync bs=4M

Once the dd operation is complete, unmount and eject the SD card and boot your Beaglebone Black into Kali Linux. When booting you will need to press and hold the “BOOT” button, it’s the one closest to the microSD card.


Updated on: 2022-Jul-26
Author: steev