Linux/dd

From Omnia
Revision as of 05:11, 9 October 2017 by Kenneth (talk | contribs) (→‎Pad File)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

dd recovery

conv=sync,noerror
dd if=/dev/sda of=/dev/sdb bs=1M conv=sync,noerror

"conv=sync tells dd to pad each block to the left with nulls, so that if, due to error, the full block cannot be read, the full length of the original data is preserved, even though not all of the data itself can be included in the image. that way you at least know how damaged the data is, which might provide you with forensic clues, and if you can't take an image at all due to bad blocks or whatever, you can't analyze any of the data. some is better than none. conv=sync,noerror is necessary to prevent dd from stopping on error and make a dump with same location for each blocks, than source. conv=sync is largely meaningless without noerror." [1]

References:

direct io

dd if=/dev/zero of=out.img bs=1M count=1000 oflag=direct

Pad File

Error: size of old.img is not a multiple of 512

Pad to multiple of 512

dd if=old.img of=new.img obs=512 conv=sync

Add specific amount of bytes:

dd if=/dev/zero bs=1 count=20 >> out.img

pad the output file with zeroes until the file size reaches 100 KB:

dd if=inputFile.bin ibs=1k count=100 of=paddedFile.bin conv=sync

Pad with 0xFF:

dd if=/dev/zero ibs=1k count=100 | tr "\000" "\377" >paddedFile.bin
hexdump -C paddedFile.bin
dd if=inputFile.bin of=paddedFile.bin conv=notrunc

References:

Append Data

dd if=/dev/shm/test bs=1G >>/data/sdb/test
dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append conv=notrunc 

Ref: unix - How to append data in a file by dd? - Super User - https://superuser.com/questions/850267/how-to-append-data-in-a-file-by-dd