LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Some questions on using did command to image (https://www.linuxquestions.org/questions/linux-newbie-8/some-questions-on-using-did-command-to-image-4175520237/)

MBA Whore 09-26-2014 08:33 PM

Some questions on using did command to image
 
I know the dd command can make a bit-by-bit clone. I know it can also make an image. The image should avoid copying unused blocks therefore that is what I want to use.

So, here are my questions:

1) What command line syntax would I use to make the dd image and compress it at the same time?

2) What command line syntax would I use to uncompress and restore the dd image at the same time?

3) What limitations regarding files system type (ext, nfts, fat, etc) and what limitations regarding hard drive size (both source and destination) do I face with this approach?

This looks like it has potential but the command line is very scary. Any insight or resources would be appreciated.

Thank you.

Beryllos 09-27-2014 03:20 AM

dd is not the most appropriate tool for this task because it has no way of determining which blocks are unused. To do that, you would need something else that can analyze the file system and create a list of blocks to save. I don't know how to do that, but I would like to find out.

However, if you insist on using dd, one simple approach would begin by filling the unused space with zeroes. Example:
Code:

dd if=/dev/zero of=bigfile
rm bigfile

Then create the dd image, and finally compress it with gzip or any compressor you like. The zero-filled blocks will be highly compressible.

If you execute dd and gzip as two consecutive commands, the destination would have to be large enough to temporarily hold both the uncompressed image and the compressed image. If you pipe the output of dd into gzip, you eliminate the need for temporary storage of the uncompressed image. Example:
Code:

dd if=/dev/sda1 | gzip - > dd_image_sda1.gz    #  to make the dd image and compress it

gzip -cd dd_image_sda1.gz | dd of=/dev/sda1    # to uncompress and restore the dd image

Please note, I have not actually saved or restored a dd image in this way. I've only read the manual and worked out a plan. You will have to test and debug it yourself. Before trying it on an important hard drive, I would test it on a spare drive or a small flash drive and see how that works.

Quote:

3) What limitations regarding files system type (ext, nfts, fat, etc)
The method outlined above should work for any of those file systems, provided it is not encrypted or compressed.

ondoho 09-27-2014 07:57 AM

let's take 1 step back:

what are you trying to achieve with that?

jomen 09-27-2014 01:54 PM

To simply answer the questions:

There is no way to avoid copying unused blocks using dd.
It creates a bit-by-bit copy. That includes all blocks, of course.
All you can do is fill the empty space with zeroes, so that the compressed image will be small (the zeroes compress very well to almost nothing).
See the example by beryllos.

1.)
Code:

dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c  > /mnt/sdb1/sda.img.gz
2.)
Code:

gunzip -c /mnt/sdb1/sda.img.gz | dd of=/dev/sda
/dev/sda is your source, /dev/sdb1 is some drive you use to store the backup image to.

3.)
There are no limitations on filesystems at all - dd does a bit by bit copy and does not care at all about filesystems.

The target must be of equal or larger size than the original. A smaller target disk (where you want to restore to) is not possible with this.

I lifted the info from here and have indeed actually successfully used it multiple times:
https://wiki.archlinux.org/index.php/disk_cloning

MBA Whore 09-27-2014 10:19 PM

Interesting. I was hoping to make a backup (image) that would avoid unused blocks but it looks like I can't do so. I will just look for some other imaging solution. Thank you all.

ondoho 09-28-2014 08:31 AM

rsync?

jomen 09-28-2014 08:33 AM

See if fsarchiver or partimage (part of clonezilla) suit your purpose.

RockDoctor 10-06-2014 01:27 PM

FWIW, I've been using fsarchiver to make backup images, and have found it to work well enough.


All times are GMT -5. The time now is 08:52 PM.