4

I have an lvm ext3 partition that is larger than the drive I would like to clone it onto, but is nowhere close to full, so all of the data, itself, would fit.

What would be the best way to clone this drive to the smaller one?

I would prefer to not have to resize the partition first, if possible.

5 Answers 5

4

LVM has built-in support for removing disks from volume groups!. No need for weird uses of copy commands or shrinking.

It is unclear if you mean by "partition" a logical volume. Also, when you say that you wish to use the smaller disk do you mean to get rid of the larger one?

Assuming that you want to stop using the larger disk/partition and remove it from the volume group you would have to:

  • add (pvcreate) the smaller disk/partition to the volume group
  • move (pvmove) the physical extents away from larger disk/partition. See this
  • remove (pvremove) the larger disk/partition from the volume group and do what you will with it.

Oh, and get a good backup first.

1
  • 1
    If the space is indeed enough on the smaller disk, the native LVM tools are definitely the way to go! Jun 23, 2009 at 10:09
2

An easy way to do this is to plug the new drive into your computer, configure LVM and otherwise partition this drive the way you want, make the file systems, and then use rsync or just cp -a to copy the files over. While not a high tech way of going about it, this will suffice for most people's needs.

1
  • Since LVM only deals in block devices, making a file-by-file copy is the only way to go if you do not want to resize the filesystem. May 4, 2009 at 20:55
1

Use LVM Mirror copy. This will copy the data live to the new location (including any updates), for as long as the mirror runs. See 4.4.1.3. Creating Mirrored Volumes at CentOS. Once you have the data cloned, you can "break the mirror", and specify that you want LVM to look at the "new" drive vs. the "old" drive when that happens.

EDIT: As Brent Nesbitt pointed out, you'll want to shrink your volume first. Gparted will do the job for you, provided that the filesystem supports shrinking. EXT3 will shrink.

2nd EDIT: Here is a similar question.

0

I have not used LVM, but the process would be to shrink the filesystem first, to a size that will fit on the new drive, before copying. This can be done using gparted (also known as Partition Manager)

0
0

If you're not willing to first shrink the LVM logical volume, you're looking at copying the data with "cp -a", "cd /oldstorage ; find . -depth -print0 | cpio -pdmu0 /newstorage", "rsync -a /oldstorage/ /newstorage/", or the like.

For a logical volume that is not nearly full, it is more efficient than to do this than to copy an entire volume that includes unused space.

1
  • I prefer to mkfifo /tmp/tarpipe and then use a pair of tar processes, one archiving into it from the source fs and one extracting on the destination.
    – XTL
    Mar 15, 2011 at 9:23

You must log in to answer this question.

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