How to move from one drive to another that's a different size?

21

12

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

Posted 2009-07-23T14:30:06.063

Reputation: 8 599

1http://superuser.com/questions/32164/easiest-way-to-clone-boot-partition-onto-new-hard-drive was asked for windows drives/partitions – warren – 2009-09-10T06:33:28.197

Answers

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.

craigmoliver

Posted 2009-07-23T14:30:06.063

Reputation: 546

you say 'clone the drive' though he asked clone the partition. Also he said different file system. – barlop – 2014-06-24T07:57:32.987

1It's just two freewares and it's quite painless. ISOs boot no problem. – craigmoliver – 2009-07-24T04:20:27.707

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. – Thomas Watnedal – 2009-10-05T13:20:02.907

2I like the free part here, though nothing beats GOOD working software that does everything (instead of 3 freewares together) – Ivo Flipse – 2009-07-23T14:44:10.987

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

Posted 2009-07-23T14:30:06.063

Reputation: 8 599

Beware that when combining dd and tar as proposed in the answer, the root filesystem will likely change its UUID which can make the boot fail under some circumstances. I usually prefer to copy (through tar), chroot to the copy target (mount -o bind the /dev directory first!) and then issue grub-install or even dpkg-reconfigure grub-pc or whatever the Linux distribution prefers the GRUB reinstallation procedure to be called. When using cpio be aware of its size limits (tar can really be recommended here?) – linux-fan – 2019-10-31T20:45:16.077

1

What version of tar has an --xattrs option? Not mine. I suggest using rsync or plain cp instead: http://serverfault.com/questions/306538/how-to-move-linux-to-another-partition/306699#306699

– Teddy – 2011-08-31T06:43:33.867

2Speaking of meta-data, the --xattrs option (store ACLs and SELinux info) should be used too. – Cristian Ciupitu – 2009-09-08T11:19:19.880

The 2 tars connected with a pipe could be replaced with cpio --pass-through. – Cristian Ciupitu – 2009-09-08T11:20:58.270

thanks, @Christian, for the --xattrs call – warren – 2009-09-08T11:52:02.187

2I 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 – 2009-07-23T15:01:49.647

1you're right on the p - I've added that :) – warren – 2009-07-23T15:37:08.160

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

Posted 2009-07-23T14:30:06.063

Reputation: 3 153

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 – 2009-07-23T15:38:21.683

Something to consider next time you install :-) – pgs – 2009-07-23T15:50:03.750

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

Posted 2009-07-23T14:30:06.063

Reputation: 4 827

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 – 2009-09-08T15:59:18.340

1:) – Johan – 2009-09-08T19:17:10.907

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.

Shoan

Posted 2009-07-23T14:30:06.063

Reputation: 290

there's one I'd not thoguht of :) – warren – 2009-11-05T13:17:46.890

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

Posted 2009-07-23T14:30:06.063

Reputation: 9 888

4

Acronis True Image is another alternative (http://www.acronis.com/homecomputing/products/trueimage/)

– fretje – 2009-07-23T14:35:39.753

6Unfortuately this method requires purchasing Norton Ghost – craigmoliver – 2009-07-23T14:36:40.220

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

Posted 2009-07-23T14:30:06.063

Reputation: 2 646

1

I also found Disk Copy, which doesn't appear to be on the Wikipedia list, but have never used it.

warren

Posted 2009-07-23T14:30:06.063

Reputation: 8 599

Unfortunately, it is windows-only, and this question was tagged linux. – programmer5000 – 2017-03-13T14:55:52.527

1Disk Copy is a good one. – craigmoliver – 2009-08-09T01:00:52.110