97 lines
3.3 KiB
Bash
Executable File
97 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Kali Linux ARM build-script for Banana Pro (32-bit)
|
|
# https://gitlab.com/kalilinux/build-scripts/kali-arm
|
|
#
|
|
# This is a supported device - which you can find pre-generated images for
|
|
# More information: https://www.kali.org/docs/arm/banana-pro/
|
|
#
|
|
|
|
# Hardware model
|
|
hw_model=${hw_model:-"banana-pro"}
|
|
# Architecture
|
|
architecture=${architecture:-"armhf"}
|
|
# Variant name for image and dir build
|
|
variant=${variant:-"${architecture}"}
|
|
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
|
|
desktop=${desktop:-"xfce"}
|
|
|
|
# Load default base_image configs
|
|
source ./common.d/base_image.sh
|
|
|
|
# Network configs
|
|
include network
|
|
add_interface eth0
|
|
|
|
# Third stage
|
|
cat <<EOF >> "${work_dir}"/third-stage
|
|
status_stage3 'Copy rpi services'
|
|
cp -p /bsp/services/rpi/*.service /etc/systemd/system/
|
|
|
|
status_stage3 'Install the kernel packages'
|
|
eatmydata apt-get install -y linux-image-armmp u-boot-menu u-boot-sunxi
|
|
|
|
status_stage3 'Enable login over serial (No password)'
|
|
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> /etc/inittab
|
|
EOF
|
|
|
|
# Run third stage
|
|
include third_stage
|
|
|
|
# Clean system
|
|
include clean_system
|
|
trap clean_build ERR SIGTERM SIGINT
|
|
|
|
# Calculate the space to create the image and create
|
|
make_image
|
|
|
|
# Create the disk partitions
|
|
status "Create the disk partitions"
|
|
parted -s "${image_dir}/${image_name}.img" mklabel msdos
|
|
parted -s -a minimal "${image_dir}/${image_name}.img" mkpart primary "$fstype" 4MiB 100%
|
|
|
|
# Set the partition variables
|
|
loopdevice=$(losetup -f --show "${image_dir}/${image_name}.img")
|
|
device=$(kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1)
|
|
sleep 5s
|
|
device="/dev/mapper/${device}"
|
|
rootp=${device}p1
|
|
|
|
if [[ $fstype == ext4 ]]; then
|
|
features="^64bit,^metadata_csum"
|
|
elif [[ $fstype == ext3 ]]; then
|
|
features="^64bit"
|
|
fi
|
|
mkfs -O "$features" -t "$fstype" -L ROOTFS "${rootp}"
|
|
|
|
# Create the dirs for the partitions and mount them
|
|
status "Create the dirs for the partitions and mount them"
|
|
mkdir -p "${base_dir}"/root
|
|
mount ${rootp} "${base_dir}"/root
|
|
|
|
# Create an fstab so that we don't mount / read-only
|
|
status "Fix rootfs entry in /etc/fstab"
|
|
UUID=$(blkid -s UUID -o value ${rootp})
|
|
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
|
|
|
status "Edit the extlinux.conf file to set root uuid and proper name"
|
|
# Ensure we don't have root=/dev/sda3 in the extlinux.conf which comes from running u-boot-menu in a cross chroot
|
|
# We do this down here because we don't know the UUID until after the image is created
|
|
sed -i -e "0,/root=.*/s//root=UUID=$(blkid -s UUID -o value ${rootp}) rootfstype=$fstype console=tty1 consoleblank=0 ro rootwait/g" ${work_dir}/boot/extlinux/extlinux.conf
|
|
# And we remove the "GNU/Linux because we don't use it
|
|
sed -i -e "s|.*GNU/Linux Rolling|menu label Kali Linux|g" ${work_dir}/boot/extlinux/extlinux.conf
|
|
|
|
status "Set the default options in /etc/default/u-boot"
|
|
echo 'U_BOOT_MENU_LABEL="Kali Linux"' >> ${work_dir}/etc/default/u-boot
|
|
echo 'U_BOOT_PARAMETERS="console=tty1 consoleblank=0 ro rootwait"' >> ${work_dir}/etc/default/u-boot
|
|
|
|
status "Rsyncing rootfs into image file"
|
|
rsync -HPavz -q ${work_dir}/ ${base_dir}/root/
|
|
sync
|
|
|
|
status "dd to ${loopdevice} (u-boot bootloader)"
|
|
dd if=${work_dir}/usr/lib/u-boot/Bananapro/u-boot-sunxi-with-spl.bin of=${loopdevice} bs=1024 seek=8
|
|
|
|
# Load default finish_image configs
|
|
include finish_image
|