修改适用于ARM平台上的Ubuntu rootfs(根文件系统)

来源:互联网 发布:洪恩软件开天辟地下载 编辑:程序博客网 时间:2024/06/05 19:56

0、背景

 本文在RK3399开发板上的Ubuntu rootfs(根文件系统)基础上进行用户自定义软件,并生成可以进行烧录的统一固件。

1、获得Ubuntu rootfs

Ubuntu rootfs镜像压缩包
将ubuntu-rootfs.img.tar.bz2里面的ubuntu-rootfs.img解压出来,用于后面的镜像挂载。
创建一个目录,我们接下来在这个目录中构建目标rootfs

mkdir ~/ubuntu-rootfscd ubuntu-rootfs 

将ubuntu-rootfs.img拷贝到ubuntu-rootfs里面

2、挂载ubuntu-rootfs.img

sudo mount -o loop ubuntu-rootfs.img ~/ubuntu-rootfs

//将ubuntu-rootfs.img挂载到刚才建的目录(~/ubuntu-rootfs)里

3、下载qemu static解释器

由于我们要chroot,所以需要能够在chroot环境执行armhf版本的binary,所以我们要接触linux的binfmt机制和qemu static解释器

sudo apt-get install qemu-user-staticasudo cp /usr/bin/qemu-arm-static /home/cjn/ubuntu-rootfs/usr/bin/

4、先将本机的dns配置复制到目标rootfs,后面联网时会用到

sudo cp -b /etc/resolv.conf ~/ubuntu-rootfs/etc/resolv.conf

5、挂载相关文件系统并chroot

sudo mount -t proc /proc ~/ubuntu-rootfs/procsudo mount -t sysfs /sys ~/ubuntu-rootfs/syssudo mount -o bind /dev ~/ubuntu-rootfs/devsudo mount -o bind /dev/pts ~/ubuntu-rootfs/dev/pts# 进入chroot环境sudo chroot ~/ubuntu-rootfs/# 更新reposudo apt-get update

6、 添加自己的软件,此时进行的所有操作和改变,都是在根文件系统中进行的

7、退出chroot环境

exit

8、卸载ubuntu-rootfs.img镜像

sudo umount /home/cjn/ubuntu-rootfs

大功告成

原创粉丝点击