企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 定制Raspberry Pi镜像 本文针对开发者描述何如创建一个**定制的Raspberry Pi ARM版Kali Linux镜像**的方法.如果你只是想安装Kali镜像,请查阅我们的文章[“安装Kali Linux ARM版到Raspberry Pi”](http://cn.docs.kali.org/general-use/%e5%ae%89%e8%a3%85kali-linux-arm%e7%89%88%e6%9c%ac%e5%88%b0raspberry-pi "Kali on Raspberry Pi"). ### 01\. 创建Kali rootfs 创建一个**armel**架构的如Kali文档中所述的[Kali rootfs](http://cn.docs.kali.org/development-cn/%e5%87%86%e5%a4%87kali-linux-arm-chroot "Kali ARM 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交叉编译环境](http://cn.docs.kali.org/development-cn/arm%e4%ba%a4%e5%8f%89%e7%bc%96%e8%af%91 "ARM Cross Compilation")来编译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