Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to get a copy of an HDD that is a real 1:1, I mean not just the filesystem but also the geometry and the partition table and everything in between.

if I'll just use

dd if=/dev/sdb of=/tmp/file

this will generate what I'm looking for ?

share|improve this question
2  
Only if the disk is sane. It will also be inefficient because dd reads only 512 bytes at a time. Add conv=noerror,sync to copy disks with errors (or better use ddrescue) and use bigger block size otherwise to improve performance (or better, use ddrescue) –  Stéphane Chazelas Jun 15 at 19:57
add comment

3 Answers 3

up vote 6 down vote accepted

Yes, this should be fine. Be sure to unmount your disk first and make sure there is enough space in the target directory. /tmp is a tmpfs in memory and not on disk on some systems, look at the output of mount to check.

On a root shell you can also simply do:

cat /dev/sdb >/tmp/file
share|improve this answer
add comment

Alternatively, just copy it:

cp /dev/sdb /tmp/sdb.img

Please note Stephane's comment below for a potential benefit of using cp.

share|improve this answer
4  
cp --sparse=always with GNU cp could help you save space. –  Stéphane Chazelas Jun 15 at 19:59
    
Will this copy boot loaders and partition tables? –  Sparhawk Jun 16 at 5:02
1  
@Sparhawk - cp is at least simpler. You can likely achieve much the same performance and results using dd- and with GNU dd even something akin to --sparse=always - but it will take some tweaking. cp is pretweaked. And yes, you should be able to simply cp the image back over the /dev/ice but any such action will, of course, be completely destructive to whatever was on the /dev/ice before you did. –  mikeserv Jun 16 at 5:18
3  
@Sparhawk, a good cp implementation will automatically optimise the block size, so will be faster than dd. Don't use --sparse=always when you copy to a disk though, only when copying to a file. –  Graeme Jun 16 at 8:17
1  
@StéphaneChazelas For me, cp --sparse=always created an identical file to dd. I wonder if it works for volumes, but not whole devices? –  Sparhawk Jul 13 at 2:33
show 2 more comments

There is an informative article on the Arch distro wiki here

share|improve this answer
add comment

Your Answer

 
discard

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.