I now bring the resolution in English.
The script calculates the parameters bs and count from the file length
of the .iso file for the call of dd, so that exactly the desired bytes
are transferred.
It is not so much about how to copy an image to a stick, but how to
check the copying process as quickly as possible using the known hash.
Or how to check later whether the content of the stick has changed.
In order to obtain the same hash for an error-free copying process,
exactly as many bytes must be read as written.
So that this does not take too long, the trivial solution bs=1 and
count=size should be avoided. Further below you will find some
information about the times, which differ considerably, especially with
large files.
The remedy is the calculated parameters of the script. If a bs smaller
than 512 is calculated, which has never happened to me, reading takes a
little longer. bs with several MiBs are processed in smaller parts anyway.
The question remains: am I the only one doing this check? Why is the
hash checked when downloading but not when writing?
I have searched 2 times for a long time for errors caused by bad sticks
and looked for a solution and built myself a script. Not long ago I had
strange phenomena after an installation. I checked the stick because I
hadn't used my script to copy and the hash didn't match, copied again
and the phenomena were gone.
I would like to point out Thomas Pircher's elegant variant, which
achieves the same thing without a loop with a bit operation, namely the
largest possible power of two dividing the file length without remainder.
bs="$((cnt & ~(cnt -1)))"
cnt=$((cnt / bs))
However, I recommend that in your own scripts you only use command
combinations that you understand.
Here is the influence of the parameters on the time. bs=1 is
catastrophically bad.
localhost:~ #time dd if=/dev/sdb bs=1 count=2147483648| sha256sum
2147483648+0 records in
2147483648+0 records out
7006df13cead40a8e19b0a63849e957da6c9eb0291bf4cf13401dcd43129f9de -
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 2297.46 s, 935 kB/s
real 38m17.466s
user 6m26.279s
sys 52m45.180s
localhost:~ #time dd if=/dev/sdb bs=16777216 count=128| sha256sum
128+0 records in
128+0 records out
7006df13cead40a8e19b0a63849e957da6c9eb0291bf4cf13401dcd43129f9de -
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 128.502 s, 16.7 MB/s
real 2m8.504s
user 0m10.391s
sys 0m2.317s
localhost:~ #time dd if=/dev/sdb bs=512 count=4194304| sha256sum
4194304+0 records in
4194304+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 118.927 s, 18.1 MB/s
7006df13cead40a8e19b0a63849e957da6c9eb0291bf4cf13401dcd43129f9de -
real 1m58.929s
user 0m19.580s
sys 0m9.095s
localhost:~ #time dd if=/dev/sdb bs=4096 count=524288| sha256sum
524288+0 records in
524288+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 118.817 s, 18.1 MB/s
7006df13cead40a8e19b0a63849e957da6c9eb0291bf4cf13401dcd43129f9de -
real 1m58.819s
user 0m18.354s
sys 0m3.578s
localhost:~ #
Franz
attachment.html (6.53 KB)