前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【RK3399】制作ubuntu20.04 roomfs

【RK3399】制作ubuntu20.04 roomfs

作者头像
嵌入式与Linux那些事
发布2022-12-01 13:47:15
1.3K0
发布2022-12-01 13:47:15
举报
文章被收录于专栏:嵌入式与Linux那些事

firefly自带的文件系统,由于缺少一些基本功能模块,因此,我们可以自己手动制作一个ubuntu20.04的文件系统。

下载Ubuntu根文件系统

http://cdimage.ubuntu.com/ubuntu-base/releases/

安装虚拟机

代码语言:javascript
复制
apt-get install qemu-user-static

解压

代码语言:javascript
复制
mkdir ubuntu-rootfs
tar -xpf ubuntu-base-20.04.5-base-arm64.tar.gz  -C ubuntu-rootfs

复制一下虚拟机的运行环境

代码语言:javascript
复制
cp -b /etc/resolv.conf ubuntu-rootfs/etc/resolv.conf
cp /usr/bin/qemu-aarch64-static ubuntu-rootfs/usr/bin/

复制官方外设驱动文件

将开发板挂载到虚拟机上,将开发板的/vendor,/system,/lib/firmware,这三个文件夹复制到我们自己的文件系统中。

挂载根文件系统

创建ch-mount.sh文件,写入以下脚本

代码语言:javascript
复制
#!/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 -o bind /dev/pts ${2}dev/pts
    echo "CHROOT..."
    sudo chroot ${2}
    echo "Success!"
}
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 trailing '/')"
    echo ""
    echo "For example: ch-mount -m /media/sdcard/"
    echo ""
    echo 1st parameter : ${1}
    echo 2nd parameter : ${2}
fi

把下载好的脚本置于ubuntu-rootfs目录的上一级目录,并修改权限:

代码语言:javascript
复制
chmod a+x ch-mount.sh
./ch-mount.sh -m ubuntu-rootfs/

执行mount动作,注意退出后一定再执行 ./ch-mount.sh -u ubuntu-rootfs/,否则你的本机ubuntu系统会出问题,需要重启才能恢复正常。

拷贝bash依赖库

执行挂载脚本时遇到以下错误,可以拷贝bash动态库。

代码语言:javascript
复制
➜  tools sudo chroot ubuntu-rootfs 
chroot: failed to run command ‘/bin/zsh’: No such file or directory

查看/bin/bash文件所依赖的动态链接库,然后依次拷贝到相应目录。由于我安装了zsh,所以除了拷贝bash动态库外,还需要拷贝zsh动态库。没有安装zsh的可以不用拷贝zsh动态库。

代码语言:javascript
复制
zhongyi@ubuntu:~$ ldd /bin/zsh
        linux-vdso.so.1 (0x00007ffd5c1dc000)
        libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x00007f4b4d9d7000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4b4d7d3000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f4b4d5a9000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4b4d20b000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4b4ce1a000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4b4debc000)
zhongyi@ubuntu:~$ ldd /bin/bash
        linux-vdso.so.1 (0x00007ffd8335a000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f50a4d2a000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f50a4b26000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f50a4735000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f50a526e000)
代码语言:javascript
复制
$ mkdir lib64
$ cp /lib64/ld-linux-x86-64.so.2 ./lib64/
$ mkdir ./lib/x86_64-linux-gnu
$ cp /lib/x86_64-linux-gnu/libtinfo.so.5 ./lib/x86_64-linux-gnu/
$ cp /lib/x86_64-linux-gnu/libdl.so.2 ./lib/x86_64-linux-gnu/
$ cp /lib/x86_64-linux-gnu/libc.so.6 ./lib/x86_64-linux-gnu/ 
$ cp /lib/x86_64-linux-gnu/libcap.so.2 ./lib/x86_64-linux-gnu/ 
$ cp /lib/x86_64-linux-gnu/libm.so.6 ./lib/x86_64-linux-gnu/ 
$ cp /lib/x86_64-linux-gnu/libc.so.6 ./lib/x86_64-linux-gnu/ 
$cp /bin/bash ubuntu-rootfs/bin
$cp /bin/zsh ubuntu-rootfs/bin

执行挂载

成功挂载后,会看到自动切换为root用户。

代码语言:javascript
复制
zhongyi@ubuntu:~/tools$ ./ch-mount.sh -m ubuntu-rootfs/
MOUNTING...
CHROOT...
zsh: failed to load module `zsh/zle': /usr/lib/x86_64-linux-gnu/zsh/5.4.2/zsh/zle.so: cannot open shared object file: No such file or directory     
#已经成功挂载
ubuntu# 

安装必要的软件

代码语言:javascript
复制
apt-get update
apt-get -y install  vim nfs-common  sudo ssh net-tools ethtool wireless-tools  xfce4-power-manager xinit  network-manager iputils-ping rsyslog   bash-completion lxtask htop  synaptic  --no-install-recommends

更换源

代码语言:javascript
复制
vim /etc/apt/source.list
#添加中科大源
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe

#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

#添加清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

设置账户名和密码

代码语言:javascript
复制
useradd -s '/bin/bash' -m -G adm,sudo firefly
passwd firefly
passwd root

设置主机名

代码语言:javascript
复制
echo 'ubuntu.firefly' > /etc/hostname

添加主机入口到/etc/hosts

代码语言:javascript
复制
127.0.0.1 localhost 
127.0.0.1 ubuntu.firefly
127.0.1.1 firefly 

添加nameserver

代码语言:javascript
复制
vim /etc/resolvconf/resolv.conf.d/head
#添加nameserver
nameserver 114.114.114.114
nameserver 8.8.8.8

取消挂载

代码语言:javascript
复制
exit
./ch-mount.sh -u ubuntu-rootfs/

创建 mkrootfs.sh文件,写入以下脚本,其中2048取决于你的根文件系统实际大小,比如安装了桌面环境后若大小超过2048M,就改大一点

代码语言:javascript
复制
#!/bin/bash
# 
dd if=/dev/zero of=ubuntu-rootfs.img bs=1M count=2048
sudo  mkfs.ext4  ubuntu-rootfs.img
rm -r rootfs
mkdir  rootfs
sudo mount ubuntu-rootfs.img rootfs/
sudo cp -rfp ubuntu-rootfs/*  rootfs/
sudo umount rootfs/
e2fsck -p -f ubuntu-rootfs.img
resize2fs  -M ubuntu-rootfs.img

执行制作

代码语言:javascript
复制
➜  tools ./mkrootfs.sh
➜  tools ls -al |grep *.img
-rw-rw-r--  1 zhongyi zhongyi 1497706496 Sep 30 21:32 ubuntu-rootfs.img

烧写镜像

代码语言:javascript
复制
sudo upgrade_tool di -rootfs ubuntu-rootfs.img

本文参考

https://blog.csdn.net/Alex_Vinci/article/details/122818828

https://dev.t-firefly.com/thread-12739-1-1.html

https://blog.csdn.net/vcsuanfadaima/article/details/112280308

https://www.csdn.net/tags/OtTaIg1sNTAwNTQtYmxvZwO0O0OO0O0O.html

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-10-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 嵌入式与Linux那些事 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 下载Ubuntu根文件系统
  • 安装虚拟机
  • 解压
  • 复制官方外设驱动文件
  • 挂载根文件系统
  • 拷贝bash依赖库
  • 执行挂载
  • 安装必要的软件
  • 更换源
  • 设置账户名和密码
  • 设置主机名
  • 添加主机入口到/etc/hosts
  • 添加nameserver
  • 取消挂载
  • 烧写镜像
  • 本文参考
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档