How to : use bpi-tools migrate command to build yourself image

=========================================================== example: step fo BPI-M2+ image build: 0. sudo su

  1. bpi-tools --update ; bpi-tools --upgrade
  2. bpi-migrate -u -G
  3. bpi-migrate -r root.tgz --uboot BPI_M2P_720P.img.gz

=========================================================== build image just need use bpi-migrate command but note : we will update this command at any time so you need use bpi-tools to update this tools at first below is log for reference:

root@bpi-iot-ros:/home/mikey# cd /tmp
root@bpi-iot-ros:/tmp# bpi-tools --update ; bpi-tools --upgrade
F_UPDATE=yes
BPIFILE=/root/.bpi-tools.lst
Wait for download index file ...
OK!!\n

bpi files:
bpi-tools   	v1.2.0
bpi-bootsel 	v1.0.5
bpi-copy    	v1.0.10a
bpi-get     	v1.0.3
bpi-migrate 	v1.2.2a
bpi-hw      	v1.2.8
F_UPGRADE=yes

download bpi files:
bpi-tools
bpi-tools: OK
bpi-tools: v1.2.0
bpi-bootsel
bpi-bootsel: OK
bpi-bootsel: v1.0.5
bpi-copy
bpi-copy: OK
bpi-copy: v1.0.10a
bpi-get
bpi-get: OK
bpi-get: v1.0.3
bpi-migrate
bpi-migrate: OK
bpi-migrate: v1.2.2a
bpi-hw
bpi-hw: OK
bpi-hw: v1.2.8

upgrade bpi files:
/usr/bin/bpi-tools
/usr/bin/bpi-bootsel
/usr/bin/bpi-copy
/usr/bin/bpi-get
/usr/bin/bpi-migrate
/usr/bin/bpi-hw

bpi files:
/usr/bin/bpi-tools	v1.2.0
/usr/bin/bpi-bootsel	v1.0.5
/usr/bin/bpi-copy	v1.0.10a
/usr/bin/bpi-get	v1.0.3
/usr/bin/bpi-migrate	v1.2.2a
/usr/bin/bpi-hw	v1.2.8
root@bpi-iot-ros:/tmp#

===========================================================
root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# bpi-migrate -u -G
update
download
BPIMODE=
BPIFILE=/root/.bpi-migrate.lst
Wait for download index file ...
OK!!\n

download bpi files:
u-boot-2016.05-bpi-m1-m1p-r1-legacy.img.gz
u-boot-2016.05-bpi-m1-m1p-r1-legacy.img.gz: OK
u-boot-2016.05-bpi-m1-legacy.img.gz
u-boot-2016.05-bpi-m1-legacy.img.gz: OK
u-boot-2016.05-bpi-m1p-legacy.img.gz
u-boot-2016.05-bpi-m1p-legacy.img.gz: OK
u-boot-2016.05-bpi-r1-legacy.img.gz
u-boot-2016.05-bpi-r1-legacy.img.gz: OK
BPI_M2P_720P-openelec.img.gz
BPI_M2P_720P-openelec.img.gz: OK
BPI_M2_720P.img.gz
BPI_M2_720P.img.gz: OK
BPI_M2P_720P.img.gz
BPI_M2P_720P.img.gz: OK
BPI_M3_720P.img.gz
BPI_M3_720P.img.gz: OK
uboot-bpi-m2.img.gz
uboot-bpi-m2.img.gz: OK
BPI-BOOT.tgz
BPI-BOOT.tgz: OK
bpi-tools.tgz
bpi-tools.tgz: OK
3.3.0-BPI-M2-Kernel.tgz
3.3.0-BPI-M2-Kernel.tgz: OK
3.4.39-BPI-M2P-Kernel.tgz
3.4.39-BPI-M2P-Kernel.tgz: OK
3.4.39-BPI-M3-Kernel.tgz
3.4.39-BPI-M3-Kernel.tgz: OK
3.4.112-sun7i.tgz
3.4.112-sun7i.tgz: OK
3.4.112-sun8i.tgz
3.4.112-sun8i.tgz: OK
3.10.101-pine64-bpi-m64.tgz
3.10.101-pine64-bpi-m64.tgz: OK
4.2.0-BPI-kernel+.tgz
4.2.0-BPI-kernel+.tgz: OK
bpi-m2-video.tgz
bpi-m2-video.tgz: OK
libvdpau_sunxi.tgz
libvdpau_sunxi.tgz: OK
brcm.tgz
brcm.tgz: OK
bt.tgz
bt.tgz: OK
root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# 
===========================================================

root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# bpi-migrate -r root.tgz --uboot BPI_M2P_720P.img.gz
ROOTFILE=root.tgz
UBOOTIMGGZ=BPI_M2P_720P.img.gz
BPIMODE=migratefromroot
migratefromroot
IMGFILE=root.tgz-bpi-m3.img
Info: Try to create NEW IMAGE root.tgz-bpi-m3.img with root.tgz
==============================================================
Fri Jul  8 17:44:46 CST 2016
SIZE=7456, RAWSIZE=100, BOOTSIZE=256, OFFSET=356

#####################
# Creating img file #
#    7456 = 8G EMMC #
#####################

7.28GiB 0:04:34 [27.1MiB/s] [                       <=>                        ]
15269888+0 records in
15269888+0 records out
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 274.777 s, 28.5 MB/s
7456+0 records in
7456+0 records out
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 274.781 s, 28.5 MB/s

#########################
 +>/dev/loop1 
 +->/dev/loop1p1 
 +->/dev/loop1p2 
#########################


#############################
# Creating partitions table #
#############################

Model: Loopback device (loopback)
Disk /dev/loop1: 7818MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End     Size    Type     File system  Flags
 1      105MB  373MB   268MB   primary               boot, lba
 2      373MB  7817MB  7444MB  primary


########################
# Creating filesystems #
########################

mkfs.fat 3.0.28 (2015-05-16)
unable to get drive geometry, using default 255/63
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done                            
Creating filesystem with 1817344 4k blocks and 455168 inodes
Filesystem UUID: 83d1a6e3-5737-4ddb-b661-54d76cd8b90d
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 


##########################
# Burning the bootloader #
##########################

102392+0 records in
102392+0 records out
104849408 bytes (105 MB, 100 MiB) copied, 5.56543 s, 18.8 MB/s

######################
# Copying boot files #
######################

total 23776
drwxr-xr-x  4 root root   16384 Jul  4 17:22 .
drwxr-xr-x 27 root root    4096 Jul  2 15:46 ..
drwxr-xr-x 13 root root    4096 Jul  4 17:00 bananapi
-rwxr-xr-x  1 root root   13221 Jul  4 02:40 bcm2708-rpi-b.dtb
-rwxr-xr-x  1 root root   13484 Jul  4 02:40 bcm2708-rpi-b-plus.dtb
-rwxr-xr-x  1 root root   13257 Jul  4 02:40 bcm2708-rpi-cm.dtb
-rwxr-xr-x  1 root root   14567 Jul  4 02:40 bcm2709-rpi-2-b.dtb
-rwxr-xr-x  1 root root   15237 Jul  4 02:40 bcm2710-rpi-3-b.dtb
-rwxr-xr-x  1 root root     763 Jul  4 17:21 boot.cmd
-rwxr-xr-x  1 root root   17932 Jul  4 02:40 bootcode.bin
-rwxr-xr-x  1 root root     835 Jul  4 17:23 boot.scr
-rwxr-xr-x  1 root root     377 Jul  4 16:59 boot.scr.org
-rwxr-xr-x  1 root root     136 Mar 26 12:22 cmdline.txt
-rwxr-xr-x  1 root root     197 Jul  4 10:51 .config
-rwxr-xr-x  1 root root    1635 May 27 12:09 config.txt
-rwxr-xr-x  1 root root   18693 Aug 21  2015 COPYING.linux
-rwxr-xr-x  1 root root    2504 Jul  4 02:40 fixup_cd.dat
-rwxr-xr-x  1 root root    6482 Jul  4 02:40 fixup.dat
-rwxr-xr-x  1 root root    9717 Jul  4 02:40 fixup_db.dat
-rwxr-xr-x  1 root root    9717 Jul  4 02:40 fixup_x.dat
-rwxr-xr-x  1 root root     145 May 27 12:50 issue.txt
-rwxr-xr-x  1 root root 4224232 Jul  4 02:40 kernel7.img
-rwxr-xr-x  1 root root 4123112 Jul  4 02:40 kernel.img
-rwxr-xr-x  1 root root    1494 Nov 18  2015 LICENCE.broadcom
-rwxr-xr-x  1 root root   18974 Mar 18 08:58 LICENSE.oracle
drwxr-xr-x  2 root root    8192 Jul  4 10:48 overlays
-rwxr-xr-x  1 root root   36912 Mar  3 11:42 script.bin
-rwxr-xr-x  1 root root  617432 Jul  4 02:40 start_cd.elf
-rwxr-xr-x  1 root root 4926264 Jul  4 02:40 start_db.elf
-rwxr-xr-x  1 root root 2746552 Jul  4 02:40 start.elf
-rwxr-xr-x  1 root root 3877720 Jul  4 02:40 start_x.elf
-rwxr-xr-x  1 root root      26 Jul  1 13:53 uEnv.txt
-rwxr-xr-x  1 root root 3526808 Jul  4 05:13 uInitrd

##################
# Copying rootfs #
##################

sudo mount -t ext4 /dev/loop1p2 /mnt
tar xvf root.tgz --keep-directory-symlink -C /mnt
tar xvf bpi-tools.tgz --keep-directory-symlink -C /mnt
tar xvf 3.3.0-BPI-M2-Kernel.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.39-BPI-M2P-Kernel.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.39-BPI-M3-Kernel.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.112-sun8i.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.112-sun7i.tgz --keep-directory-symlink -C /mnt
tar xvf 3.10.101-pine64-bpi-m64.tgz --keep-directory-symlink -C /mnt
tar xvf libvdpau_sunxi.tgz --keep-directory-symlink -C /mnt
tar xvf bt.tgz --keep-directory-symlink -C /mnt
tar xvf brcm.tgz --keep-directory-symlink -C /mnt
total 48
drwxr-xr-x  8 root root  4096 Jul  8 17:51 .
drwxr-xr-x 27 root root  4096 Jul  2 15:46 ..
-rw-r--r--  1 root root    29 Jul  8 17:43 DATE
drwxr-xr-x  4 root root  4096 Jul  4 20:48 etc
drwxr-xr-x  4 root root  4096 Nov 27  2015 lib
drwx------  2 root root 16384 Jul  8 17:50 lost+found
drwxr-xr-x  3 root root  4096 Nov 27  2015 system
drwxr-xr-x  5 root root  4096 Jul  4 20:48 usr
drwxr-xr-x  3 root root  4096 Jul  4 21:22 var

release_loopdev

sudo losetup -d /dev/loop1

losetup -d /dev/loop0
###########
# Done !! #
###########
Fri Jul  8 17:51:42 CST 2016
==============================================================
RUNTIME 6:56
OK!!
root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# 
root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# bpi-migrate -r root.tgz --uboot BPI_M2P_720P.img.gz
ROOTFILE=root.tgz
UBOOTIMGGZ=BPI_M2P_720P.img.gz
BPIMODE=migratefromroot
migratefromroot
IMGFILE=root.tgz-bpi-m3.img
Info: Try to create NEW IMAGE root.tgz-bpi-m3.img with root.tgz
==============================================================
Fri Jul  8 17:44:46 CST 2016
SIZE=7456, RAWSIZE=100, BOOTSIZE=256, OFFSET=356

#####################
# Creating img file #
#    7456 = 8G EMMC #
#####################

7.28GiB 0:04:34 [27.1MiB/s] [                       <=>                        ]
15269888+0 records in
15269888+0 records out
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 274.777 s, 28.5 MB/s
7456+0 records in
7456+0 records out
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 274.781 s, 28.5 MB/s

#########################
 +>/dev/loop1 
 +->/dev/loop1p1 
 +->/dev/loop1p2 
#########################


#############################
# Creating partitions table #
#############################

Model: Loopback device (loopback)
Disk /dev/loop1: 7818MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End     Size    Type     File system  Flags
 1      105MB  373MB   268MB   primary               boot, lba
 2      373MB  7817MB  7444MB  primary


########################
# Creating filesystems #
########################

mkfs.fat 3.0.28 (2015-05-16)
unable to get drive geometry, using default 255/63
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done                            
Creating filesystem with 1817344 4k blocks and 455168 inodes
Filesystem UUID: 83d1a6e3-5737-4ddb-b661-54d76cd8b90d
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 


##########################
# Burning the bootloader #
##########################

102392+0 records in
102392+0 records out
104849408 bytes (105 MB, 100 MiB) copied, 5.56543 s, 18.8 MB/s

######################
# Copying boot files #
######################

total 23776
drwxr-xr-x  4 root root   16384 Jul  4 17:22 .
drwxr-xr-x 27 root root    4096 Jul  2 15:46 ..
drwxr-xr-x 13 root root    4096 Jul  4 17:00 bananapi
-rwxr-xr-x  1 root root   13221 Jul  4 02:40 bcm2708-rpi-b.dtb
-rwxr-xr-x  1 root root   13484 Jul  4 02:40 bcm2708-rpi-b-plus.dtb
-rwxr-xr-x  1 root root   13257 Jul  4 02:40 bcm2708-rpi-cm.dtb
-rwxr-xr-x  1 root root   14567 Jul  4 02:40 bcm2709-rpi-2-b.dtb
-rwxr-xr-x  1 root root   15237 Jul  4 02:40 bcm2710-rpi-3-b.dtb
-rwxr-xr-x  1 root root     763 Jul  4 17:21 boot.cmd
-rwxr-xr-x  1 root root   17932 Jul  4 02:40 bootcode.bin
-rwxr-xr-x  1 root root     835 Jul  4 17:23 boot.scr
-rwxr-xr-x  1 root root     377 Jul  4 16:59 boot.scr.org
-rwxr-xr-x  1 root root     136 Mar 26 12:22 cmdline.txt
-rwxr-xr-x  1 root root     197 Jul  4 10:51 .config
-rwxr-xr-x  1 root root    1635 May 27 12:09 config.txt
-rwxr-xr-x  1 root root   18693 Aug 21  2015 COPYING.linux
-rwxr-xr-x  1 root root    2504 Jul  4 02:40 fixup_cd.dat
-rwxr-xr-x  1 root root    6482 Jul  4 02:40 fixup.dat
-rwxr-xr-x  1 root root    9717 Jul  4 02:40 fixup_db.dat
-rwxr-xr-x  1 root root    9717 Jul  4 02:40 fixup_x.dat
-rwxr-xr-x  1 root root     145 May 27 12:50 issue.txt
-rwxr-xr-x  1 root root 4224232 Jul  4 02:40 kernel7.img
-rwxr-xr-x  1 root root 4123112 Jul  4 02:40 kernel.img
-rwxr-xr-x  1 root root    1494 Nov 18  2015 LICENCE.broadcom
-rwxr-xr-x  1 root root   18974 Mar 18 08:58 LICENSE.oracle
drwxr-xr-x  2 root root    8192 Jul  4 10:48 overlays
-rwxr-xr-x  1 root root   36912 Mar  3 11:42 script.bin
-rwxr-xr-x  1 root root  617432 Jul  4 02:40 start_cd.elf
-rwxr-xr-x  1 root root 4926264 Jul  4 02:40 start_db.elf
-rwxr-xr-x  1 root root 2746552 Jul  4 02:40 start.elf
-rwxr-xr-x  1 root root 3877720 Jul  4 02:40 start_x.elf
-rwxr-xr-x  1 root root      26 Jul  1 13:53 uEnv.txt
-rwxr-xr-x  1 root root 3526808 Jul  4 05:13 uInitrd

##################
# Copying rootfs #
##################

sudo mount -t ext4 /dev/loop1p2 /mnt
tar xvf root.tgz --keep-directory-symlink -C /mnt
tar xvf bpi-tools.tgz --keep-directory-symlink -C /mnt
tar xvf 3.3.0-BPI-M2-Kernel.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.39-BPI-M2P-Kernel.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.39-BPI-M3-Kernel.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.112-sun8i.tgz --keep-directory-symlink -C /mnt
tar xvf 3.4.112-sun7i.tgz --keep-directory-symlink -C /mnt
tar xvf 3.10.101-pine64-bpi-m64.tgz --keep-directory-symlink -C /mnt
tar xvf libvdpau_sunxi.tgz --keep-directory-symlink -C /mnt
tar xvf bt.tgz --keep-directory-symlink -C /mnt
tar xvf brcm.tgz --keep-directory-symlink -C /mnt
total 48
drwxr-xr-x  8 root root  4096 Jul  8 17:51 .
drwxr-xr-x 27 root root  4096 Jul  2 15:46 ..
-rw-r--r--  1 root root    29 Jul  8 17:43 DATE
drwxr-xr-x  4 root root  4096 Jul  4 20:48 etc
drwxr-xr-x  4 root root  4096 Nov 27  2015 lib
drwx------  2 root root 16384 Jul  8 17:50 lost+found
drwxr-xr-x  3 root root  4096 Nov 27  2015 system
drwxr-xr-x  5 root root  4096 Jul  4 20:48 usr
drwxr-xr-x  3 root root  4096 Jul  4 21:22 var

release_loopdev

sudo losetup -d /dev/loop1

losetup -d /dev/loop0
###########
# Done !! #
###########
Fri Jul  8 17:51:42 CST 2016
==============================================================
RUNTIME 6:56
OK!!
root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# 

root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# ls -l root.tgz-bpi-m3.img
-rw-r--r-- 1 root root 7818182656 Jul  8 17:51 root.tgz-bpi-m3.img
root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT#

root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT# bpi-migrate -h
bpi-migrate(v1.2.2a), migrate a system to bananapi image environment.

Usage: bpi-migrate [OPTIONS]...
       bpi-migrate [ --help | -v | --version ]

Options:

  -u, --update                    update index files
  -G, --download                  download files for bpi-migrate
  -r, --root rootfile             user root file for BPI-ROOT (ex. root.tgz)
  -b, --boot bootfile             user boot file for BPI-BOOT (ex. boot.tgz)
  -s, --size                      image size(defaut: 7456 MB for eMMC)
  -B, --BOOTSIZE                  BPI-BOOT partition size(default: 256 MB)
  -h, --help                      Print usage
  -v, --version                   Print version information and quit

ex: (prepare env.)
  1. mkdir BPI-ROOT ; cd BPI-ROOT
  2. bpi-migrate -u -G ; #download files for bpi-migrate

ex: (default create BPI-M3 image)
  0. sudo su
  1. bpi-migrate -r /pathtouser/root.tgz

ex: (create BPI-M2P image)
  0. sudo su
  1. bpi-migrate -r /pathtouser/root.tgz --uboot BPI_M2P_720P.img.gz

ex: (create BPI-R1 image)
  0. sudo su
  1. bpi-migrate -r root.tgz --uboot u-boot-2016.05-bpi-r1-legacy.img.gz

for test only:
  -d, --device device             device
  -i, --imgfile imgfile           imgfile
  -S, --src src                   src from
  -D, --dst dst                   dst to

root@bpi-iot-ros:/media/mikey/U3TB-C/SD/BPI-ROOT#

Hi Guys,

I have been looking at this process to determine if I could modify it so then I can create a bootable / installable image of my existing BPi-M2P, but I am most in the detail.

Do you have a process for creating a bootable image from a running BPi-M2P device which is currently booting and running from the 8GB eMMC memory?

Best regards,

Rick