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.

1

7 Answers 7

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.

4
  • 2
    I like the free part here, though nothing beats GOOD working software that does everything (instead of 3 freewares together)
    – Ivo Flipse
    Jul 23, 2009 at 14:44
  • 1
    It's just two freewares and it's quite painless. ISOs boot no problem. Jul 24, 2009 at 4:20
  • I can confirm that this works. I successfully moved my secondary drive with Windows 7 from a 160GB drive to a 1TB drive. Cloned it to my linux disk with Clonezilla. Restored it on the new disk and resized it with the Windows 7 Disk Management tool. This was from a NTFS to a NTFS though. Oct 5, 2009 at 13:20
  • you say 'clone the drive' though he asked clone the partition. Also he said different file system.
    – barlop
    Jun 24, 2014 at 7:57
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).

6
  • 2
    I like this solution because it's so simple, but I think you would need some extra options like p (preserve permissions) to get all of the meta-data.
    – Jay Conrod
    Jul 23, 2009 at 15:01
  • 1
    you're right on the p - I've added that :)
    – warren
    Jul 23, 2009 at 15:37
  • 2
    Speaking of meta-data, the --xattrs option (store ACLs and SELinux info) should be used too. Sep 8, 2009 at 11:19
  • The 2 tars connected with a pipe could be replaced with cpio --pass-through. Sep 8, 2009 at 11:20
  • 1
    What version of tar has an --xattrs option? Not mine. I suggest using rsync or plain cp instead: serverfault.com/questions/306538/…
    – Teddy
    Aug 31, 2011 at 6:43
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.

2
  • That is a great idea - except if you're not running LVM, it's a bit of a pain :) Thanks for the suggestion, though!
    – warren
    Jul 23, 2009 at 15:38
  • 1
    Something to consider next time you install :-)
    – pgs
    Jul 23, 2009 at 15:50
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.

2
  • good idea - though for those among us (<whistle mode="innocent"/>) who don't have a "backup" solution, this might also be a Good Time to come up with one :)
    – warren
    Sep 8, 2009 at 15:59
  • 1
    :)
    – Johan
    Sep 8, 2009 at 19:17
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.

1
  • there's one I'd not thoguht of :)
    – warren
    Nov 5, 2009 at 13:17
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.

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]

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .