侧边栏壁纸
博主头像
塞塞哇 博主等级

开源创客

  • 累计撰写 38 篇文章
  • 累计创建 9 个标签
  • 累计收到 11 条评论

目 录CONTENT

文章目录

基于update.img构建二开定制化Ubuntu根文件系统

塞塞蛙
2024-05-22 / 0 评论 / 0 点赞 / 400 阅读 / 0 字

基于update.img构建二开定制化Ubuntu根文件系统

此教程是根据官方Ubutnu20的完整镜像包拆包后进行二次定制化构建。

选择二开的原因是在官方包基础上已经集成大部分工具和驱动程序,即我们在使用的时候只需要在基础之上部署好自己所需要的环境,再二次打包后进行替换,节省搭建环境时间以及免调试!

* 下载官方Ubutnu20镜像包

官方Ubuntu20下载地址:https://lceda001.feishu.cn/wiki/JnISwzuAuiRUt2kCSZTcfNainze

* 解包提取rootfs.img

下载开发工具:https://lceda001.feishu.cn/wiki/Z67Owir2piLkrHkxTchcQ5prnMg

本次我们使用的工具是:RKDevTool_Release_v2.92

打开工具,在高级中选择下载的固件并执行解包

0

解包好的输出路径可在工具目录下:

\RKDevTool_Release_v2.92\Output\Android 找到解包的镜像

image-hdyw.png

其中rootfs.img为我们需要操作的镜像文件

* 拷贝镜像复制文件内容

将rootfs.img复制到Ubuntu开发环境下的虚拟机中。

在rootfs.img所在的路径下创建两个文件夹ubuntu20_base,ubuntu_base_rootfs

mkdir ubuntu20_base
mkdir ubuntu_base_rootfs

赋予权限

sudo chmod 777 ubuntu20_base 
sudo chmod 777 ubuntu_base_rootfs

挂载镜像到 ubuntu_base_rootfs

​​sudo mount rootfs.img ubuntu_base_rootfs/

复制文件内容到 ubuntu20_base

sudo cp -rfp ubuntu_base_rootfs/* ubuntu20_base

卸载挂载

sudo umount ubuntu_base_rootfs

删除原始镜像(可选)

sudo rm -rf rootfs.img

* 虚拟环境进入根文件系统

安装QEMU环境

sudo apt install qemu-user-static

复制网络环境

sudo cp /etc/resolv.conf  ubuntu20_base/etc/

复制仿真环境

sudo cp /usr/bin/qemu-aarch64-static ubuntu20_base/usr/bin/

更改apt源

​​vim ubuntu20_base/etc/apt/sources.list

打开编译器后,清空里面的内容可使用 按下:号输入 %d回车

复制下面的内容并保存退出

# 默认注释了源码仓库,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse

创建挂载工具

​​sudo vim mount.sh

挂载脚本文件内容:

#!/bin/bash
function mnt() {
    echo "MOUNTING"
    sudo mount -t proc /proc ${2}proc
    sudo mount -t sysfs /sys ${2}sys
    sudo mount -o bind /dev ${2}dev
    #sudo mount -t devpts -o gid=5,mode=620 devpts ${2}dev/pts
    sudo mount -o bind /dev/pts ${2}dev/pts
    sudo chroot ${2}
}
function umnt() {
    echo "UNMOUNTING"
    sudo umount ${2}proc
    sudo umount ${2}sys
    sudo umount ${2}dev/pts
    sudo umount ${2}dev
}
if [ "$1" == "-m" ] && [ -n "$2" ];
then
        mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
        umnt $1 $2
else
        echo ""
        echo "Either 1'st, 2'nd or both parameters were missing"
        echo ""
        echo "1'st parameter can be 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 /media/sdcard"
        echo ""
        echo 1st parameter : ${1}
        echo 2nd parameter : $[2]
fi

添加脚本执行权限

​​sudo chmod +x mount.sh

挂载根文件系统

./mount.sh -m ubuntu20_base/

此命令执行成功后你就进入了仿真ubuntu环境了,我们可以在里面安装自己的软件配置等。

执行apt更新命令

​​apt update

安装自己的软件,这里不做过多赘述了。

退出根文件系统

命令

​​exit

卸载挂载的文件系统

sudo ./mount.sh -u ubuntu20_base/
  1. 重新打包根文件系统镜像

制作自己的根文件系统,大小依据自己的根文件系统而定,注意依据 ubuntu20_base 文件夹的大小来修改 count 值(可配合sudo du -sh xxx)

创建空镜像

sudo dd if=/dev/zero of=ubuntu_rootfs.img bs=1M count=6000

格式化

sudo mkfs.ext4 ubuntu_rootfs.img

挂载镜像到指定文件夹

sudo mount ubuntu_rootfs.img ubuntu_base_rootfs

复制ubuntu20_base里的全部内容到ubuntu_base_rootfs文件夹内

sudo cp -rfp ubuntu20_base/* ubuntu_base_rootfs

卸载镜像

sudo umount ubuntu_base_rootfs/

修复及检测镜像文件系统

sudo e2fsck -p -f ubuntu_rootfs.img

镜像压缩

sudo resize2fs -M ubuntu_rootfs.img

最终得到了ubuntu_rootfs.img根文件系统,我们可以将此系统直接烧到开发板上验证了!

* 打包update.img镜像

在下图中的目录下新建文件夹

image-omlo.png

package-file文件可以在解包的时候找到此文件,需要复制到指定的这个文件下。

创建文件夹 Image 大小写注意

将文件复制到Image内

image-kdry.png

删除原先的rootfs.img文件

修改ubuntu_rootfs.img文件名为 rootfs.img

返回上一级,在目录下打开命令行控制台

0

输入执行的bat文件

成功的输出

0

0

* 测试烧录

image-cfjg.png

参考文章:

https://oshwhub.com/forum/post/a81bfab590fa4d2b9312c95c8c8c3f9b

https://lceda001.feishu.cn/wiki/Da5owUV4dipiqUkZycbcxckinvc

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区