前情提要:
从零开始的ZYNQ学习(基于矿卡EBAZ4205)(一)
从零开始的ZYNQ学习(基于矿卡EBAZ4205)(二)
本文由长春理工大学电子信息工程学院C&I实验室所有,已获得原作者发布授权。转载请注明出处。
本文编写过程中参考了很多前辈的记录,在此表示感谢,已将所有参考项列于文末。
当前版本R1.0(预发布)。
作者联系方式:E-mail: [email protected]
还记得吗?在6.4-(3)-2)章节中,我们设置“Image Packaging Configuration(镜像打包配置)”->“Root filesystem type(根文件系统类型)”为“INITRAMFS”。这一章我们拟将其改为“SD Card”模式并基于TF卡移植一个Ubuntu,当然相关的教程已是非常多了,这只是我个人的学习记录而已(后辈の自嘲)。至于为什么不移植到NAND Flash?那是因为板载NAND的容量不足以安装它。
Ubuntu和其它的发行版一样,都是基于Linux内核,不同的是它们使用的根文件系统,因此,我们希望移植一个Ubuntu的时候,我们实际上需要做的是构建一个Ubuntu的根文件系统。Debootstrap就是Debian/Ubuntu下完成该任务的工具。在Fedora下也有相似的工具名为Febootstarp。Bootstrap意为“引导”,两种工具的命名均是在此基础上增加了前缀。
制作根文件系统自然要在Linux环境下,因此我们需要配置宿主机的Linux系统并安装必要的工具和环境,本章使用的宿主机系统为Ubuntu20.04。
为了让学习更简单一些,本章我们不使用chroot命令和qemu,而是将根文件系统的解包放在板端进行。
首先安装Debootstrap,在Terminal中执行:
sudo apt install debootstrap
Debootstrap生成Ubuntu根文件系统分为两个阶段,第一个阶段是在宿主机上下载Ubuntu的必要包,第二阶段则是展开它们。
保证宿主机的联网状态,随便找一个目录,在Terminal中执行:
sudo debootstrap --arch=armhf --foreign bionic ./rootfs
即可在当前目录下生成一个名为rootfs的根文件夹,Debootstrap会将Ubuntu对应版本所需包下载到该文件夹中。
注:Ubuntu系统每个版本会有一个代号,例如:
Ubuntu16.04 —— Xenial
Ubuntu17.04 —— Zesty
Ubuntu18.04 —— Bionic
Ubuntu19.04 —— Disco
Ubuntu20.04 —— Focal
Ubuntu21.04 —— Hirsute
截至目前Debootstrap(arch=armhf)仅支持以上项目中的Xenial和Bionic。
有了前面章节的基础,这里要进行的操作非常简单,首先准备一张TF卡并在宿主机下使用Gparted分成两个区,第一分区为几十到几百兆的FAT/FAT32/RAW格式,第二分区为ext4格式,并对两分区进行格式化。
仿照先前的步骤重新生成一个Petalinux工程,并将Petalinux工程配置中的“Image Packaging Configuration(镜像打包配置)”->“Root filesystem type(根文件系统类型)”改为“SD Card”模式。将编译、打包后的BOOT.BIN和image.ub存放在TF卡的第一分区(这里生成的image.ub少了约6MB,因为其中不再包含initramfs),将Debootstrap生成的Rootfs中的内容复制到第二分区。
注:复制时可使用“sudo cp -r 源目录 目标目录”,防止root目录权限问题无法复制。
使矿卡从该TF启动,即可进入到控制台(使用/bin/sh),注意此时未对系统配置,因此不支持命令补全和特殊字符等。在终端执行:
/debootstrap/debootstrap --second-stage
即可解压Ubuntu Rootfs:
# /debootstrap/debootstrap --second-stage
I: Installing core packages...
I: Unpacking required packages...
...
I: Configuring required packages...
...
I: Unpacking the base system...
..
I: Configuring the base system...
...
I: Base system installed successfully.
此时切记**不要断电!**在重启之前一定先把用户创建完成!!不然面对登录对话你会欲哭无泪:P
我喜欢风,因此这里使用wind作为登录用户名和密码。
首先设置当前账户(root)密码:
passwd
输入并二次确认密码。接着创建名为“wind”的用户:
useradd -m wind
注:使用-m参数可自动在/home/目录下创建该用户目录。
注:此处用户将使用/bin/sh登录,这很不方便,但为了有不一样的体验,暂不使用/bin/bash,下一章再说:D
而后为用户设置密码:
passwd wind
输入并二次确认密码,重新上电即可进入Ubuntu:
U-Boot 2017.01 (Nov 11 2020 - 19:34:58 +0800)
Board: Xilinx Zynq
DRAM: ECC disabled 256 MiB
NAND: 128 MiB
MMC: sdhci@e0100000: 0 (SD)
In: serial
Out: serial
Err: serial
Net: ZYNQ GEM: e000b000, phyaddr ffffffff, interface gmii
eth0: ethernet@e000b000
U-BOOT for EBAZ4205_linux_TF_with_external_rootfs
...(此处省略部分Uboot启动信息)
Starting kernel ...
...(此处省略部分Kernel启动信息)
Freeing unused kernel memory: 1024K (c0900000 - c0a00000)
systemd[1]: System time before build time, advancing clock.
systemd[1]: Failed to insert module 'autofs4': No such file or directory
cgroup: cgroup2: unknown option "nsdelegate"
systemd[1]: systemd 237 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid)
systemd[1]: Detected architecture arm.
Welcome to Ubuntu 18.04 LTS!
systemd[1]: Set hostname to .
systemd[1]: File /lib/systemd/system/systemd-journald.service:36 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
systemd[1]: Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
[ OK ] Started Dispatch Password Requests to Console Directory Watch.
systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[ OK ] Started Forward Password Requests to Wall Directory Watch.
systemd[1]: Reached target Paths.
[ OK ] Reached target Paths.
systemd[1]: Reached target Local Encrypted Volumes.
[ OK ] Reached target Local Encrypted Volumes.
systemd[1]: Reached target Swap.
[ OK ] Reached target Swap.
[ OK ] Created slice System Slice.
[ OK ] Listening on Journal Socket.
[ OK ] Listening on udev Kernel Socket.
[ OK ] Listening on udev Control Socket.
Starting Set the console keyboard layout...
[ OK ] Listening on /dev/initctl Compatibility Named Pipe.
Starting Remount Root and Kernel File Systems...
Starting Load Kernel Modules...
Starting udev Coldplug all Devices...
[ OK ] Reached target Remote File Systems.
Starting Create Static Device Nodes in /dev...
[ OK ] Created slice User and Session Slice.
[ OK ] Reached target Slices.
[ OK ] Listening on Syslog Socket.
[ OK ] Listening on Journal Socket (/dev/log).
Starting Journal Service...
[ OK ] Created slice system-serial\x2dgetty.slice.
[ OK ] Started Remount Root and Kernel File Systems.
[ OK ] Started Journal Service.
[ OK ] Started Set the console keyboard layout.
[ OK ] Started Load Kernel Modules.
[ OK ] Started Create Static Device Nodes in /dev.
Starting Apply Kernel Variables...
Mounting Kernel Configuration File System...
[ OK ] Reached target Local File Systems (Pre).
Starting Flush Journal to Persistent Storage...
Starting udev Kernel Device Manager...
[ OK ] Reached target Local File Systems.
Starting Set console font and keymap...
Starting Load/Save Random Seed...
[ OK ] Started udev Coldplug all Devices.
[ OK ] Started Apply Kernel Variables.
[ OK ] Started udev Kernel Device Manager.
[ OK ] Mounted Kernel Configuration File System.
[ OK ] Started Set console font and keymap.
[ OK ] Started Load/Save Random Seed.
[ OK ] Found device /dev/ttyPS0.
[ OK ] Started Flush Journal to Persistent Storage.
Starting Create Volatile Files and Directories...
[ OK ] Started Create Volatile Files and Directories.
Starting Network Name Resolution...
Starting Update UTMP about System Boot/Shutdown...
Starting Network Time Synchronization...
[ OK ] Started Update UTMP about System Boot/Shutdown.
[ OK ] Started Network Name Resolution.
[ OK ] Reached target Host and Network Name Lookups.
[ OK ] Started Network Time Synchronization.
[ OK ] Reached target System Initialization.
[ OK ] Listening on D-Bus System Message Bus Socket.
[ OK ] Reached target Sockets.
[ OK ] Reached target Basic System.
Starting Login Service...
Starting System Logging Service...
[ OK ] Started Regular background program processing daemon.
[ OK ] Started Set the CPU Frequency Scaling governor.
Starting Dispatcher daemon for systemd-networkd...
[ OK ] Started Daily Cleanup of Temporary Directories.
Starting Permit User Sessions...
[ OK ] Started D-Bus System Message Bus.
[ OK ] Started Login Service.
[ OK ] Started Message of the Day.
[ OK ] Reached target System Time Synchronized.
[ OK ] Started Daily apt download activities.
[ OK ] Started Daily apt upgrade and clean activities.
[ OK ] Started Discard unused blocks once a week.
[ OK ] Reached target Timers.
[ OK ] Started System Logging Service.
[ OK ] Started Permit User Sessions.
Starting Set console scheme...
[ OK ] Started Serial Getty on ttyPS0.
[ OK ] Started Set console scheme.
[ OK ] Created slice system-getty.slice.
[ OK ] Started Getty on tty1.
[ OK ] Reached target Login Prompts.
[ OK ] Started Dispatcher daemon for systemd-networkd.
[ OK ] Reached target Multi-User System.
[ OK ] Reached target Graphical Interface.
Starting Update UTMP about System Runlevel Changes...
[ OK ] Started Update UTMP about System Runlevel Changes.
Ubuntu 18.04 LTS ubuntu ttyPS0
ubuntu login:
在这里输入刚才设置过的用户名和密码即可登陆成功:
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.9.0-xilinx-v2017.4 armv7l)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
修改/etc/apt/sources.list文件,改为以下内容:
deb http://ports.ubuntu.com/ubuntu-ports bionic main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports bionic-updates main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports bionic-proposed main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports bionic-backports main restricted universe multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports bionic main restricted universe multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted universe multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports bionic-updates main restricted universe multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports bionic-proposed main restricted universe multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports bionic-backports main restricted universe multiverse
在命令行中执行:
sudo vi /etc/apt/sources.list
命令模式下使用:
dd
删除仅有的一行,而后使用:
i
转换到插入模式,在终端直接粘贴上面的源地址,按ESC键返回。而后输入:
:wq
保存并退出。
注:如果执行sudo提权时提示:
[用户名] is not in the sudoers file. This incident will be reported.
则依次执行:
su #进入root sudo adduser [用户名] sudo #添加用户到sudo组 su [用户名]
而后该账户即可使用sudo提权。
注:如果认为vi操作比较麻烦,可以直接把卡挂载到宿主机上修改。
注:vi的操作效果可能因虚拟终端设置而异,即可能存在显示错乱问题,这姑且算是…正常的。
由于初始的根文件系统没有配置网络,因此也没办法方便地下载工具和组件。配置网络使用的相关软件安装包链接如下:
Net-tools Download for Linux (apk, deb, rpm, tgz, txz, xz)
Ethtool Download for Linux (apk, deb, eopkg, ipk, rpm, tgz, txz, xz, zst)
Ifupdown Download for Linux (apk, deb)
Iputils-ping Download for Linux (deb, ipk)
下载后保存在TF卡中,板端上电,在安装包所在目录执行:
sudo dpkg -i [文件名]
即可从deb包中安装。
**================================================================================**
系统基本工具安装、网络连接配置以及镜像生成过程等请参见后续章节8.2-(1)和8.2-(3)-4)。
由于后续章节先于本章写完,因此烦请读者往后翻翻吧~;P
**================================================================================**
如果你是严格按照上面记录进行复现,且不说在调试过程中的诸多限制,Debootstrap支持的Ubuntu版本太老就已经使人意兴阑珊。我们不经意间想到:如果官方能够将各版本的Ubuntu最小根文件系统制作好并打包,我们不就可以省过漫长的下载-解包的过程,而是拿来直接使用了吗?
Ubuntu Base就是这样的最小根文件系统。本章将尝试基于Ubuntu Base 20.04.1 LTS (Focal Fossa)制作可供矿卡运行的根文件系统。
在宿主机任意目录下解压Ubuntu Base。
注:以下演示中,该目录使用压缩包本来的名称。命令执行所在目录为目标根文件系统上一级。
Qemu是一种通用的开源计算机仿真器和虚拟器。随着Qemu的发展,安装也变得与以前不同:
sudo apt install qemu-system-[架构] #系统级虚拟机
sudo apt install qemu-user #进程级虚拟机
sudo apt install qemu-utils #qemu工具包
安装完成后,将qemu-arm复制到目标根文件系统中:
sudo cp /usr/bin/qemu-arm ubuntu-base-20.04.1-base-armhf/usr/bin/
而后拷贝bash执行所需环境,动态库主要集中在宿主机的/lib/x86_64-linux-gnu/和/lib64/目录下。
使用ldd命令可列出bash指令:
wkc@ubuntu:~$ ldd /bin/bash linux-vdso.so.1 (0x00007ffe341b4000) libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f66323f0000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f66323ea000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f66321f8000) /lib64/ld-linux-x86-64.so.2 (0x00007f6632564000)
同理查看qemu-arm的依赖:
wkc@ubuntu:~$ ldd /usr/bin/qemu-arm linux-vdso.so.1 (0x00007ffc45d09000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff048120000) libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007ff04811a000) libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff047ff1000) libgnutls.so.30 => /lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007ff047e1b000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff047e10000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff047c2f000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff047ade000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff047ac3000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff047aa0000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff0478ae000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff0478a8000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007ff047835000) libp11-kit.so.0 => /lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007ff0476fd000) libidn2.so.0 => /lib/x86_64-linux-gnu/libidn2.so.0 (0x00007ff0476dc000) libunistring.so.2 => /lib/x86_64-linux-gnu/libunistring.so.2 (0x00007ff04755a000) libtasn1.so.6 => /lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007ff047544000) libnettle.so.7 => /lib/x86_64-linux-gnu/libnettle.so.7 (0x00007ff04750a000) libhogweed.so.5 => /lib/x86_64-linux-gnu/libhogweed.so.5 (0x00007ff0474d2000) libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007ff04744c000) /lib64/ld-linux-x86-64.so.2 (0x00007ff04a62d000) libffi.so.7 => /lib/x86_64-linux-gnu/libffi.so.7 (0x00007ff047440000)
我比较嫌麻烦,因此直接把/lib/x86_64-linux-gnu/文件夹里的东西都复制过去了:
mkdir ubuntu-base-20.04.1-base-armhf/lib64 sudo cp /lib64/ld-linux-x86-64.so.2 ubuntu-base-20.04.1-base-armhf/lib64/ mkdir ubuntu-base-20.04.1-base-armhf/lib/x86_64-linux-gnu sudo cp /lib/x86_64-linux-gnu/lib* ubuntu-base-20.04.1-base-armhf/lib/x86_64-linux-gnu/
而后为目标根文件系统配置网络:
sudo cp /etc/resolv.conf ubuntu-base-20.04.1-base-armhf/etc/resolv.conf
在终端执行:
sudo chroot ./ubuntu-base-20.04.1-base-armhf
即可切换到目标根文件系统。
在chroot环境下执行:
apt update
apt upgrade
apt install sudo ifupdown net-tools ethtool udev wireless-tools iputils-ping resolvconf wget apt-utils wpasupplicant vim git gcc build-essential openssh-server nfs-common
即可在宿主机上为目标根文件系统安装基本应用。
注:如果安装过程中出现:
perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_TIME = "zh_CN.UTF-8", LC_MONETARY = "zh_CN.UTF-8", LC_ADDRESS = "zh_CN.UTF-8", LC_TELEPHONE = "zh_CN.UTF-8", LC_NAME = "zh_CN.UTF-8", LC_MEASUREMENT = "zh_CN.UTF-8", LC_IDENTIFICATION = "zh_CN.UTF-8", LC_NUMERIC = "zh_CN.UTF-8", LC_PAPER = "zh_CN.UTF-8", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C").
安装中文支持包即可:
apt install language-pack-zh-hans
在宿主机语言为中文时,chroot从宿主机继承语言设置,可能会出现上述情况。
首先设置当前账户(root)密码:
passwd
输入并二次确认密码。接着创建名为“wind”的用户,设置使用bash和sudo身份:
useradd -s '/bin/bash' -m -G adm,sudo wind
注:使用-m参数可自动在/home/目录下创建该用户目录。
而后为用户设置密码:
passwd wind
输入并二次确认密码即可。
注:笔者在chroot环境中操作时,passwd提示:
passwd: Authentication token manipulation error passwd: password unchanged
笔者的做法是执行:
passwd -d root passwd -d wind
以删除用户的密码,在板端运行时再重新设置即可。
注:板端运行过程中,使用sudo提示:
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
则在root下设置setuid位即可:
chmod 4755 /usr/bin/sudo
如果不经验证直接打包镜像,一旦出了错误就会白费很多精力。验证的步骤可参见7.3章节,在板端运行一遍:
U-Boot 2017.01 (Nov 11 2020 - 19:34:58 +0800)
Board: Xilinx Zynq
DRAM: ECC disabled 256 MiB
NAND: 128 MiB
MMC: sdhci@e0100000: 0 (SD)
In: serial
Out: serial
Err: serial
Net: ZYNQ GEM: e000b000, phyaddr ffffffff, interface gmii
eth0: ethernet@e000b000
U-BOOT for EBAZ4205_linux_TF_with_external_rootfs
...(此处省略部分Uboot启动信息)
Starting kernel ...
...(此处省略部分Kernel启动信息)
Freeing unused kernel memory: 1024K (c0900000 - c0a00000)
random: fast init done
systemd[1]: System time before build time, advancing clock.
systemd[1]: Failed to look up module alias 'autofs4': Function not implemented
cgroup: cgroup2: unknown option "nsdelegate"
systemd[1]: systemd 245.4-4ubuntu3.3 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid)
systemd[1]: Detected architecture arm.
Welcome to Ubuntu 20.04.1 LTS!
systemd[1]: Set hostname to .
systemd[1]: /lib/systemd/system/dbus.socket:5: ListenStream= references a path below legacy directory /var/run/, updating /var/run/dbus/system_bus_socket → /run/dbus/system_bus_socket; please update the unit file accordingly.
systemd[1]: system-getty.slice: unit configures an IP firewall, but the local system does not support BPF/cgroup firewalling.
systemd[1]: (This warning is only shown for the first unit using IP firewalling.)
systemd[1]: Created slice system-getty.slice.
[ OK ] Created slice system-getty.slice.
systemd[1]: Created slice system-modprobe.slice.
[ OK ] Created slice system-modprobe.slice.
systemd[1]: Created slice system-serial\x2dgetty.slice.
[ OK ] Created slice system-serial\x2dgetty.slice.
systemd[1]: Created slice User and Session Slice.
[ OK ] Created slice User and Session Slice.
systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
[ OK ] Started Dispatch Password …ts to Console Directory Watch.
systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[ OK ] Started Forward Password R…uests to Wall Directory Watch.
systemd[1]: Condition check resulted in Arbitrary Executable File Formats File System Automount Point being skipped.
systemd[1]: Reached target Local Encrypted Volumes.
[ OK ] Reached target Local Encrypted Volumes.
systemd[1]: Reached target Remote File Systems.
[ OK ] Reached target Remote File Systems.
systemd[1]: Reached target Slices.
[ OK ] Reached target Slices.
systemd[1]: Reached target Swap.
[ OK ] Reached target Swap.
systemd[1]: Listening on initctl Compatibility Named Pipe.
[ OK ] Listening on initctl Compatibility Named Pipe.
systemd[1]: Condition check resulted in Journal Audit Socket being skipped.
systemd[1]: Listening on Journal Socket (/dev/log).
[ OK ] Listening on Journal Socket (/dev/log).
systemd[1]: Listening on Journal Socket.
[ OK ] Listening on Journal Socket.
systemd[1]: Listening on udev Control Socket.
[ OK ] Listening on udev Control Socket.
systemd[1]: Listening on udev Kernel Socket.
[ OK ] Listening on udev Kernel Socket.
systemd[1]: Condition check resulted in Huge Pages File System being skipped.
systemd[1]: Condition check resulted in POSIX Message Queue File System being skipped.
systemd[1]: Condition check resulted in Kernel Debug File System being skipped.
systemd[1]: Condition check resulted in Kernel Trace File System being skipped.
systemd[1]: Starting Journal Service...
Starting Journal Service...
systemd[1]: Condition check resulted in Create list of static device nodes for the current kernel being skipped.
systemd[1]: Condition check resulted in Load Kernel Module drm being skipped.
systemd[1]: Started Nameserver information manager.
[ OK ] Started Nameserver information manager.
systemd[1]: Reached target Network (Pre).
[ OK ] Reached target Network (Pre).
systemd[1]: Condition check resulted in Set Up Additional Binary Formats being skipped.
systemd[1]: Starting Load Kernel Modules...
Starting Load Kernel Modules...
systemd[1]: Starting Remount Root and Kernel File Systems...
Starting Remount Root and Kernel File Systems...
systemd[1]: Starting udev Coldplug all Devices...
Starting udev Coldplug all Devices...
systemd[1]: Started Journal Service.
[ OK ] Started Journal Service.
[ OK ] Finished Load Kernel Modules.
[ OK ] Finished Remount Root and Kernel File Systems.
Mounting Kernel Configuration File System...
Starting Flush Journal to Persistent Storage...
Starting Load/Save Random Seed...
systemd-journald[676]: Received client request to flush runtime journal.
Starting Apply Kernel Variables...
Starting Create System Users...
[ OK ] Mounted Kernel Configuration File System.
[ OK ] Finished Load/Save Random Seed.
[ OK ] Finished Apply Kernel Variables.
[ OK ] Finished Flush Journal to Persistent Storage.
[ OK ] Finished udev Coldplug all Devices.
Starting Helper to synchronize boot up for ifupdown...
[ OK ] Finished Helper to synchronize boot up for ifupdown.
[ OK ] Finished Create System Users.
Starting Create Static Device Nodes in /dev...
[ OK ] Finished Create Static Device Nodes in /dev.
[ OK ] Reached target Local File Systems (Pre).
[ OK ] Reached target Local File Systems.
Starting Raise network interfaces...
Starting Create Volatile Files and Directories...
Starting udev Kernel Device Manager...
[ OK ] Finished Create Volatile Files and Directories.
Starting Network Name Resolution...
Starting Network Time Synchronization...
Starting Update UTMP about System Boot/Shutdown...
[ OK ] Finished Update UTMP about System Boot/Shutdown.
[ OK ] Started udev Kernel Device Manager.
[ OK ] Finished Raise network interfaces.
[ OK ] Found device /dev/ttyPS0.
[ OK ] Started Network Time Synchronization.
[ OK ] Reached target System Initialization.
[ OK ] Started resolvconf-pull-resolved.path.
[ OK ] Started Daily Cleanup of Temporary Directories.
[ OK ] Reached target Paths.
[ OK ] Reached target System Time Set.
[ OK ] Reached target System Time Synchronized.
[ OK ] Started Daily apt download activities.
[ OK ] Started Daily apt upgrade and clean activities.
[ OK ] Started Periodic ext4 Onli…ata Check for All Filesystems.
[ OK ] Started Discard unused blocks once a week.
[ OK ] Started Message of the Day.
[ OK ] Reached target Timers.
[ OK ] Listening on D-Bus System Message Bus Socket.
[ OK ] Reached target Sockets.
[ OK ] Reached target Basic System.
[ OK ] Started D-Bus System Message Bus.
Starting Remove Stale Onli…t4 Metadata Check Snapshots...
Ubuntu 20.04.1 LTS localhost.localdomain ttyPS0
localhost login:
输入之前创建的用户名(root或wind)即可直接登录:
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 4.9.0-xilinx-v2017.4 armv7l)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
注:在板端为用户设置密码的步骤不再重复,仿照先前所述即可。
注:板端运行时无需宿主机的qemu和chroot运行库,可手动删除相关目录和文件,不删除也不会有影响。
将矿卡网口和PC网口直连,直连可能需要使用交叉线。
测试时本地以太网设置为:
以太网适配器 以太网:
IPv4 地址 : 169.254.134.39
子网掩码 : 255.255.255.0
默认网关 : 169.254.134.1
开发板中设置网络为:
sudo ifconfig eth0 169.254.134.37 broadcast 169.254.134.255 netmask 255.255.255.0
双机互ping非常完美:
wind@localhost:~$ ping 169.254.134.39
PING 169.254.134.39 (169.254.134.39) 56(84) bytes of data.
64 bytes from 169.254.134.39: icmp_seq=1 ttl=128 time=1.89 ms
64 bytes from 169.254.134.39: icmp_seq=2 ttl=128 time=0.700 ms
64 bytes from 169.254.134.39: icmp_seq=3 ttl=128 time=2.86 ms
64 bytes from 169.254.134.39: icmp_seq=4 ttl=128 time=0.835 ms
64 bytes from 169.254.134.39: icmp_seq=5 ttl=128 time=0.677 ms
64 bytes from 169.254.134.39: icmp_seq=6 ttl=128 time=0.660 ms
^C
--- 169.254.134.39 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5172ms
rtt min/avg/max/mdev = 0.660/1.270/2.858/0.831 ms
正在 Ping 169.254.134.37 具有 32 字节的数据:
来自 169.254.134.37 的回复: 字节=32 时间<1ms TTL=64
来自 169.254.134.37 的回复: 字节=32 时间<1ms TTL=64
来自 169.254.134.37 的回复: 字节=32 时间=1ms TTL=64
来自 169.254.134.37 的回复: 字节=32 时间<1ms TTL=64
169.254.134.37 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 1ms,平均 = 0ms
将矿卡和PC连接在同一路由器,测试中手动设置矿卡的IP地址:
sudo ifconfig eth0 192.168.1.150
查看PC的网络配置:
C:\Users\[用户名]>ipconfig
...
无线局域网适配器 WLAN:
IPv4 地址 : 192.168.1.100
子网掩码 : 255.255.255.0
默认网关 : 192.168.1.1
双机互ping结果:
wind@localhost:~$ ping 192.168.1.100
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=128 time=4.38 ms
64 bytes from 192.168.1.100: icmp_seq=2 ttl=128 time=2.09 ms
64 bytes from 192.168.1.100: icmp_seq=3 ttl=128 time=2.64 ms
64 bytes from 192.168.1.100: icmp_seq=4 ttl=128 time=4.22 ms
64 bytes from 192.168.1.100: icmp_seq=5 ttl=128 time=4.14 ms
64 bytes from 192.168.1.100: icmp_seq=6 ttl=128 time=1.88 ms
64 bytes from 192.168.1.100: icmp_seq=7 ttl=128 time=7.34 ms
64 bytes from 192.168.1.100: icmp_seq=8 ttl=128 time=4.30 ms
64 bytes from 192.168.1.100: icmp_seq=9 ttl=128 time=5.83 ms
64 bytes from 192.168.1.100: icmp_seq=10 ttl=128 time=10.0 ms
^C
--- 192.168.1.100 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9014ms
rtt min/avg/max/mdev = 1.878/4.687/10.048/2.381 ms
正在 Ping 192.168.1.150 具有 32 字节的数据:
来自 192.168.1.150 的回复: 字节=32 时间=8ms TTL=64
来自 192.168.1.150 的回复: 字节=32 时间=4ms TTL=64
来自 192.168.1.150 的回复: 字节=32 时间=3ms TTL=64
来自 192.168.1.150 的回复: 字节=32 时间=8ms TTL=64
192.168.1.150 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 3ms,最长 = 8ms,平均 = 5ms
注:手动设置矿卡的IP地址时,注意不要与同网络中其它主机冲突,可在路由器管理界面查看或设置为自动获取IP。
自动获取IP所需工具,可在连接互联网后手动安装。
首先需配置DNS服务器,执行:
sudo vim /etc/resolv.conf
编辑该文件,修改nameserver项为:
nameserver 8.8.8.8
注:DNS服务器地址可使用上述的谷歌DNS服务器,也可以使用各运营商提供的DNS服务。
配置矿卡的IP地址,以及在系统路由表中添加网关地址:
sudo ifconfig eth0 192.168.1.150
sudo route add default gw 192.168.1.1
注:如果路由表中没有有效网关,则与外网通信时会报错:Network is unreachable(网络不可达)。使用命令:
route
可查看本地路由表。
此时ping必应等网站就可以正常ping通啦!看!
wind@localhost:~# ping cn.bing.com
PING a-0001.a-msedge.net (204.79.197.200) 56(84) bytes of data.
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=1 ttl=111 time=61.0 ms
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=2 ttl=111 time=60.3 ms
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=3 ttl=111 time=60.3 ms
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=5 ttl=111 time=60.7 ms
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=6 ttl=111 time=60.2 ms
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=7 ttl=111 time=60.6 ms
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=8 ttl=111 time=60.4 ms
64 bytes from a-0001.a-msedge.net (204.79.197.200): icmp_seq=9 ttl=111 time=60.5 ms
^C
--- a-0001.a-msedge.net ping statistics ---
9 packets transmitted, 8 received, 11.1111% packet loss, time 8014ms
rtt min/avg/max/mdev = 60.215/60.500/61.014/0.250 ms
在上述DNS服务器修改方式中,重新启动矿卡则文件内容会被重置(其实文件注释里已经说过了,不过我打赌你没看>v<),所以为了让系统记住修改,需要修改另外的文件:
sudo vim /etc/systemd/resolved.conf
将DNS行解注释,修改为:
[Resolve]
DNS=8.8.8.8
...
再次重启系统,则DNS服务器不需重新设置了。
注:有报告说这种修改方式存在无效的可能,不过在笔者调试时,确实解决了联网问题。
同样,为了实现在开机时对网络的自动设置,可做如下修改:
sudo vim /etc/network/interfaces
在其中添加如下设置即可(请根据具体需求更改参数):
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
以下操作在目标根文件系统上层目录依次进行:
mkdir rootfs
dd if=/dev/zero of=Ubuntu20.04_EBAZ4205.img bs=1M count=2500 #生成的空镜像大小需根据待写入文件数量确定
mkfs.ext4 Ubuntu20.04_EBAZ4205.img
sudo mount Ubuntu20.04_EBAZ4205.img rootfs/
sudo cp -rfp [目标根文件系统文件夹]/* rootfs/
sudo umount rootfs/
e2fsck -p -f Ubuntu20.04_EBAZ4205.img #检查档案完整性
resize2fs -M Ubuntu20.04_EBAZ4205.img #重新调整镜像大小
最终得到该分区的镜像文件可作他用。
至此,基于Ubuntu Base 20.04的系统移植完成。
本文编写过程中参考的所有资料均列在下方。本文若与任何列表之外的文章、博客、视频、教程等描述相同或相似则纯属巧合。
另在此处再次对以下资料的作者们表示感谢。
————2020-11-18 @燕卫博————