目录
Ubuntu 的移植非常简单,不需要我们编译任何东西,因为 Ubuntu 官方已经将根文件系统 制作好了!我们只需要简单配置一下 Ubuntu 官方提供的 base 根文件系统,使其在我们的开发 板上跑起来即可。因此我们首先需要下载 Ubuntu-base,为了和我们的教程一致,本章我们移植 Ubuntu 16.04 版本根文件系统,有兴趣的可以移植其他版本的 Ubuntu 内核,比如 18.04。首先 肯定是到 Ubuntu 官 方 去 下 载 16.04 的 根 文 件 系 统 , 根 文 件 系 统 下 载 地 址 为 http://cdimage.ubuntu.com/,下载界面如图 A3.1.1 所示:
点击图 A3.1.1 中的 ubuntu-base,进入到 ubuntu-base 下载界面,如图 A3.1.2 所示:
点击图 A3.1.2 中的“releases”,下载 releases 版本的根文件系统,进去以后如图 A3.1.3 所 示:
从图 A3.1.3 可以看出,Ubuntu 提供了从 12.04 开始,一直到最新的 19.10 版本的 ubuntu base 供大家下载。我们选择 16.04.5,点击以后进入如图 A3.1.4 所示界面:
点击图 A3.1.4 中的“release”,进入 16.04.5 的下载界面,如图 A3.1.5 所示:
从图 A3.1.5 可以看出,Ubuntu 针对不同的 CPU 架构提供相应的 ubuntu base 根文件系统, 有 amd64(64 位 X86)、armhf、i386(32 位 X86)、powerpc、ppc64el 等系统的。I.MX6ULL 是 CortexA 内核的 CPU,并且有硬件浮点运算单元,因此选择 armhf 版本。在图 A3.1.5 中找到“ubuntubase-16.04.5-base-armhf.tar.gz”,也就是 16.04.5 版本的 ubuntu base 根文件系统,将其下载下来。
ubuntu 根文件系统构建
解压缩 ubuntu base 根文件系统
cd /home/zuozhongkai/linux/nfs //进入到 nfs 目录下mkdir ubuntu_rootfs //创建名为“ ubuntu_rootfs ”目录
sudo tar -vzxf ubuntu-base-16.04.5-base-armhf.tar.gz
解压完成以后如图 A3.2.1.1 所示:
安装 qemu
sudo apt-get install qemu-user-static
cd /home/zuozhongkai/linux/nfs/ubuntu_rootfs // 进入到 ubuntu_rootfs 目录下sudo cp /usr/bin/qemu-arm-static ./usr/bin/ //拷贝 qemu-arm-static
设置软件源
cd /home/zuozhongkai/linux/nfs/ubuntu_rootfs // 进入到 ubuntu_rootfs 目录下sudo cp /etc/resolv.conf ./etc/resolv.conf //拷贝 resolv.conf
#中科大源
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
大家将示例代码 A3.2.3.1 中的源添加到 sources.list 文件中即可。
在主机挂载并配置根文件系统
1、在主机挂载根文件系统
1 #!/bin/bash
2 echo "MOUNTING"
3 sudo mount -t proc /proc /home/zuozhongkai/linux/nfs/ubuntu_rootfs/proc
4 sudo mount -t sysfs /sys /home/zuozhongkai/linux/nfs/ubuntu_rootfs/sys
5 sudo mount -o bind /dev /home/zuozhongkai/linux/nfs/ubuntu_rootfs/dev
6 sudo mount -o bind /dev/pts /home/zuozhongkai/linux/nfs/ubuntu_rootfs/dev/pts
7 sudo chroot /home/zuozhongkai/linux/nfs/ubuntu_rootfs
1 #!/bin/bash
2 echo "UNMOUNTING"
3 sudo umount /home/zuozhongkai/linux/nfs/ubuntu_rootfs/proc
4 sudo umount /home/zuozhongkai/linux/nfs/ubuntu_rootfs/sys
5 sudo umount /home/zuozhongkai/linux/nfs/ubuntu_rootfs/dev/pts
6 sudo umount /home/zuozhongkai/linux/nfs/ubuntu_rootfs/dev
sudo chmod 777 mount.sh unmount.sh
./mount.sh
挂载成功以后如图 A3.2.4.1 所示:
2、安装常用的命令和软件
apt updateapt install sudoapt install vimapt install kmodapt install net-toolsapt install ethtoolapt install ifupdownapt install language-pack-en-baseapt install rsyslogapt install htopapt install iputils-ping
3、设置 root 用户密码
passwd root //设置 root 用户密码
输入“passwd root”以后会让你输入 root 用户密码,输入两次,如图 A3.2.4.2 所示:
有兴趣的话也可以新建其他的用户并设置密码。
4、设置本机名称和 IP 地址
echo "alientek_imx6ul" > /etc/hostnameecho "127.0.0.1 localhost" >> /etc/hostsecho "127.0.0.1 alientek_imx6ul" >> /etc/hosts
5、设置串口终端
ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.
service
exit
退出以后再执行一下 unmount.sh 脚本取消挂载,命令如下:
./unmount.sh
至此,ubuntu base 根文件系统就已经制作好了,接下来就是挂载到开发板上去测试。
ubuntu 根文件系统测试
nfs 挂载测试
setenv bootargs ‘ console=tty1 console=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.1.253:/home/zuozhongkai/linux/nfs/ ubuntu_rootfs rw ip=192.168.1.251:192.168.1.253:192.168.1.1:255.255.255.0::eth0:off ’saveenv //保存环境变量
ubuntu 系统使用
添加新用户
1、添加新用户
adduser zuozhongkai //添加普通用户
新用户添加完成以后就可以重启开发板,然后使用新用户登录。
2、设置新用户可以使用 sudo 命令
su // 切换回 root 用户
chmod u+w /etc/sudoers
zuozhongkai ALL=(ALL:ALL) ALL
修改完成以后保存退出,重新恢复/etc/sudoers 的只读属性,使用如下命令:
chmod u-w /etc/sudoers
sudo fdisk -l
如果 sudo 运行正常的话就会打印出当前开发板的所有存储信息。
网络 DHCP 配置
su // 切换到 root 用户echo auto eth0 > /etc/network/interfaces.d/eth0echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0/etc/init.d/networking restart
安装软件
sudo apt-get install mplayer // 安装 mplayer
等待安装完成,完成以后就可以使用 mplayer 了,非常的方便。
FTP 服务器搭建
gcc 和 make 工具安装
sudo apt-get install gcc //安装 gcc 编译器sudo apt-get install make //安装 make 工具