cp /dev/hda3 /dev/hdb3

Doubletwist doubletwist at fearthepenguin.net
Wed Oct 13 16:56:39 UTC 2004


smurspm1 at xs4all.nl wrote:
> I have a HD that was giving error messages and in general not
> bootable/workable.
> 
> So I wanted to make a backup of the documents on that hard drive. I
> entered this command:cp  /dev/hda3 /dev/hdb3. So far so good.
> 
> The cp command also asked this:cp: overwrite `/dev/hdb3'? I replied yes.
> 
> After about a hour I checked the progress. For some reason the command
> that I entered copied the destination (hdb3) to the source hda3. Now you
> understand that I'm not happy and I see no way of restoring the partition.
> 
> But I want to know what I did wrong?
> 


I think what you want is:
dd if=/dev/hda3 of=/dev/hdb3

Assuming hdb3 is the same size [or larger] than hda3, that will make 
hdb3 exactly the same as hda3.

After your cp gaffe, you might have to fdisk /dev/hdb again, I'm not 
exactly sure what effect cp'ing something directly to the device has as 
I've never tried that. :) But I'm fairly sure any data that was on hdb3 
is now gone.

Probably a better way to copy the data from hda3 is to recreate your 
hdb3 partition and format it, and mount both hda3 and hdb3:

ie:
mount /dev/hda3 /mnt/original
mount /dev/hdb3 /mnt/new
cd /mnt/original
tar cpf - . | (cd /mnt/new; tar xpvf -)

That will make a copy of the data instead of doing a bit-by-bit image of 
the partition. It really depends on what you're trying to accomplish.

DT




More information about the ubuntu-users mailing list