在imx6ull上构建ubuntu-base系统
大家肯定会有疑问,能不能在 ALPHA 开发板上运行 Ubuntu 呢?答案肯定是可以的, Ubu
ntu 是 Linux 系统的一种,可以简单的将 Ubuntu 理解为一个根文件系统,和我们用busybox、 buildroot 制作的根文件系统一样。因此移植 Ubuntu 也就是将 Ubuntu 根文件系统移植到我们的开发板上,但是因为 I.MX6ULL 孱弱的性能,本章我们就只移植 Ubuntu 的最小根文件系统,没有图形化界面。
下载ubuntu-base系统
I.MX6ULL 是 Cortex-A 内核的 CPU,并且有硬件浮点运算单元,因此选择 armhf 版本。
ubuntu-base-22.04-base-armhf.tar.gz

nfs目录下创建文件夹存放rootfs系统,然后解压

安装 qemu
需要在 PC 的 Ubuntu 上安装 qemu 工具,命令如下:
sudo apt-get install qemu-user-static
安装后吧刚刚安装的 qemu-user-static 拷贝到刚刚解压出来的 ubuntu base 目录中,也就是 ubuntu_rootfs/usr/bin 目录下,命令如下:
sudo cp /usr/bin/qemu-arm-static ./usr/bin/

编辑软件源
我们在 ubuntu 下使用 apt-get 安装软件的时候,是从网上下载软件并安装的,因此需要指
定软件源。在设置软件源之前先将 Ubuntu 主机下的 DNS 配置文件/etc/resolv.conf 拷贝到根文件
系统中,命令如下:
sudo cp /etc/resolv.conf ./etc/resolv.conf
设置软件源,打开根文件系统中的 ubuntu_rootfs/etc/apt/sources.list 文件,在此文件最后面
添加软件源,比如国内常用的清华源、中科大源等等,这些软件源可以直接在网上查找。
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
sudo tee /etc/apt/sources.list << 'EOF'
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
EOF

使用脚本挂载和卸载
创建挂载和卸载脚本
ubuntu-base根目录下创建
mount.sh
#!/bin/bash
echo "MOUNTING"
sudo mount -t proc /proc /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/proc
sudo mount -t sysfs /sys /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/sys
sudo mount -o bind /dev /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/dev
sudo mount -o bind /dev/pts /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/dev/pts
sudo chroot /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs
unmount.sh
!/bin/bash
echo "UNMOUNTING"
sudo umount /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/proc
sudo umount /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/sys
sudo umount /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/dev/pts
sudo umount /home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs/dev
添加777权限
挂载rootfs

安装常用的命令和软件
apt update
首先检查/tmp目录属性,
ls -ld /tmp

chmod 1777 /tmp
ls -ld /tmp

安装sudo
apt install sudo

安装安全证书
sudo apt install ca-certificates -y
apt update正常

修复 Locale 警告
apt install locales -y
locale-gen zh_CN.UTF-8
locale-gen en_US.UTF-8
# 设置默认 locale(可选)
update-locale LANG=en_US.UTF-8
安装其他软件
apt install vim
apt install kmod
apt install net-tools
apt install ethtool
apt install ifupdown
apt install language-pack-en-base
apt install rsyslog
apt install htop
apt install iputils-ping
apt install systemctl
apt install file
apt-get install systemd-sysv
apt-get install udev
设置 root 用户密码
passwd root
设置为000000
设置本机名称和ip
echo "imxmyboard" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 imxmyboard" >> /etc/hosts

echo "alientek_imx6ul" > /etc/hostname
✅ 必须做
-
这个文件设置了系统的主机名
-
执行后会在命令行显示为:root@alientek_imx6ul:~#
-
很多网络服务和程序会读取这个文件
/etc/hosts 中的两行配置
第一行:127.0.0.1 localhost
✅ 必须做
-
这是标准的本地回环地址配置
-
几乎所有 Linux 系统都有这一行
-
缺少会导致很多程序(如 sudo、很多服务)运行缓慢或报错
第二行:127.0.0.1 alientek_imx6ul
⚠️ 不是必须,但建议做
-
将主机名也指向本地回环地址
-
主要作用:
-
避免某些程序解析主机名时去查询 DNS(加快速度)
-
防止主机名被解析成外网 IP 导致奇怪的问题
添加串口终端
ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service
上述命令报错,安装apt-get install udev,apt-get install systemd-sysv后解决
在 chroot (QEMU) 环境下,你可以通过执行以下两条命令,手动为 ttymxc0 创建串口服务的系统软链接。这和执行 systemctl enable 的效果是一样的:
1. 创建 getty 服务的自启动目录(如果它还不存在的话)
mkdir -p /etc/systemd/system/getty.target.wants/
2. 创建软链接,将 systemd 的串口模板映射给 ttymxc0
ln -s /lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttymxc0.service
退出挂载

uboot配置环境变量
setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs \
nfsroot=192.168.2.4:/home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs rw \
ip=dhcp'
2026年4月14日更新为192.168.2.11
setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs \
nfsroot=192.168.2.11:/home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs rw \
ip=dhcp'
setenv serverip '192.168.2.11'
console=ttymxc0,115200 root=/dev/nfs nfsroot=... rw ip=dhcp quiet systemd.show_status=false
setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs \
nfsroot=192.168.2.4:/home/lhb/linux/imx6ull/nfs/ubuntu2204_rootfs rw \
ip=dhcp quiet systemd.show_status=false'
在 Linux 内核的启动参数(bootargs)中,root=/dev/nfs 是一个非常特殊且关键的占位符。
简单来说,它的意思是告诉 Linux 内核: “不要去 eMMC、SD 卡或者任何本地硬盘上找根文件系统(RootFS)了,我的根目录是通过网络(NFS)挂载过来的!”
如果碰到串口终端问题

rootfs文件夹本身修改权限
# 把文件夹所有者改为 root
sudo chown root:root ubuntu2204_rootfs
# 把文件夹权限改为 755 (drwxr-xr-x)
sudo chmod 755 ubuntu2204_rootfs
注意解压rootfs时使用sudo
sudo tar -vxzf ubuntu-base-22.04-base-armhf.tar.gz

强制指定串口的终端类型
在 chroot 环境中,编辑 /etc/profile 文件:
bash
nano /etc/profile
在文件的末尾添加以下两行:
export TERM=linux
export TERMINFO=/lib/terminfo
确保 devpts 被正确挂载
bash 需要伪终端(PTY)系统来管理进程组(作业控制)。如果 /dev/pts 没有挂载,就会报 no job control 和 cannot set terminal process group。
在 chroot 环境中,检查或编辑 /etc/fstab 文件:
bash
nano /etc/fstab
确保文件中有以下这两行(如果没有,请手动添加进去):
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
修复 securetty (允许 root 正常登录)
echo "ttymxc0" >> /etc/securetty

多串口问题
ls -l /etc/systemd/system/getty.target.wants/

删除错误串口
rm /etc/systemd/system/getty.target.wants/getty@ttymxc0.service
创建正确的串口
ln -sf /lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttymxc0.service
设置域名服务器
nameserver 114.114.114.114
nameserver 192.168.2.1

需要删除软链接然后手动设置

rm -f /etc/resolv.conf
echo "nameserver 114.114.114.114" > /etc/resolv.conf
echo "nameserver 192.168.2.1" >> /etc/resolv.conf
设置后可以正常apt更新

添加普通用户
adduser lhb
默认情况下新用户是不能使用 sudo 命令的,即使你输入了密码也不能使用 sudo,会提示“
zuozhongkai is not in the sudoers file. This incident will be reported.”错误,如图
我们需要修改/etc/sudoers 文件,首先使用如下命令切换回 root 用户:
su //切换回 root 用户
/etc/sudoers 文件默认是只读的,因此需要先修改此文件的写权限,使用如下命令:
chmod u+w /etc/sudoers
然后使用 vi 打开/etc/sudoers,找到“root ALL=(ALL:ALL) ALL”这一行,在这一行下面
添加:
zuozhongkai ALL=(ALL:ALL) ALL
表示“zuozhongkai”这个用户可以执行 sudo 命令,但是要输入密码,设置完成以后如图
vim /etc/sudoers
修改完成以后保存退出,重新恢复/etc/sudoers 的只读属性,使用如下命令:
chmod u-w /etc/sudoers
编译程序测试

保存镜像
在你的 Ubuntu 虚拟机(宿主机)里执行:
cd /home/lhb/linux/imx6ull/nfs/
sudo tar -cvpzf ubuntu2204_rootfs_perfect_base.tar.gz ubuntu2204_rootfs/


浙公网安备 33010602011771号