☰
【嵌入式开发】通过Ubuntu Base构建一个ARM64架构的Ubuntu根文件系统
2026/10/7 19:23:51 网站建设 项目流程

Ubuntu Base是Ubuntu官网提供的一个最小化的文件系统,本文将介绍一下如何通过Ubuntu官方提供的Ubuntu Base包来构建一个ARM64架构的Ubuntu根文件系统
1.创建一个2G大小的ext4镜像

ddif=/dev/zeroof=ubuntu-24.04.4-ext4.imgbs=2Gcount=1mkfs.ext4 ubuntu-24.04.4-ext4.img

2.下载并解压ubuntu base包

mkdirubuntu-rootfsmount-text4-orw ubuntu-24.04.4-ext4.img ubuntu-rootfswgethttp://cdimage.ubuntu.com/ubuntu-base/releases/24.04.4/release/ubuntu-base-24.04.4-base-arm64.tar.gzsudotarxvf ubuntu-base-24.04.4-base-arm64.tar.gz-Cubuntu-rootfs

3.搭建arm64模拟环境(安装qemu-user-static)

sudoapt-getinstallqemu-user-staticcp/usr/bin/qemu-aarch64-static ubuntu-rootfs/usr/bin/

4.拷贝当前主机的网络配置文件

cp/etc/resolv.conf ubuntu-rootfs/etc/cp/etc/host.conf ubuntu-rootfs/etc/cp/etc/hosts ubuntu-rootfs/etc/

注:主要是拷贝DNS解析器配置文件resolv.conf,不拷贝的话切换到ARM64 Ubuntu根文件系统时将无法使用网络
5.通过chroot切换根文件系统为ubuntu-rootfs

sudomount-tproc /proc ubuntu-rootfs/procsudomount-tsysfs /sys ubuntu-rootfs/syssudomount-obind/dev ubuntu-rootfs/devsudomount-obind/dev/pts ubuntu-rootfs/dev/ptssudochrootubuntu-rootfs

6.安装基础软件包

apt-get-yinstallvimapt-get-yinstallsystemdapt-get-yinstallsudoapt-get-yinstalllocalesapt-get-yinstallnet-toolsapt-get-yinstallopenssh-serverapt-get-yinstallresolvconfapt-get-yinstallinetutils-pingapt-get-yinstallnetplan.ioapt-get-yinstallnetwork-managerapt-get-yinstallrsyslogapt-get-yinstallbash-completionapt-get-yinstallkmod

7.修改root密码

passwdroot

8.添加用户和用户组

groupaddmyuseruseradd-s/bin/bash-m-d/home/myuser-gmyuser myuserpasswdmyuser

9.将新用户添加到sudo组

chmod+w /etc/sudoersvi/etc/sudoers

添加如下内容:

myuserALL=(ALL:ALL)ALL

移除/etc/sudoers文件的写权限

chmod-w/etc/sudoers

10.设置主机名

vi/etc/hostname

修改为Ubuntu
11.设置自动更新dns

dpkg-reconfigure resolvconf

12.退出ARM64根文件系统

sudoumountubuntu-rootfs/procsudoumountubuntu-rootfs/syssudoumountubuntu-rootfs/dev/ptssudoumountubuntu-rootfs/devsudoumountubuntu-rootfs

之后就可以将ubuntu-24.04.4-ext4.img刷到开发板中使用了

备注:
1.执行apt-get命令时提示如下错误:

Get:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease[265kB]Err:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease Couldn't create temporaryfile/tmp/apt.conf.eSH1gIforpassing config to apt-key Get:2 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease[114kB]

解决方法:

chmod777/tmp-R

2.host系统和ubuntu base要对应起来,否则会提示如下错误:

qemu: Unsupported syscall:278

如果系统不对应,apt-get安装软件时也可能会报错

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询