# cloning  disk

## shaumux

I got a new disk of the same size as the current one(500G).

Now i want to clone the current setup to the new disk.

I suppose i can do it with dd command, but is that suitable for this size?

If i do it with the dd command do i need to first create the partition or initialize the disc?

Is it safe to use kill -USR1 dd_pid to view the progress?

What bs should i use for maximum speed , considering i have 4G ram and 512M swap?

Thanks

----------

## Kobboi

You can do a speed test with the "count" option of dd and you'll probably notice that the blocksize won't have a huge effect. I recently created a 40G disk image with dd, with a block size of say, 1M or something. For the progress, I just looked at the output file's size.

----------

## shaumux

I am cloning a disk to another disk not to an image.

----------

## d2_racing

You should try this :

```

# time dd if=/dev/sda of=/dev/sdb bs=4096 conv=noerrors

```

----------

## Hu

 *shaumux wrote:*   

> I suppose i can do it with dd command, but is that suitable for this size?
> 
> If i do it with the dd command do i need to first create the partition or initialize the disc?
> 
> 

 

dd can be used for this purpose.  If you invoke it as d2_racing described, then it will copy the partition table and other metadata automatically, so no preparation is necessary.  However, using dd will copy all the contents of the source disk, even areas that do not contain meaningful data.  If you have a significant amount of free space, you may find it more efficient to mount the filesystem on the source disk, create a filesystem on the destination disk, and copy data at the filesystem level.  A pair of tar processes can be used for this.  Running tar -C /mnt/src -c -f - --one-file-system . | tar -C /mnt/dst -x -f - should work.  This is from memory, so check the syntax to be sure.

----------

## Mad Merlin

 *d2_racing wrote:*   

> You should try this :
> 
> ```
> 
> # time dd if=/dev/sda of=/dev/sdb bs=4096 conv=noerrors
> ...

 

...and then go to sleep. It should be done by the time you wake up.

----------

## Shadow Skill

What should I do if I suspect that the source disk has bad sectors if I want to clone with dd or ddrescue?  Is it safe to run either of these commands while the source disk is mounted?  In my case the destination disk is larger than the source disk.  The source disk is 250gb and the destination disk is 1.5tb.

Edit: Yes I am aware that the thread is a bit old.  :Smile: 

----------

## your_WooDness

Hi Shadow,

I made good experiences with clonezilla --> http://clonezilla.org/. It can create images of disks and also clone disks. But if you definitely know that you have bad sectors on the source disk, I think it would be better to create a new partition table and filesystem on the new disk and the copy all the stuff over with "cp -a" or "rsync -a". Otherwise, dd will copy over bad sectors and you will have bad files on the new disk.

According to your question of the mounted source disk during dd, well, I would rather use a live CD to do that. I have no real reason for that. Just a feeling cause you copy block and no filesystem related things... If you use "cp -a" or "rsync -a" you can leave out /sys, /proc, /dev and just create these directories on the new filesystem.[/url]

WooD

----------

## r3tep

If you think, your hdd could have bad sectors, check its smart-statistics sys-apps/smartmontools but it will only show a tendency.

You should give sys-fs/ddrescue a try. You can specify an big block-size which will be used to copy files very fast. If an error occurs, ddrescue falls back to a smaller block-size (which can be defined) and tries to minimize the errors. Some log-files can be defined for further recovery.

But if you're sure, that your hdd doesn't contain bad sectors, you should imho go the way provided by your file-system. Hu described a good way.

----------

## d2_racing

In fact, with the tar command, you will be more free to copy the new data elsewhere and also you will not have the limitation of the partition size.

----------

## Shadow Skill

I use Windows' bootloader to get into Grub so how might I clone the MBR and Windows partition so that they function as before while making a new partition for Gentoo?  My main thing is that I do not feel like reinstalling Windows because that means I would have to reinstall steam which means re-downloading a bunch of crap that will probably end up taking longer than it would for me to do a Gentoo install from scratch; well and the fact that I can't even find my windows Vista DVD.  I should have mentioned earlier that I dual boot.

My Fdisk output:

 *Quote:*   

> Disk /dev/sda: 250.1 GB, 250059350016 bytes
> 
> 255 heads, 63 sectors/track, 30401 cylinders
> 
> Units = cylinders of 16065 * 512 = 8225280 bytes
> ...

 

My Smart test output : http://pastie.org/762804

----------

## DirtyHairy

If you suspect your source of having bad blocks, using dd is _definitely_ a bad idea (imho) as it can potentially leave you with a corrupt file system. Better create a file system and copy all files. Apart from using tar, rsync is also an option (as a bonus, rsync -nxav will inform you about any files it had problems reading).

----------

