Creating image with dd

I have issues lately when I build the image with dd.
In 30% of the cases one of the two partitions isn’t created correctly although dd had said, that everything is ok.
But when I enter the sd card into my linux pc, one of the partitions cannot be read.
Most of the time a second build is correct.
I just tested with a brand new sd card and a freshly rebooted pc.

Am I the only one having this issue?

I normally use “pv”, that is nearly the same than dd, and never have a problem like that.

I am creating my images only with dd. Do you use the option “bs=1M” for setting the block size? That’s what I normaly use, perhaps this fixes your problem?

Regards, Holger

Could be that it isn’t syncing writes to the disk at the end of the operation. I use
sudo dd if=imgfile of=dev oflag=sync status=progress bs=4M

2 Likes

I always use this simple command:

pv 2020-06-01-zynthianos-buster-lite-armhf-1.0.0.img > /dev/sdc

and never never have a single problem.

I use “pv” because it gives a nice progress feedback :wink:

Regards,

Ok, it’s my problem. Nothing helped. pv is nice and fast. You need to be root though. sudo is not enough.

Maybe my latest Mint update is the root cause.

I think I found a relation.
When I plugin the sd card, two partitions will be mounted.
When I want to change the sd card, I eject one partition and the other one will be unmounted automatically.
The next creation fails and only one partition is shown. When I create the image again, I can eject the sd card by ejecting only this single partition (old one, which doesn’t exist anymore)
Then the sdcard was correctly built.

OS issue, I reckon. Next Mint version is near and I hope for the best.

I’m unconvinced by pv. It’s just a tool for monitoring data rate through a pipe. You still might get issues if you don’t sync after the write before you remove the sdcard.

Doing a “sync” doesn’t cost a penny … i always do it after pv :wink:

I use dd on Mac OSX, and you can press CTRL-T during the copy to see progress:
dd bs=32m if=image.img of=/dev/rdisk2

There’s a quite easy explanation for that:

sudo give root permission to the command being executed, not for stdin and stdout.
So trying to pump stdout onto a file that needs root permissions will always fail.

So to be able to write to a file you need a tool that does that for you:

tee

Tee will write to a file and to stdout as well, so:

pv 2020-06-01-zynthianos-buster-lite-armhf-1.0.0.img | sudo /dev/sdc

Will write to the disk but also dump everything to stdout, so avoiding some GB shown on stdout, just dump that:

pv 2020-06-01-zynthianos-buster-lite-armhf-1.0.0.img | sudo /dev/sdc >/dev/null

Another way would be to start a shell with root permission and excute your command in that context:

sudo bash -c 'pv 2020-06-01-zynthianos-buster-lite-armhf-1.0.0.img > /usr/local/bin/hello'

Hope I could bring some info to the problem

Regards

Schnuffle

With coreutils 8.24 and above you can use the built-in progress:
dd if=/path/to/input of=/path/to/output status=progress

I still advocate this.