簡介
自己擁有一塊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燒寫工具
在燒寫前需要注意工具珊的地址和分區名字要根據上面導出來的分區信息要一致,否則會燒寫失敗