Getting Kali Linux on a Cubieboard

Here’s an abbreviated tutorial for getting Kali Linux (1.0ish) running on a Cubieboard. (In case you’re wondering, Kali is the successor to BackTrack.) I use Berryboot as the bootloader, which allows us to multiboot and use compressed file systems (>50% compression, saving ~2 GB for a full install of Kali), and also makes it easy to swap around and play with different operating systems.

Installing the quick and dirty way

Do step 1 below.

Download one of these:

Now skip to step 10 below.

Installing the dirtier way

What you’ll need: a USB flash drive (~4 GB), Debian/Ubuntu Linux (e.g. Kali on VMware works great).

  1. Begin by installing Berryboot onto a microSD card. The easiest way is to empty the microSD slot, boot into the built-in Android system on the Cubieboard NAND, download the Berryboot APK, and follow the instructions.
  2. Install some tools on your Linux box:
    apt-get -y install squashfs-tools kpartx
  3. Now we need to build a squashfs image of the rootfs that Berryboot can boot form. We’ll do this the easy way: by modifying the Kali Raspberry Pi image. Download the image onto your Linux box (you do have a Linux box, don’t you?):
    curl -O "http://cdimage.kali.org/kali-images/kali-linux-1.0-armel-raspberrypi.img.gz"
  4. Unzip the Kali Raspberry Pi image:
    gunzip kali-linux-1.0-armel-raspberrypi.img.gz
  5. Mount the image:
    kpartx -av kali-linux-1.0-armel-raspberrypi.img
    mount /dev/mapper/loop0p2 /mnt
  6. Modify the mount point:
    sed -i 's/^\/dev\/mmcblk/#\0/g' /mnt/etc/fstab
  7. We need to configure the kernel modules that will be loaded. Note that Berryboot ships its own kernel modules, so we don’t need the actual blobs themselves. Create or overwrite these files (these are borrowed from the Cubieboard hwpack):
    /mnt/etc/modules:

    # /etc/modules: kernel modules to load at boot time.
    #
    # This file contains the names of kernel modules that should be loaded
    # at boot time, one per line. Lines beginning with "#" are ignored.
    
    #For SATA Support
    sw_ahci_platform
    
    #Display and GPU
    lcd
    hdmi
    ump
    disp
    mali
    mali_drm
    8192cu

    /mnt/etc/modprobe.d/8192cu.conf:

    # Workaround for dropping connections because power save
    options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
  8. Now we need to package up the rootfs we customized into a squashfs image:
    mksquashfs /mnt ~/kali-on-cubie.img -comp lzo -e lib/modules
  9. Clean up:
    umount /mnt
    kpartx -d kali-linux-1.0-armel-raspberrypi.img
  10. Now we need to get the image onto the microSD card so that Berryboot can use it. Copy your new image (kali-on-cubie.img) to a USB flash drive.
  11. Boot your Cubieboard with Berryboot (i.e. the microSD card inserted). Click “Edit Menu”. Click (and hold) “Add OS”, and you’ll get a dropdown menu; select “Install from USB stick”, and choose the kali-on-cubie.img we just created.
  12. Close the menu editor. Boot Kali.
  13. Eat cake to celebrate.

Installing the unicycle caving way

Instead of using the prebuilt ARM image for Raspberry Pi, we’ll build the rootfs “from scratch” (kind of). This lets us use the armhf architecture, which Google tells me is better than armel (Cubieboard has a more modern processor that supports the faster armhf instructions, whereas Raspberry Pi only supports armel). Also, we can customize the image, leaving out packages which we might not need in a memory/storage constrained environment.

Basically, all we need to do is to build the rootfs following the instructions that are conveniently laid out in the Kali docs. For posterity, I preserve the scripts below.

After building the rootfs, we resume at step 6 above, of course substituting the actual path of our new rootfs for /mnt (which is the path of the rootfs that would have been mounted from the prebuilt image).

apt-get install debootstrap qemu-user-static

# define which packages you want here. If you want everything, add "kali-linux-full". See also this kali.list.chroot for ideas.
export packages="xfce4 kali-menu wpasupplicant kali-defaults initramfs-tools uboot-mkimage nmap openssh-server"
export architecture="armhf"

cd ~
mkdir -p arm-stuff
cd arm-stuff/
mkdir -p kernel
mkdir -p rootfs
cd rootfs

debootstrap --foreign --arch $architecture kali kali-$architecture http://archive.kali.org/kali
cp /usr/bin/qemu-arm-static kali-$architecture/usr/bin/

cd ~/arm-stuff/rootfs
LANG=C chroot kali-$architecture /debootstrap/debootstrap --second-stage

cat << EOF > kali-$architecture/etc/apt/sources.list
deb http://http.kali.org/kali kali main contrib non-free
deb http://security.kali.org/kali-security kali/updates main contrib non-free
EOF

echo "kali" > kali-$architecture/etc/hostname

cat << EOF > kali-$architecture/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOF

cat << EOF > kali-$architecture/etc/resolv.conf
nameserver 8.8.8.8
EOF

export MALLOC_CHECK_=0 # workaround for LP: #520465
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive

mount -t proc proc kali-$architecture/proc
mount -o bind /dev/ kali-$architecture/dev/
mount -o bind /dev/pts kali-$architecture/dev/pts

cat << EOF > kali-$architecture/debconf.set
console-common console-data/keymap/policy select Select keymap from full list
console-common console-data/keymap/full select en-latin1-nodeadkeys
EOF

cat << EOF > kali-$architecture/third-stage
#!/bin/bash
dpkg-divert --add --local --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d
cp /bin/true /usr/sbin/invoke-rc.d

apt-get update
apt-get install locales-all
#locale-gen en_US.UTF-8

debconf-set-selections /debconf.set
rm -f /debconf.set
apt-get update
apt-get -y install git-core binutils ca-certificates initramfs-tools uboot-mkimage
apt-get -y install locales console-common less nano git
echo "root:toor" | chpasswd
sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules
rm -f /etc/udev/rules.d/70-persistent-net.rules
apt-get --yes --force-yes install $packages

rm -f /usr/sbin/invoke-rc.d
dpkg-divert --remove --rename /usr/sbin/invoke-rc.d

rm -f /third-stage
EOF

chmod +x kali-$architecture/third-stage
LANG=C chroot kali-$architecture /third-stage

cat << EOF > kali-$architecture/cleanup
#!/bin/bash
rm -rf /root/.bash_history
apt-get update
apt-get clean
rm -f cleanup
EOF

chmod +x kali-$architecture/cleanup
LANG=C chroot kali-$architecture /cleanup

umount kali-$architecture/proc
umount kali-$architecture/dev/pts
umount kali-$architecture/dev/

cd ..

These instructions were adapted from BerryBoot’s docs.

This entry was posted in Pub and tagged , , . Bookmark the permalink.

3 Responses to Getting Kali Linux on a Cubieboard

  1. Marcus says:

    How about the Cubieboard 3 (Cubietruck)? I cannot find any images for it. And also Berryboot doesn’t work, it simply doesn’t start from SD then (just the red power LED is on then)… Any ideas?

  2. syee says:

    I too would like to know how to do this for cubietruck

  3. Pingback: Kali-linux op de Cubieboard 2 en CubieTruck | Auerplace Blog