I've tried using dd to back up my computer's hard drive, but I met with some rather confusing results. I've seen on multiple sources (e.g.: http://www.backuphowto.info/linux-backup-hard-disk-clone-dd, http://debianhelp.co.uk/ddcommand.htm) that they include something of the sort:
dd if=/dev/sda of=~/backup.img
1) Unless I'm very confused, this will try backing up the entire disk to a file on the disk, won't it?
I have attempted to use this method, but first compressed the output to save space. In order to prevent the compressed file from taking up a bunch of space by trying to copy all the free data, I used zerofree to write 0s to all my disk's unused space. My disk has a total capacity of ~320GB, and about 100GB of that is used, leaving ~220GB free.
When I tried using the following command:
dd if=/dev/sda | gzip -c > ~/image.img.gz
The backed up file reached a size of ~160GB before I quit the backup (with the intent of figuring out how to back up to an external disk, a task at which I've since succeeded).
2) Why would the backup take up so much space? Is it because dd sees the file to which it's been writing and then tries backing that up as well? Or is it possible that I didn't manage to use zerofree quite properly, and so there's just a bunch of random junk data being backed up despite my efforts to prevent that from happening?