Ubuntu – GZip of drive image created by using `dd` command

catcloneddgzipzip

I created yesterday a drive image using GZip.

I opened the 51.3 GiB file named ssd.img.gz to see one icon thats a package of 3.9 GiB, yes, thats THree point Nine Gigabytes in size and has the name of the image as ssd.img

That does not seem right to me, has the image creation worked or not?

Yes the drives have data and an operating system on it.

Should I have used cat instead? only I did and it kept on saying that it had nothing to do.

Would using the | zip instead be a better option?

** EDIT **

The command used was:

mark@zotac:~$ sudo -l
Enter password:<entered password to get in to root>
root@zotac:~# dd if=/dev/sda | gzip -c > "/media/mark/Seagate External Drive/ssd.img.gz

the terminal spent the best part of 10 Hours at building the image, something in itself that I also found suspect, why so log when copying the files to a folder that I wanted, some 40GiB took 45 minutes…

The source drive /dev/sda had no mounted partitions.

** EDIT **

Just to clarify, I am trying to make an image of the drive to back up later if things go wrong with a repair, the drive itself needs to be a file on a drive as the target drive partition is using almost all of the drive, the partitions can't be resized on it without formatting it and I am not about to lose 1.4TB of data.

So the dd if=/dev/sda of=/<target> isn't what I need, what I do need is an image of the drive that I can restore the image from to the drive should the repair go wrong.

So what command do I use, dd or cat? Why does | zip keep telling me it has nothing to do when used with cat but no error or warning with dd

Best Answer

If the disk is almost full, there is no sense in compressing the image; it will take ages with no practical effect. And restoring will be much slower too.

dd copies physical, byte-by-byte partitions or disks. It works by reading N bytes from the input and writing them to the output, and then repeating. N is by default 512 bytes.

To copy a disk/partition physically, use

dd bs=10M if=/dev/sda of=/path/to/dest/image.img 

this will read blocks of 10Mbytes at a time. If you have plenty of RAM you can up that number too. The size of the file will be exactly the same as the size of the disk/partition used (but it can occupy less disk sometime --- dd can create sparse files).

You can check the progress in another terminal with

ls -lh /path/to/dest/image.img 

which will give you the size of the image file (more or less --- it will be in chunks, really).

Triple check (with mount) that no partition of the disk to copy is mounted or used anywhere, or the created image will be invalid (and worst things can happen, too). Be careful about swap areas, too.

You can mount the image to check if it's ok with a loopback filesystem and a bit of tricks.

Anyway, there are also tools that helps the tasks: How to make a disk image and restore from it later?

If your system is not recent (the system from where you are booting, I mean), be warned of this bug --- fixed from 14.04 onward, but still there for older kernels.