RK3288/RK3399 Ubuntu 系统备份

简介

自己拥有一块Firefly-RK3399开发板,并在开发板上面安装了Ubuntu16.04系统,而且在开发板上面做了一些环境配置和软件开发工作,现在需要将这块开发板的环境及系统克隆到另外一块开发板上。所以需要将系统做备份,然后烧录到新的开发板上面。

步骤

导出开发板镜像

  • 准备工作
    a.AndroidTool_Release_v2.43,RK平台的固件烧录工具
    b.Parameter 文件,开发板的分区信息文件,可在开发板系统中通过如下命令获得

    cat /proc/cmdline

    输出如下信息:
androidboot.baseband=N/A 
androidboot.selinux=permissive 
androidboot.hardware=rk30board 
androidboot.console=ttyFIQ0 
root=/dev/mmcblk1p6 rw rootfstype=ext4 
mtdparts=rk29xxnand:0x00002000@0x00002000(uboot),
0x00002000@0x00004000(trust),
0x00008000@0x00006000(resource),
0x00008000@0x0000e000(kernel),
0x00002000@0x00017000(backup),
-@0x00019000(boot) 
storagemedia=emmc 
uboot_logo=0x02000000@0x7dc00000 
loader.timestamp=2017-02-24_16:13:37 
SecureBootCheckOk=0 
androidboot.mode=emmc

这里已kernel分区说明,0x00008000@0x0000e000(kernel),分区名字前面是其大小和起始位置
@前面是分区大小,@后面是分区起始位置
数值的单位是sector(扇区),1个sector 为512 Bytes,kernel 分区的起始位置是0xe000,大小是0x8000(16M),这两个数等会导出就直接用到。

  • 导出分区镜像
    这里只导出kernel 分区做说明,其他分区参考操作即可
    这里写图片描述
    a. 打开Android 开发工具,
    b. 切换到高级功能,
    c. 切换到LOADER 设备
    d. 填写起始扇区(0xe000) 及扇区数(0x8000)
    e. 在Android 开发工具对应目录下会生成Output 目录
    f. Output 目录下就是导出的ExportImage.img 就是kernel 镜像
    g. 把ExportImage.img 改名为kernel.img,然后继续导出其他分区
    这里写图片描述
    这里写图片描述
    对于想一次导出整个分区的看法,如果想一次导出整个分区,整个导出的Img 会很大,可能也会出错,
    也可能到出来了但是烧录出错等等问题,所以,建议一个个分区导出,然后在打包成update.img ,这样虽然麻烦一些,
    但是,至少不会出错。

导出开发板文件系统

-@0x00019000(boot)域就是开发板的文件系统,使用AndroidTool_Release工具不好导出,所以需要使用另外一种方式,其操作步骤如下:

  • 在开发板的UBUNTU系统上面安装软件rsync :

    sudo apt-get install rsync
  • 在开发板的UBUNTU系统上面安装软件openssh的服务端openssh-server并修改root登录权限 :

sudo apt-get install openssh-server
sudo vi /etc/ssh/sshd_config

修改PermitRootLogin选项用以确保root登录权限足够
这里写图片描述
重启开发板或者重启ssh服务

# /etc/init.d/ssh restart
  • PC端安装openssh客户端openssh-client
sudo apt-get install openssh-client
  • PC端安装rsync
sudo apt-get install rsync
  • 在PC端通过rsync命令同步开发板上的文件
    新建目录ubuntu_make :
    mkdir ubuntu_make
    cd ubuntu_make
    在PC端当前目录新建ubuntu目录:mkdir ubuntu
    同步数据:sudo rsync -avx root@开发板IP:/ ubuntu/
    开发板IP为客户端通过ifconfig确认
  • 在ubuntu文件夹下面增加文件/etc/onlyone.sh
sudo vi /etc/onlyone.sh
内容为:
#!/bin/sh

read line < /proc/cmdline
for arg in $line; do
        if [ "5" -le "$(expr length $arg)" ]; then
                if [ "root=" = "$(expr substr $arg 1 5)" ]; then
                {
                        debug_arg=$(expr $arg : 'root=\(.*\)')
                        resize2fs $debug_arg
                }
                fi
        fi
done 

修改文件权限

sudo chmod 777 /etc/onlyone.sh
  • 制作rootfs文件系统
    使用脚本打包ubuntu系统,脚本如下
#!/bin/bash

#ubuntu(ubuntu-core) build already annotation
#not Often compiled      .......too slow and need root
MAKE_THEARD=`cat /proc/cpuinfo| grep "processor"| wc -l`
RESULT="Image-rk3288-ubuntu"

function creat_result_dir()
{
    if [ ! -d $RESULT ];
        then
        {
            mkdir Image-rk3288-ubuntu
        }
    fi
}

function ubuntu_core_build() 
{
    dd if=/dev/zero of=linux-rootfs-core.img bs=1M count=1000
    sudo mkfs.ext4 -F -L linuxroot linux-rootfs-core.img

    if [ ! -d mount ];
        then
        {
            mkdir mount
        }
    fi
    sudo mount linux-rootfs-core.img mount
    sudo cp -a ubuntu_core/* mount
    sudo umount mount
    e2fsck -p -f linux-rootfs-core.img
    resize2fs -M linux-rootfs-core.img
    rm -rf mount
    mv linux-rootfs-core.img $RESULT
}
function ubuntu_build() 
{
    dd if=/dev/zero of=linux-rootfs.img bs=1M count=5000
    sudo mkfs.ext4 -F -L linuxroot linux-rootfs.img

    if [ ! -d mount ];
        then
        {
            mkdir mount
        }
    fi
    sudo mount linux-rootfs.img mount
    sudo cp -a ubuntu/* mount
    sudo umount mount
    e2fsck -p -f linux-rootfs.img
    resize2fs -M linux-rootfs.img
    rm -rf mount
    mv linux-rootfs.img $RESULT
}

function ubuntu_clean() 
{
    rm $RESULT/linux-rootfs.img
}
function ubuntu_core_clean() 
{
    rm $RESULT/linux-rootfs-core.img
}
function result_clean() 
{
    rm -rf $RESULT
}

creat_result_dir
if [ $1 == "clean" ]
    then
    {
        if [ ! -n $2 ]
            then
            {
                ubuntu_core_clean
                ubuntu_clean
                result_clean
                echo clean Img oK
            }
        elif [ $2 == "ubuntu" -o $2 == "ubuntu/" ]
            then
            {
                ubuntu_clean
            }
        elif [ $2 == "ubuntu_core" -o $2 == "ubuntu_core/" -o $2 == "ubuntu-core" -o $2 == "ubuntu-core/" ]
            then
            {
                ubuntu_core_clean
            }
        else
            {
                ubuntu_core_clean
                ubuntu_clean
                result_clean
                echo clean Img oK
            }
        fi
    }
elif [ $1 == "ubuntu_core" -o $1 == "ubuntu_core/" -o $1 == "ubuntu-core" -o $1 == "ubuntu-core/" ]
    then
    {
        ubuntu_core_build
    }
elif [ $1 == "ubuntu" -o $1 == "ubuntu/" ]
    then
    {
        ubuntu_build
    }
else
    {
        ubuntu_core_build
        ubuntu_build
    }
fi

将脚本拷贝到ubuntu_make目录并运行脚本

./make_ubuntu.sh ubuntu

最终在Image-rk3288-Ubuntu目录下生成rootfs文件

镜像烧录到新的开发板中

烧录的过程中使用到了上面导出的镜像、分区信息和AndroidTool烧写工具
在烧写前需要注意工具珊的地址和分区名字要根据上面导出来的分区信息要一致,否则会烧写失败
这里写图片描述

猜你喜欢

转载自blog.csdn.net/oxp7085915/article/details/80291057
今日推荐