Web lists-archives.com

Re: Some help with dd backing up into an iso




On 03/06/2017 04:11 PM, GiaThnYgeia wrote:
I am not very confident I am doing this right and it seems wrong,  I
can't locate any documentation that results into proper options.
I tried backing up an 8gb USB that has 2 partitions in it, one had 1.7gb
of data on it.
I used dd if=/dev/sdb of=usbfilename.iso
The resulting image was the full size of the disk.
To test the validity I restored reversing the order of the filenames
if/of  but that took for ever and it was a hog on resources.  After a
while I just gave up and killed the process.  I looked at the disk and
it seemed complete with all files in tact, so maybe I killed it
somewhere in the verification process.
So I used a program called etcher which I have used with 100% success in
the past and was surprisingly fast in burning images.
It took for ever as well, eventually it run a verification routine and
it was done.
Is there someway one can avoid creating such a large iso for no reason,
when the filesize is a fraction of the whole disk.  One way I thought of
was to shrink the partitions to just about 99% full, and leave the blank
part of the disk as not allocated.  Would that help?
Is there some fancy command line that does just that?

Copying a raw device to a file, or vice-versa, I call "imaging".


ISO implies binary data structures ("format") on optical media so as to create a file system containing files and directories.


AFAIK USB flash drives use the same formats as hard disk drives and solid-state drives ("master boot record" (MBR) partition table, partition(s), and file system(s) within those partition(s)).


ISO and HDD/SSD formats are fundamentally different. Taking an image of a USB flash drive and naming the output file with an *.iso extension will not translate the format to ISO. Achieving that result requires tools other than 'dd'.


As for reducing the size of image files, the standard trick is to zero out the unused blocks first, and then compress the binary data stream while you take the image:

    # dd if=/dev/sda | gzip > myimage.img


For Linux and ext2, ext3, and ext4 file systems, the tool for zeroing unused blocks is zerofree(8):

https://manpages.debian.org/jessie/zerofree/zerofree.8.en.html


If you have an SSD, fstrim(8) will discard all unused blocks, regardless of file system. They should then read as zeros:

https://manpages.debian.org/jessie/util-linux/fstrim.8.en.html


But, most USB flash drives come factory formatted with FAT32. The 'sdelete' Windows utility can be used to zero unused blocks for both NTFS and FAT file systems:

https://technet.microsoft.com/en-us/sysinternals/sdelete.aspx


David