Author: zzssdd2
E-mail: zzssdd2@foxmail.com
一、Ubuntu-base20.04.3
Ubuntu官方已经制作好了各架构、各版本的base版根文件系统,只需下载下来做少许改动即可。
-
下载Ubuntu Base 20.04.3 LTS (Focal Fossa)
ubuntu-base-20.04.3-base-armhf.tar.gz 2021-08-19 10:56 22M
-
解压
mkdir rootfs sudo chmod 777 rootfs tar -zxvf ubuntu-base-20.04.3-base-armhf.tar.gz -C rootfs #避免后面更新软件报错 sudo chmod 777 ./rootfs/tmp/
-
安装工具
sudo apt-get install qemu-user-static sudo cp /usr/bin/qemu-arm-static ./rootfs/usr/bin/
-
拷贝主机DNS
sudo cp /etc/resolv.conf ./rootfs/etc/resolv.conf
-
更换下载源
cp ./rootfs/etc/apt/source.list ./rootfs/etc/apt/source.list.bak vim ./rootfs/etc/apt/source.list `Esc` + `:` %s/ports.ubuntu.com/mirror.tuna.tsinghua.edu.cn/g `Enter`
-
创建挂载脚本
vim mount.sh
内容如下:
#!/bin/bash mnt() { echo "MOUNTING" sudo mount -t proc /proc ${2}proc sudo mount -t sysfs /sys ${2}sys sudo mount -o bind /dev ${2}dev sudo mount -o bind /dev/pts ${2}dev/pts sudo chroot ${2} } umnt() { echo "UNMOUNTING" sudo umount ${2}proc sudo umount ${2}sys sudo umount ${2}dev/pts sudo umount ${2}dev } if [ "$1" == "-m" ] && [ -n "$2" ] ; then mnt $1 $2 elif [ "$1" == "-u" ] && [ -n "$2" ]; then umnt $1 $2 else echo "" echo "Either 1'st, 2'nd or both parameters were missing" echo "" echo "1'st parameter can be one of these: -m(mount) OR -u(umount)" echo "2'nd parameter is the full path of rootfs directory(with trailing '/')" echo "" echo "For example: ch-mount -m /media/sdcard/" echo "" echo 1st parameter : ${1} echo 2nd parameter : ${2} fi
更改权限:
sudo chmod +x mount.sh
-
挂载
source mount.sh -m ./rootfs/
-
安装软件
apt update apt install sudo vim kmod net-tools ethtool ifupdown rsyslog htop iputils-ping language-pack-en-base ssh
注意:
ssh
必须安装,不然后面链接串口服务会出错 -
设置用户名和密码
root@zsd-virtual-machine:/# passwd root New password: Retype new password: passwd: password updated successfully root@zsd-virtual-machine:/# adduser zsd New password: Retype new password: `Enter` `Enter` ...... `Enter` `Enter`
-
设置IP和名称
root@zsd-virtual-machine:/# echo "zzssdd2-imx6ull" > /etc/hostname root@zsd-virtual-machine:/# echo "127.0.0.1 localhost" >> /etc/hosts root@zsd-virtual-machine:/# echo "127.0.0.1 zzssdd2-imx6ull" >> /etc/hosts
-
设置串口终端
ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service
注意:
如果提示报错提示如下:
root@zsd-virtual-machine:/# ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service /usr/bin/ln: failed to create symbolic link '/etc/systemd/system/getty.target.wants/getty@ttymxc0.service': No such file or directory
说明
/etc/systemd/system/
目录下没有getty.target.wants
目录。解决方法:安装
ssh
会创建该目录,然后重新执行一遍设置串口终端命令即可。 -
退出
#退出qemu模拟器 exit #取消挂载 source mount.sh -u ./rootfs/ #打包 sudo tar -czvf ubuntu-base-20.04.3-rootfs.tar.gz rootfs/*
二、Debian 11
- 直接使用三方制作好的Debian根文件系统,比如Linaro
- 使用Multistrap或Debootstrap工具构建自己的Debian根文件系统
下面我使用debootstrap
工具构建Debian11根文件系统(别问为什么不用multistrap,问就是不会︶︹︺)
-
安装工具
sudo apt install binfmt-support qemu qemu-user-static debootstrap
-
抽取Debain文件系统
sudo debootstrap --arch=armhf --foreign bullseye rootfs https://mirrors.tuna.tsinghua.edu.cn/debian/
参数说明:
arch
:CPU架构bullseye
:debian版本名,这是版本11的名称foreign
:在与主机架构不相同时需要指定此参数,仅做初始化的解包rootfs
:要存放文件系统的文件夹https://mirrors.tuna.tsinghua.edu.cn/debian/
:下载源,这里使用国内的清华源抽取成功后如下:
$ ls ./rootfs/ bin debootstrap etc lib root sbin tmp var boot dev home proc run sys usr
-
复制
qemu-arm-static
到刚构建的基本系统中sudo cp /usr/bin/qemu-arm-static ./rootfs/usr/bin
-
完成文件系统引导
sudo DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true chroot rootfs debootstrap/debootstrap --second-stage
参数说明:
-
chroot rootfs
更改根目录为
rootfs
:就是变更当前进程及其子进程的可见根路径。变更后,程序无法访问可见根目录外文件和命令。 -
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
避免
debconf
向用户询问任何问题(非交互式),相当于是静默配置安装。 -
debootstrap
man debootstrap 或 debootstrap --help
完成后提示如下:
I: Base system installed successfully.
-
-
更换下载源
#备份 sudo cp ./rootfs/etc/apt/sources.list ./rootfs/etc/apt/sources.list.bak #编辑 sudo vim ./rootfs/etc/apt/sources.list #换成如下内容: # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
-
创建挂载脚本
vim mount.sh
内容如下:
#!/bin/bash mnt() { echo "MOUNTING" sudo mount -t proc /proc ${2}proc sudo mount -t sysfs /sys ${2}sys sudo mount -o bind /dev ${2}dev sudo mount -o bind /dev/pts ${2}dev/pts sudo chroot ${2} } umnt() { echo "UNMOUNTING" sudo umount ${2}proc sudo umount ${2}sys sudo umount ${2}dev/pts sudo umount ${2}dev } if [ "$1" == "-m" ] && [ -n "$2" ] ; then mnt $1 $2 elif [ "$1" == "-u" ] && [ -n "$2" ]; then umnt $1 $2 else echo "" echo "Either 1'st, 2'nd or both parameters were missing" echo "" echo "1'st parameter can be one of these: -m(mount) OR -u(umount)" echo "2'nd parameter is the full path of rootfs directory(with trailing '/')" echo "" echo "For example: ch-mount -m /media/sdcard/" echo "" echo 1st parameter : ${1} echo 2nd parameter : ${2} fi
更改权限:
sudo chmod +x mount.sh
-
挂载
source mount.sh -m ./rootfs/
-
执行以下命令
# <file system> <mount point> <type> <options> <dump> <pass> echo "proc /proc proc defaults 0 0" >> etc/fstab
-
设置Linux中的
locale
环境参数export LC_ALL=C
如果不设置在后面安装软件时会有如下提示:
perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = "zh_CN:en_US:en", LC_ALL = (unset), LC_PAPER = "zh_CN.UTF-8", LC_NUMERIC = "zh_CN.UTF-8", LC_IDENTIFICATION = "zh_CN.UTF-8", LC_MEASUREMENT = "zh_CN.UTF-8", LC_NAME = "zh_CN.UTF-8", LC_TELEPHONE = "zh_CN.UTF-8", LC_ADDRESS = "zh_CN.UTF-8", LC_MONETARY = "zh_CN.UTF-8", LC_TIME = "zh_CN.UTF-8", LANG = "zh_CN.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). /usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory /usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory /usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
-
安装软件
apt update apt install sudo apt install net-tools apt install ethtool apt install htop apt install ssh ......
-
设置用户
#设置root用户密码 passwd root #添加新用户 adduser zzssdd2
-
设置以太网
echo "auto eth0" > /etc/network/interfaces.d/eth0 echo "iface eth0 inet dhcp" >> /etc/network/interfaces.d/eth0
-
设置IP和名称
echo "zzssdd2-imx6ull" > /etc/hostname echo "127.0.0.1 localhost" >> /etc/hosts echo "127.0.0.1 zzssdd2-imx6ull" >> /etc/hosts
-
退出
#退出qemu环境 exit # 取消挂载 source mount.sh -u ./rootfs/ #打包 sudo tar -zcvf debian_bullseye-rootfs.tar.gz ./rootfs/*
三、Buildroot
Buildroot是一个简单、高效且易于使用的工具,可以通过交叉编译生成嵌入式Linux系统。更详细的了解参考官方手册The Buildroot user manual
下面使用buildroot-2021.08.1
版本对IMX6ULL平台进行配置。
-
下载:https://buildroot.org/download.html
-
解压 :
tar -jxvf buildroot-2021.08.1.tar.bz2
-
进入图形配置界面:
make menuconfig
注:下面贴出来的都是经过手动配置更改的选项,没有贴出来的则表示使用默认设置
-
配置
Target options
Target options ---> Target Architecture (ARM (little endian)) Target Binary Format (ELF) Target Architecture Variant (cortex-A7) Target ABI (EABIhf) Floating point strategy (NEON/VFPv4) ARM instruction set (ARM)
-
配置
Toolchain
Toolchain ---> Toolchain type (External toolchain) Toolchain (Custom toolchain) Toolchain origin (Pre-installed toolchain) (/usr/local/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf) Toolchain path ($(ARCH)-none-linux-gnueabihf) Toolchain prefix External toolchain gcc version (10.x) External toolchain kernel headers series (4.20.x) External toolchain C library (glibc/eglibc) [ ] Toolchain has RPC support? [*] Toolchain has C++ support?
-
配置
System configuration
System configuration ---> (zzssdd2) System hostname (Hello zzssdd2) System banner /dev management (Dynamic using devtmpfs + mdev) (root) Root password (eth0) Network interface to configure through DHCP
-
配置
Target packages
这一步根据自己的需求选择安装需要的包即可(这里为了下一步编译快一些我保持默认选择)。
-
按需配置完成后:
Save
-->Exit
--> 执行make
命令等待编译完成后在Buildroot根目录下的output/images
目录下可以看到编译好的根文件系统。注意:
- 如果编译之前执行过
make
则需要先执行make clean
清理一下再执行make
命令,否则可能报错。 - 如果遇到某些包下载巨慢、下不动、下载失败的情况,可以根据编译信息提示的地址复制到浏览器手动下载。下载下来后将其复制到Buildroot根目录下的
dl
目录下,然后CTRL+C
终止编译 -->make clean
清除上次编译 -->make
重新编译。
- 如果编译之前执行过
四、验证
参考开发板直连电脑搭建NFS&TFTP环境第四节