
Ubuntu Base是Ubuntu官网提供的一个最小化的文件系统本文将介绍一下如何通过Ubuntu官方提供的Ubuntu Base包来构建一个ARM64架构的Ubuntu根文件系统1.创建一个2G大小的ext4镜像ddif/dev/zeroofubuntu-24.04.4-ext4.imgbs2Gcount1mkfs.ext4 ubuntu-24.04.4-ext4.img2.下载并解压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-rootfs3.搭建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-rootfssudomount-tproc /proc ubuntu-rootfs/procsudomount-tsysfs /sys ubuntu-rootfs/syssudomount-obind/dev ubuntu-rootfs/devsudomount-obind/dev/pts ubuntu-rootfs/dev/ptssudochrootubuntu-rootfs6.安装基础软件包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-yinstallkmod7.修改root密码passwdroot8.添加用户和用户组groupaddmyuseruseradd-s/bin/bash-m-d/home/myuser-gmyuser myuserpasswdmyuser9.将新用户添加到sudo组chmodw /etc/sudoersvi/etc/sudoers添加如下内容myuserALL(ALL:ALL)ALL移除/etc/sudoers文件的写权限chmod-w/etc/sudoers10.设置主机名vi/etc/hostname修改为Ubuntu11.设置自动更新dnsdpkg-reconfigure resolvconf12.退出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 Couldnt create temporaryfile/tmp/apt.conf.eSH1gIforpassing config to apt-key Get:2 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease[114kB]解决方法:chmod777/tmp-R2.host系统和ubuntu base要对应起来否则会提示如下错误:qemu: Unsupported syscall:278如果系统不对应apt-get安装软件时也可能会报错