Decrease LVM size & migrating to normal partition

The main goal of these described steps is to virtualize an asterisk server – from the blade server into the VMWare virtual machine.


Asterisk was set up few years ago on two partitions – /boot (100mb) and LVM (500gb – 495gb for root and 5gb swap). But actually used space on the hard drive was less than 6-8 gb.
As backups are done using VMWare tools, I’ve decided to away from LVM type 8e, decrease it to 20gb and copy to a normal partition 83.
That’s why I’ve skip the step of making backups.
So I’ve made sector-by-sector copy of the hard drive using Acronis True Image into one *.tib file. And then have restored the archive into the virtual machine vmdk-HDD. There are one more advantage of going away from LVM – True Image extra steps to restore LVM volumes to prepared LVMs

The next step – boot VM from system-rescue-cd(.org) and

Missing e2fsck check wont allow you to resize the volumes.
vgdisplay and lvdisplay commands may provide you any detailed information about the existing LVM volumes.
Decreasing the volume to 20gb:

(the option “-r” let us omit using resize2fs – we decreasing file system size simultaneously with the volume).
Now, according to the pvmove man-page we have the possibility to move extents around on the same device:

In case of message “No extents available for allocation” (overlapping regions are forbidden) we could move the volume in 2 steps:

Start and the end can be found via command

Further we shrinking the physical volume to 20gb:

Run fdisk /dev/sda, and at its prompt, run p to look at your existing partitions. Note the starting sector number of your sda2 partition. Then delete the sda2 partition — this doesn’t touch the actual data, just removes the record of where it starts and ends — and create a new sda2 with the same starting sector and a size of 20.1G. The partition’s type code should be 8e, “Linux LVM”.
Change the grub.conf content to point / (root) to a new /dev/sda2:

I’ve also commented the volume group line in /etc/mtab.
Now boot from the Centos rescue CD and use F5 option (we’ve downloaded the same version which was installed).
Do chroot into /mnt/sysimage and type the next:

Finally, it’s time to creating new sda3 partition (swap), point to it in fstab file, reboot and begin to reconfigure network settings.