RK3588构建ubuntu22.04根文件系统

embedded/2024/9/24 23:39:28/

前言

RK系列的平台提供了buildroot和debian的系统,使用脚本可以直接构建出来,但是没有提供ubuntu的系统,很多厂商只提供一个rootfs.img的固件包,没有将方法开源出来。本文实现了从ubuntu官网开始构建一个ubuntu22.04根文件系统。

ubuntu-base

什么是ubuntu base?, ubuntu针对不同的CPU架构提供相应的ubuntu base 根文件系统,目前提供的架构有amd64, arm64m armhf, i386, s390x, ppc64.
ubuntu base 是用于为特定需求创建自定义映像的最小rootfs, 是ubuntu可以运行的最小环境。

Ubuntu Base 22.04.4 LTS (Jammy Jellyfish)下载地址:
https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/
在这里插入图片描述
本文最终运行的环境是RK3588,所以下载的是ubuntu-base-22.04-base-arm64.tar.gz的压缩包。
解压:

bash">mkdir rootfs
tar -zxvf ubuntu-base-22.04-base-arm64.tar.gz -C rootfs/

挂载构建文件系统

配置网络

bash">sudo cp /etc/resolv.conf rootfs/etc/

安装qemu,
qemu是用来仿真arm64平台的,使得arm64的系统可以再x86平台运行起来。

bash">$sudo apt install qemu-user-static
sudo cp /usr/bin/qemu-aarch64-static rootfs/usr/bin/

修改源改为阿里源:

ubuntu 阿里 arm源地址:
https://developer.aliyun.com/mirror/ubuntu-ports?spm=a2c6h.13651104.d-1008.9.742b4763eLldW3

bash">sudo vim rootfs/etc/apt/sources.list
bash">deb http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse

设置权限

bash">cd rootfs
sudo chmod 777 -R tmp/
cd ..

编写挂载脚本mount.sh,内容如下:

bash">#!/bin/bashfunction mnt() {echo "MOUNTING"sudo mount -t proc /proc ${2}procsudo mount -t sysfs /sys ${2}syssudo mount -o bind /dev ${2}devsudo mount -o bind /dev/pts ${2}dev/ptssudo chroot ${2}
}function umnt(){echo "unmounting"sudo umount ${2}procsudo umount ${2}syssudo umount ${2}dev/ptssudo umount ${2}dev}if [ "$1" == "-m" ] && [ -n "$2" ];
thenmnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
thenumnt $1 $2
elseecho ""echo "Either 1'st, 2'nd or both parameters were missing"echo ""echo "1'st parameter can ben one of these: -m(mount) OR -u(umount)"echo "2'nd parameter is the full path of rootfs directory(with tralling '/')"echo ""echo "For example: ch-mount -m /meadia/sdcard"echo ""echo 1st parameter : ${1}echo 2nd parameter : ${2}
fi

挂载

bash"> ./mount.sh -m rootfs/

挂载完后,就会切换到ubuntu22.04的根文件系统,因为使用了qemu,后面就可以再arm64平台操作执行了。
进入后先执行,apt update,更新最新的源

bash">apt update

如果执行中出现如下错误

bash">W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-security/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy-backports/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu-ports/dists/jammy/InRelease: No system certificates available. Try installing ca-certificates.

这是因为https是加密协议,需要直接使用阿里源会要求安装证书。而我们刚开展做新的系统apt又用不了,所以此处将source.list中的https都替换为http即可。

如果出现下列错误,说明是文件没有权限,在挂载前就需要将rootfs/tmp目录设置可读写权限。

bash">W: GPG error: http://mirrors.aliyun.com/ubuntu-ports jammy InRelease: Couldn't create temporary file /tmp/apt.conf.nNgmYa for passing config to apt-key
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports jammy InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease: Couldn't create temporary file /tmp/apt.conf.cnD2Tw for passing config to apt-key
E: The repository 'http://mirrors.aliyun.com/ubuntu-ports jammy-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

安装需要的包

bash">apt install sudo vim udev net-tools ethtool udhcpc netplan.io language-pack-en-base language-pack-zh-han* iputils-ping openssh-sftp-server  ntp usbutils alsa-utils libmtp9  ssh  htop network-managerapt install gcc g++

桌面安装

如果需要使用桌面,建议直接安装轻量级的桌面lxde,

bash">apt install lxde

添加用户

bash">adduser ubuntu
adduser ubuntu sudo

退出挂载的文件系统

bash">exit
./mount.sh -u rootfs/

制作rootfs

创建一个空镜像文件

bash">dd if=/dev/zero of=ubuntu2204_rootfs.img bs=1M count=5120

将该文件格式化为ext4文件系统

bash">mkfs.ext4 ubuntu2204_rootfs.img

创建一个空的文件,挂载镜像

bash">mkdir temp
sudo mount ubuntu2204_rootfs.img temp/
bash">cp -rfp rootfs/* temp/
# -r:递归文件夹
# -f:强制
# -p:不拷贝符号链接的目标文件,仅拷贝该符号链接

卸载镜像

bash">umount temp/

e2fsck 检查镜像的文件系统。resize2fs 减小镜像文件的大小

bash">$ e2fsck -p -f ubuntu2204_rootfs.img
$ resize2fs -M ubuntu2204_rootfs.img

至此,最小的ubuntn22.04文件系统做完,可以直接烧录到RK板子上。


http://www.ppmy.cn/embedded/21350.html

相关文章

深圳杯东三省联赛数学建模挑战赛2024D题

音板的振动模态分析与参数识别 音乐来自乐器,乐器产生于制造,而制造需要数理逻辑。 在20世纪末,我国就已经形成了较为完整的乐器工业生产体系,基本可以加工世界上所有大类乐器,门类齐全,品种众多。其中&am…

Hotcoin Academy 市场洞察-2024年4月15日-21日

加密货币市场表现 BTC ETF在本周出现净流出,大盘有较大跌幅,BTC一度跌破60000美金,ETH一度跌破2800美金,整体以横盘为主,行情在周末有略微回升趋势。BTC市占率创21年4月来新高,目前市值1.28万亿&#xff0c…

成为程序员后你都明白了什么?

方向一:技术成长 作为程序员的技术成长和突破,我将其划分为几个阶段。 1、基础知识阶段。我投入大量时间学习编程语言的基础知识,如数据类型、循环、函数等,并通过具体的编程任务将所学知识转化为实战经验。 2、进阶技术阶段。…

idea 的使用和安装 以及简介

Java开发工具 大家刚才写代码的时候都是用记事本写的,但是有没有觉得记事本写代码不太方便啊!记事本写代码单词写错了没有提示,格式也不好调整,写代码之后还需要我们到命令行使用javac命令手动编译,然后运行。 有没有一…

SQL中top的使用

1.介绍&#xff1a;查询最热门&#xff0c;最高的分的前几条数据 2.top的使用 &#xff08;1&#xff09;返回确定数目的记录个数 语法格式&#xff1a; SELECT TOP n <列名表> FROM <表名> [查询条件] 其中&#xff0c;n为要返回结果集中的记录条数 &#xf…

深度学习与目标检测:从卷积神经网络到YOLOv8概念介绍

深度学习与目标检测&#xff1a;从卷积神经网络到YOLOv8的深入探索 随着人工智能技术的迅猛发展&#xff0c;深度学习和计算机视觉领域取得了举世瞩目的成果。在目标检测这一关键任务中&#xff0c;卷积神经网络&#xff08;CNN&#xff09;和YOLO系列模型发挥着至关重要的作用…

代码随想录训练营25day-贪心算法3

一、1005 k次取反后最大化数组 主要是用贪心的思维解决问题&#xff0c;达到训练的目的。题目中说明了必须要用k次&#xff0c;数组也有负数或者正数&#xff0c;怎么让数组最大化呢&#xff1f; 1 k次范围内&#xff0c;把所有的负数全部翻转&#xff0c;这样能够最大化&…

【MySQL】函数

1. 函数简介 SQL 语言中&#xff0c;包括了内置函数和自定义函数。内置函数是系统内置的通用函数&#xff0c;而自定义函数是我们根据自己的需要编写的。MySQL提供的内置函数实现的功能角度可以分为 数值函数、字符串函数、日期和时间函数、流程控制函数、加密与解密函数、获取…