21

I've run into this scenario a few time: I need to replace a drive because I need more space, it's having problems, moving to a new box, etc.

What's the best way to copy data from one partition size to another (presuming the target has enough space)?

What about if it's a different file system (such as ReiserFS to ext4)?

If it's just a new drive on an existing system, how do I ensure I don't need to reinstall to get everything working?

Update - many of the options are highly viable, and I've changed this question to community wiki because I don't think there's a "right" answer.

warren
  • 10,322

7 Answers7

10

Clone the drive using CloneZilla, then use gparted to resize it. Keep your old one in case if goes wrong :-)

By the way, this way is free.

5

The solution I've used in the past is tar. If the partitions are the exact same size and type, you can use dd.

Here's my answer to the quandary:

  1. boot using a live cd distro such as Slax

  2. verify the partitions you want are on the new drive

  3. make sure both the old and new drives are mounted, for example /tmp/driveold and /tmp/drivenew

  4. run from a terminal the following tar command:

    (tar cp --xattrs /tmp/driveold/path) | (tar x /tmp/drivenew/path)

  5. repeat for each partition you need to copy

This works for every partition I've ever tried it on (excluding /boot, for which I ensure the partitions are identical, and use dd).

warren
  • 10,322
2

This is one reason I like LVM. Just add the new disk to the volume group, pvmove the logical volumes from the old to new disk, remove the old disk from the volume group, and then from the system. If it's your boot disk you're replacing then you also need to update your boot loader.

pgs
  • 3,361
2

+1 to warren and to use tar.

However, I usually tries to restore from my backups instead. And moving from one disk to a new one seems like a good opportunity to see if your backup plan is working.

If you simulate a disk failure (pull the power from the old disk), start to recover to the new disk. And when you are done, you start up the old disk and diff them to see if you got all the files.

If they are identical you both have moved all your data, and you know that your backup plan is valid and working.

Johan
  • 5,515
2

Another option would be to boot from a liveCD and mount the old drive as read only. This is to prevent the livecd from changing it during the copy. Then rsync -avz /mnt/olddisk/ /mnt/newdisk (the trailing slash after olddisk is necessary). As the others have mentioned, if this is the boot disk that is being expanded you will need to rerun grub-install <new device> before it can be bootable.

alfplayer
  • 5,803
Shoan
  • 350
1

Create image from original partition and put this image to new HDD.

Norton Ghostâ„¢ 14.0 do that or other image software


Here is list of disk cloning software

Comparison of disk cloning software [wikipedia]

MicTech
  • 10,496
1

Most disk cloning utilities can do this. I like using g4u from a livecd. Ghost is nice, but I'd rather use a free one.

chills42
  • 2,712