构建debian for ARM
本文介绍在装有ubuntu 16.04的PC机上构建ARM平台的debian根文件系统
linux主机版本:
$ uname -a
Linux mypc 4.15.0-50-generic #54~16.04.1-Ubuntu SMP Wed May 8 15:55:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
安装 qemu 和 debootstrap 等工具
$ sudo apt-get install binfmt-support qemu qemu-user-static debootstrap multibootstrap
用 debootstrap 抽取系统
在工作目录下创建文件系统目录debian_stretch
$sudo debootstrap --arch=armel --foreign stretch debian_stretch http://cdn.debian.net/debian
arch指定了cpu架构, stretch为Debian系统代号.
抽取完进行第二阶段
因为在主机是x86架构,不能安装 arm 架构的软件。需要依靠 qemu-arm-static 来模拟成 arm 环境进行安装。
- 复制 qemu-arm-static 到刚构建的基本系统中
$ sudo cp /usr/bin/qemu-arm-static debian_stretch/usr/bin
- 用 qemu-arm-static 来模拟 arm
$ sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot debian_stretch debootstrap/debootstrap --second-stage
该命令意思是设置一些环境变量,然后切换根目录到debian_stetch,
- 执行目录debian_stetch/debootstrap下的命令:
$ debootstrap --second-stage.
终端上最后会打印
I: Base system installed successfully.
修改文件,目录等
$ sudo cd debian_stretch
$ sudo echo "proc /proc proc defaults 0 0" >> etc/fstab
$ sudo mkdir -p usr/share/man/man1/
创建dev/console设备节点
$ sudo mknod dev/console c 5 1
收尾工作
切换到 qemu
$ sudo chroot debian_stretch
设置软件源
# vi /etc/apt/source.list
deb http://cdn.debian.net/debian wheezy main contrib non-free
deb-src http://cdn.debian.net/debian wheezy main contrib non-free
更新软件
# apt-get update
设置root密码
# passwd root
创建新用户
(debian不能以root用户登陆,所以创建一个普通用户,登陆系统后再切换到root用户)
# adduser pi
设置用户密码
# passwd pi
退出 qemu 环境
# exit