I have a MicroSD card that is 64GB in size. I wrote an image to it that is 16GB in size with this:
$ sudo dd if=my_image.img of=/dev/sdb bs=4M
3798+1 records in
3798+1 records out
15931539456 bytes (16 GB, 15 GiB) copied, 657.848 s, 24.2 MB/s
Now, I want to take an image of the first 15931539456 bytes (16GB) of the same 64GB SD card with dd, to end up with an image that has the same checksum as the image I started with.
From what I understand, dd's result above (3798+1) shows that there were 3798 complete reads from the source image, and 1 partial read, because the size of the source image doesn't split evenly into 4M chunks. So how do I tell dd to now copy 15931539456 bytes from the SD card into a new file, 4M at a time?
I'm assuming I can do something like:
sudo dd if=/dev/sdb of=new_image.img bs=1 count=15931539456
but having a buffer that small would make the operation take forever. Is there any way to tell it to use a buffer of 4M, but only copy X number of bytes, even if that results in a short read at the end?
sudo dd if=/dev/sdb of=new_image.img bs=15931539456 count=1
? Also, your file size is a multiple of several reasonable block sizes, up as high as 2^19 (512k). Or if you prefer to use a block size that is not a divisor of the file size, then transfer slightly too much data and then usetruncate(1)
to shrink the file to the exact size you want. – Jim L. Sep 10 '19 at 23:30truncate
route then, or the 512k blocksize. – Jim L. Sep 10 '19 at 23:54