Shortly I will be deploying a slew of Linux hosts that will contain IUP's moodle cluster - (very, very poor choice by-the-way). Since this cluster will contain more Linux hosts than I want to sit and change disks for during an install, I decided to leverage VMware's template capabilities to streamline the process.
I started by creating a smallish (not a kitchen sink install) install of RHEL5. This was pretty simple specs: [15G disk, 1G mem, eth0]. I partitioned the 15G base disk as follows: [512m /boot 1g swap remainder /]. I placed the Root vol on a Linux lvm for expansion reason (which is the really cool part).
Alright now to the cool stuff (the previous was just a standard RH build). I mentioned before that / was on a lvm vg. I did this to easily expand the volume if needed and to conserve space on the template. Now I can create a vm of any size Linux disk with the following steps:
Create a vm from your template. Obviously you need a vmfs place for your vm. Make this as big as you want the machine to be disk wise if your using a particular vmfs volume for your vm.
Fire up the vm. Your vm will see only the 15g disk - cool. In this first step you will need to use
fdisk or parted to rearange the partitions on the disk. Make sure
you write stuff down. It is safe to modify the partition table as long as you keep the same start sectors on the
/boot and / partitions. I usually move swap to the end of the disk (depending on where it is), and then expand /
to the remainder using the sector count. This is the only step where you are required to reboot after words.
Ok now we are back up with our larger partitions. We need to tell some software components of the lvm stack that
the underlying disk has gotten bigger. We use pvscan to view the physical volume info and
pvresize /dev/your-device-partition to resize the PV. You can run pvscan again to see that
you just increased the physical volume. Sweet!
Alright now we need to increase the size on our logical volume. This gets a bit more interesting but not too much
if you keep it simple. Here we go. We should view things first so we run lvscan, this shows us what
our current LV layout is. Now we will increase this to engulf our new PV size so we run lvresize --extents 100%
VG /dev/vg.01/your-vol-here. Lets recap what this command just did. The lvresize grew the LV according to how many 'extents' there were available in the underlying PV, we wanted 100%. Now were getting somewhere with growing the size here.. if you look at lvscan again you will see a bigger size.
Great we are on the last step here.. All that's left is to grow the filesystem. In the Linux world this has always
been fairly simple. We run resizie2fs to make this happen. Here's how resize2fs /dev/mapper/your-volume. Once this is done run a df -h you will see your fancy new larger disk.
Posted by Kevin Foote in work on March 06, 2009

