Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Maybe this will sound like dumb question but the way i'm trying to do it doesn't work.

I'm on livecd, drive is unmounted, etc.

When i do backup this way

sudo dd if=/dev/sda2 of=/media/disk/sda2-backup-10august09.ext3 bs=64k

...normally it would work but i don't have enough space on external hd i'm copying to (it ALMOST fits into it). So I wanted to compress this way

 sudo dd if=/dev/sda2 | gzip > /media/disk/sda2-backup-10august09.gz

...but i got permissions denied. I don't understand.

share|improve this question
Don't. This is not a backup. Check the 'dump' and 'restore' commands. –  Juliano Aug 10 '09 at 16:07
Or tar or cpio.... –  chris Aug 10 '09 at 17:06
Juliano, what do you mean by 'this is not backup'? –  Phil Aug 10 '09 at 21:26
This is not a backup because backups are serious, well-structured and uses proper tools intended to create backups. You are just making a copy of the raw data of a partition. To restore this data, you will need another partition with the same geometry, which is not guaranteed. Also, if you damage a single block of your archive (superblock, inode tables, root directory, etc), you risk losing all your data. With a proper backup this wouldn't happen. –  Juliano Aug 11 '09 at 2:09
"To restore this data, you will need another partition with the same geometry, which is not guaranteed" Why would he need that, can't he mount the partition image on a loopback device? –  Kyle Brandt Aug 12 '09 at 13:54
show 1 more comment

3 Answers

up vote 14 down vote accepted

Do you have access to the sda2-backup...gz file? Sudo only works with the command after it, and doesn't apply to the redirection. If you want it to apply to the redirection, then run the shell as root so all the children process are root as well:

sudo bash -c "dd if=/dev/sda2 | gzip > /media/disk/sda2-backup-10august09.gz"

Alternatively, you could mount the disk with the uid / gid mount options (assuming ext3) so you have write permissions as whatever user you are. Or, use root to create a folder in /media/disk which you have permissions for.

Other Information that might help you:

  • The block size only really matters for speed for the most part. The default is 512 bytes which you want to keep for the MBR and floppy disks. Larger sizes to a point should speed up the operations, think of it as analogous to a buffer. Here is a link to someone who did some speed benchmarks with different block sizes. But you should do your own testing, as performance is influenced by many factors. Take also a look at the other answer by andreas
  • If you want to accomplish this over the network with ssh and netcat so space may not be as big of an issue, see this serverfault question.
  • Do you really need an image of the partition, there might be better backup strategies?
  • dd is a very dangerous command, use of instead 'of' 'if' and you end up overwriting what you are trying to backup!! Notice how the keys o and i are next to each other? So be very very very careful.
share|improve this answer
i'll try this. how do i also make it bs=64k? (and do i have to?) –  Phil Aug 10 '09 at 15:40
The bs=64k only makes the transfer go faster because dd will be reading blocks of 64k each instead of the default block size of (I don't remember). –  chris Aug 10 '09 at 16:44
What chris said, and if you want to include it put it after dd and before the pipe symbol ( | ) as it is an argument to dd. –  Kyle Brandt Aug 10 '09 at 16:49
add comment

In the first case, the dd is running as root.

In the second case, the dd is running as root but the gzip is running as you.

Change the permissions on /media/disk, give yourself a root shell, or run the gzip as root too.

share|improve this answer
add comment

In addition, you can replace gzip with bzip2 --best for much better compression

share|improve this answer
At a cost of lots of time. See changelog.complete.org/archives/… "How to think about compression" for more details. –  Bill Weiss Aug 10 '09 at 21:03
@BillWeiss: Thanks for your comment, very interesting read! –  andreas Oct 18 '13 at 9:06
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.