环境搭建
安装依赖包
sudo apt-get install multistrap qemu qemu-user-static binfmt-support dpkg-cross
建立工作目录:
mkdir emdebian
cd emdebian
mkdir mindb
cd mindb
编辑multistrap_mindb.conf配置文件
示例如下:
具体语法请参考:https://wiki.debian.org/Multistrap
这里使用了较快的清华大学的镜像站
[General]
directory=target-rootfs
cleanup=true
noauth=true
unpack=true
debootstrap=Debian Net Utils
aptsources=Debian
[Debian]
packages=apt kmod lsof
source=http://mirrors.tuna.tsinghua.edu.cn/debian/
keyring=debian-archive-keyring
suite=stretch
components=main contrib non-free
[Net]
#Basic packages to enable the networking
packages=netbase net-tools ethtool udev iproute iputils-ping ifupdown isc-dhcp-client ssh
source=http://mirrors.tuna.tsinghua.edu.cn/debian/
[Utils]
#General purpose utilities
packages=locales adduser vim less wget dialog usbutils
source=http://mirrors.tuna.tsinghua.edu.cn/debian/
创建根文件系统
sudo multistrap -a armhf -f multistrap_mindb.conf
执行完成后,target-rootfs即是所需的根文件系统。
配置软件包
使用QEMU来配置软件包,将target-rootfs作为root挂载来操作。
sudo cp /usr/bin/qemu-arm-static target-rootfs/usr/bin
sudo mount -o bind /dev/ target-rootfs/dev/
sudo LC_ALL=C LANGUAGE=C LANG=C chroot target-rootfs dpkg --configure -a
#这里就可以模拟板子情况执行相关命令,比如安装额外的软件包
sudo umount target-rootfs/dev/ #最后记得卸载
其中出现选择系统shell的提示框,选否,即不使用dash。
做最后的一些配置
#!/bin/sh
#Directory contains the target rootfs
TARGET_ROOTFS_DIR="target-rootfs"
#Board hostname
filename=$TARGET_ROOTFS_DIR/etc/hostname
echo acqua > $filename
#Default name servers
filename=$TARGET_ROOTFS_DIR/etc/resolv.conf
echo nameserver 8.8.8.8 > $filename
echo nameserver 8.8.4.4 >> $filename
#Default network interfaces
filename=$TARGET_ROOTFS_DIR/etc/network/interfaces
echo auto eth0 >> $filename
echo allow-hotplug eth0 >> $filename
echo iface eth0 inet dhcp >> $filename
#eth0 MAC address
echo hwaddress ether 00:04:25:12:34:56 >> $filename
#Set the the debug port
filename=$TARGET_ROOTFS_DIR/etc/inittab
echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $filename
#Set rules to change wlan dongles
filename=$TARGET_ROOTFS_DIR/etc/udev/rules.d/70-persistent-net.rules
echo SUBSYSTEM=='"net", ACTION=="add", DRIVERS=="?", ATTR{address}=="", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"' > $filename
#microSD partitions mounting
filename=$TARGET_ROOTFS_DIR/etc/fstab
echo /dev/mmcblk0p1 /boot vfat noatime 0 1 > $filename
echo /dev/mmcblk0p2 / ext4 noatime 0 1 >> $filename
echo proc /proc proc defaults 0 0 >> $filename
#Add the standard Debian non-free repositories useful to load
#closed source firmware (i.e. WiFi dongle firmware)
filename=$TARGET_ROOTFS_DIR/etc/apt/sources.list
echo deb http://http.debian.net/debian/ stretch main contrib non-free > $filename
设置密码和其它操作
sudo chroot target-rootfs passwd
sudo LC_ALL=C LANGUAGE=C LANG=C chroot target-rootfs apt-get install packagename