01. 创建Kali rootfs
创建一个armel架构的如Kali文档中所述的Kali rootfs.最后生成的rootfs将位于~/arm-stuff/rootfs/kali-armel目录.
02. 创建镜像文件
然后,我们创建用于存放我们Raspberry Pi rootfs和boot镜像的物理镜像文件.
- apt-get install kpartx xz-utils sharutils
- cd ~
- mkdir -p arm-stuff
- cd arm-stuff/
- mkdir -p images
- cd images
- dd if=/dev/zero of=kali-custom-rpi.img bs=1MB count=5000
复制代码
03. 分区并挂载镜像文件
- parted kali-custom-rpi.img --script -- mklabel msdos
- parted kali-custom-rpi.img --script -- mkpart primary fat32 0 64
- parted kali-custom-rpi.img --script -- mkpart primary ext4 64 -1
复制代码- loopdevice=`losetup -f --show kali-custom-rpi.img`
- device=`kpartx -va $loopdevice| sed -E 's/.*(loop[0-9])p.*/1/g' | head -1`
- device="/dev/mapper/${device}"
- bootp=${device}p1
- rootp=${device}p2
- mkfs.vfat $bootp
- mkfs.ext4 $rootp
- mkdir -p root
- mkdir -p boot
- mount $rootp root
- mount $bootp boot
复制代码
04. 复制和修改Kali rootfs
- rsync -HPavz /root/arm-stuff/rootfs/kali-armel/ root
- echo nameserver 8.8.8.8 > root/etc/resolv.conf
复制代码
05. 编译Raspberry Pi内核和模块
如果你不是以ARM硬件作为开发环境,需要搭建ARM交叉编译环境来编译ARM内核和模块.完成后,执行如下命令.
- cd ~/arm-stuff
- mkdir -p kernel
- cd kernel
- git clone https://github.com/raspberrypi/tools.git
- git clone https://github.com/raspberrypi/linux.git raspberrypi
- cd raspberrypi
- export ARCH=arm
- export CROSS_COMPILE=~/arm-stuff/kernel/toolchains/arm-eabi-linaro-4.6.2/bin/arm-eabi-
- make bcmrpi_cutdown_defconfig
- # configure your kernel !
- make menuconfig
- make -j$(cat /proc/cpuinfo|grep processor|wc -l)
- make modules_install INSTALL_MOD_PATH=~/arm-stuff/images/root
- cd ../tools/mkimage/
- python imagetool-uncompressed.py ../../raspberrypi/arch/arm/boot/Image
- cd ~/arm-stuff/images
- git clone git://github.com/raspberrypi/firmware.git rpi-firmware
- cp -rf rpi-firmware/boot/* boot/
- rm -rf rpi-firmware
复制代码
- cp ~/arm-stuff/kernel/tools/mkimage/kernel.img boot/
- echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > boot/cmdline.txt
- umount $rootp
- umount $bootp
- kpartx -dv $loopdevice
- losetup -d $loopdevice
复制代码
使用dd工具克隆这个文件到你的SD卡.在本例中,我们假设存储设备在/dev/sdb.请按需修改.
- dd if=kali-pi.img of=/dev/sdb bs=1M
复制代码
dd操作完成后,卸载并弹出SD卡.然后启动进入到Kali Linux |