i.MX6ULL - Ubuntu 18.04.05 LTS根文件系统移植教程
目录
1、根文件系统配置及测试
根文件系统的移植很简单的,ubuntu官方已经帮我们做好了,可以下载下来直接时候,但是这个根文件系统太过于精简(例如连ifconfig都没法使用),一些常用的工具都没有,所以我们还需要自己简单的配置一下才行。
ubuntu-base文件系统下载地址:http://cdimage.ubuntu.com/ubuntu-base/releases/
注:以下操作均在root下进行!
安装运行模拟器:
sudo apt install qemu-user-static
创建用于ubuntu-base根文件系统目录,并解压到该文件夹:
mkdir /ubuntu-18.04.5-lts-rootfs
tar xvf ubuntu-base-18.04.5-base-armhf.tar.gz -C /ubuntu-18.04.5-lts-rootfs
cd /ubuntu-18.04.5-lts-rootfs
拷贝CPU架构为ARM的模拟器到根文件系统:
sudo cp /usr/bin/qemu-arm-static ./usr/bin/
拷贝主机下的DNS配置文件,没有这个文件的话我们无法使用apt-get下载软件:
sudo cp /etc/resolv.conf ./etc/resolv.conf
添加源,打开sources.list
这个文件,在这个文件最后追加中科大源:
vi etc/apt/sources.list
添加:
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
在主机上挂载ubuntu-base文件系统,因为我们还需要下载一些常用工具,需要挂载的目录和文件有proc、sys、dev、dev/pts
这四个,挂载之后使用chroot
将主机的根文件系统切换成我们现在配置的ubuntu-base文件系统,操作命令如下:
sudo mount -t proc /proc ./proc
sudo mount -t sysfs /sysfs ./sys
sudo mount -o bind /dev ./dev
sudo mount -o bind /dev/pts ./dev/pts
sudo chroot ./
安装常用软件工具:
apt-get update
apt-get install -y sudo vim kmod net-tools ethtool ifupdown language-pack-en-base rsyslog htop iputils-ping dosfstools systemd
注意:ubuntu18必须安装systemd,否则没有串口设备文件
安装samba(可选):见博客:https://blog.csdn.net/qq153471503/article/details/79221047
安装ssh(可选):见博客:https://blog.csdn.net/qq153471503/article/details/79221199
设置root密码:
passwd root
设置主机名称:
echo "imx6ull" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 imx6ull" >> /etc/hosts
其中imx6ull
是主机名称,改成你要设置的即可。
设置串口终端:以串口1为例,它的设备文件名称为ttymxc0,所以使用ln命令创建一个软链接文件指向/lib/systemd/system/getty@.service
:
ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service
还配置网络自启,ubuntu-base根文件系统开机后默认网卡是没启动的。
我的板子支持双网口,这里以网口1(也就是eth0)示例:
echo auto eth0 > /etc/network/interfaces.d/eth0
echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0
(可选)如果你有网口2,那么在设置网口2(eth1)的配置:
echo auto eth1 > /etc/network/interfaces.d/eth1
echo iface eth1 inet dhcp >> /etc/network/interfaces.d/eth1
最后,退出当前文件系统,取消挂载proc、sys、dev、dev/pts
这四个目录和文件:
exit
sudo umount ./proc
sudo umount ./sys
sudo umount ./dev/pts
sudo umount ./dev
此时ubuntu-base根文件系统就配置完了,使用NFS挂载一下试试:
成功!
打包文件系统用于MfgTool工具烧写,进入ubuntu-base根文件系统目录:
cd /ubuntu-18.04.5-lts-rootfs
打包:
tar -vcjf ubuntu-18.04.5-lts-rootfs.tar.bz2 ./*
然后就可以将ubuntu-18.04.5-lts-rootfs.tar.bz2
使用 MfgTool 工具将 ubuntu 根文件系统烧写到开发板的EMMC或
NAND中了。
3、SSH远程登录测试
我使用的是mobaxtrem这个软件:
没问题!
2、samba与windows数据互传测试
4、如何将开发板设置为静态IP地址
系统开机的时候出现:
A start job is running for Raise network interface(5min 13s )
这是因为如果开发板开机的时候没有插网线,或者网络配置的不对,系统默认开机检测网络的超时时间是5分钟,这太长了!所以我们改为3s:
sudo vim /etc/systemd/system/network-online.target.wants/networking.service
将里面的TimeoutStartSec=5min
修改为TimeoutStartSec=3sec
,重启系统即可!
开发板静态IP地址设置:
vim /etc/network/interfaces.d/eth0
改为:
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.28.234
netmask 255.255.255.0
gateway 192.168.28.1
boardcast 192.168.28.255
vim /etc/network/interfaces.d/eth1
改为:
auto eth1
#iface eth1 inet dhcp
iface eth1 inet static
address 192.168.28.235
netmask 255.255.255.0
gateway 192.168.28.1
boardcast 192.168.28.255
!!重要!!
还需要配置DNS!否则无法访问外网,当你ping www.baidu.com
的时候,会出现以下错误:
Temporary failure in name resolution
Q:为什么使用DHCP动态获取IP地址的时候不需要设置DNS?
A:因为DHCP自动获取了!
网上的增加DNS的方法:
方法①:修改/etc/resolv.conf
文件,增加nameserver 114.114.114.114
,固然可行,但是重启开发板之后该文件又恢复默认了!所以此方法在我这里失败!
方法②:在/etc/network/interfaces.d/eth0
文件中加入dns-nameservers 8.8.8.8.8 114.114.114.114
,试过了,失败!
方法③:
以上两个办法都失败了,遂又仔细研究了之后,发现/etc/resolv.conf
有软链接,说明这是一个运行时文件,所以手动修改没有用,重启还是会恢复默认:
打开该文件中有注释:man systemd-resolved.service
所以这个文件是由systemd
工具所管理的,而systemd
工具的配置是在/etc/systemd
目录下,进入这个文件夹:
有一个resolved.conf
文件,猜测该文件就是DNS的配置文件,里面的内容都被屏蔽了,所以我们开启DNS的配置:
重启系统即可!
在查看一下/run/systemd/resolve/resolv.conf
文件,可以看到我们添加的DNS已经被写入该文件:
附上成功ping百度的截图:
ends…