Why didn't `dd conv=sparse` save space as I expected?
If you are absolutely sure there were zero-filled blocks then the reason you saved no space was the large buffer you used. From man dd
:
sparse
try to seek rather than write the output for NUL input blocks
You used bs=32M
, so you needed a whole 32 MiB block of zeros at a right offset for the conv=sparse
option to do its job if only just once.
The option bs
sets ibs
(input block size) and obs
(output block size). While the manual mentions input blocks, it is actually the obs
that matters.
Here are the results of some tests. (As I am the OP, I did the tests with the very same device.) Each file is named according to <obs_used>.img
pattern. Pay attention to the first column:
$ ls -hlst *.img
250M -rw-r--r-- 1 root root 250M Oct 18 22:02 4M.img
250M -rw-r--r-- 1 root root 250M Oct 18 22:02 2M.img
249M -rw-r--r-- 1 root root 250M Oct 18 22:02 1M.img
248M -rw-r--r-- 1 root root 250M Oct 18 22:01 512K.img
248M -rw-r--r-- 1 root root 250M Oct 18 22:01 256K.img
247M -rw-r--r-- 1 root root 250M Oct 18 22:00 128K.img
247M -rw-r--r-- 1 root root 250M Oct 18 21:57 64K.img
247M -rw-r--r-- 1 root root 250M Oct 18 21:56 32K.img
246M -rw-r--r-- 1 root root 250M Oct 18 21:55 16K.img
246M -rw-r--r-- 1 root root 250M Oct 18 21:54 8K.img
246M -rw-r--r-- 1 root root 250M Oct 18 21:53 4K.img
246M -rw-r--r-- 1 root root 250M Oct 18 21:52 2K.img
246M -rw-r--r-- 1 root root 250M Oct 18 21:51 1K.img
246M -rw-r--r-- 1 root root 250M Oct 18 21:44 512.img
The conclusion is: you shouldn't use large obs
with conv=sparse
option. The common sector size is 512 bytes, so bs=512
seems just right. Your command should have been:
dd if=/dev/sdb of=myusb.img conv=sparse bs=512