# Replicating a 'bad' disk with dd. Will this work?

## meulie

Hi all!

I have a drive that is beginning to fail (160 GB. several partitions, both Windows & Linux). Now I have purchased a new 160 GB drive, and was wondering whether a liveCD and dd is the easy way to get all data over on the new drive...

dd doesn't care about partitions, right? It just copies the drive sector for sector?

But what will it do when it encounters a bad sector on the source drive? Will this sector also get marked as bad on the destination drive?

----------

## frostschutz

I would copy the partition table (probably using sfdisk) which hopefully avoids geometry problems, and then dd each partition with conv=noerror,sync options. Sectors that can't be read from the source drive will then be zeroed out on the destination drive.

----------

## meulie

Would there be any geometry problems, with 2 identical drives?

Is sfdisk also present on the current Gentoo LiveCD?

----------

## Maedhros

Moved from Unsupported Software to Kernel & Hardware.

----------

## LinuxLoader

The easiest way maybe will be to ghost both drives ... but after that u will need to rebuild the jurnal tree ( etx3 or reiserfs)

----------

## lbrtuk

dding will work fine. I've done it many times before.

----------

## meulie

 *lbrtuk wrote:*   

> dding will work fine. I've done it many times before.

 

So just dd is enough, as long as the drives have identical geometry?  Great!    :Cool: 

----------

## lbrtuk

 *meulie wrote:*   

> So just dd is enough, as long as the drives have identical geometry?

 

Most the time it will work fine even if they don't. Linux ignores most of the wierd BIOS interfaces these days and uses LBA. The worst that could really happen is you'd need to reinstall grub.

----------

## meulie

Well, I tried dd, but it was going soo vvveeerrryyy ssslllooowww (est. duration: 1 week!), that I cancelled it and went for a fresh install instead...    :Cool: 

----------

## syg00

IIRC dd defaults to a blocksize of 512 bytes (1 sector).

Easy to rectify, and you can enhance the performance no end.

IMHO any "imaging/ghosting" solution is a bad choice - even same sized drives from the same manufacturer often have different cylinder counts.

----------

## fangorn

Just build up new filesystems on the new harddisk, copy the necessary stuff like /etc, /home and the world file (windows partitions dont matter if they have some slight damages  :Twisted Evil:  ) and do a "emerge -e world" on the new disc. Takes much less than a week and you have the same system on a consistent filesystem.

----------

## meulie

 *fangorn wrote:*   

> Just build up new filesystems on the new harddisk, copy the necessary stuff like /etc, /home and the world file (windows partitions dont matter if they have some slight damages  ) 

 

Do you mean Windows is more fault-tolerant?    :Mr. Green: 

----------

## lbrtuk

 *syg00 wrote:*   

> IMHO any "imaging/ghosting" solution is a bad choice - even same sized drives from the same manufacturer often have different cylinder counts.

 

Shouldn't matter nowadays. I'm not aware of any system in linux (or BSD for that matter) that still addresses by CHS.

----------

## syg00

CHS vs LBA has nothing to do with it - just the amount of data.

 Here's a recent thread I was involved in on LQ - supposedly same drives, target turned out to be smaller.

Damn !!!.

----------

## lbrtuk

Oh yes, I see. I suppose I wouldn't try and clone two 'identically' sized disks in the first place. I'd always leave a margin for error.

The solution is probably to always leave a ~50MB gap at the end of your partitioning, so you can be more sure that you can swap in an 'identically' sized drive in case of emergencies.

----------

## fangorn

 *meulie wrote:*   

>  *fangorn wrote:*   Just build up new filesystems on the new harddisk, copy the necessary stuff like /etc, /home and the world file (windows partitions dont matter if they have some slight damages  )  
> 
> Do you mean Windows is more fault-tolerant?   

 

I do mean, if there is an error in the Windows filesystem, does it matter if the windows partition is only there for the virusses that write to first partition in table (Yeah, first 1 MB of first HDD got wiped once  :Wink:  )

For changing the OS you would have to BOOT!!! Who wants to do something stupid like that???  :Twisted Evil: 

----------

## Voorhees51

I use dd to copy hard disks all the time. I've got a nice script on a live CD I made that allows me to dd a drive, gzip it, then upload it to an FTP server.

It also allows me to download it back from the FTP server on to a drive and I haven't had a problem with it yet.

It's nice so when I do an install I can just run the script and it copies it to the server, and have a copy of it for when I need it or something goes wrong.  Also nice so I can just pull down a server image, or an image with X installed.

----------

## Rainmaker

how about this tool?

 *Quote:*   

> Medusa% ddrescue --help
> 
> GNU ddrescue - Data recovery tool.
> 
> Copies data from one file or block device to another,
> ...

 

It skips the possible bad blocks you have on your original drive.

It will be just as slow though

----------

## opopanax

I wouldn't say windows is fault-tolerant--it's more fault ignorant.  Windows will merrily copy away your bad files (if it doesn't crash the kernel), bad sectors and all, and not repair them, or tell you they're bad.  Bad files, bad bad!

----------

## Corona688

 *Rainmaker wrote:*   

> It will be just as slow though

  For copying a dying hard drive, you want sector by sector.  Better you get scattered sectors full of zeros around your duplicate, than scattered blocks of 256KB full of zeroes around  :Surprised:   dd_rescue is smart, and copies large blocks when the going is smooth, smaller blocks when it finds errors.  No special options are needed to make dd_rescue do what you want.

plain dd can also what you want, but be SURE to use the 'conv=noerror,sync'  option!  Otherwise, when it skips a bad sector in the input, it will produce NO output.  It took a few tries to figure this out.  Much, much weirdness can ensue when you misalign an entire filesystem by one sector somewhere in the middle.

----------

## Corona688

 *sketelsen wrote:*   

> I wouldn't say windows is fault-tolerant--it's more fault ignorant.

  amen to that.  I only really learned to program once I started using linux and realized everything I wrote crashed instantly.  It's embarassing to discover just how bad your programs are...  I was deleting the video surface 60 times per second and windows didn't even blink until much later, dying in irrelevant places with heap errors;  on linux it would crash instantly in the place where the error happened.

----------

