Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

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.

share|improve this answer
1  
If the space is indeed enough on the smaller disk, the native LVM tools are definitely the way to go! –  Server Horror Jun 23 '09 at 10:09

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.

share|improve this answer
    
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. –  David Schmitt May 4 '09 at 20:55

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.

share|improve this answer
    
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 '11 at 9:23

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.

share|improve this answer

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.