官方推荐的是直接在
Host
机器上使用SDK
构建相关镜像,但是使用Docker
方便隔离各个编译环境。
测试通过的Host
环境:
Ubuntu24.04
主机。
WSL2
。
- 拉取
Docker
镜像
官方推荐Ubuntu22.04
版本。docker pull ubuntu:22.04
- 创建容器
docker run --name dev-orangepi -it --privileged=true --net=host -v /lib/modules:/lib/modules -v /dev:/dev -v $HOME/workspace:$HOME/workspace ubuntu:22.04 /bin/bash
- 修改源
官方推荐清华源,参考此文档:清华源 - 安装一些基本依赖工具
这些工具不是全部必须的,只是因为我的初始Docker
环境是用我其它环境的Dockerfile
构建的,里面的工具我也不清楚哪些是必须的。可以先忽略此步骤,后面遇到缺什么装什么。apt-get update apt-get upgrade -y apt-get install -y vim apt-get install -y libncurses5-dev build-essential bison flex libssl-dev git fdisk
- 拉取
SDK
cd ~/workspace git clone https://github.com/orangepi-xunlong/orangepi-build.git -b next
- 构建镜像
直接图形化界面选择构建完整镜像。我构建的文件系统是无桌面Ubuntu20.04 Server
版本。./build.sh
- 各种问题
chroot
报错
[ o.k. ] Installing base system [ Stage 2/2 ]
chroot: failed to run command '/bin/bash': No such file or directory
[ error ] ERROR in function create_rootfs_cache [ ./build.sh:305 -> scripts/main.sh:641 -> scripts/main.sh:610 -> scripts/debootstrap.sh:50 -> scripts/debootstrap.sh:236 -> scripts/general.sh:0 ]
[ error ] Debootstrap base system for current orangepi5plus focal no second stage failed
[ o.k. ] Process terminated
在Host
构建没有问题,Host
构建完后,再使用Docker
构建,Docker
内也能成功构建。
网上搜到一篇类似的文章,可能是解决方案:issues
挂载<path to>/binfmt_misc
问题
mount: /proc/sys/fs/binfmt_misc: permission denied.
mount: /proc/sys/fs/binfmt_misc: permission denied.
update-binfmts: warning: Couldn't mount the binfmt_misc filesystem on /proc/sys/fs/binfmt_misc.
mount: /proc/sys/fs/binfmt_misc: permission denied.
update-binfmts: warning: Couldn't mount the binfmt_misc filesystem on /proc/sys/fs/binfmt_misc.
创建Docker
容器需要--privileged
选项。
使用如下的命令可测试创建的Docker
是否能够成功挂载:
sudo apt-get update && sudo apt install -y qemu-user-binfmt
sudo update-binfmts --enable qemu-aarch64
update-binfmts --display| grep qemu-aarch64
# 状态为 enabled 即正常
qemu-aarch64 (enabled):
sfdisk
工具未安装
[ error ] ERROR in function prepare_partitions [ ./build.sh:305 -> scripts/main.sh:641 -> scripts/main.sh:610 -> scripts/debootstrap.sh:93 -> scripts/debootstrap.sh:630 -> scripts/general.sh:0 ]
[ error ] Partition fail. Please check [ ~/workspace/orangepi-build/output/debug/install.log ]
[ o.k. ] Process terminated
需要查看对应的log
文件才能知道具体报错信息:
# 查看log
vim ~/workspace/orangepi-build/output/debug/install.log
# 最后的报错信息
~/workspace/orangepi-build/scripts/debootstrap.sh: line 629: sfdisk: command not found
安装工具:
sudo apt install fdisk
check_loop_device
函数报错
[ error ] ERROR in function check_loop_device [ ./build.sh:305 -> scripts/main.sh:641 -> scripts/main.sh:610 -> scripts/debootstrap.sh:93 -> scripts/debootstrap.sh:666 -> scripts/image-helpers.sh:108 -> scripts/general.sh:0 ]
[ error ] Device node /dev/loop3p2 does not exist
[ o.k. ] Process terminated
解决方案:
# 创建`Docker`时添加如下参数
-v /lib/modules:/lib/modules -v /dev:/dev
解决过程:
网上没有搜出来直接的解决方案,有说要先确保有loop
驱动的存在:
docker挂载ISO/分区时报failed to setup loop device: No such file or directory - OSCHINA - 中文开源技术交流社区
尝试一下:
lsmod | grep loop
实际上这个命令什么也不会输出,说的是
loop.ko
必须以built-in
的方式被内核加载,所以是看不到有驱动模块的。
https://askubuntu.com/questions/666880/loop-module-not-present-on-ubuntu-installation
modprobe loop
# 报错
modprobe: FATAL: Module loop not found in directory /lib/modules/6.11.0-26-generic
理论上这命令也是没用的,上面说了,
loop
并不是通过ko
方式加载。但是却发现了这个命令在Host
执行没问题,但在Docker
执行会报错。
参考该文档,映射/lib/modules
目录到Docker
:
执行完上面步骤后仍然不能解决问题,尝试将/dev
目录也映射到Docker
,成功解决问题。
成功生成镜像:
[ o.k. ] SHA256 calculating [ Orangepi5plus_1.2.0_ubuntu_focal_server_linux6.1.43.img ]
[ o.k. ] Done building [ ~/workspace/OrangePi5/orangepi-build/output/images/Orangepi5plus_1.2.0_ubuntu_focal_server_linux6.1.43/Orangepi5plus_1.2.0_ubuntu_focal_server_linux6.1.43.img ]
[ o.k. ] Runtime [ 20 min ]
[ o.k. ] Repeat Build Options [ sudo ./build.sh BOARD=orangepi5plus BRANCH=current BUILD_OPT=image RELEASE=focal BUILD_MINIMAL=no BUILD_DESKTOP=no KERNEL_CONFIGURE=no COMPRESS_OUTPUTIMAGE=sha,gpg,img ]