copying an lvm partition to a smaller disk, and renaming volume groups.

Posted by dlamblin on Server Fault See other posts from Server Fault or by dlamblin
Published on 2009-08-24T17:31:18Z Indexed on 2010/12/30 10:56 UTC
Read the original article Hit count: 424

Filed under:
|

I was trying to shrink a vmdk (VMWare disk image) file to be as small as possible, and found two recommendations. The first is to cat /dev/zero into the fs then delete it, and run VMWare tools' shrink. This works okay. The second is to copy everything into a new vmdk. I went the second route. I did not use dd because I actaully want to use as few blocks as possible, instead of having a block-by-clok copy. Any unlinked files will still have blocks that aren't zeroed out. Secondly the centos image was mostly lvm, except for the boot partition, and my target was going to be 4gb instead of 8gb.

I did use dd for the first 40mb to get the boot blocks and partition copied. I then used parted to create an identical primary boot, and smaller primary lvm. Then I used pvcreate on that device sdb2, vgcreate, and lvcreate to create a root and swap. I used mkfs.ext3fs on the root partition and then rsync -av / /2root excluding /proc /sys /2root /dev. So far everything went fine.

My problem is that:

  1. The result is 2.7 GB while the source was 2.1 GB. This is weird to me.
  2. The second vgroup is called VolGroup01, while the original was called VolGroup00.

How can I rename the VolGroup01 to VolGroup00 and swap it out after all this?

© Server Fault or respective owner

Related posts about lvm

Related posts about vmdk