I've created a sparse file with dd. How do I copy contents of another file there, leaving all the zero blocks unallocated?
Asked
Active
Viewed 715 times
4
d33tah
- 1,371
- 14
- 28
1 Answers
3
The solution is apparently to use cp --sparse=always. My first attempt was with writing some Python code, but unfortunately the MD5 sums didn't match (could anyone tell me why? the code's in edit history).
d33tah
- 1,371
- 14
- 28
-
1
-
-
No, filesystem gives you zeros where it finds an unallocated block, so the error had to be in your script. The block size is important for other reason: if you seek by 6 empty 512B sectors, then one with some data an then again seek say 4 empty sectors, you save nothing, because the data in the one sector causes the fs to allocate whole 4K block. – peterph Jan 09 '13 at 22:35
-
3GNU
taralso has the-S, --sparseoption to handle sparse files effectively, btw. – peterph Jan 09 '13 at 22:36 -
@d33tah your python code is losing a byte every time it seeks because of the
-1in the seek target, which isn't necessary. You should seek ahead a full 512 bytes each time. – Jul 20 '13 at 17:37
cp, the overwritten file disappears. It doesn't matter if that file used to be sparse; these things are not contagious. – Tobu Jul 20 '13 at 13:40