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
1 2 3 4 |
/dev/sda1 - 100mb /boot /dev/sda2 — 500gb LVM 8e: /dev/VolGroup00/LogVol00 — 495gb root / /dev/VolGroup00/LogVol01 — 5gb swap |
The next step – boot VM from system-rescue-cd(.org) and
1 |
e2fsck -fa /dev/VolGroup00/LogVol00 |
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:
1 |
lvresize -r -L -475G /dev/VolGroup00/LogVol00 |
(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:
1 |
pvmove --alloc anywhere /dev/sda2 |
In case of message “No extents available for allocation” (overlapping regions are forbidden) we could move the volume in 2 steps:
1 |
pvmove --alloc anywhere /dev/sda2:1000-1999 |
Start and the end can be found via command
1 |
pvs -v --segments /dev/sda2 |
Further we shrinking the physical volume to 20gb:
1 |
pvresize -v --setphysicalvolumesize 20G /dev/sda2 |
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:
1 |
mkinitrd -v -f --omit-lvm-modules --without-dmraid initrd2.6.18-348.1.1.img 2.6.18-348.1.1 |
Finally, it’s time to creating new sda3 partition (swap), point to it in fstab file, reboot and begin to reconfigure network settings.