Cloning Image to another card

I prepared Linux system in the SD820C board, loaded with all packages i need.
How can i clone the whole image of the working card to another card ?

On Linux you can easily clone an SDCARD with cat or dd.

example (replace sdcard device with your own /dev/sdX):

# Save sdcard to a file
dd bs=4M if=/dev/sdb of=./sdcard.img
# Write saved image to a sdcard
dd bs=4M  if=./sdcard.img of=/dev/sdb

or

# Clone sdcard1(/dev/sdb) to sdcard2 (/dev/sdc)
dd bs=4M if=/dev/sdb of=/dev/sdb

But I would also suggest you to look at the following topic, which explains why itā€™s not recommended to cloning an already ā€˜initializedā€™ system:

This is not exactly what i want.
I would like to dump the image from the eMMC, as is, and burn it to another card.
I can dd read sda from the source card (is it enough) , but how can i burn it then to the eMMC of another card ?
I canā€™t write sda of working system.

Hi @salex,

For your usecase, you can use the below steps:

  1. Extract the current image using dd:
    $ dd if=/dev/sdx of= ./raw.img bs=4M

Note: Replace /dev/sdx with RootFS partition.

  1. Convert the extracted raw image into sparse image using img2simg utility:
    $ img2simg raw.img system.img
  1. Finally you can flash the system.img using fastboot.

Beware that by doing the above steps, you can easily messup with your RootFS (please see the thread which @Loic mentioned)

Hope this helps!

Thanks,
Mani

Hi
I think if you have qualcomm download tool(QFIL), you can read images from device, then move it to sd card.

Hi @Mani,

This way is pretty easy, when i saw it i thought it is too good to be true.
Practically it didnā€™t worked for me.
May be iā€™m doing something wrong. Here is the operations:

  1. Read source card image (command run from remote ubuntu machine)

ssh linaro@10.0.0.9 ā€œsudo dd if=/dev/sdaā€ | dd of=image1.img

resulting image size 24.5 GB
2. Convert to sparse:

img2simg image1.img image_sparse.img

resulting image size 13.3 GB
3. On the tarfet card, enter fastboot mode and burn

sudo fastboot flash rootfs image_sparse.img

The result was:

Target reported max download size of 536870912 bytes
sending sparse ā€˜rootfsā€™ (520735 KB)ā€¦
OKAY [26.070s]
writing ā€˜rootfsā€™ ā€¦
FAILED (remote:size too lirge)
finished total time: 26.084s
Am i doing something wrong ?

Alex.

Hi @salex,

Target reported max download size of 536870912 bytes
sending sparse ā€˜rootfsā€™ (520735 KB)ā€¦
OKAY [26.070s]
writing ā€˜rootfsā€™ ā€¦
FAILED (remote:size too lirge)
finished total time: 26.084s
Am i doing something wrong ?

This could be because, dd will create an image equal to the size of the partition. In this case, since rootfs partition is ~24G, the resulting image is also the same size.

To overcome this issue, you can use the resize2fs utility on the raw image to shrink the size of the image (donā€™t worry, your data will be safe) and then convert it to sparse image and flash.

Thanks,
Mani

The commands above will have backed up the partition table as well as the root partition itself. This makes the image too large to copy to other devices (and also prevents you from running filesystem aware tools on it).

Use /dev/sda1 instead of /dev/sda to backup just the rootfs.

Also it would be a good idea to use ext2simg instead of img2simg to prepare the image for fastboot. ext2simg will write faster (and cause less wear on your flash) because it will not write unallocated space.

1 Like

Hi @Mani,
Iā€™m trying to run resize2fs on the image i got according to @danielt recommendation.
I get following error:

resize2fs: Filesystem has unsupported read-only feature(s) while trying to open image1.img
Couldnā€™t find valid filesystem superblock

Why ?

Alex.

It looks like resize2fs doesnā€™t recognise it as filesystem image. Try running tools like file on the image to find out what is actually in it.

@danielt, @Mani
Thank you for your help so far.
I have partial success.
On my Ubuntu 14.04 i had to compile latest (for that system) version of resize2fs (1.43), then it performed the resize.
After resize2fs and img2simg i burned the image with fastboot, but it boots only on serial connection and logs in automatically as root.
After that i can switch user, or connect to the card with ssh as linaro.
When i try to boot it regularly, as linaro user, the card doesnā€™t goes up.
Looks like permissions problem or some start up driver is corrupted.
How can i solve it ?

Update: It works.
I found that if the UART wires are connected to the USB-TTL dongle (even if the dongle is not connected to the PC), the system is not starting correctly. That was happened to me.

Thanks for the help.

Alex.

Does the board you are cloning from run the same kernel version and the board
you are cloning to?

Both boards need to be installed with the same snapshot for rootfs cloning to
be reliable.

If i understand your question, the kernel should be compatible because of boot loader and partitioning.

Iā€™m afraid I donā€™t understand the answer either!

The board that you copied the rootfs from would have been running a snapshot build of some sort.

Did you install the same snapshot build to the other board before attempting to write the custom rootfs?

Hi
I have same issue on dragonboard410c.
I would like to dump the image from the eMMC, and flash it to another dragonboard eMMC.
However I failed to convert img to simg.

ssh linaro@10.0.0.9 ā€œsudo dd if=/dev/mmcblk0p10ā€ | dd of=image1.img

img2simg image1.img image_sparse.img

Then, I got following error messages.

img2simg: ā€¦/ā€¦/core/libsparse/sparse.c:143: write_all_blocks: Assertion `pad >= 0ā€™ failed.
Aborted (core dumped)

Please give me any advices.

Thanks.
Kazuo

Hi kazuo,

For me the following sequence worked :

  1. ddā€¦ image.img - read source image

  2. resize2fs - M image.img

The utility resize2fs worked correctly from version 1.43.1 and up.

If you donā€™t have such, download the sources of e2fsprogs package and build.

  1. Img2simg image.img sparse_image.img

Only after all those steps i could burn successfully with fastboot.

Please give me any advices.

This is almost certainly a bug in img2simg; it should be able to cope
with all possible image content without assertinng.

Perhaps check you are using the latest version. If you are already using
the latest version then are you comfortable in a debugger?

Hi @salex @danielt

Thank you for your help.

Since tools version were old, I updated it.
And I got success to fastboot flash.

But I have another issue.

I flashed image file to rootfs partition.
When dragonboard booted, x window did not run and booted by cui mode.

I compared eMMC use%, got following logs.

copy from

linaro@linaro-alip:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 463096 0 463096 0% /dev
tmpfs 94764 4496 90268 5% /run
/dev/disk/by-partlabel/rootfs 6239800 5422732 800684 88% /
tmpfs 473816 1800 472016 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 473816 0 473816 0% /sys/fs/cgroup
tmpfs 94760 0 94760 0% /run/user/0
tmpfs 94760 8 94752 1% /run/user/1000

copy to

linaro@linaro-alip:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 463096 0 463096 0% /dev
tmpfs 94764 5664 89100 6% /run
/dev/disk/by-partlabel/rootfs 5422276 5421008 0 100% /
tmpfs 473816 0 473816 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 473816 0 473816 0% /sys/fs/cgroup
tmpfs 94760 0 94760 0% /run/user/0
tmpfs 94760 0 94760 0% /run/user/1000

I found available rootfs size decreases and use% is 100%.

Can you think of anything that might have caused it?

If you used resize2fs to shrink the file system then you will need to undo the resize after you restore (alternatively you might be able to use ext2img instead to ensure unallocated parts of the filesystem are not burned).

Hi @danielt

Thank you for your help.

I used ext2simg instead of img2simg, got success.

Thank you so much !